From b2b962e9ea0e386b1bda4deba0eb879e763c71d2 Mon Sep 17 00:00:00 2001 From: Stropho Date: Sun, 8 Oct 2017 23:29:45 +0200 Subject: [PATCH] npm update: scripts/tasks, presets,.. - run tests sequantally from npm scripts - gulp - ignore error in run tasks (so the process doesn't break) - preset-env + spread operator --- .babelrc | 13 ++++++++++++- .eslintrc.json | 5 ++++- gulpfile.babel.js | 36 ++++++++++++++++++++++++++++-------- package.json | 18 ++++++++++++------ 4 files changed, 56 insertions(+), 16 deletions(-) diff --git a/.babelrc b/.babelrc index 1f84844..b7657c1 100644 --- a/.babelrc +++ b/.babelrc @@ -1,6 +1,17 @@ { "presets": [ - "es2015" + [ + "env", { + "targets": { + "node": "current" + } + } + ] + ], + "plugins": [ + "transform-es2015-parameters", + "transform-es2015-destructuring", + "transform-object-rest-spread" ], "env": { "test": { diff --git a/.eslintrc.json b/.eslintrc.json index 00980e7..ffd6337 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -16,7 +16,10 @@ "es6": true }, "parserOptions": { - "sourceType": "module" + "sourceType": "module", + "ecmaFeatures": { + "experimentalObjectRestSpread": true + } }, "extends": "idiomatic" } diff --git a/gulpfile.babel.js b/gulpfile.babel.js index c1dd09d..f80c575 100644 --- a/gulpfile.babel.js +++ b/gulpfile.babel.js @@ -1,14 +1,18 @@ import gulp from 'gulp'; import sourceMaps from 'gulp-sourcemaps'; -import run from 'gulp-run-command' +import run from 'gulp-run-command'; import babel from 'gulp-babel'; import path from 'path'; import del from 'del'; +import fs from 'fs'; +import concat from 'gulp-concat'; +import gulpJsdoc2md from 'gulp-jsdoc-to-markdown'; const paths = { es6Path: './src/**/*.*', es6: [ './src/**/*.js', '!./src/**/*.json' ], es5: './dist', + docs: './jsdoc2md', unitTest: './test/unit/**/*.spec.js', integrationTest: './test/integration/**/*.spec.js', @@ -26,7 +30,7 @@ gulp.task( 'build', [ 'clean:dist', 'copy:nonJs' ], () => { return gulp.src( paths.es6 ) .pipe( sourceMaps.init() ) .pipe( babel( { - presets: [ 'es2015' ] + presets: [ 'env' ] } ) ) .pipe( sourceMaps.write( '.', { sourceRoot: paths.sourceRoot } ) ) .pipe( gulp.dest( paths.es5 ) ); @@ -45,19 +49,35 @@ gulp.task( 'watch', [ 'build' ], () => { } ); gulp.task( 'test:unit', - run(`mocha '${paths.unitTest}' --compilers js:babel-core/register --require './test/mocha.conf.js'`) + run(`mocha '${paths.unitTest}' --compilers js:babel-core/register --require './test/mocha.conf.js'`, + {ignoreErrors: true} + ) ); gulp.task( 'test:integration', - run(`mocha '${paths.integrationTest}' --compilers js:babel-core/register --require './test/mocha.conf.js'`) + run(`mocha '${paths.integrationTest}' --compilers js:babel-core/register --require './test/mocha.conf.js'`, + {ignoreErrors: true} + ) ); -gulp.task( 'test', ['test:unit', 'test:integration']); - - gulp.task( 'test:unit:watch', () => { - gulp.start([ 'test:unit' ]); gulp.watch( [paths.unitTest, paths.es6], [ 'test:unit' ] ); } ); +gulp.task('docs', () => { + return gulp.src(paths.es6) + .pipe(concat('README.md')) + .pipe(gulpJsdoc2md({ + template: fs.readFileSync(`${paths.docs}/README.hbs`, 'utf8'), + partial: [ + `${paths.docs}/contribute.hbs`, + `${paths.docs}/intro.hbs` + ] + })) + .on('error', (err) => { + console.log('jsdoc2md failed:', err.message) + }) + .pipe(gulp.dest('./')) +}); + gulp.task( 'default', [ 'watch' ] ); diff --git a/package.json b/package.json index 08821fa..e88c567 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "short-key-generator", "version": "0.0.9", - "description": "Generate sequence of keys based on specific alphabet", + "description": "Generate sequence of short keys based on specific alphabet and provide a keymap", "keywords": [ "short", "key", @@ -34,9 +34,11 @@ "lint": "npm run lint:src && npm run lint:test", "test:integration": "npm run lint:test && gulp test:integration", "test:unit": "gulp test:unit", - "test": "npm run lint:test && gulp test", - "test:unit:watch": "gulp test:unit:watch", - "all": "npm run lint && gulp test && npm run coverage && npm run build" + "test": "npm run lint:test && gulp test:unit && gulp test:integration", + "test:unit:watch": "npm run test:unit && gulp test:unit:watch", + "all": "npm run lint && gulp test:unit && gulp test:integration && npm run coverage && npm run build && npm run docs", + "clean": "gulp clean:dist", + "docs": "gulp docs" }, "dependencies": { "bidirectional-map": "^1.0.3" @@ -45,8 +47,10 @@ "babel-cli": "^6.26.0", "babel-core": "^6.11.4", "babel-istanbul": "^0.12.2", - "babel-plugin-istanbul": "^1.0.3", - "babel-preset-es2015": "^6.9.0", + "babel-plugin-transform-es2015-destructuring": "^6.23.0", + "babel-plugin-transform-es2015-parameters": "^6.24.1", + "babel-plugin-transform-object-rest-spread": "^6.26.0", + "babel-preset-env": "^1.6.0", "chai": "^3.5.0", "del": "^2.2.2", "eslint": "^4.10.0", @@ -54,7 +58,9 @@ "eslint-plugin-mocha": "^4.0.0", "gulp": "^3.9.1", "gulp-babel": "^6.1.2", + "gulp-concat": "^2.6.1", "gulp-format-md": "*", + "gulp-jsdoc-to-markdown": "^1.2.2", "gulp-run-command": "0.0.9", "gulp-sourcemaps": "^1.6.0", "mocha": "*",