npmci/dist/mod_node/index.js
2017-10-09 18:10:01 +02:00

87 lines
6.8 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`);
process.exit(1);
}
}
else {
plugins.beautylog.error(`>>npmci node ...<< cli arguments invalid... Please read the documentation.`);
process.exit(1);
}
});
/**
* 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 = '8';
}
else if (versionArg === 'legacy') {
version = '8';
}
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.npmGlobalTools) {
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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi90cy9tb2Rfbm9kZS9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7O0FBQUEsNENBQTJDO0FBQzNDLCtDQUE4QztBQUM5Qyw4Q0FLc0I7QUFFdEI7OztHQUdHO0FBQ1EsUUFBQSxTQUFTLEdBQUcsQ0FBTyxPQUFPLEVBQUUsRUFBRTtJQUN2QyxFQUFFLENBQUMsQ0FBQyxPQUFPLENBQUMsQ0FBQyxDQUFDLE1BQU0sSUFBSSxDQUFDLENBQUMsQ0FBQyxDQUFDO1FBQzFCLElBQUksTUFBTSxHQUFXLE9BQU8sQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUE7UUFDakMsTUFBTSxDQUFDLENBQUMsTUFBTSxDQUFDLENBQUMsQ0FBQztZQUNmLEtBQUssU0FBUztnQkFDWixNQUFNLGVBQU8sQ0FBQyxPQUFPLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUE7Z0JBQzNCLEtBQUssQ0FBQTtZQUNQO2dCQUNFLE9BQU8sQ0FBQyxTQUFTLENBQUMsS0FBSyxDQUFDLCtCQUErQixNQUFNLGtCQUF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