npmci/dist/mod_node/index.js

86 lines
6.7 KiB
JavaScript
Raw Normal View History

2017-08-27 13:24:17 +00:00
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const plugins = require("../npmci.plugins");
const npmciConfig = require("../npmci.config");
const npmci_bash_1 = require("../npmci.bash");
/**
* handle cli input
* @param argvArg
*/
exports.handleCli = (argvArg) => __awaiter(this, void 0, void 0, function* () {
if (argvArg._.length >= 3) {
let action = argvArg._[1];
switch (action) {
case 'install':
yield exports.install(argvArg._[2]);
break;
default:
plugins.beautylog.error(`>>npmci node ...<< action >>${action}<< not supported`);
process.exit(1);
2017-08-27 13:24:17 +00:00
}
}
else {
plugins.beautylog.error(`>>npmci node ...<< cli arguments invalid... Please read the documentation.`);
process.exit(1);
2017-08-27 13:24:17 +00:00
}
});
/**
* Install a specific version of node
* @param versionArg
*/
exports.install = (versionArg) => __awaiter(this, void 0, void 0, function* () {
plugins.beautylog.log(`now installing node version ${versionArg}`);
let version;
if (versionArg === 'stable') {
version = 'stable';
}
else if (versionArg === 'lts') {
2017-10-09 16:10:01 +00:00
version = '8';
2017-08-27 13:24:17 +00:00
}
else if (versionArg === 'legacy') {
2017-10-09 16:10:01 +00:00
version = '8';
2017-08-27 13:24:17 +00:00
}
else {
version = versionArg;
}
if (yield npmci_bash_1.nvmAvailable.promise) {
yield npmci_bash_1.bash(`nvm install ${version} && nvm alias default ${version}`);
plugins.beautylog.success(`Node version ${version} successfully installed!`);
}
else {
plugins.beautylog.warn('Nvm not in path so staying at installed node version!');
}
yield npmci_bash_1.bash('node -v');
yield npmci_bash_1.bash('npm -v');
// lets look for further config
2018-04-04 20:25:13 +00:00
yield npmciConfig.getConfig().then((configArg) => __awaiter(this, void 0, void 0, function* () {
2017-08-27 13:24:17 +00:00
plugins.beautylog.log('Now checking for needed global npm tools...');
2017-08-28 15:19:31 +00:00
for (let npmTool of configArg.npmGlobalTools) {
2017-08-27 13:24:17 +00:00
plugins.beautylog.info(`Checking for global "${npmTool}"`);
let whichOutput = yield npmci_bash_1.bashNoError(`which ${npmTool}`);
2018-04-04 20:25:13 +00:00
let toolAvailable = !(/not\sfound/.test(whichOutput) || whichOutput === '');
2017-08-27 13:24:17 +00:00
if (toolAvailable) {
plugins.beautylog.log(`Tool ${npmTool} is available`);
}
else {
plugins.beautylog.info(`globally installing ${npmTool} from npm`);
if (yield npmci_bash_1.yarnAvailable.promise) {
yield npmci_bash_1.bash(`yarn global add ${npmTool}`);
}
else {
yield npmci_bash_1.bash(`npm install ${npmTool} -q -g`);
}
}
}
plugins.beautylog.success('all global npm tools specified in npmextra.json are now available!');
}));
});
2018-04-04 20:25:13 +00:00
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi90cy9tb2Rfbm9kZS9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7O0FBQUEsNENBQTRDO0FBQzVDLCtDQUErQztBQUMvQyw4Q0FBK0U7QUFFL0U7OztHQUdHO0FBQ1EsUUFBQSxTQUFTLEdBQUcsQ0FBTSxPQUFPLEVBQUMsRUFBRTtJQUNyQyxFQUFFLENBQUMsQ0FBQyxPQUFPLENBQUMsQ0FBQyxDQUFDLE1BQU0sSUFBSSxDQUFDLENBQUMsQ0FBQyxDQUFDO1FBQzFCLElBQUksTUFBTSxHQUFXLE9BQU8sQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUM7UUFDbEMsTU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