85 lines
6.6 KiB
JavaScript
85 lines
6.6 KiB
JavaScript
|
"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`);
|
||
|
}
|
||
|
}
|
||
|
else {
|
||
|
plugins.beautylog.error(`>>npmci node ...<< cli arguments invalid... Please read the documentation.`);
|
||
|
}
|
||
|
});
|
||
|
/**
|
||
|
* 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') {
|
||
|
version = '6';
|
||
|
}
|
||
|
else if (versionArg === 'legacy') {
|
||
|
version = '6';
|
||
|
}
|
||
|
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
|
||
|
yield npmciConfig.getConfig()
|
||
|
.then((configArg) => __awaiter(this, void 0, void 0, function* () {
|
||
|
plugins.beautylog.log('Now checking for needed global npm tools...');
|
||
|
for (let npmTool of configArg.globalNpmTools) {
|
||
|
plugins.beautylog.info(`Checking for global "${npmTool}"`);
|
||
|
let whichOutput = yield npmci_bash_1.bashNoError(`which ${npmTool}`);
|
||
|
let toolAvailable = !((/not\sfound/.test(whichOutput)) || whichOutput === '');
|
||
|
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!');
|
||
|
}));
|
||
|
});
|
||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi90cy9tb2Rfbm9kZS9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7O0FBQUEsNENBQTJDO0FBQzNDLCtDQUE4QztBQUM5Qyw4Q0FLc0I7QUFFdEI7OztHQU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