fix(core): update

This commit is contained in:
Philipp Kunz 2018-12-09 02:50:00 +01:00
parent a1876963a8
commit 74c1324e55
2 changed files with 24 additions and 6 deletions

View File

@ -37,15 +37,23 @@ export let handleCli = async argvArg => {
* authenticates npm with token from env var * authenticates npm with token from env var
*/ */
const prepare = async () => { const prepare = async () => {
const npmrcPrefix: string = '//registry.npmjs.org/:_authToken='; const config = await configModule.getConfig();
const npmToken: string = process.env.NPMCI_TOKEN_NPM; let npmrcFileString: string = '';
const npmrcFileString: string = npmrcPrefix + npmToken; plugins.smartparam.forEachMinimatch(process.env, 'NPMCI_TOKEN_NPM*', npmEnvArg => {
if (npmToken) { const npmRegistryUrl = npmEnvArg.split('|')[0];
logger.log('info', 'found access token'); const npmToken = npmEnvArg.split('|')[1];
npmrcFileString = `//${npmRegistryUrl}/:_authToken="${npmToken}"\n`;
});
if (npmrcFileString.length > 0) {
logger.log('info', 'found one or more access tokens');
logger.log('info', `setting default npm registry to ${config.npmRegistryUrl}`);
await bash(`npm set registry https:${config.npmRegistryUrl}`);
} else { } else {
logger.log('error', 'no access token found! Exiting!'); logger.log('error', 'no access token found! Exiting!');
process.exit(1); process.exit(1);
} }
plugins.smartfile.memory.toFsSync(npmrcFileString, '/root/.npmrc'); plugins.smartfile.memory.toFsSync(npmrcFileString, '/root/.npmrc');
return; return;
}; };
@ -55,6 +63,7 @@ const prepare = async () => {
*/ */
const publish = async () => { const publish = async () => {
let npmAccessCliString = ``; let npmAccessCliString = ``;
let npmRegistryCliString = ``;
const config = await configModule.getConfig(); const config = await configModule.getConfig();
// -> configure package access level // -> configure package access level
@ -65,6 +74,14 @@ const publish = async () => {
npmAccessCliString = `--access=${config.npmAccessLevel}`; npmAccessCliString = `--access=${config.npmAccessLevel}`;
} }
// -> configure registry url
if (config.npmRegistryUrl) {
npmAccessCliString = `--registry=${config.npmRegistryUrl}`;
} else {
logger.log('error', `no registry url specified. Can't publish!`);
process.exit(1);
}
// -> preparing // -> preparing
logger.log('info', `now preparing environment:`); logger.log('info', `now preparing environment:`);
prepare(); prepare();
@ -84,7 +101,7 @@ const publish = async () => {
// -> publish it // -> publish it
logger.log('info', `now invoking npm to publish the package!`); logger.log('info', `now invoking npm to publish the package!`);
await bash(`npm publish ${npmAccessCliString}`); await bash(`npm publish ${npmAccessCliString} ${npmRegistryCliString}`);
logger.log('success', `Package was successfully published!`); logger.log('success', `Package was successfully published!`);
}; };

View File

@ -8,6 +8,7 @@ import { KeyValueStore } from '@pushrocks/npmextra';
export interface INpmciOptions { export interface INpmciOptions {
npmGlobalTools: string[]; npmGlobalTools: string[];
npmAccessLevel?: 'private' | 'public'; npmAccessLevel?: 'private' | 'public';
npmRegistryUrl?: string;
dockerRegistryRepoMap: any; dockerRegistryRepoMap: any;
dockerBuildargEnvMap: any; dockerBuildargEnvMap: any;
} }