From 88cd8204b497a5fcc2cc141f8599fe6f883c13e3 Mon Sep 17 00:00:00 2001 From: Tim De Pauw Date: Thu, 16 Jun 2016 23:19:31 +0200 Subject: [PATCH] Revisit build --- .babelrc | 3 +- .travis.yml | 2 ++ gulpfile.babel.js | 75 ++++++++++++++++++----------------------------- package.json | 2 +- test/.babelrc | 4 --- 5 files changed, 34 insertions(+), 52 deletions(-) delete mode 100644 test/.babelrc diff --git a/.babelrc b/.babelrc index c13c5f6..0603968 100644 --- a/.babelrc +++ b/.babelrc @@ -1,3 +1,4 @@ { - "presets": ["es2015"] + "presets": ["es2015"], + "plugins": ["async-to-promises"] } diff --git a/.travis.yml b/.travis.yml index f22a45e..1330be8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,8 @@ matrix: - node_js: iojs - node_js: 4 - node_js: 5 + - node_js: 6 + - node_js: node env: COVERALLS=1 after_success: - '[[ "$COVERALLS" ]] && gulp coveralls' diff --git a/gulpfile.babel.js b/gulpfile.babel.js index ec127ae..ead8a12 100644 --- a/gulpfile.babel.js +++ b/gulpfile.babel.js @@ -10,17 +10,13 @@ import stableStringify from 'json-stable-stringify' import path from 'path' import marshal from './test/lib/marshal' +const COVERAGE_THRESHOLDS = {global: 80} + const $ = loadPlugins() -const plumb = () => $.plumber({ +const plumb = () => $.if(!process.env.CI, $.plumber({ errorHandler: $.notify.onError('<%= error.message %>') -}) - -const test = (strict = false) => { - return gulp.src(['test/lib/setup.js', 'test/integration/**/*.js'], {read: false}) - .pipe($.if(!strict, plumb())) - .pipe($.mocha({reporter: 'spec'})) -} +})) gulp.task('clean', () => del('lib')) @@ -37,15 +33,9 @@ gulp.task('lint', () => { return gulp.src('src/**/*.js') .pipe(plumb()) .pipe($.standard()) - .pipe($.standard.reporter('default', { - breakOnError: false - })) + .pipe($.standard.reporter('default', {breakOnError: false})) }) -gulp.task('build', (cb) => seq('lint', 'test', 'transpile', cb)) - -gulp.task('cleanbuild', (cb) => seq('clean', 'build', cb)) - gulp.task('pre-coverage', () => { return gulp.src('src/**/*.js') .pipe($.istanbul({instrumenter: Instrumenter})) @@ -53,50 +43,43 @@ gulp.task('pre-coverage', () => { }) gulp.task('coverage', ['pre-coverage'], () => { - return test(true) + return gulp.src(['test/lib/setup.js', 'test/{unit,integration}/**/*.js', '!**/_*.js'], {read: false}) + .pipe(plumb()) + .pipe($.mocha({reporter: 'spec'})) .pipe($.istanbul.writeReports()) - .pipe($.istanbul.enforceThresholds({thresholds: {global: 85}})) + .pipe($.istanbul.enforceThresholds({thresholds: COVERAGE_THRESHOLDS})) }) -gulp.task('coveralls', ['coverage'], () => { +gulp.task('test', (cb) => seq('lint', 'coverage', cb)) + +gulp.task('coveralls', () => { return gulp.src('coverage/lcov.info') .pipe($.coveralls()) }) -gulp.task('test', test) +gulp.task('build', (cb) => seq('test', 'clean', 'transpile', cb)) -gulp.task('write-exp', () => { - const parse = require('./src/').default +const buildExp = async (filePath, expPath, parse) => { + const data = await fsp.readFile(filePath, 'utf8') + const parsed = parse(data) + const marshaled = marshal(parsed) + const stringified = stableStringify(marshaled, {space: 2}) + await fsp.outputFile(expPath, stringified, 'utf8') + gutil.log('Created', gutil.colors.magenta(expPath)) +} +gulp.task('write-exp', async () => { + const parse = require('./src/').default const fixturesRoot = path.resolve(__dirname, 'test/fixtures') const expectedRoot = path.resolve(__dirname, 'test/integration/expected') - - const promises = [] - const errors = [] - for (const relPath of globule.find({cwd: fixturesRoot, src: '**/*.xml'})) { + const fixtures = globule.find({cwd: fixturesRoot, src: '**/*.xml'}) + await Promise.all(fixtures.map((relPath) => { const filePath = path.join(fixturesRoot, relPath) const expPath = path.join(expectedRoot, gutil.replaceExtension(relPath, '.json')) - const working = fsp.readFile(filePath, 'utf8') - .then((data) => parse(data)) - .then((parsed) => marshal(parsed)) - .then((marshaled) => stableStringify(marshaled, {space: 2})) - .then((data) => fsp.outputFile(expPath, data, 'utf8')) - .then(() => gutil.log('Created', gutil.colors.magenta(expPath))) - .catch((err) => { - gutil.log('Error creating', gutil.colors.magenta(expPath) + ':', err.stack) - errors.push({path: expPath, error: err}) - }) - promises.push(working) - } - - return Promise.all(promises) - .then(() => { - if (errors.length > 0) { - throw new gutil.PluginError('write-exp', `Failed to create ${errors.length} file(s)`) - } - }) + return buildExp(filePath, expPath, parse) + })) }) -gulp.task('watch', () => gulp.watch('{src,test}/**/*', ['cleanbuild'])) +gulp.task('watch', () => gulp.watch('{src,test}/**/*', ['build'])) -gulp.task('default', ['cleanbuild'], () => gulp.start('watch')) +gulp.task('default', ['build'], () => gulp.start('watch')) diff --git a/package.json b/package.json index 0eec93e..ecad514 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "scripts": { "clean": "gulp clean", "build": "gulp build", - "prepublish": "npm run clean && npm run build", + "prepublish": "npm run build", "test": "gulp test" }, "repository": "zentrick/iab-vast-parser", diff --git a/test/.babelrc b/test/.babelrc deleted file mode 100644 index 0603968..0000000 --- a/test/.babelrc +++ /dev/null @@ -1,4 +0,0 @@ -{ - "presets": ["es2015"], - "plugins": ["async-to-promises"] -}