Skip to content

Commit

Permalink
Merge pull request #156 from benmosher/makefile
Browse files Browse the repository at this point in the history
~Makefile~ gulpfile!
  • Loading branch information
benmosher committed Jan 17, 2016
2 parents ed26c39 + 8be5929 commit ff0ef21
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 12 deletions.
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ script:
- "npm run-script ci-test"
- "for resolver in ./resolvers/*; do cd $resolver && npm test && cd ../..; done"

after_success:
- npm run coveralls
# something broke remap-istanbul :-(
# after_success:
# - npm run coveralls
4 changes: 1 addition & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@ test_script:
- npm --version
# Lint
- ./node_modules/.bin/eslint ./src
# Compile
- npm run-script pretest
# core tests
- ./node_modules/.bin/mocha tests/lib/ --recursive --reporter dot
- ./node_modules/.bin/gulp test
# resolver tests
- cd .\resolvers\webpack && npm test && cd ..\..
- cd .\resolvers\node && npm test && cd ..\..
Expand Down
88 changes: 88 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
var gulp = require('gulp')
, changed = require('gulp-changed')
, babel = require('gulp-babel')
, mocha = require('gulp-mocha')
, path = require('path')
, glob = require('glob')
, fs = require('fs')

var SRC = 'src/**/*.js'
, DEST = 'lib'

gulp.task('src', function () {
return gulp.src(SRC)
.pipe(changed(DEST))
.pipe(babel())
.pipe(gulp.dest(DEST))
})

/**
* Delete any file under `dest` that has no corresponding file in `src`.
* I.E. remove generated files that have been orphaned via deletion of their source.
* @param {string} src
* @param {string} dest
* @param {Function} done - callback upon completion
*/
function wipeExtras(src, dest, done) {
// glob into 'lib' and delete whatever isn't there
glob(dest + '/**/*.js', function (err, files) {
if (err) {
done(err); return
}

function checkFile(index) {
if (index >= files.length) {
done(); return
}

var libFilename = files[index]
, srcFilename = path.resolve(src, path.relative(path.resolve(dest), libFilename))

fs.stat(srcFilename, function (err) {
if (err) {
fs.unlink(libFilename, function () {
checkFile(index + 1)
})
} else {
checkFile(index + 1)
}
})
}


checkFile(0)
})
}

gulp.task('wipe-extras', function (done) {
var unfinished = 2
function megadone(err) {
if (err) { done(err); return }
if (--unfinished === 0) done()
}
wipeExtras('src', DEST, megadone)
wipeExtras('tests/src', 'tests/lib', megadone)
})

gulp.task('prepublish', ['src', 'wipe-extras'])

gulp.task('tests', function () {
return gulp.src('tests/src/**/*.js')
.pipe(changed('tests/lib'))
.pipe(babel())
.pipe(gulp.dest('tests/lib'))
})

// used externally by Istanbul, too
gulp.task('pretest', ['src', 'tests', 'wipe-extras'])

gulp.task('test', ['pretest'], function () {
return gulp.src('tests/lib/**/*.js', { read: false })
.pipe(mocha({ reporter: 'dot' }))
// NODE_PATH=./lib mocha --recursive --reporter dot tests/lib/
})

gulp.task('watch-test', function () {
gulp.watch(SRC, ['test'])
gulp.watch('tests/' + SRC, ['test'])
})
17 changes: 10 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@
"test": "tests"
},
"scripts": {
"watch": "babel -d lib/ src/ --watch & mocha --recursive --reporter dot --compilers js:babel/register --watch tests/src/",
"cover": "npm run pretest && NODE_PATH=./lib istanbul cover --dir reports/coverage _mocha tests/lib/ -- --recursive --reporter dot; remap-istanbul -i reports/coverage/coverage.json -o reports/coverage/lcov-report --type html",
"test": "NODE_PATH=./lib mocha --recursive --reporter dot tests/lib/",
"ci-test": "eslint ./src && npm run-script pretest && istanbul cover --report lcovonly --dir reports/coverage _mocha tests/lib/ -- --recursive --reporter dot",
"watch": "NODE_PATH=./lib gulp watch-test",
"cover": "gulp pretest && NODE_PATH=./lib istanbul cover --dir reports/coverage _mocha tests/lib/ -- --recursive -R progress",
"test": "NODE_PATH=./lib gulp test",
"ci-test": "eslint ./src && gulp pretest && istanbul cover --report lcovonly --dir reports/coverage _mocha tests/lib/ -- --recursive --reporter dot",
"debug": "NODE_PATH=./lib mocha debug --recursive --reporter dot tests/lib/",
"compile": "rm -rf lib/ && babel -d lib/ src/",
"prepublish": "eslint ./src && npm run compile",
"pretest": "npm run compile && babel -d tests/lib/ tests/src/",
"prepublish": "eslint ./src && gulp prepublish",
"coveralls": "remap-istanbul -i reports/coverage/coverage.json -o reports/coverage/lcov.info --type lcovonly && cat ./reports/coverage/lcov.info | coveralls"
},
"repository": {
Expand Down Expand Up @@ -44,6 +42,11 @@
"eslint": ">=1.8.0",
"eslint-import-resolver-node": "file:./resolvers/node",
"eslint-import-resolver-webpack": "file:./resolvers/webpack",
"glob": "^6.0.2",
"gulp": "^3.9.0",
"gulp-babel": "5.x",
"gulp-changed": "^1.3.0",
"gulp-mocha": "^2.2.0",
"istanbul": "^0.4.0",
"mocha": "^2.2.1",
"redux": "^3.0.4",
Expand Down

0 comments on commit ff0ef21

Please sign in to comment.