npm-commands-ngs
Version:
Reusable commands for NPM
36 lines (35 loc) • 1.51 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.NpmCommands = void 0;
const node_child_process_1 = require("node:child_process");
const DEF_REGISTRY = 'https://registry.npmjs.org';
const DEF_DEP_MSG = 'which offers more features, better tests and offers security fixes. Any enhancements or bug fix requests to this version are no more supported.';
class NpmCommands {
static getPackageView(pkgName, task) {
if (pkgName) {
return (0, node_child_process_1.execSync)(`npm view ${pkgName} ${task || ''}`)
.toString()
.trim();
}
else {
throw new Error(`missing required project: ${pkgName ?? ''}`);
}
}
static deprecatePackage(pkgName, version, registry, message) {
if (pkgName && version) {
(0, node_child_process_1.execSync)(`npm deprecate ${pkgName}@"<${version}" "please update to ${version}@${version}, ${message || DEF_DEP_MSG}" --registry=${registry || DEF_REGISTRY}`);
}
else {
throw new Error(`missing required project: ${pkgName ?? ''} or version: ${version ?? ''}`);
}
}
static updateVersion(projectPath, type) {
if (projectPath) {
(0, node_child_process_1.execSync)(`cd ${projectPath} && npm version ${type || 'patch'}`);
}
else {
throw new Error(`missing required projectPath: ${projectPath ?? ''}`);
}
}
}
exports.NpmCommands = NpmCommands;