Skip to content

Commit

Permalink
Simplify nsp setup
Browse files Browse the repository at this point in the history
  • Loading branch information
SBoudrias committed Dec 25, 2016
1 parent 7ec1c65 commit e671614
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 34 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ That'll generate a project with all the common tools setup. This includes:
- [Babel](https://babeljs.io/) ES2015 transpiler
- [mocha](http://mochajs.org/) unit test
- [ESLint](http://eslint.org/) linting and code style checking
- [nsp](https://nodesecurity.io/) known vulnerability check
- [Istanbul](https://gotwarlost.github.io/istanbul/) code coverage (optionally tracked on [Coveralls](https://coveralls.io/))
- [Travis CI](https://travis-ci.org/) continuous integration (optional)
- [License](https://spdx.org/licenses/)
Expand Down
1 change: 1 addition & 0 deletions generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ module.exports = Generator.extend({
}

this.composeWith(require.resolve('../editorconfig'));
this.composeWith(require.resolve('../nsp'));

this.composeWith(require.resolve('../eslint'), {
es2015: this.props.babel
Expand Down
3 changes: 1 addition & 2 deletions generators/gulp/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ module.exports = Generator.extend({
'gulp-istanbul': '^1.1.1',
'gulp-line-ending-corrector': '^1.0.1',
'gulp-mocha': '^3.0.1',
'gulp-nsp': '^2.4.2',
'gulp-plumber': '^1.1.0'
},
scripts: {
Expand Down Expand Up @@ -84,7 +83,7 @@ module.exports = Generator.extend({

gulpfile: function () {
var tasks = ['static', 'test'];
var prepublishTasks = ['nsp'];
var prepublishTasks = [];

if (this.options.coveralls) {
tasks.push('coveralls');
Expand Down
5 changes: 0 additions & 5 deletions generators/gulp/templates/gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ var eslint = require('gulp-eslint');
var excludeGitignore = require('gulp-exclude-gitignore');
var mocha = require('gulp-mocha');
var istanbul = require('gulp-istanbul');
var nsp = require('gulp-nsp');
var plumber = require('gulp-plumber');
<% if (includeCoveralls) { -%>
var coveralls = require('gulp-coveralls');
Expand All @@ -33,10 +32,6 @@ gulp.task('static', function () {
.pipe(eslint.failAfterError());
});

gulp.task('nsp', function (cb) {
nsp({package: path.resolve('package.json')}, cb);
});

gulp.task('pre-test', function () {
return gulp.src('<%- projectRoot %>')
.pipe(excludeGitignore())
Expand Down
27 changes: 27 additions & 0 deletions generators/nsp/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict';
var Generator = require('yeoman-generator');
var rootPkg = require('../../package.json');

module.exports = class extends Generator {
constructor(args, options) {
super(args, options);

this.option('generateInto', {
type: String,
required: false,
defaults: '',
desc: 'Relocate the location of the generated files.'
});
}

writing() {
this.fs.extendJSON(this.destinationPath(this.options.generateInto, 'package.json'), {
devDependencies: {
nsp: rootPkg.devDependencies.nsp
},
scripts: {
prepublish: 'nsp'
}
});
}
};
7 changes: 0 additions & 7 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
'use strict';
var path = require('path');
var gulp = require('gulp');
var eslint = require('gulp-eslint');
var excludeGitignore = require('gulp-exclude-gitignore');
var mocha = require('gulp-mocha');
var istanbul = require('gulp-istanbul');
var nsp = require('gulp-nsp');
var plumber = require('gulp-plumber');

gulp.task('static', function () {
Expand All @@ -16,10 +14,6 @@ gulp.task('static', function () {
.pipe(eslint.failAfterError());
});

gulp.task('nsp', function (cb) {
nsp({package: path.resolve('package.json')}, cb);
});

gulp.task('pre-test', function () {
return gulp.src(['**/*.js', '!**/templates/**'])
.pipe(excludeGitignore())
Expand Down Expand Up @@ -48,5 +42,4 @@ gulp.task('watch', function () {
gulp.watch(['**/*.js', 'test/**'], ['test']);
});

gulp.task('prepublish', ['nsp']);
gulp.task('default', ['static', 'test']);
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
"repository": "yeoman/generator-node",
"scripts": {
"test": "gulp",
"prepublish": "gulp prepublish"
"prepublish": "nsp"
},
"dependencies": {
"generator-license": "^4.0.0",
"generator-travis": "^1.1.3",
"git-remote-origin-url": "^2.0.0",
"github-username": "^3.0.0",
"inquirer-npm-name": "^2.0.0",
"lodash": "^4.3.0",
"lodash": "^4.17.3",
"parse-author": "^1.0.0",
"yeoman-generator": "^1.0.1"
},
Expand All @@ -36,10 +36,10 @@
"gulp-exclude-gitignore": "^1.0.0",
"gulp-istanbul": "^1.1.1",
"gulp-mocha": "^3.0.1",
"gulp-nsp": "^2.4.2",
"gulp-plumber": "^1.1.0",
"mocha": "^3.1.2",
"mockery": "^2.0.0",
"nsp": "^2.6.2",
"pinkie-promise": "^2.0.1",
"yeoman-assert": "^2.2.1",
"yeoman-test": "^1.5.1"
Expand Down
4 changes: 2 additions & 2 deletions test/gulp.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ describe('node:gulp', function () {

it('includes babel configuration', function () {
assert.fileContent('gulpfile.js', 'gulp.task(\'babel\'');
assert.fileContent('gulpfile.js', 'gulp.task(\'prepublish\', [\'nsp\', \'babel\']);');
assert.fileContent('gulpfile.js', 'gulp.task(\'prepublish\', [\'babel\']);');
assert.fileContent('package.json', 'gulp-babel');
assert.fileContent('.gitignore', 'dist');
});
Expand Down Expand Up @@ -174,7 +174,7 @@ describe('node:gulp', function () {

it('includes babel configuration', function () {
assert.fileContent('other/gulpfile.js', 'gulp.task(\'babel\'');
assert.fileContent('other/gulpfile.js', 'gulp.task(\'prepublish\', [\'nsp\', \'babel\']);');
assert.fileContent('other/gulpfile.js', 'gulp.task(\'prepublish\', [\'babel\']);');
assert.fileContent('other/package.json', 'gulp-babel');
assert.fileContent('other/.gitignore', 'dist');
});
Expand Down
20 changes: 20 additions & 0 deletions test/nsp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';
var path = require('path');
var assert = require('yeoman-assert');
var helpers = require('yeoman-test');
var rootPkg = require('../package.json');

describe('node:nsp', function () {
it('setup nsp in project', function () {
return helpers.run(path.join(__dirname, '../generators/nsp')).then(function () {
assert.jsonFileContent('package.json', {
devDependencies: {
nsp: rootPkg.devDependencies.nsp
},
scripts: {
prepublish: 'nsp'
}
});
});
});
});
22 changes: 7 additions & 15 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,7 @@ beeper@^1.0.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/beeper/-/beeper-1.1.1.tgz#e6d5ea8c5dad001304a70b22638447f69cb2f809"

"binaryextensions@1 || 2":
version "2.0.0"
resolved "https://registry.yarnpkg.com/binaryextensions/-/binaryextensions-2.0.0.tgz#e597d1a7a6a3558a2d1c7241a16c99965e6aa40f"

binaryextensions@~1.0.0:
"binaryextensions@1 || 2", binaryextensions@~1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/binaryextensions/-/binaryextensions-1.0.1.tgz#1e637488b35b58bda5f4774bf96a5212a8c90755"

Expand Down Expand Up @@ -2277,9 +2273,9 @@ lodash@^3.2.0, lodash@^3.6.0:
version "3.10.1"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-3.10.1.tgz#5bf45e8e49ba4189e17d482789dfd15bd140b7b6"

lodash@^4.0.0, lodash@^4.11.1, lodash@^4.14.0, lodash@^4.17.2, lodash@^4.3.0, lodash@^4.6.1:
version "4.17.2"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.2.tgz#34a3055babe04ce42467b607d700072c7ff6bf42"
lodash@^4.0.0, lodash@^4.11.1, lodash@^4.14.0, lodash@^4.17.2, lodash@^4.17.3, lodash@^4.3.0, lodash@^4.6.1:
version "4.17.3"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.3.tgz#557ed7d2a9438cac5fd5a43043ca60cb455e01f7"

lodash@~1.0.1:
version "1.0.2"
Expand Down Expand Up @@ -2532,7 +2528,7 @@ npm-name@^3.0.0:
lodash.zip "^4.0.0"
registry-url "^3.0.0"

nsp@^2.0.0:
nsp@^2.0.0, nsp@^2.6.2:
version "2.6.2"
resolved "https://registry.yarnpkg.com/nsp/-/nsp-2.6.2.tgz#93dfb4c5b2885cc354d8ca18b73f09e52b9c8b16"
dependencies:
Expand Down Expand Up @@ -3298,11 +3294,7 @@ text-table@^0.2.0, text-table@~0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/text-table/-/text-table-0.2.0.tgz#7f5ee823ae805207c00af2df4a84ec3fcfa570b4"

"textextensions@1 || 2":
version "2.0.1"
resolved "https://registry.yarnpkg.com/textextensions/-/textextensions-2.0.1.tgz#be8cf22d65379c151319f88f0335ad8f667abdca"

textextensions@~1.0.0:
"textextensions@1 || 2", textextensions@~1.0.0:
version "1.0.2"
resolved "https://registry.yarnpkg.com/textextensions/-/textextensions-1.0.2.tgz#65486393ee1f2bb039a60cbba05b0b68bd9501d2"

Expand Down Expand Up @@ -3799,7 +3791,7 @@ yeoman-generator@^0.24.1:
yeoman-test "^1.0.0"
yeoman-welcome "^1.0.0"

yeoman-generator@^1.0.0:
yeoman-generator@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/yeoman-generator/-/yeoman-generator-1.0.1.tgz#68992724f54a30c506d178fa8b756b115b7b64fe"
dependencies:
Expand Down

0 comments on commit e671614

Please sign in to comment.