2018-04-04 20:25:13 +00:00
|
|
|
import * as plugins from '../npmci.plugins';
|
|
|
|
import * as npmciConfig from '../npmci.config';
|
|
|
|
import { bash, bashNoError, nvmAvailable, yarnAvailable } from '../npmci.bash';
|
2017-08-27 13:24:17 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* handle cli input
|
|
|
|
* @param argvArg
|
|
|
|
*/
|
2018-04-04 20:25:13 +00:00
|
|
|
export let handleCli = async argvArg => {
|
2017-08-27 13:24:17 +00:00
|
|
|
if (argvArg._.length >= 3) {
|
2018-04-04 20:25:13 +00:00
|
|
|
let action: string = argvArg._[1];
|
2017-08-27 13:24:17 +00:00
|
|
|
switch (action) {
|
|
|
|
case 'install':
|
2018-04-04 20:25:13 +00:00
|
|
|
await install(argvArg._[2]);
|
|
|
|
break;
|
2017-08-27 13:24:17 +00:00
|
|
|
default:
|
2018-04-04 20:25:13 +00:00
|
|
|
plugins.beautylog.error(`>>npmci node ...<< action >>${action}<< not supported`);
|
|
|
|
process.exit(1);
|
2017-08-27 13:24:17 +00:00
|
|
|
}
|
|
|
|
} else {
|
2018-04-04 20:25:13 +00:00
|
|
|
plugins.beautylog.error(
|
|
|
|
`>>npmci node ...<< cli arguments invalid... Please read the documentation.`
|
|
|
|
);
|
|
|
|
process.exit(1);
|
2017-08-27 13:24:17 +00:00
|
|
|
}
|
2018-04-04 20:25:13 +00:00
|
|
|
};
|
2017-03-08 13:50:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Install a specific version of node
|
|
|
|
* @param versionArg
|
|
|
|
*/
|
2018-04-04 20:25:13 +00:00
|
|
|
export let install = async versionArg => {
|
|
|
|
plugins.beautylog.log(`now installing node version ${versionArg}`);
|
|
|
|
let version: string;
|
2017-02-19 13:46:05 +00:00
|
|
|
if (versionArg === 'stable') {
|
2018-04-04 20:25:13 +00:00
|
|
|
version = 'stable';
|
2017-02-19 13:46:05 +00:00
|
|
|
} else if (versionArg === 'lts') {
|
2018-04-04 20:25:13 +00:00
|
|
|
version = '8';
|
2017-02-19 13:46:05 +00:00
|
|
|
} else if (versionArg === 'legacy') {
|
2018-04-04 20:25:13 +00:00
|
|
|
version = '8';
|
2017-02-19 13:46:05 +00:00
|
|
|
} else {
|
2018-04-04 20:25:13 +00:00
|
|
|
version = versionArg;
|
2017-08-27 13:24:17 +00:00
|
|
|
}
|
2017-03-11 00:10:37 +00:00
|
|
|
if (await nvmAvailable.promise) {
|
2018-04-04 20:25:13 +00:00
|
|
|
await bash(`nvm install ${version} && nvm alias default ${version}`);
|
|
|
|
plugins.beautylog.success(`Node version ${version} successfully installed!`);
|
2017-02-19 13:46:05 +00:00
|
|
|
} else {
|
2018-04-04 20:25:13 +00:00
|
|
|
plugins.beautylog.warn('Nvm not in path so staying at installed node version!');
|
2017-08-27 13:24:17 +00:00
|
|
|
}
|
2018-04-04 20:25:13 +00:00
|
|
|
await bash('node -v');
|
|
|
|
await bash('npm -v');
|
2017-02-19 13:46:05 +00:00
|
|
|
// lets look for further config
|
2018-04-04 20:25:13 +00:00
|
|
|
await npmciConfig.getConfig().then(async configArg => {
|
|
|
|
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: string = await bashNoError(`which ${npmTool}`);
|
|
|
|
let toolAvailable: boolean = !(/not\sfound/.test(whichOutput) || whichOutput === '');
|
|
|
|
if (toolAvailable) {
|
|
|
|
plugins.beautylog.log(`Tool ${npmTool} is available`);
|
|
|
|
} else {
|
|
|
|
plugins.beautylog.info(`globally installing ${npmTool} from npm`);
|
|
|
|
if (await yarnAvailable.promise) {
|
|
|
|
await bash(`yarn global add ${npmTool}`);
|
2017-02-19 13:46:05 +00:00
|
|
|
} else {
|
2018-04-04 20:25:13 +00:00
|
|
|
await bash(`npm install ${npmTool} -q -g`);
|
2017-02-19 13:46:05 +00:00
|
|
|
}
|
|
|
|
}
|
2018-04-04 20:25:13 +00:00
|
|
|
}
|
|
|
|
plugins.beautylog.success('all global npm tools specified in npmextra.json are now available!');
|
|
|
|
});
|
|
|
|
};
|