Skip to content
This repository has been archived by the owner on Sep 12, 2024. It is now read-only.

Commit

Permalink
refactored gulpfile
Browse files Browse the repository at this point in the history
  • Loading branch information
petethepig committed Dec 21, 2015
1 parent e1823d5 commit 0ea45f6
Show file tree
Hide file tree
Showing 7 changed files with 249 additions and 223 deletions.
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
language: node_js
node_js:
- "node"
before_install:
before_run:
- npm install -g bower gulp
- bower install
script: gulp test
- gulp clean
script: gulp travis-ci
224 changes: 3 additions & 221 deletions gulpfile.babel.js
Original file line number Diff line number Diff line change
@@ -1,235 +1,17 @@
// generated using generator-gulp-webapp 1.0.3
import gulp from 'gulp';
import marked from 'marked';
import highlight from 'highlight.js';
import gulpLoadPlugins from 'gulp-load-plugins';
import browserSync from 'browser-sync';
import requireDir from 'require-dir';
import del from 'del';
import fs from 'fs';
import childProcess from 'child_process';

const $ = gulpLoadPlugins();
const reload = browserSync.reload;
const exec = childProcess.exec;

marked.setOptions({
renderer: new marked.Renderer(),
gfm: true,
tables: true,
breaks: false,
pedantic: false,
sanitize: true,
smartLists: true,
smartypants: false,
highlight: (code, lang) => {
return highlight.highlightAuto(code, [lang]).value;
}
});

function markdownFilter(code) {
code = code
.replace(/[\s\S]*(?=#+ Notable Features)/m, '')
.replace(/#+ Copyright[\s\S]*/m, '');
return marked(code);
}

function readJson(path) {
return JSON.parse(fs.readFileSync(path, 'utf8'));
}

function banner() {
var pkg = readJson('./package.json');
var bower = readJson('./bower.json');
return `
/*!
* ${bower.name}
* version: ${pkg.version}
* authors: ${bower.authors}
* license: ${bower.license}
* ${bower.homepage}
*/
`.replace(/\n\s{0,4}/g, '\n').replace('\n', '');
}

function bump(type) {
return gulp.src('./package.json')
.pipe($.bump({type: type}))
.pipe(gulp.dest('./'))
.pipe($.callback(() => { gulp.start('build:min'); }));
};

gulp.task('images', () => {
return gulp.src('website/images/*')
.pipe(gulp.dest('dist/website/images'))
});

gulp.task('styles', () => {
return gulp.src([
'src/styles/*.scss',
'website/styles/*.scss'
])
.pipe($.plumber())
.pipe($.sass.sync({
outputStyle: 'expanded',
precision: 10,
includePaths: ['.']
}).on('error', $.util.log))
.pipe($.autoprefixer({browsers: ['last 1 version']}))
.pipe(gulp.dest('.tmp/styles'))
.pipe(reload({stream: true}));
});

gulp.task('scripts', () => {
return gulp.src([
'src/scripts/*.coffee',
'website/scripts/*.coffee'
])
.pipe($.include()).on('error', $.util.log)
.pipe($.plumber())
.pipe($.coffee().on('error', $.util.log))
.pipe(gulp.dest('.tmp/scripts'))
.pipe(reload({stream: true}));
});

gulp.task('html', ['styles', 'scripts'], () => {
return gulp.src('website/*.html')
.pipe($.fileInclude({
prefix: '@@',
basepath: '@file',
filters: {
markdown: markdownFilter
}
})).on('error', $.util.log)
.pipe(gulp.dest('.tmp'))
.pipe(reload({stream: true}));
});
requireDir('./tasks');

gulp.task('clean', del.bind(null, ['.tmp', '.publish', 'dist']));

gulp.task('serve', ['html', 'styles', 'scripts'], () => {
browserSync({
notify: false,
port: 9000,
ghostMode: {
clicks: false,
forms: false,
scroll: false
},
server: {
baseDir: ['.tmp', 'website'],
routes: {
'/bower_components': 'bower_components',
'/docs': '.tmp/docs.html',
'/tests': '.tmp/tests.html',
'/examples': '.tmp/examples.html'
}
}
});

gulp.watch([
'{src,website}/scripts/**/*.coffee',
'src/templates/**/*.html',
'website/**/*.html',
'**/*.md'
]).on('change', reload);

gulp.watch('{src,website}/styles/**/*.scss', ['styles']);
gulp.watch('{src,website}/scripts/**/*.coffee', ['scripts']);
gulp.watch('src/templates/**/*.html', ['scripts']);
gulp.watch('website/**/*.html', ['html']);
gulp.watch('**/*.md', ['html']);
});

gulp.task('build', ['scripts', 'styles'], () => {
return gulp.src(['.tmp/scripts/daterangepicker.js', '.tmp/styles/daterangepicker.css'])
.pipe($.header(banner()))
.pipe(gulp.dest('dist/'))
.pipe($.size({title: 'build', gzip: true}));
});

gulp.task('build:min', ['build'], () => {
return gulp.src(['dist/daterangepicker.js', 'dist/daterangepicker.css'])
.pipe($.if('*.js', $.uglify({preserveComments: 'license'})))
.pipe($.if('*.css', $.minifyCss({compatibility: '*'})))
.pipe($.if('*.js', $.extReplace('.min.js')))
.pipe($.if('*.css', $.extReplace('.min.css')))
.pipe(gulp.dest('dist/'))
.pipe($.size({title: 'build:min', gzip: true}));
});

gulp.task('build:website', ['html', 'scripts', 'styles', 'images'], () => {
const assets = $.useref.assets({searchPath: ['.tmp', 'website', '.']});

return gulp.src('.tmp/*.html')
.pipe(assets)
.pipe($.if('*.js', $.uglify({preserveComments: 'license'})))
.pipe($.if('*.css', $.minifyCss({compatibility: '*'})))
.pipe(assets.restore())
.pipe($.useref())
.pipe(gulp.dest('dist/website'))
.pipe($.size({title: 'build:website', gzip: true}));
});

gulp.task('serve:website', ['build:website'], () => {
browserSync({
notify: false,
port: 9000,
server: {
baseDir: ['dist/website']
}
});
});

gulp.task('github:pages', ['build:website'], () => {
return gulp.src('./dist/website/**/*')
.pipe($.ghPages());
});

gulp.task('consistency-check', ['build:min'], (cb) => {
exec('git status', function callback(error, stdout, stderr) {
const pendingChanges = stdout.match(/modified:\s*dist/)
if (pendingChanges) {
throw new Error('consistency check failed');
} else {
cb();
}
});
});

gulp.task('github:release', ['consistency-check'], () => {
if (!process.env.GITHUB_TOKEN) {
throw new Error('env.GITHUB_TOKEN is empty');
}

var manifest = readJson('./package.json');
const match = manifest.repository.url.split('/').slice(-2)

return gulp.src([
'dist/daterangepicker.js',
'dist/daterangepicker.css',
'dist/daterangepicker.min.js',
'dist/daterangepicker.min.css'
])
.pipe($.githubRelease({
manifest: manifest,
owner: match[0],
repo: match[1]
}));
});

gulp.task('bump:major', () => {
return bump('major');
});

gulp.task('bump:minor', () => {
return bump('minor');
});

gulp.task('bump:patch', () => {
return bump('patch');
});

gulp.task('test', ['build:website'], () => {
gulp.task('travis-ci', ['build:website'], () => {
return gulp
.src('dist/website/tests.html')
.pipe($.mochaPhantomjs());
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"marked": "^0.3.5",
"mocha": "^2.3.4",
"opn": "^1.0.1",
"require-dir": "^0.3.0",
"wiredep": "^2.2.2"
},
"repository": {
Expand Down
71 changes: 71 additions & 0 deletions tasks/build.babel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import gulp from 'gulp';
import fs from 'fs';
import gulpLoadPlugins from 'gulp-load-plugins';
import browserSync from 'browser-sync';

const $ = gulpLoadPlugins();
const reload = browserSync.reload;


function readJson(path) {
return JSON.parse(fs.readFileSync(path, 'utf8'));
}

function banner() {
var pkg = readJson('./package.json');
var bower = readJson('./bower.json');
return `
/*!
* ${bower.name}
* version: ${pkg.version}
* authors: ${bower.authors}
* license: ${bower.license}
* ${bower.homepage}
*/
`.replace(/\n\s{0,4}/g, '\n').replace('\n', '');
}

gulp.task('styles', () => {
return gulp.src([
'src/styles/*.scss',
'website/styles/*.scss'
])
.pipe($.plumber())
.pipe($.sass.sync({
outputStyle: 'expanded',
precision: 10,
includePaths: ['.']
}).on('error', $.util.log))
.pipe($.autoprefixer({browsers: ['last 1 version']}))
.pipe(gulp.dest('.tmp/styles'))
.pipe(reload({stream: true}));
});

gulp.task('scripts', () => {
return gulp.src([
'src/scripts/*.coffee',
'website/scripts/*.coffee'
])
.pipe($.include()).on('error', $.util.log)
.pipe($.plumber())
.pipe($.coffee().on('error', $.util.log))
.pipe(gulp.dest('.tmp/scripts'))
.pipe(reload({stream: true}));
});

gulp.task('build', ['scripts', 'styles'], () => {
return gulp.src(['.tmp/scripts/daterangepicker.js', '.tmp/styles/daterangepicker.css'])
.pipe($.header(banner()))
.pipe(gulp.dest('dist/'))
.pipe($.size({title: 'build', gzip: true}));
});

gulp.task('build:min', ['build'], () => {
return gulp.src(['dist/daterangepicker.js', 'dist/daterangepicker.css'])
.pipe($.if('*.js', $.uglify({preserveComments: 'license'})))
.pipe($.if('*.css', $.minifyCss({compatibility: '*'})))
.pipe($.if('*.js', $.extReplace('.min.js')))
.pipe($.if('*.css', $.extReplace('.min.css')))
.pipe(gulp.dest('dist/'))
.pipe($.size({title: 'build:min', gzip: true}));
});
24 changes: 24 additions & 0 deletions tasks/bump.babel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import gulp from 'gulp';
import gulpLoadPlugins from 'gulp-load-plugins';

const $ = gulpLoadPlugins();


function bump(type) {
return gulp.src('./package.json')
.pipe($.bump({type: type}))
.pipe(gulp.dest('./'))
.pipe($.callback(() => { gulp.start('build:min'); }));
};

gulp.task('bump:major', () => {
return bump('major');
});

gulp.task('bump:minor', () => {
return bump('minor');
});

gulp.task('bump:patch', () => {
return bump('patch');
});
42 changes: 42 additions & 0 deletions tasks/github.babel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import gulp from 'gulp';
import gulpLoadPlugins from 'gulp-load-plugins';

const $ = gulpLoadPlugins();


gulp.task('github:pages', ['build:website'], () => {
return gulp.src('./dist/website/**/*')
.pipe($.ghPages());
});

gulp.task('consistency-check', ['build:min'], (cb) => {
exec('git status', function callback(error, stdout, stderr) {
const pendingChanges = stdout.match(/modified:\s*dist/)
if (pendingChanges) {
throw new Error('consistency check failed');
} else {
cb();
}
});
});

gulp.task('github:release', ['consistency-check'], () => {
if (!process.env.GITHUB_TOKEN) {
throw new Error('env.GITHUB_TOKEN is empty');
}

var manifest = readJson('./package.json');
const match = manifest.repository.url.split('/').slice(-2)

return gulp.src([
'dist/daterangepicker.js',
'dist/daterangepicker.css',
'dist/daterangepicker.min.js',
'dist/daterangepicker.min.css'
])
.pipe($.githubRelease({
manifest: manifest,
owner: match[0],
repo: match[1]
}));
});
Loading

0 comments on commit 0ea45f6

Please sign in to comment.