2018-04-04 20:25:13 +00:00
|
|
|
import * as plugins from './mod.plugins';
|
|
|
|
import * as configModule from '../npmci.config';
|
2018-05-27 12:34:38 +00:00
|
|
|
import { bash, bashNoError, nvmAvailable } 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 >= 2) {
|
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();
|
|
|
|
break;
|
2017-08-27 13:24:17 +00:00
|
|
|
case 'prepare':
|
2018-04-04 20:25:13 +00:00
|
|
|
await prepare();
|
|
|
|
break;
|
2017-08-27 13:24:17 +00:00
|
|
|
case 'test':
|
2018-04-04 20:25:13 +00:00
|
|
|
await test();
|
|
|
|
break;
|
2017-08-28 11:08:21 +00:00
|
|
|
case 'publish':
|
2018-04-04 20:25:13 +00:00
|
|
|
await publish();
|
|
|
|
break;
|
2017-08-27 13:24:17 +00:00
|
|
|
default:
|
2018-04-04 20:25:13 +00:00
|
|
|
plugins.beautylog.error(`>>npmci npm ...<< 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.log(
|
|
|
|
`>>npmci npm ...<< 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-08-27 13:24:17 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* authenticates npm with token from env var
|
|
|
|
*/
|
|
|
|
let prepare = async () => {
|
2018-04-04 20:25:13 +00:00
|
|
|
let npmrcPrefix: string = '//registry.npmjs.org/:_authToken=';
|
|
|
|
let npmToken: string = process.env.NPMCI_TOKEN_NPM;
|
|
|
|
let npmrcFileString: string = npmrcPrefix + npmToken;
|
2017-08-27 13:24:17 +00:00
|
|
|
if (npmToken) {
|
2018-04-04 20:25:13 +00:00
|
|
|
plugins.beautylog.info('found access token');
|
2017-08-27 13:24:17 +00:00
|
|
|
} else {
|
2018-04-04 20:25:13 +00:00
|
|
|
plugins.beautylog.error('no access token found! Exiting!');
|
|
|
|
process.exit(1);
|
2017-08-27 13:24:17 +00:00
|
|
|
}
|
2018-04-04 20:25:13 +00:00
|
|
|
plugins.smartfile.memory.toFsSync(npmrcFileString, '/root/.npmrc');
|
|
|
|
return;
|
|
|
|
};
|
2017-08-27 13:24:17 +00:00
|
|
|
|
2018-04-04 20:43:15 +00:00
|
|
|
/**
|
|
|
|
* publish a package to npm
|
|
|
|
*/
|
2017-08-28 11:08:21 +00:00
|
|
|
let publish = async () => {
|
2018-04-04 20:25:13 +00:00
|
|
|
let npmAccessCliString = ``;
|
|
|
|
const config = await configModule.getConfig();
|
2018-04-29 14:12:32 +00:00
|
|
|
|
|
|
|
// -> configure package access level
|
2018-04-04 20:25:13 +00:00
|
|
|
if (
|
|
|
|
config.npmAccessLevel &&
|
|
|
|
(config.npmAccessLevel === 'public' || config.npmAccessLevel === 'private')
|
|
|
|
) {
|
|
|
|
npmAccessCliString = `--access=${config.npmAccessLevel}`;
|
|
|
|
}
|
2018-04-29 14:12:32 +00:00
|
|
|
|
2018-05-03 18:40:26 +00:00
|
|
|
// -> preparing
|
2018-05-03 21:52:51 +00:00
|
|
|
plugins.beautylog.log(`now preparing environment:`);
|
2018-05-03 18:40:26 +00:00
|
|
|
prepare();
|
|
|
|
await bash(`npm -v`);
|
|
|
|
|
2018-04-29 14:12:32 +00:00
|
|
|
// -> build it
|
2018-05-27 12:34:38 +00:00
|
|
|
await bash(`npm install`);
|
|
|
|
await bash(`npm run build`);
|
2018-04-29 14:12:32 +00:00
|
|
|
|
2018-05-03 21:52:51 +00:00
|
|
|
plugins.beautylog.success(`Nice!!! The build for the publication was successfull!`);
|
2018-05-04 13:58:11 +00:00
|
|
|
plugins.beautylog.log(`Lets clean up so we don't publish any packages that don't belong to us:`);
|
2018-05-03 21:52:51 +00:00
|
|
|
// -> clean up before we publish stuff
|
2018-05-27 13:41:58 +00:00
|
|
|
await bashNoError(`rm -r ./.npmci_cache`);
|
|
|
|
await bash(`rm -r ./node_modules`);
|
2018-05-03 21:52:51 +00:00
|
|
|
|
|
|
|
plugins.beautylog.success(`Cleaned up!:`);
|
|
|
|
|
2018-04-29 14:12:32 +00:00
|
|
|
// -> publish it
|
2018-05-03 18:40:26 +00:00
|
|
|
plugins.beautylog.log(`now invoking npm to publish the package!`);
|
2018-04-04 20:25:13 +00:00
|
|
|
await bash(`npm publish ${npmAccessCliString}`);
|
2018-05-03 18:07:49 +00:00
|
|
|
plugins.beautylog.success(`Package was successfully published!`);
|
2018-04-04 20:25:13 +00:00
|
|
|
};
|
2017-08-28 11:08:21 +00:00
|
|
|
|
2017-08-27 13:24:17 +00:00
|
|
|
let install = async (): Promise<void> => {
|
2018-04-04 20:25:13 +00:00
|
|
|
plugins.beautylog.info('now installing dependencies:');
|
2018-05-27 12:34:38 +00:00
|
|
|
await bash('npm install');
|
2018-04-04 20:25:13 +00:00
|
|
|
};
|
2017-08-27 13:24:17 +00:00
|
|
|
|
|
|
|
export let test = async (): Promise<void> => {
|
2018-04-04 20:25:13 +00:00
|
|
|
plugins.beautylog.info('now starting tests:');
|
2018-05-27 12:34:38 +00:00
|
|
|
await bash('npm test');
|
2018-04-04 20:25:13 +00:00
|
|
|
};
|