Skip to content

Instantly share code, notes, and snippets.

@bjankord
Last active February 24, 2017 11:53
Show Gist options
  • Save bjankord/c5d1b0a578a2c7122e8e1a906f0ab1bd to your computer and use it in GitHub Desktop.
Save bjankord/c5d1b0a578a2c7122e8e1a906f0ab1bd to your computer and use it in GitHub Desktop.
"scripts": {
"compile": "node ../../scripts/compile.js",
"lint": "node ../../scripts/lint.js",
"pretest": "node ../../scripts/pretest.js",
"release:major": "npm test && npm run compile && npm version major -m \"Released version %s\" && npm publish && git push",
"release:minor": "npm test && npm run compile && npm version minor -m \"Released version %s\" && npm publish && git push",
"release:patch": "npm test && npm run compile && npm version patch -m \"Released version %s\" && npm publish && git push",
"test": "node ../../scripts/test.js"
}
const shell = require('shelljs');
// Paths are relative to location script is called from
// Uncomment next line to view work directory scripts are executed from
// shell.exec('pwd');
shell.exec('npm run lint');
const shell = require('shelljs');
// Paths are relative to location script is called from
// Uncomment next line to view work directory scripts are executed from
// shell.exec('pwd');
shell.exec('../../node_modules/.bin/eslint **/*.js, **/*.jsx');
if (shell.exec('../../node_modules/.bin/eslint **/*.js, **/*.jsx').code !== 0) {
shell.echo('Error: JS lint errors detected');
shell.exit(1);
}
shell.exec('../../node_modules/.bin/eslint **/*.js, **/*.jsx', function(code, stdout, stderr) {
if (code !== 0) {
process.exit(1);
}
// console.log('Exit code:', code);
// console.log('Program output:', stdout);
// console.log('Program stderr:', stderr);
});
const shell = require('shelljs');
// Paths are relative to location script is called from
// Uncomment next line to view work directory scripts are executed from
// shell.exec('pwd');
shell.exec('../../node_modules/.bin/jest --config ../../jestconfig.json');
@bjankord
Copy link
Author

I'm running into an issue when pretest.js is run. If there is lint, it will report in the output but continue on to running tests. I've tried thowing and error and exiting the node process with no luck.

if (shell.exec('../../node_modules/.bin/eslint **/*.js, **/*.jsx').code !== 0) {
  shell.echo('Error: Style lint errors detected');
  shell.exit(1);
}

shell.exec('../../node_modules/.bin/eslint **/*.js, **/*.jsx', function(code, stdout, stderr) {
  if (code !== 0) {
    process.exit(1);
  }
  // console.log('Exit code:', code);
  // console.log('Program output:', stdout);
  // console.log('Program stderr:', stderr);
});

@bjankord
Copy link
Author

Using the following in lint.js

shell.exec('../../node_modules/.bin/eslint **/*.js, **/*.jsx', function(code, stdout, stderr) {
  if (code !== 0) {
    shell.exit(code);
  }
});

And call npm run lint in the npm-script "pretest" rather than node ../../scripts/pretest.js seems to cause the script to error out correctly if there is lint rather than moving on to running tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment