Skip to content

Commit 602343a

Browse files
committed
[added] 'skipBuildStep' special case option
1 parent bb7ae94 commit 602343a

File tree

2 files changed

+42
-16
lines changed

2 files changed

+42
-16
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,22 @@ Then you can do it as simple as adding this option to your `package.json`
102102
```
103103
and that's all.
104104

105+
#### The special case. `build` step in `tests` step.
106+
107+
If you run building scripts within your `npm run test` step, e.g.
108+
```json
109+
"scripts": {
110+
"test": "npm run lint && npm run build && npm run tests-set",
111+
}
112+
```
113+
then you can disable superfluous `npm run build` step running
114+
by setting `'release-script'.skipBuildStep` option:
115+
```json
116+
"release-script": {
117+
"skipBuildStep": "true"
118+
}
119+
```
120+
105121
#### Options
106122

107123
All options for this package are kept under `'release-script'` node in your project's `package.json`

src/release.js

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ const githubToken = process.env.GITHUB_TOKEN;
4747

4848
const altPkgRootFolder = configOptions.altPkgRootFolder;
4949

50+
const skipBuildStep = configOptions.skipBuildStep;
51+
5052
//------------------------------------------------------------------------------
5153
// command line options
5254
const yargsConf = yargs
@@ -151,6 +153,18 @@ function getOwnerAndRepo(url) {
151153
return (gitUrlBase || url).split('/');
152154
}
153155

156+
function runAndGitRevertOnError(cmd) {
157+
const res = exec(cmd);
158+
if (res.code !== 0) {
159+
// if error, then revert and exit
160+
console.log(`"${cmd}" command failed, reverting version bump`.red);
161+
run('git reset HEAD .');
162+
run('git checkout package.json');
163+
console.log('Version bump reverted'.red);
164+
printErrorAndExit(res.output);
165+
}
166+
}
167+
154168
function releaseAdRepo(repo, srcFolder, tmpFolder, vVersion) {
155169
if (!repo || !srcFolder || !tmpFolder || !vVersion) {
156170
printErrorAndExit('Bug error. Create github issue: releaseAdRepo - One of parameters is not set.');
@@ -188,11 +202,6 @@ function release({ type, preid, npmTagName }) {
188202
}
189203
console.info('Current with latest changes from remote'.cyan);
190204

191-
// check linting and tests
192-
console.log('Running: '.cyan + 'linting and tests'.green);
193-
run('npm run test');
194-
console.log('Completed: '.cyan + 'linting and tests'.green);
195-
196205
// version bump
197206
const oldVersion = npmjson.version;
198207
let newVersion;
@@ -215,21 +224,22 @@ function release({ type, preid, npmTagName }) {
215224
console.log('Version changed from '.cyan + oldVersion.green + ' to '.cyan + newVersion.green);
216225
safeRun('git add package.json');
217226

227+
// npm run test
228+
// this step is placed after version bumping
229+
// for the case when documents are been built in "npm run test" script
230+
console.log('Running: '.cyan + '"npm run test"'.green);
231+
config.silent = !skipBuildStep;
232+
runAndGitRevertOnError('npm run test');
233+
config.silent = !argv.verbose;
234+
console.log('Completed: '.cyan + '"npm run test"'.green);
235+
218236
// npm run build
219-
if (npmjson.scripts.build) {
237+
if (npmjson.scripts.build && !skipBuildStep) {
220238
console.log('Running: '.cyan + 'build'.green);
221-
const res = exec('npm run build');
222-
if (res.code !== 0) {
223-
// if error, then revert and exit
224-
console.log('Build failed, reverting version bump'.red);
225-
run('git reset HEAD .');
226-
run('git checkout package.json');
227-
console.log('Version bump reverted'.red);
228-
printErrorAndExit(res.output);
229-
}
239+
runAndGitRevertOnError('npm run build');
230240
console.log('Completed: '.cyan + 'build'.green);
231241
} else {
232-
console.log('There is no "build" script in package.json. Skipping this step.'.yellow);
242+
console.log('Skipping "npm run build" step.'.yellow);
233243
}
234244

235245
const vVersion = `v${newVersion}`;

0 commit comments

Comments
 (0)