Skip to content
This repository has been archived by the owner on Feb 2, 2023. It is now read-only.

Commit

Permalink
fix: verify travis npm publis process
Browse files Browse the repository at this point in the history
  • Loading branch information
klemenoslaj committed Apr 19, 2019
1 parent f5bc07e commit ab75d6c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@
"packages": "dist",
"plugins": [
"./scripts/release.js",
"@semantic-release/github",
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator"
"@semantic-release/commit-analyzer"
]
},
"config": {
Expand Down
27 changes: 19 additions & 8 deletions scripts/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,38 @@ const shell = require('shelljs');

async function prepare({ packages }, context) {
const PLACEHOLDER_VERSION = '0.0.0-development';
const { nextRelease: { version }, logger } = context;
const { nextRelease: { version }, logger, env } = context;

shell
.ls(`${packages}/*/package.json`)
.forEach(file => {
shell.exec(`npm version ${version} --no-git-tag-version`, { cwd: dirname(file) });
shell.exec(`npm version ${version} --no-git-tag-version`, { cwd: dirname(file), env });
shell.sed('-i', PLACEHOLDER_VERSION, version, file);
logger.log(`Write version ${version} to package.json in ${file}`);
});
}

async function publish({ packages }, context) {
const { logger } = context;
const { logger, env } = context;

if (!env.NPM_TOKEN) {
throw new Error('NPM_TOKEN environment');
}

shell
.ls(`${packages}/*/package.json`)
.map(file => ({ pkgPath: dirname(file), package: JSON.parse(shell.cat(file)) }))
.forEach(({ pkgPath: packagePath, package }) => {
shell.exec(`npm publish ${packagePath} --access public`, { cwd: packagePath });
.ls(`${packages}/*/package.json`)
.map(file => ({ pkgPath: dirname(file), package: JSON.parse(shell.cat(file)) }))
.forEach(({ pkgPath: cwd, package }) => {
const config = `${cwd}/.npmrc`;
shell.ShellString('//registry.npmjs.org/:_authToken = ${NPM_TOKEN}').to(config);
logger.log(`Wrote NPM_TOKEN to ${config}`);

if (shell.exec(`npm publish --access public`, { cwd, env }).code === 0) {
logger.log(`Published ${package.name}@${package.version}.`);
});
} else {
throw new Error(`The release of ${package.name} failed.`);
}
});
}

module.exports = { prepare, publish };

0 comments on commit ab75d6c

Please sign in to comment.