Skip to content

Commit

Permalink
[added] 'skipBuildStep' special case option
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexKVal committed Sep 16, 2015
1 parent bb7ae94 commit 602343a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 16 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,22 @@ Then you can do it as simple as adding this option to your `package.json`
```
and that's all.

#### The special case. `build` step in `tests` step.

If you run building scripts within your `npm run test` step, e.g.
```json
"scripts": {
"test": "npm run lint && npm run build && npm run tests-set",
}
```
then you can disable superfluous `npm run build` step running
by setting `'release-script'.skipBuildStep` option:
```json
"release-script": {
"skipBuildStep": "true"
}
```

#### Options

All options for this package are kept under `'release-script'` node in your project's `package.json`
Expand Down
42 changes: 26 additions & 16 deletions src/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ const githubToken = process.env.GITHUB_TOKEN;

const altPkgRootFolder = configOptions.altPkgRootFolder;

const skipBuildStep = configOptions.skipBuildStep;

//------------------------------------------------------------------------------
// command line options
const yargsConf = yargs
Expand Down Expand Up @@ -151,6 +153,18 @@ function getOwnerAndRepo(url) {
return (gitUrlBase || url).split('/');
}

function runAndGitRevertOnError(cmd) {
const res = exec(cmd);
if (res.code !== 0) {
// if error, then revert and exit
console.log(`"${cmd}" command failed, reverting version bump`.red);
run('git reset HEAD .');
run('git checkout package.json');
console.log('Version bump reverted'.red);
printErrorAndExit(res.output);
}
}

function releaseAdRepo(repo, srcFolder, tmpFolder, vVersion) {
if (!repo || !srcFolder || !tmpFolder || !vVersion) {
printErrorAndExit('Bug error. Create github issue: releaseAdRepo - One of parameters is not set.');
Expand Down Expand Up @@ -188,11 +202,6 @@ function release({ type, preid, npmTagName }) {
}
console.info('Current with latest changes from remote'.cyan);

// check linting and tests
console.log('Running: '.cyan + 'linting and tests'.green);
run('npm run test');
console.log('Completed: '.cyan + 'linting and tests'.green);

// version bump
const oldVersion = npmjson.version;
let newVersion;
Expand All @@ -215,21 +224,22 @@ function release({ type, preid, npmTagName }) {
console.log('Version changed from '.cyan + oldVersion.green + ' to '.cyan + newVersion.green);
safeRun('git add package.json');

// npm run test
// this step is placed after version bumping
// for the case when documents are been built in "npm run test" script
console.log('Running: '.cyan + '"npm run test"'.green);
config.silent = !skipBuildStep;
runAndGitRevertOnError('npm run test');
config.silent = !argv.verbose;
console.log('Completed: '.cyan + '"npm run test"'.green);

// npm run build
if (npmjson.scripts.build) {
if (npmjson.scripts.build && !skipBuildStep) {
console.log('Running: '.cyan + 'build'.green);
const res = exec('npm run build');
if (res.code !== 0) {
// if error, then revert and exit
console.log('Build failed, reverting version bump'.red);
run('git reset HEAD .');
run('git checkout package.json');
console.log('Version bump reverted'.red);
printErrorAndExit(res.output);
}
runAndGitRevertOnError('npm run build');
console.log('Completed: '.cyan + 'build'.green);
} else {
console.log('There is no "build" script in package.json. Skipping this step.'.yellow);
console.log('Skipping "npm run build" step.'.yellow);
}

const vVersion = `v${newVersion}`;
Expand Down

0 comments on commit 602343a

Please sign in to comment.