@clabs/packages-publisher
Advanced tools
Comparing version 0.0.1-alpha.0 to 0.0.1-alpha.1
@@ -13,3 +13,3 @@ "use strict"; | ||
exports.argumentsBuilder = exports.command = exports.ARG_NAMES = void 0; | ||
var assertPath_1 = require("../../common/assertPath"); | ||
var assert_path_1 = require("../../common/arguments/assert-path"); | ||
var ARG_NAMES; | ||
@@ -20,3 +20,2 @@ (function (ARG_NAMES) { | ||
ARG_NAMES["otp"] = "otp"; | ||
ARG_NAMES["verbose"] = "verbose"; | ||
ARG_NAMES["skipBuild"] = "skipBuild"; | ||
@@ -30,2 +29,3 @@ ARG_NAMES["outputPath"] = "outputPath"; | ||
return yargs | ||
.version(false) | ||
.options((_a = {}, | ||
@@ -49,9 +49,2 @@ _a[ARG_NAMES.path] = { | ||
}, | ||
_a[ARG_NAMES.verbose] = { | ||
type: 'boolean', | ||
desc: 'Output information throughout the process.', | ||
"default": false, | ||
alias: 'v', | ||
demandOption: false | ||
}, | ||
_a[ARG_NAMES.otp] = { | ||
@@ -74,3 +67,3 @@ type: 'string', | ||
.check(function (argv) { | ||
(0, assertPath_1.assertPathArg)(argv); | ||
(0, assert_path_1.assertPathArg)(argv); | ||
return argv; | ||
@@ -77,0 +70,0 @@ }) |
@@ -46,5 +46,5 @@ "use strict"; | ||
var prompts_1 = __importDefault(require("prompts")); | ||
var getPackageJsons_1 = require("../../common/getPackageJsons"); | ||
var get_package_jsons_1 = require("../../common/get-package-jsons"); | ||
var logger_1 = require("../../common/logging/logger"); | ||
var errorUtils_1 = require("../../common/errorUtils"); | ||
var error_utils_1 = require("../../common/error-utils"); | ||
var build_1 = require("./steps/build"); | ||
@@ -192,7 +192,8 @@ var npmPublish_1 = require("./steps/npmPublish"); | ||
return __awaiter(this, void 0, void 0, function () { | ||
var path, initialOtp, dryRun, skipBuild, verbose, otp, enabled2FA, shouldLog, packages; | ||
var path, initialOtp, dryRun, skipBuild, otp, enabled2FA, packages; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
path = args.path, initialOtp = args.otp, dryRun = args.dryRun, skipBuild = args.skipBuild, verbose = args.verbose; | ||
path = args.path, initialOtp = args.otp, dryRun = args.dryRun, skipBuild = args.skipBuild; | ||
(0, logger_1.logIfDryRunMode)(dryRun); | ||
otp = (0, exports.OTPHandler)(initialOtp); | ||
@@ -205,11 +206,10 @@ return [4 /*yield*/, (0, npmPublish_1.checkValidUserHas2FA)()]; | ||
} | ||
shouldLog = verbose === true; | ||
packages = (0, getPackageJsons_1.getAllPackageJsons)(path); | ||
logger_1.logger.heading('Packages found:', shouldLog); | ||
logger_1.logger.log("- \"".concat(Object.keys(packages).join('"\n - "'), "\"\n"), shouldLog); | ||
packages = (0, get_package_jsons_1.getAllPackageJsons)(path); | ||
(0, logger_1.logPackagesFound)(packages); | ||
logger_1.logger.info('Versions above will be used for publishing'); | ||
if (!skipBuild) return [3 /*break*/, 2]; | ||
logger_1.logger.warn('Building was skipped', shouldLog); | ||
logger_1.logger.warn('Building was skipped'); | ||
return [3 /*break*/, 4]; | ||
case 2: | ||
logger_1.logger.heading('Building packages', shouldLog); | ||
logger_1.logger.heading('Building packages'); | ||
return [4 /*yield*/, buildPackages(packages, resultCollector)]; | ||
@@ -220,3 +220,3 @@ case 3: | ||
case 4: | ||
logger_1.logger.heading("Publishing packages".concat(dryRun ? ' (dry-run mode)' : ''), shouldLog); | ||
logger_1.logger.heading("Publishing packages".concat(dryRun ? ' (dry-run mode)' : '')); | ||
return [4 /*yield*/, publishPackages(packages, otp, dryRun, resultCollector)]; | ||
@@ -237,3 +237,3 @@ case 5: | ||
case 0: | ||
resultCollector = (0, resultCollector_1.resultBuilder)(args.verbose); | ||
resultCollector = (0, resultCollector_1.resultBuilder)(); | ||
_a.label = 1; | ||
@@ -256,3 +256,3 @@ case 1: | ||
if (error) { | ||
(0, errorUtils_1.exitWithError)(error); | ||
(0, error_utils_1.exitWithError)(error); | ||
} | ||
@@ -259,0 +259,0 @@ return [2 /*return*/]; |
@@ -7,4 +7,3 @@ "use strict"; | ||
var arguments_1 = require("./arguments"); | ||
var resultBuilder = function (verbose) { | ||
if (verbose === void 0) { verbose = false; } | ||
var resultBuilder = function () { | ||
var result = {}; | ||
@@ -36,10 +35,8 @@ return { | ||
} | ||
if (verbose) { | ||
if (buildResult.status === 'success') { | ||
logger_1.logger.success("\"".concat(packageName, "\" built")); | ||
} | ||
else { | ||
logger_1.logger.error("\"".concat(packageName, "\" build failed")); | ||
} | ||
if (buildResult.status === 'success') { | ||
logger_1.logger.success("\"".concat(packageName, "\" built")); | ||
} | ||
else { | ||
logger_1.logger.error("\"".concat(packageName, "\" build failed")); | ||
} | ||
}, | ||
@@ -56,22 +53,20 @@ addPublishResult: function (packageName, publishResult) { | ||
} | ||
if (verbose) { | ||
var status_1 = publishResult.status, version = publishResult.version, context = publishResult.context, error = publishResult.error; | ||
var versionAndTag = version | ||
? "version \"".concat((0, kleur_1.bold)(version.number), "\" (tag: ").concat(version.tag, ")") | ||
: ''; | ||
var defaultSuccessText = "\"".concat(packageName, "\" published with ").concat(versionAndTag); | ||
var dryRunSuccess = "\"".concat(packageName, "\" would be successfully published with ").concat(versionAndTag); | ||
switch (status_1) { | ||
case 'success': | ||
logger_1.logger.success(context === arguments_1.ARG_NAMES.dryRun ? dryRunSuccess : defaultSuccessText); | ||
break; | ||
case 'skipped': | ||
logger_1.logger.warn("\"".concat(packageName, "\" skipped - ").concat(context)); | ||
break; | ||
case 'error': | ||
logger_1.logger.error("\"".concat(packageName, "\" publishing failed\n").concat(error.message)); | ||
break; | ||
default: | ||
break; | ||
} | ||
var status = publishResult.status, version = publishResult.version, context = publishResult.context, error = publishResult.error; | ||
var versionAndTag = version | ||
? "version \"".concat((0, kleur_1.bold)(version.number), "\" (tag: ").concat(version.tag, ")") | ||
: ''; | ||
var defaultSuccessText = "\"".concat(packageName, "\" published with ").concat(versionAndTag); | ||
var dryRunSuccess = "\"".concat(packageName, "\" would be successfully published with ").concat(versionAndTag); | ||
switch (status) { | ||
case 'success': | ||
logger_1.logger.success(context === arguments_1.ARG_NAMES.dryRun ? dryRunSuccess : defaultSuccessText); | ||
break; | ||
case 'skipped': | ||
logger_1.logger.warn("\"".concat(packageName, "\" skipped - ").concat(context)); | ||
break; | ||
case 'error': | ||
logger_1.logger.error("\"".concat(packageName, "\" publishing failed\n").concat(error.message)); | ||
break; | ||
default: | ||
break; | ||
} | ||
@@ -78,0 +73,0 @@ } |
@@ -55,3 +55,3 @@ "use strict"; | ||
var execa_1 = __importDefault(require("execa")); | ||
var errorUtils_1 = require("../../../common/errorUtils"); | ||
var error_utils_1 = require("../../../common/error-utils"); | ||
var logger_1 = require("../../../common/logging/logger"); | ||
@@ -81,3 +81,3 @@ exports.yarn = { | ||
context: 'yarn', | ||
error: __assign(__assign({}, (0, errorUtils_1.getErrorProperties)(error_1)), { stderr: error_1.stderr }) | ||
error: __assign(__assign({}, (0, error_utils_1.getErrorProperties)(error_1)), { stderr: error_1.stderr }) | ||
}]; | ||
@@ -98,3 +98,3 @@ case 3: | ||
context: 'yarn build', | ||
error: __assign(__assign({}, (0, errorUtils_1.getErrorProperties)(error_2)), { stderr: error_2.stderr }) | ||
error: __assign(__assign({}, (0, error_utils_1.getErrorProperties)(error_2)), { stderr: error_2.stderr }) | ||
}]; | ||
@@ -101,0 +101,0 @@ case 6: return [2 /*return*/]; |
@@ -71,3 +71,3 @@ "use strict"; | ||
var semver_1 = __importDefault(require("semver")); | ||
var errorUtils_1 = require("../../../common/errorUtils"); | ||
var error_utils_1 = require("../../../common/error-utils"); | ||
var logger_1 = require("../../../common/logging/logger"); | ||
@@ -121,3 +121,3 @@ var arguments_1 = require("../arguments"); | ||
error_1 = _b.sent(); | ||
if ((0, errorUtils_1.isExecaError)(error_1)) { | ||
if ((0, error_utils_1.isExecaError)(error_1)) { | ||
parsedError = parseJson(error_1.stdout); | ||
@@ -149,3 +149,3 @@ if ((parsedError && parsedError.code === 'E401') || | ||
error_2 = _a.sent(); | ||
if ((0, errorUtils_1.isExecaError)(error_2) && error_2.stderr.includes('npm ERR! code E404')) { | ||
if ((0, error_utils_1.isExecaError)(error_2) && error_2.stderr.includes('npm ERR! code E404')) { | ||
// Do nothing, this error happens when package has not been published. | ||
@@ -228,3 +228,3 @@ } | ||
logger_1.logger.debug(error_3); | ||
if ((0, errorUtils_1.isExecaError)(error_3) && error_3.stderr.includes('npm ERR! code EOTP')) { | ||
if ((0, error_utils_1.isExecaError)(error_3) && error_3.stderr.includes('npm ERR! code EOTP')) { | ||
return [2 /*return*/, { | ||
@@ -241,3 +241,3 @@ status: 'error', | ||
context: 'npm publish', | ||
error: (0, errorUtils_1.getErrorProperties)(error_3) | ||
error: (0, error_utils_1.getErrorProperties)(error_3) | ||
}]; | ||
@@ -244,0 +244,0 @@ case 5: return [2 /*return*/]; |
@@ -5,3 +5,3 @@ "use strict"; | ||
var kleur_1 = require("kleur"); | ||
var assertPath_1 = require("../../common/assertPath"); | ||
var assert_path_1 = require("../../common/arguments/assert-path"); | ||
var ARG_NAMES; | ||
@@ -13,2 +13,4 @@ (function (ARG_NAMES) { | ||
ARG_NAMES["forcePreId"] = "forcePreId"; | ||
ARG_NAMES["dryRun"] = "dryRun"; | ||
ARG_NAMES["fix"] = "fix"; | ||
})(ARG_NAMES = exports.ARG_NAMES || (exports.ARG_NAMES = {})); | ||
@@ -51,7 +53,8 @@ var INCREMENT_TYPE_NAMES; | ||
}) | ||
.version(false) | ||
.options((_a = {}, | ||
_a[ARG_NAMES.path] = { | ||
type: 'string', | ||
desc: 'Path to packages to be bumped', | ||
demandOption: true | ||
desc: 'Path to packages to be bumped (required if not set in package.json)', | ||
demandOption: false | ||
}, | ||
@@ -67,5 +70,19 @@ _a[ARG_NAMES.preId] = { | ||
}, | ||
_a[ARG_NAMES.dryRun] = { | ||
type: 'boolean', | ||
desc: 'Run the command in dry-run mode. Will not update any package.', | ||
demandOption: false, | ||
alias: 'dry-run' | ||
}, | ||
_a[ARG_NAMES.fix] = { | ||
type: 'boolean', | ||
desc: 'If passed, it will try to fix version discrepancy and prompt if not possible', | ||
demandOption: false, | ||
alias: 'f' | ||
}, | ||
_a)) | ||
.example(exports.commandName, 'minor --path ./packages') | ||
.example(exports.commandName, 'prerelease --preId alpha --path ./packages') | ||
.example(exports.commandName, 'minor // no path is needed if already set in package.json') | ||
.example(exports.commandName, 'minor --path ./packages ') | ||
.example(exports.commandName, 'minor --no-verbose // will not print anything while command is running') | ||
.example(exports.commandName, 'prerelease --preId alpha') | ||
.example(exports.commandName, 'prerelease --preId=rc --path=./packages') | ||
@@ -76,3 +93,3 @@ .group([ARG_NAMES.path, ARG_NAMES.preId, ARG_NAMES.forcePreId], 'Bump version flags:') | ||
assertValidArgs({ incrementType: incrementType, path: path, preId: preId, forcePreId: forcePreId }); | ||
(0, assertPath_1.assertPathArg)(argv); | ||
(0, assert_path_1.assertPathArg)(argv); | ||
return argv; | ||
@@ -79,0 +96,0 @@ }); |
@@ -18,6 +18,10 @@ "use strict"; | ||
exports.__esModule = true; | ||
exports.handler = exports.findPackagesAndUpdate = exports.NoPackagesError = void 0; | ||
exports.handler = exports.findPackagesAndUpdate = exports.VersionError = exports.NoPackagesError = void 0; | ||
var kleur_1 = require("kleur"); | ||
var filesystem_utils_1 = require("../../../filesystem-utils"); | ||
var getPackageJsons_1 = require("../../common/getPackageJsons"); | ||
var error_utils_1 = require("../../common/error-utils"); | ||
var file_system_1 = require("../../common/file-system"); | ||
var get_version_1 = require("../../common/get-version"); | ||
var get_package_jsons_1 = require("../../common/get-package-jsons"); | ||
var constants_1 = require("../../common/logging/constants"); | ||
var logger_1 = require("../../common/logging/logger"); | ||
var utils_1 = require("./utils"); | ||
@@ -29,3 +33,3 @@ var NoPackagesError = /** @class */ (function (_super) { | ||
_this.name = 'NoPackagesError'; | ||
Error.captureStackTrace(_this, filesystem_utils_1.NoDirectoryError); | ||
Error.captureStackTrace(_this, NoPackagesError); | ||
return _this; | ||
@@ -36,35 +40,85 @@ } | ||
exports.NoPackagesError = NoPackagesError; | ||
var VersionError = /** @class */ (function (_super) { | ||
__extends(VersionError, _super); | ||
function VersionError(message) { | ||
var _this = _super.call(this, "Encountered the following problem(s)".concat(constants_1.NEW_LINE).concat(message)) || this; | ||
_this.name = 'VersionError'; | ||
Error.captureStackTrace(_this, VersionError); | ||
return _this; | ||
} | ||
return VersionError; | ||
}(Error)); | ||
exports.VersionError = VersionError; | ||
/** | ||
* Updates the `version` field in `package.json` with the new version | ||
* as well as the packages in the `dependencies`/`devDependencies` | ||
* that are part of the ones being updated. | ||
* | ||
* i.e.: If the packages being updated are `packageA` and `packageB`, | ||
* and the dependencies in `packageA` include `packageB`, then the | ||
* version of `packageB` in that dependencies will be updated as well. | ||
* | ||
* Example: | ||
* When processing `packageA` with a new major version (2.0.0), then | ||
* its partial package.json will look like the following. | ||
* Before: | ||
* { version: '1.0.0', dependencies: { packageB: '1.0.0' } [...]} | ||
* After running this function: | ||
* { version: '2.0.0', dependencies: { packageB: '2.0.0' } [...] } | ||
* | ||
*/ | ||
function updatePackageAndDepsWithVersion(json, newVersion, isPackage) { | ||
json.version = newVersion; | ||
for (var depName in json.dependencies) { | ||
if (isPackage(depName)) { | ||
json.dependencies[depName] = newVersion; | ||
} | ||
} | ||
for (var depName in json.devDependencies) { | ||
if (isPackage(depName)) { | ||
json.devDependencies[depName] = newVersion; | ||
} | ||
} | ||
return json; | ||
} | ||
function findPackagesAndUpdate(args) { | ||
var path = args.path, incrementType = args.incrementType, prereleaseId = args.preId; | ||
var packages = (0, getPackageJsons_1.getAllPackageJsons)(path); | ||
var packageNames = Object.keys(packages); | ||
if (packageNames.length === 0) { | ||
var path = args.path, incrementType = args.incrementType, prereleaseId = args.preId, dryRun = args.dryRun, fix = args.fix; | ||
(0, logger_1.logIfDryRunMode)(dryRun); | ||
var packages = (0, get_package_jsons_1.getAllPackageJsons)(path); | ||
if (Object.keys(packages).length === 0) { | ||
throw new NoPackagesError(); | ||
} | ||
var updatePackageAndDepsWithVersion = function (_a) { | ||
var json = _a.json, path = _a.path; | ||
var newVersion = (0, utils_1.getNewVersion)({ | ||
current: json.version, | ||
increment: incrementType, | ||
prereleaseId: prereleaseId | ||
}); | ||
json.version = newVersion; | ||
for (var depName in json.dependencies) { | ||
if (packageNames.includes(depName)) { | ||
json.dependencies[depName] = newVersion; | ||
} | ||
(0, logger_1.logPackagesFound)(packages); | ||
var _a = (0, get_version_1.getCurrentVersion)(packages, fix), currentVersion = _a.version, issues = _a.issues, solution = _a.solution; | ||
if (issues && !fix) { | ||
throw new VersionError(issues.map(function (e) { return e.toString(); }).join(constants_1.NEW_LINE + constants_1.NEW_LINE)); | ||
} | ||
if (solution) { | ||
var issuesText = issues | ||
.map(function (e, index) { return "\t(".concat(index + 1, ") ").concat(e.toString()); }) | ||
.join(constants_1.NEW_LINE); | ||
logger_1.logger.heading((0, kleur_1.yellow)('Fix current version')); | ||
logger_1.logger.log(" Issue(s):".concat(constants_1.NEW_LINE).concat((0, kleur_1.yellow)(issuesText))); | ||
logger_1.logger.log(" Solution:".concat(constants_1.NEW_LINE, "\t").concat((0, kleur_1.green)(solution))); | ||
} | ||
var newVersion = (0, utils_1.getNewVersion)({ | ||
current: currentVersion, | ||
increment: incrementType, | ||
prereleaseId: prereleaseId | ||
}); | ||
var isPackage = function (name) { return name in packages; }; | ||
for (var packageName in packages) { | ||
var _b = packages[packageName], json = _b.json, path_1 = _b.path; | ||
var updatedJson = updatePackageAndDepsWithVersion(json, newVersion, isPackage); | ||
if (!dryRun) { | ||
(0, file_system_1.writePackageJson)(path_1, updatedJson); | ||
} | ||
for (var depName in json.devDependencies) { | ||
if (packageNames.includes(depName)) { | ||
json.devDependencies[depName] = newVersion; | ||
} | ||
} | ||
(0, filesystem_utils_1.writePackageJson)(path, json); | ||
}; | ||
// // Here we update the `package.json` objects with updated | ||
// // versions and dependencies. | ||
for (var packageName in packages) { | ||
var packageInfo = packages[packageName]; | ||
updatePackageAndDepsWithVersion(packageInfo); | ||
} | ||
logger_1.logger.logSpacer(); | ||
if (dryRun) { | ||
logger_1.logger.info("Versions would be bumped to ".concat(newVersion)); | ||
} | ||
else { | ||
logger_1.logger.success("Bumped versions to ".concat(newVersion)); | ||
} | ||
} | ||
@@ -77,3 +131,4 @@ exports.findPackagesAndUpdate = findPackagesAndUpdate; | ||
catch (e) { | ||
if (e instanceof filesystem_utils_1.NoDirectoryError) { | ||
logger_1.logger.logSpacer(); | ||
if (e instanceof file_system_1.NoDirectoryError) { | ||
console.error("".concat((0, kleur_1.red)("No directory found in path '".concat(process.cwd(), "/").concat(argv.path, "'")))); | ||
@@ -86,5 +141,5 @@ process.exit(1); | ||
} | ||
throw e; | ||
(0, error_utils_1.exitWithError)(e); | ||
} | ||
} | ||
exports.handler = handler; |
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
exports.__esModule = true; | ||
exports.logger = void 0; | ||
exports.logIfDryRunMode = exports.logPackagesFound = exports.logger = void 0; | ||
var kleur_1 = require("kleur"); | ||
@@ -9,7 +20,8 @@ var symbols_1 = require("./symbols"); | ||
}; | ||
var getLogger = function (shouldLog) { | ||
if (shouldLog === false) { | ||
var getLogger = function (logOptions) { | ||
var debugFn = logOptions.debug ? console.debug : noopFn; | ||
if (logOptions.shouldLog === false) { | ||
return { | ||
log: noopFn, | ||
debug: noopFn, | ||
debug: debugFn, | ||
info: noopFn, | ||
@@ -20,50 +32,89 @@ error: noopFn, | ||
} | ||
return console; | ||
return __assign(__assign({}, console), { debug: debugFn }); | ||
}; | ||
exports.logger = { | ||
/** | ||
* Logs message in yellow color with a leading symbol (⚠). | ||
*/ | ||
warn: function (message, shouldLog) { | ||
return getLogger(shouldLog).warn((0, kleur_1.yellow)("".concat(symbols_1.symbols.warning, " ").concat(message))); | ||
}, | ||
/** | ||
* Logs message with a leading blue symbol (ℹ). | ||
*/ | ||
info: function (message, shouldLog) { | ||
return getLogger(shouldLog).info("".concat(symbols_1.symbols.info, " ").concat(message)); | ||
}, | ||
/** | ||
* | ||
* Logs message with underline and a line break preprended. | ||
*/ | ||
heading: function (message, shouldLog) { | ||
return getLogger(shouldLog).info((0, kleur_1.underline)("\n".concat(message))); | ||
}, | ||
/** | ||
* Logs message in red color with a leading symbol (✖). | ||
*/ | ||
error: function (message, shouldLog) { | ||
return getLogger(shouldLog).error((0, kleur_1.red)("".concat(symbols_1.symbols.error, " ").concat(message))); | ||
}, | ||
/** | ||
* Logs message in green color with a leading symbol (✔). | ||
*/ | ||
success: function (message, shouldLog) { | ||
return getLogger(shouldLog).log((0, kleur_1.green)("".concat(symbols_1.symbols.success, " ").concat(message))); | ||
}, | ||
/** | ||
* Logs plain message without any color or symbol. | ||
*/ | ||
log: function (message, shouldLog) { | ||
return getLogger(shouldLog).log(message); | ||
}, | ||
/** | ||
* Logs message when the `DEBUG` environment variable is set. | ||
*/ | ||
debug: function (value) { | ||
if (process.env.DEBUG === 'true') { | ||
console.debug(value); | ||
var LoggerBuilder = function () { | ||
var logOptions = { | ||
shouldLog: false, | ||
debug: false | ||
}; | ||
return { | ||
/** | ||
* This function needs to be called at the very beginning of the process | ||
* to effectively toggle logging. If that's nto done, nothing will be logged | ||
* whenever a `logger[method]` is called. | ||
*/ | ||
setLoggingOptions: function (verboseFlag, debugEnvVar) { | ||
if (debugEnvVar === 'true') { | ||
logOptions.debug = true; | ||
} | ||
if (verboseFlag === true) { | ||
logOptions.shouldLog = true; | ||
} | ||
}, | ||
/** | ||
* Logs an empty line to create space between logs. | ||
*/ | ||
logSpacer: function () { | ||
getLogger(logOptions).log(''); | ||
}, | ||
/** | ||
* Logs message in yellow color with a leading symbol (⚠). | ||
*/ | ||
warn: function (message) { | ||
return getLogger(logOptions).warn((0, kleur_1.yellow)("".concat(symbols_1.symbols.warning, " ").concat(message))); | ||
}, | ||
/** | ||
* Logs message with a leading blue symbol (ℹ). | ||
*/ | ||
info: function (message) { | ||
return getLogger(logOptions).info("".concat(symbols_1.symbols.info, " ").concat(message)); | ||
}, | ||
/** | ||
* | ||
* Logs message with underline and a line break preprended. | ||
*/ | ||
heading: function (message) { | ||
return getLogger(logOptions).info((0, kleur_1.underline)("\n".concat(message))); | ||
}, | ||
/** | ||
* Logs message in red color with a leading symbol (✖). | ||
*/ | ||
error: function (message) { | ||
return getLogger(logOptions).error((0, kleur_1.red)("".concat(symbols_1.symbols.error, " ").concat(message))); | ||
}, | ||
/** | ||
* Logs message in green color with a leading symbol (✔). | ||
*/ | ||
success: function (message) { | ||
return getLogger(logOptions).log((0, kleur_1.green)("".concat(symbols_1.symbols.success, " ").concat(message))); | ||
}, | ||
/** | ||
* Logs plain message without any color or symbol. | ||
*/ | ||
log: function (message) { return getLogger(logOptions).log(message); }, | ||
/** | ||
* Logs message when the `DEBUG` environment variable is set. | ||
*/ | ||
debug: function (value) { | ||
getLogger(logOptions).debug(value); | ||
} | ||
}; | ||
}; | ||
exports.logger = LoggerBuilder(); | ||
function logPackagesFound(packages) { | ||
exports.logger.heading('Packages found'); | ||
Object.entries(packages).forEach(function (_a) { | ||
var packageName = _a[0], json = _a[1].json; | ||
exports.logger.log("- ".concat(packageName, " (v").concat(json.version, ")")); | ||
}); | ||
} | ||
exports.logPackagesFound = logPackagesFound; | ||
function logIfDryRunMode(dryRun) { | ||
if (dryRun) { | ||
exports.logger.logSpacer(); | ||
exports.logger.log((0, kleur_1.bgCyan)((0, kleur_1.black)(" "))); | ||
exports.logger.log((0, kleur_1.bgCyan)((0, kleur_1.black)(" Running command in dry-run mode "))); | ||
exports.logger.log((0, kleur_1.bgCyan)((0, kleur_1.black)(" "))); | ||
} | ||
}; | ||
} | ||
exports.logIfDryRunMode = logIfDryRunMode; |
@@ -11,10 +11,27 @@ "use strict"; | ||
var publish_1 = __importDefault(require("./commands/publish")); | ||
var error_utils_1 = require("./common/error-utils"); | ||
var logger_1 = require("./common/logging/logger"); | ||
exports.helpText = "\nUsage\n $0 [command]\n"; | ||
var cli = (0, yargs_1["default"])((0, helpers_1.hideBin)(process.argv)) | ||
.usage(exports.helpText) | ||
.version(false) | ||
.demandCommand() | ||
.recommendCommands() | ||
.option('verbose', { | ||
type: 'boolean', | ||
desc: 'Output information throughout the process.', | ||
"default": true, | ||
alias: 'v', | ||
demandOption: false | ||
}) | ||
.pkgConf('pkgs') | ||
.middleware(function (argv) { | ||
logger_1.logger.setLoggingOptions(argv.verbose, process.env.DEBUG); | ||
}, true) | ||
.help(); | ||
void cli.command(version_1["default"]).command(publish_1["default"]).argv; | ||
cli | ||
.command(version_1["default"]) | ||
.command(publish_1["default"]) | ||
.parseAsync() | ||
.then(function () { return process.exit(0); })["catch"](function (err) { | ||
(0, error_utils_1.exitWithError)(err); | ||
}); |
{ | ||
"version": "0.0.1-alpha.0", | ||
"version": "0.0.1-alpha.1", | ||
"name": "@clabs/packages-publisher", | ||
@@ -4,0 +4,0 @@ "repository": "celo-org/packages-publisher", |
@@ -7,3 +7,3 @@ import { execFile } from 'child_process'; | ||
import { PackageJson } from '../filesystem-utils'; | ||
import { PackageJson } from '../cli/common/file-system'; | ||
import { OUTPUT_FILE_NAME } from '../cli/commands/publish/handler'; | ||
@@ -22,3 +22,3 @@ | ||
async function usingTempDir(fn: (args: unknown) => unknown) { | ||
async function usingTempDir(fn: (args: string) => unknown) { | ||
const subTempDirName = Math.random().toString(36).substring(2); | ||
@@ -25,0 +25,0 @@ const tempDir = os.tmpdir(); |
import { Argv, PositionalOptionsType } from 'yargs'; | ||
import { assertPathArg } from '../../common/assertPath'; | ||
import { assertPathArg } from '../../common/arguments/assert-path'; | ||
@@ -8,3 +8,2 @@ export enum ARG_NAMES { | ||
otp = 'otp', | ||
verbose = 'verbose', | ||
skipBuild = 'skipBuild', | ||
@@ -19,3 +18,2 @@ outputPath = 'outputPath', | ||
[ARG_NAMES.skipBuild]: boolean; | ||
[ARG_NAMES.verbose]?: boolean; | ||
[ARG_NAMES.outputPath]?: string; | ||
@@ -29,2 +27,3 @@ }; | ||
return yargs | ||
.version(false) | ||
.options({ | ||
@@ -48,9 +47,2 @@ [ARG_NAMES.path]: { | ||
}, | ||
[ARG_NAMES.verbose]: { | ||
type: 'boolean' as PositionalOptionsType, | ||
desc: 'Output information throughout the process.', | ||
default: false, | ||
alias: 'v', | ||
demandOption: false, | ||
}, | ||
[ARG_NAMES.otp]: { | ||
@@ -57,0 +49,0 @@ type: 'string' as PositionalOptionsType, |
import { createFakePackages } from '../../../test/mock-system'; | ||
import { getAllPackageJsons } from '../../common/getPackageJsons'; | ||
import { getAllPackageJsons } from '../../common/get-package-jsons'; | ||
import { | ||
@@ -23,3 +23,3 @@ buildAndPublishAllPackages, | ||
>; | ||
jest.mock('../../common/getPackageJsons', () => ({ | ||
jest.mock('../../common/get-package-jsons', () => ({ | ||
getAllPackageJsons: jest.fn(), | ||
@@ -26,0 +26,0 @@ })); |
@@ -9,5 +9,9 @@ import { ArgumentsCamelCase } from 'yargs'; | ||
getAllPackageJsons, | ||
} from '../../common/getPackageJsons'; | ||
import { logger } from '../../common/logging/logger'; | ||
import { exitWithError } from '../../common/errorUtils'; | ||
} from '../../common/get-package-jsons'; | ||
import { | ||
logger, | ||
logPackagesFound, | ||
logIfDryRunMode, | ||
} from '../../common/logging/logger'; | ||
import { exitWithError } from '../../common/error-utils'; | ||
@@ -121,3 +125,4 @@ import { ExpectedArgs } from './arguments'; | ||
) { | ||
const { path, otp: initialOtp, dryRun, skipBuild, verbose } = args; | ||
const { path, otp: initialOtp, dryRun, skipBuild } = args; | ||
logIfDryRunMode(dryRun); | ||
const otp = OTPHandler(initialOtp); | ||
@@ -132,19 +137,15 @@ | ||
const shouldLog = verbose === true; | ||
const packages = getAllPackageJsons(path); | ||
logger.heading('Packages found:', shouldLog); | ||
logger.log(`- "${Object.keys(packages).join('"\n - "')}"\n`, shouldLog); | ||
logPackagesFound(packages); | ||
logger.info('Versions above will be used for publishing'); | ||
if (skipBuild) { | ||
logger.warn('Building was skipped', shouldLog); | ||
logger.warn('Building was skipped'); | ||
} else { | ||
logger.heading('Building packages', shouldLog); | ||
logger.heading('Building packages'); | ||
await buildPackages(packages, resultCollector); | ||
} | ||
logger.heading( | ||
`Publishing packages${dryRun ? ' (dry-run mode)' : ''}`, | ||
shouldLog | ||
); | ||
logger.heading(`Publishing packages${dryRun ? ' (dry-run mode)' : ''}`); | ||
await publishPackages(packages, otp, dryRun, resultCollector); | ||
@@ -154,3 +155,3 @@ } | ||
export async function handler(args: ArgumentsCamelCase<ExpectedArgs>) { | ||
const resultCollector = resultBuilder(args.verbose); | ||
const resultCollector = resultBuilder(); | ||
@@ -157,0 +158,0 @@ let error: unknown; |
@@ -23,3 +23,3 @@ import { ExecaError } from 'execa'; | ||
export const resultBuilder = (verbose = false) => { | ||
export const resultBuilder = () => { | ||
const result: AllPackagesResult = {}; | ||
@@ -53,8 +53,6 @@ return { | ||
if (verbose) { | ||
if (buildResult.status === 'success') { | ||
logger.success(`"${packageName}" built`); | ||
} else { | ||
logger.error(`"${packageName}" build failed`); | ||
} | ||
if (buildResult.status === 'success') { | ||
logger.success(`"${packageName}" built`); | ||
} else { | ||
logger.error(`"${packageName}" build failed`); | ||
} | ||
@@ -72,27 +70,23 @@ }, | ||
if (verbose) { | ||
const { status, version, context, error } = publishResult; | ||
const versionAndTag = version | ||
? `version "${bold(version.number)}" (tag: ${version.tag})` | ||
: ''; | ||
const defaultSuccessText = `"${packageName}" published with ${versionAndTag}`; | ||
const dryRunSuccess = `"${packageName}" would be successfully published with ${versionAndTag}`; | ||
const { status, version, context, error } = publishResult; | ||
const versionAndTag = version | ||
? `version "${bold(version.number)}" (tag: ${version.tag})` | ||
: ''; | ||
const defaultSuccessText = `"${packageName}" published with ${versionAndTag}`; | ||
const dryRunSuccess = `"${packageName}" would be successfully published with ${versionAndTag}`; | ||
switch (status) { | ||
case 'success': | ||
logger.success( | ||
context === ARG_NAMES.dryRun ? dryRunSuccess : defaultSuccessText | ||
); | ||
break; | ||
case 'skipped': | ||
logger.warn(`"${packageName}" skipped - ${context}`); | ||
break; | ||
case 'error': | ||
logger.error( | ||
`"${packageName}" publishing failed\n${error.message}` | ||
); | ||
break; | ||
default: | ||
break; | ||
} | ||
switch (status) { | ||
case 'success': | ||
logger.success( | ||
context === ARG_NAMES.dryRun ? dryRunSuccess : defaultSuccessText | ||
); | ||
break; | ||
case 'skipped': | ||
logger.warn(`"${packageName}" skipped - ${context}`); | ||
break; | ||
case 'error': | ||
logger.error(`"${packageName}" publishing failed\n${error.message}`); | ||
break; | ||
default: | ||
break; | ||
} | ||
@@ -99,0 +93,0 @@ }, |
import execa, { ExecaError } from 'execa'; | ||
import { getErrorProperties } from '../../../common/errorUtils'; | ||
import { getErrorProperties } from '../../../common/error-utils'; | ||
import { logger } from '../../../common/logging/logger'; | ||
@@ -4,0 +4,0 @@ import { Result } from '../resultCollector'; |
import execa from 'execa'; | ||
import semver from 'semver'; | ||
import { getErrorProperties, isExecaError } from '../../../common/errorUtils'; | ||
import { getErrorProperties, isExecaError } from '../../../common/error-utils'; | ||
import { logger } from '../../../common/logging/logger'; | ||
@@ -6,0 +6,0 @@ import { ARG_NAMES } from '../arguments'; |
import { red } from 'kleur'; | ||
import type { Argv } from 'yargs'; | ||
import { assertPathArg } from '../../common/assertPath'; | ||
import { assertPathArg } from '../../common/arguments/assert-path'; | ||
@@ -10,2 +10,4 @@ export enum ARG_NAMES { | ||
forcePreId = 'forcePreId', | ||
dryRun = 'dryRun', | ||
fix = 'fix', | ||
} | ||
@@ -28,2 +30,4 @@ | ||
[ARG_NAMES.forcePreId]?: boolean; | ||
[ARG_NAMES.dryRun]?: boolean; | ||
[ARG_NAMES.fix]?: boolean; | ||
}; | ||
@@ -70,7 +74,8 @@ | ||
}) | ||
.version(false) | ||
.options({ | ||
[ARG_NAMES.path]: { | ||
type: 'string', | ||
desc: 'Path to packages to be bumped', | ||
demandOption: true, | ||
desc: 'Path to packages to be bumped (required if not set in package.json)', | ||
demandOption: false, | ||
}, | ||
@@ -87,5 +92,25 @@ [ARG_NAMES.preId]: { | ||
}, | ||
[ARG_NAMES.dryRun]: { | ||
type: 'boolean', | ||
desc: 'Run the command in dry-run mode. Will not update any package.', | ||
demandOption: false, | ||
alias: 'dry-run', | ||
}, | ||
[ARG_NAMES.fix]: { | ||
type: 'boolean', | ||
desc: 'If passed, it will try to fix version discrepancy and prompt if not possible', | ||
demandOption: false, | ||
alias: 'f', | ||
}, | ||
}) | ||
.example(commandName, 'minor --path ./packages') | ||
.example(commandName, 'prerelease --preId alpha --path ./packages') | ||
.example( | ||
commandName, | ||
'minor // no path is needed if already set in package.json' | ||
) | ||
.example(commandName, 'minor --path ./packages ') | ||
.example( | ||
commandName, | ||
'minor --no-verbose // will not print anything while command is running' | ||
) | ||
.example(commandName, 'prerelease --preId alpha') | ||
.example(commandName, 'prerelease --preId=rc --path=./packages') | ||
@@ -92,0 +117,0 @@ .group( |
@@ -1,2 +0,6 @@ | ||
import { findPackagesAndUpdate, NoPackagesError } from './handler'; | ||
import { | ||
findPackagesAndUpdate, | ||
NoPackagesError, | ||
VersionError, | ||
} from './handler'; | ||
import mockFileSystem from 'mock-fs'; | ||
@@ -8,3 +12,3 @@ | ||
readPackageJson, | ||
} from '../../../filesystem-utils'; | ||
} from '../../common/file-system'; | ||
import { | ||
@@ -47,2 +51,39 @@ createFakePackageJsonString, | ||
it('should throw error if versions do not match', () => { | ||
const versionA = '1.0.0'; | ||
const versionB = '1.1.0'; | ||
const packageA: PackageJson = { | ||
name: 'packageA', | ||
version: versionA, | ||
dependencies: {}, | ||
devDependencies: {}, | ||
}; | ||
const packageB: PackageJson = { | ||
name: 'packageB', | ||
version: versionB, | ||
dependencies: { | ||
[packageA.name]: packageA.version, | ||
}, | ||
devDependencies: {}, | ||
}; | ||
const fakeFileSystemStructure = { | ||
...loadNodeModules(), | ||
packages: { | ||
packageA: { | ||
'package.json': createFakePackageJsonString(packageA), | ||
}, | ||
packageB: { | ||
'package.json': createFakePackageJsonString(packageB), | ||
}, | ||
}, | ||
}; | ||
mockFileSystem(fakeFileSystemStructure); | ||
expect(() => | ||
findPackagesAndUpdate({ path: 'packages', incrementType: 'minor' }) | ||
).toThrowError(VersionError); | ||
}); | ||
it('should work when path includes valid packages', () => { | ||
@@ -76,2 +117,6 @@ // With mocked files | ||
}, | ||
// Should be ignored | ||
invalidPackage: { | ||
'package.json': '{}', | ||
}, | ||
}, | ||
@@ -78,0 +123,0 @@ }; |
@@ -1,5 +0,7 @@ | ||
import { red } from 'kleur'; | ||
import { green, red, yellow } from 'kleur'; | ||
import { ArgumentsCamelCase } from 'yargs'; | ||
import { exitWithError } from '../../common/error-utils'; | ||
import { NoDirectoryError, writePackageJson } from '../../../filesystem-utils'; | ||
import { NoDirectoryError, writePackageJson } from '../../common/file-system'; | ||
import { getCurrentVersion } from '../../common/get-version'; | ||
import { | ||
@@ -9,3 +11,9 @@ AllPackageJsons, | ||
PackageInfo, | ||
} from '../../common/getPackageJsons'; | ||
} from '../../common/get-package-jsons'; | ||
import { NEW_LINE } from '../../common/logging/constants'; | ||
import { | ||
logger, | ||
logPackagesFound, | ||
logIfDryRunMode, | ||
} from '../../common/logging/logger'; | ||
import { VersionExpectedArgs } from './arguments'; | ||
@@ -18,44 +26,108 @@ import { getNewVersion } from './utils'; | ||
this.name = 'NoPackagesError'; | ||
Error.captureStackTrace(this, NoDirectoryError); | ||
Error.captureStackTrace(this, NoPackagesError); | ||
} | ||
} | ||
export class VersionError extends Error { | ||
constructor(message: string) { | ||
super(`Encountered the following problem(s)${NEW_LINE}${message}`); | ||
this.name = 'VersionError'; | ||
Error.captureStackTrace(this, VersionError); | ||
} | ||
} | ||
/** | ||
* Updates the `version` field in `package.json` with the new version | ||
* as well as the packages in the `dependencies`/`devDependencies` | ||
* that are part of the ones being updated. | ||
* | ||
* i.e.: If the packages being updated are `packageA` and `packageB`, | ||
* and the dependencies in `packageA` include `packageB`, then the | ||
* version of `packageB` in that dependencies will be updated as well. | ||
* | ||
* Example: | ||
* When processing `packageA` with a new major version (2.0.0), then | ||
* its partial package.json will look like the following. | ||
* Before: | ||
* { version: '1.0.0', dependencies: { packageB: '1.0.0' } [...]} | ||
* After running this function: | ||
* { version: '2.0.0', dependencies: { packageB: '2.0.0' } [...] } | ||
* | ||
*/ | ||
function updatePackageAndDepsWithVersion( | ||
json: PackageInfo['json'], | ||
newVersion: string, | ||
isPackage: (name: string) => boolean | ||
) { | ||
json.version = newVersion; | ||
for (const depName in json.dependencies) { | ||
if (isPackage(depName)) { | ||
json.dependencies[depName] = newVersion; | ||
} | ||
} | ||
for (const depName in json.devDependencies) { | ||
if (isPackage(depName)) { | ||
json.devDependencies[depName] = newVersion; | ||
} | ||
} | ||
return json; | ||
} | ||
export function findPackagesAndUpdate(args: VersionExpectedArgs) { | ||
const { path, incrementType, preId: prereleaseId } = args; | ||
const { path, incrementType, preId: prereleaseId, dryRun, fix } = args; | ||
logIfDryRunMode(dryRun); | ||
const packages: AllPackageJsons = getAllPackageJsons(path); | ||
const packageNames = Object.keys(packages); | ||
if (packageNames.length === 0) { | ||
if (Object.keys(packages).length === 0) { | ||
throw new NoPackagesError(); | ||
} | ||
logPackagesFound(packages); | ||
const updatePackageAndDepsWithVersion = ({ json, path }: PackageInfo) => { | ||
const newVersion = getNewVersion({ | ||
current: json.version, | ||
increment: incrementType, | ||
prereleaseId, | ||
}); | ||
const { | ||
version: currentVersion, | ||
issues, | ||
solution, | ||
} = getCurrentVersion(packages, fix); | ||
if (issues && !fix) { | ||
throw new VersionError( | ||
issues.map((e) => e.toString()).join(NEW_LINE + NEW_LINE) | ||
); | ||
} | ||
json.version = newVersion; | ||
if (solution) { | ||
const issuesText = issues | ||
.map((e, index) => `\t(${index + 1}) ${e.toString()}`) | ||
.join(NEW_LINE); | ||
logger.heading(yellow('Fix current version')); | ||
logger.log(` Issue(s):${NEW_LINE}${yellow(issuesText)}`); | ||
logger.log(` Solution:${NEW_LINE}\t${green(solution)}`); | ||
} | ||
for (const depName in json.dependencies) { | ||
if (packageNames.includes(depName)) { | ||
json.dependencies[depName] = newVersion; | ||
} | ||
} | ||
const newVersion = getNewVersion({ | ||
current: currentVersion, | ||
increment: incrementType, | ||
prereleaseId, | ||
}); | ||
for (const depName in json.devDependencies) { | ||
if (packageNames.includes(depName)) { | ||
json.devDependencies[depName] = newVersion; | ||
} | ||
const isPackage = (name: string) => name in packages; | ||
for (const packageName in packages) { | ||
const { json, path } = packages[packageName]; | ||
const updatedJson = updatePackageAndDepsWithVersion( | ||
json, | ||
newVersion, | ||
isPackage | ||
); | ||
if (!dryRun) { | ||
writePackageJson(path, updatedJson); | ||
} | ||
} | ||
writePackageJson(path, json); | ||
}; | ||
// // Here we update the `package.json` objects with updated | ||
// // versions and dependencies. | ||
for (const packageName in packages) { | ||
const packageInfo = packages[packageName]; | ||
updatePackageAndDepsWithVersion(packageInfo); | ||
logger.logSpacer(); | ||
if (dryRun) { | ||
logger.info(`Versions would be bumped to ${newVersion}`); | ||
} else { | ||
logger.success(`Bumped versions to ${newVersion}`); | ||
} | ||
@@ -68,2 +140,4 @@ } | ||
} catch (e) { | ||
logger.logSpacer(); | ||
if (e instanceof NoDirectoryError) { | ||
@@ -87,4 +161,4 @@ console.error( | ||
throw e; | ||
exitWithError(e); | ||
} | ||
} |
@@ -1,2 +0,3 @@ | ||
import { green, red, underline, yellow } from 'kleur'; | ||
import { black, green, red, underline, yellow, bgCyan } from 'kleur'; | ||
import { AllPackageJsons } from '../get-package-jsons'; | ||
import { symbols } from './symbols'; | ||
@@ -10,7 +11,12 @@ | ||
const getLogger = (shouldLog?: boolean): ConsoleLogger => { | ||
if (shouldLog === false) { | ||
const getLogger = (logOptions: { | ||
shouldLog: boolean; | ||
debug: boolean; | ||
}): ConsoleLogger => { | ||
const debugFn = logOptions.debug ? console.debug : noopFn; | ||
if (logOptions.shouldLog === false) { | ||
return { | ||
log: noopFn, | ||
debug: noopFn, | ||
debug: debugFn, | ||
info: noopFn, | ||
@@ -22,45 +28,90 @@ error: noopFn, | ||
return console; | ||
return { | ||
...console, | ||
debug: debugFn, | ||
}; | ||
}; | ||
export const logger = { | ||
/** | ||
* Logs message in yellow color with a leading symbol (⚠). | ||
*/ | ||
warn: (message: string, shouldLog?: boolean) => | ||
getLogger(shouldLog).warn(yellow(`${symbols.warning} ${message}`)), | ||
/** | ||
* Logs message with a leading blue symbol (ℹ). | ||
*/ | ||
info: (message: string, shouldLog?: boolean) => | ||
getLogger(shouldLog).info(`${symbols.info} ${message}`), | ||
/** | ||
* | ||
* Logs message with underline and a line break preprended. | ||
*/ | ||
heading: (message: string, shouldLog?: boolean) => | ||
getLogger(shouldLog).info(underline(`\n${message}`)), | ||
/** | ||
* Logs message in red color with a leading symbol (✖). | ||
*/ | ||
error: (message: string, shouldLog?: boolean) => | ||
getLogger(shouldLog).error(red(`${symbols.error} ${message}`)), | ||
/** | ||
* Logs message in green color with a leading symbol (✔). | ||
*/ | ||
success: (message: string, shouldLog?: boolean) => | ||
getLogger(shouldLog).log(green(`${symbols.success} ${message}`)), | ||
/** | ||
* Logs plain message without any color or symbol. | ||
*/ | ||
log: (message: string, shouldLog?: boolean) => | ||
getLogger(shouldLog).log(message), | ||
/** | ||
* Logs message when the `DEBUG` environment variable is set. | ||
*/ | ||
debug: (value: unknown) => { | ||
if (process.env.DEBUG === 'true') { | ||
console.debug(value); | ||
} | ||
}, | ||
const LoggerBuilder = () => { | ||
const logOptions = { | ||
shouldLog: false, | ||
debug: false, | ||
}; | ||
return { | ||
/** | ||
* This function needs to be called at the very beginning of the process | ||
* to effectively toggle logging. If that's nto done, nothing will be logged | ||
* whenever a `logger[method]` is called. | ||
*/ | ||
setLoggingOptions: (verboseFlag?: boolean, debugEnvVar?: string) => { | ||
if (debugEnvVar === 'true') { | ||
logOptions.debug = true; | ||
} | ||
if (verboseFlag === true) { | ||
logOptions.shouldLog = true; | ||
} | ||
}, | ||
/** | ||
* Logs an empty line to create space between logs. | ||
*/ | ||
logSpacer: () => { | ||
getLogger(logOptions).log(''); | ||
}, | ||
/** | ||
* Logs message in yellow color with a leading symbol (⚠). | ||
*/ | ||
warn: (message: string) => | ||
getLogger(logOptions).warn(yellow(`${symbols.warning} ${message}`)), | ||
/** | ||
* Logs message with a leading blue symbol (ℹ). | ||
*/ | ||
info: (message: string) => | ||
getLogger(logOptions).info(`${symbols.info} ${message}`), | ||
/** | ||
* | ||
* Logs message with underline and a line break preprended. | ||
*/ | ||
heading: (message: string) => | ||
getLogger(logOptions).info(underline(`\n${message}`)), | ||
/** | ||
* Logs message in red color with a leading symbol (✖). | ||
*/ | ||
error: (message: string) => | ||
getLogger(logOptions).error(red(`${symbols.error} ${message}`)), | ||
/** | ||
* Logs message in green color with a leading symbol (✔). | ||
*/ | ||
success: (message: string) => | ||
getLogger(logOptions).log(green(`${symbols.success} ${message}`)), | ||
/** | ||
* Logs plain message without any color or symbol. | ||
*/ | ||
log: (message: string) => getLogger(logOptions).log(message), | ||
/** | ||
* Logs message when the `DEBUG` environment variable is set. | ||
*/ | ||
debug: (value: unknown) => { | ||
getLogger(logOptions).debug(value); | ||
}, | ||
}; | ||
}; | ||
export const logger = LoggerBuilder(); | ||
export function logPackagesFound(packages: AllPackageJsons) { | ||
logger.heading('Packages found'); | ||
Object.entries(packages).forEach(([packageName, { json }]) => { | ||
logger.log(`- ${packageName} (v${json.version})`); | ||
}); | ||
} | ||
export function logIfDryRunMode(dryRun: boolean) { | ||
if (dryRun) { | ||
logger.logSpacer(); | ||
logger.log(bgCyan(black(` `))); | ||
logger.log(bgCyan(black(` Running command in dry-run mode `))); | ||
logger.log(bgCyan(black(` `))); | ||
} | ||
} |
import yargs from 'yargs/yargs'; | ||
import type { Arguments } from 'yargs'; | ||
import { hideBin as parseArgs } from 'yargs/helpers'; | ||
@@ -6,2 +7,4 @@ | ||
import publishCommand from './commands/publish'; | ||
import { exitWithError } from './common/error-utils'; | ||
import { logger } from './common/logging/logger'; | ||
@@ -15,8 +18,24 @@ export const helpText = ` | ||
.usage(helpText) | ||
.version(false) | ||
.demandCommand() | ||
.recommendCommands() | ||
.option('verbose', { | ||
type: 'boolean', | ||
desc: 'Output information throughout the process.', | ||
default: true, | ||
alias: 'v', | ||
demandOption: false, | ||
}) | ||
.pkgConf('pkgs') | ||
.middleware((argv: Arguments<{ verbose?: boolean }>) => { | ||
logger.setLoggingOptions(argv.verbose, process.env.DEBUG); | ||
}, true) | ||
.help(); | ||
void cli.command(versionCommand).command(publishCommand).argv; | ||
cli | ||
.command(versionCommand) | ||
.command(publishCommand) | ||
.parseAsync() | ||
.then(() => process.exit(0)) | ||
.catch((err) => { | ||
exitWithError(err); | ||
}); |
import mockFileSystem from 'mock-fs'; | ||
import path from 'path'; | ||
import { AllPackageJsons } from '../cli/common/getPackageJsons'; | ||
import { PackageJson } from '../filesystem-utils'; | ||
import { AllPackageJsons } from '../cli/common/get-package-jsons'; | ||
import { PackageJson } from '../cli/common/file-system'; | ||
@@ -6,0 +6,0 @@ export const createFakePackageJson = ( |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
133744
62
3526
4