@ts-common/azure-js-dev-tools
Version:
Developer dependencies for TypeScript related projects
66 lines • 3.41 kB
JavaScript
;
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for
* license information.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.checkPackageJsonVersionCheck = exports.checkPackageJsonVersion = void 0;
var tslib_1 = require("tslib");
var logger_1 = require("./logger");
var packageJson_1 = require("./packageJson");
function checkPackageJsonVersion(options) {
if (options === void 0) { options = {}; }
return {
name: "Package.json Version",
check: function () { return checkPackageJsonVersionCheck(options); },
};
}
exports.checkPackageJsonVersion = checkPackageJsonVersion;
/**
* Check the package.json file found at the provided startPath (or in one of the parent folders) to
* see if the version number has already been published. If the version number has been published,
* then a non-zero error code will be returned.
* @param startPath The path to start looking for the package.json file in.
* @param logger The logger to use. If no logger is specified, then a console logger will be used.
* @returns The exit code for this function. Zero will be returned if the package version doesn't
* exist in NPM.
*/
function checkPackageJsonVersionCheck(options) {
if (options === void 0) { options = {}; }
return tslib_1.__awaiter(this, void 0, void 0, function () {
var startPath, logger, exitCode, packageJsonFilePath, packageJson;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
startPath = options.startPath || process.cwd();
logger = options.logger || logger_1.getDefaultLogger();
logger.logSection("Looking for package.json file starting at \"" + startPath + "\"...");
packageJsonFilePath = packageJson_1.findPackageJsonFileSync(startPath);
if (!!packageJsonFilePath) return [3 /*break*/, 1];
logger.logError("Could not find a package.json file at \"" + startPath + "\" or in any of its parent folders.");
exitCode = 1;
return [3 /*break*/, 3];
case 1:
logger.logInfo("Found a package.json file at \"" + packageJsonFilePath + "\".");
packageJson = packageJson_1.readPackageJsonFileSync(packageJsonFilePath);
return [4 /*yield*/, packageJson_1.isPackageJsonPublished(packageJson)];
case 2:
if (_a.sent()) {
logger.logError("A package with the name \"" + packageJson.name + "\" and the version \"" + packageJson.version + "\" already exists in NPM.");
exitCode = 2;
}
else {
logger.logInfo("No package exists yet with the name \"" + packageJson.name + "\" and the version \"" + packageJson.version + "\".");
exitCode = 0;
}
_a.label = 3;
case 3:
process.exitCode = exitCode;
return [2 /*return*/, exitCode];
}
});
});
}
exports.checkPackageJsonVersionCheck = checkPackageJsonVersionCheck;
//# sourceMappingURL=checkPackageJsonVersion.js.map