Skip to content

Commit

Permalink
style: linted gulpfile
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanneff committed Nov 17, 2016
1 parent 926eb7e commit a4ee008
Showing 1 changed file with 37 additions and 39 deletions.
76 changes: 37 additions & 39 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
var gulp = require('gulp');
var fs = require('fs');
var gulp = require('gulp');
var fs = require('fs');
var sourcemaps = require('gulp-sourcemaps');
var babel = require('gulp-babel');
var eslint = require('gulp-eslint');
var jscs = require('gulp-jscs');
var babel = require('gulp-babel');
var eslint = require('gulp-eslint');
var jscs = require('gulp-jscs');

gulp.task('prerelease', [ 'setupNpm', 'babel', 'lint' ]);
gulp.task('predev', [ 'setupDev', 'babel', 'lint' ]);
gulp.task('prerelease', ['setupNpm', 'babel', 'lint']);

// -----------------------------------------------------------------------------
// setup for development use
Expand All @@ -33,8 +32,8 @@ function genNpmPluginXML() {
files = files.concat(emitFiles(root + 'Branch-SDK/Requests/'));

var newLineIndent = '\n ';
xml = xml.replace('<!--[Branch Framework Reference]-->', newLineIndent
+ files.join(newLineIndent));
xml = xml.replace('<!--[Branch Framework Reference]-->', newLineIndent +
files.join(newLineIndent));

fs.writeFileSync('plugin.xml', xml);
};
Expand All @@ -53,11 +52,9 @@ function getDevPluginXML() {
function setIosNpmOrDev(npmOrDev) {
if (npmOrDev === 'npm') {
content = '#define BRANCH_NPM true';
}
else if (npmOrDev === 'dev') {
} else if (npmOrDev === 'dev') {
content = '//empty';
}
else {
} else {
throw new Error('expected deployed|local, not ' + deployedOrLocal);
}
fs.writeFileSync('src/ios/BranchNPM.h', content + '\n');
Expand All @@ -70,8 +67,7 @@ function emitFiles(path) {
var fileType = null;
if (filename.match(/\.m$/)) {
fileType = 'source';
}
else if (filename.match(/\.h$/) || filename.match(/\.pch$/)) {
} else if (filename.match(/\.h$/) || filename.match(/\.pch$/)) {
fileType = 'header';
}
if (fileType) {
Expand All @@ -96,13 +92,13 @@ function babelize(taskName, dir) {
gulp.task(taskName + '-copy', () => {
return gulp.src(srcDir + '**/*.*').pipe(gulp.dest(destDir));
});
gulp.task(taskName + '-babel', [ taskName + '-copy' ], () => {
gulp.task(taskName + '-babel', [taskName + '-copy'], () => {
return gulp.src(srcPattern)
.pipe(sourcemaps.init())
.pipe(babel({
presets: [ 'es2015', 'stage-2' ]
}))
.pipe(gulp.dest(destDir));
.pipe(sourcemaps.init())
.pipe(babel({
presets: ['es2015', 'stage-2']
}))
.pipe(gulp.dest(destDir));
});
}

Expand All @@ -115,38 +111,40 @@ gulp.task('babel', babelTasks);
// -----------------------------------------------------------------------------
// linting

gulp.task('lint', [ 'eslint', 'jscs-lint' ]);
gulp.task('lint', ['eslint', 'jscs-lint']);

var srcs = [
'hooks.es6/**/*.js',
'www.es6/**/*.js',
'gulpfile.js',
'tests.es6/**/*.js',
'testbed/www/js.es6/**/*.js',
'!node_modules/**',
'!testbed/platforms/**',
'!testbed/plugins/**',
'!tests-harness/platforms/**',
'!tests-harness/plugins/**'
'hooks.es6/**/*.js',
'www.es6/**/*.js',
'gulpfile.js',
'tests.es6/**/*.js',
'testbed/www/js.es6/**/*.js',
'!node_modules/**',
'!testbed/platforms/**',
'!testbed/plugins/**',
'!tests-harness/platforms/**',
'!tests-harness/plugins/**'
];

gulp.task('eslint', () => {
return gulp.src(srcs)
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});

function jscsTask(fix) {
var ret = gulp.src(srcs)
.pipe(jscs({ fix: fix }))
.pipe(jscs.reporter())
.pipe(jscs.reporter('fail'));
.pipe(jscs({
fix: fix
}))
.pipe(jscs.reporter())
.pipe(jscs.reporter('fail'));
if (fix) {
ret.pipe(gulp.dest('.'));
}
return ret;
}

gulp.task('jscs-fix', jscsTask.bind(null, true));
gulp.task('jscs-lint', jscsTask.bind(null, false));
gulp.task('jscs-lint', jscsTask.bind(null, false));

0 comments on commit a4ee008

Please sign in to comment.