Skip to content

Commit

Permalink
Adds npm publish script.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rick Harrison committed Jul 20, 2016
1 parent 0c88498 commit be19a5a
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
.nyc_output
coverage.lcov
coverage
9 changes: 9 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
node_modules
.nyc_output
coverage.lcov
coverage

.eslintrc
circle.yml
scripts
tests
34 changes: 34 additions & 0 deletions scripts/release.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'use strict';

/* eslint no-console: 0, no-sync: 0, no-process-exit: 0 */

const execSync = require('child_process').execSync;
const fs = require('fs');
const packageJson = require('../package.json');

const nextVersion = process.argv[process.argv.length - 1];
const nextRef = `v${nextVersion}`;
const semverRegex = /[0-9]+\.[0-9]+\.[0-9](-.+)?/ig;

function validateSemver (version) {
if (!semverRegex.test(version)) {
console.error(`Version ${version} is not valid! It must be a valid semver string`);
process.exit(1);
}
}

validateSemver(nextVersion);

console.log(`Current Version: ${packageJson.version}`);
console.log(`Next Version: ${nextVersion}`);

packageJson.version = nextVersion;

fs.writeFileSync('package.json', `${JSON.stringify(packageJson, null, 2)}\n`, 'utf8');

execSync(`git commit -am 'Release Version: ${nextRef}'`);
execSync(`git tag ${nextRef}`);
execSync('git push origin master');
execSync(`git push origin ${nextRef}`);

execSync('npm publish', { stdio: [0, 1, 2] });

0 comments on commit be19a5a

Please sign in to comment.