mirror of
https://github.com/jiahaog/Nativefier
synced 2024-06-20 06:56:35 +02:00
Split gulpfile into multiple parts
This commit is contained in:
parent
45bcccd17e
commit
99fcb60a44
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "Google",
|
"name": "Google",
|
||||||
"targetUrl": "http:\/\/www.google.com",
|
"targetUrl": "file:///Users/JiaHao/Desktop/lab4.html",
|
||||||
"badge": false,
|
"badge": false,
|
||||||
"width": 1280,
|
"width": 1280,
|
||||||
"height": 800,
|
"height": 800,
|
||||||
|
|
19
gulp/build.js
Normal file
19
gulp/build.js
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
import gulp from 'gulp';
|
||||||
|
import PATHS from './helpers/src-paths';
|
||||||
|
|
||||||
|
import del from 'del';
|
||||||
|
import runSequence from 'run-sequence';
|
||||||
|
|
||||||
|
gulp.task('build', callback => {
|
||||||
|
runSequence('clean', ['build-cli', 'build-app', 'build-tests'], callback);
|
||||||
|
});
|
||||||
|
|
||||||
|
gulp.task('clean', callback => {
|
||||||
|
del(PATHS.CLI_DEST).then(() => {
|
||||||
|
del(PATHS.APP_DEST).then(() => {
|
||||||
|
del(PATHS.TEST_DEST).then(() => {
|
||||||
|
callback();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
10
gulp/build/build-app.js
Normal file
10
gulp/build/build-app.js
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
import gulp from 'gulp';
|
||||||
|
import PATHS from './../helpers/src-paths';
|
||||||
|
|
||||||
|
import webpack from 'webpack-stream';
|
||||||
|
|
||||||
|
gulp.task('build-app', ['build-static'], () => {
|
||||||
|
return gulp.src(PATHS.APP_MAIN_JS)
|
||||||
|
.pipe(webpack(require('./../../webpack.config.js')))
|
||||||
|
.pipe(gulp.dest(PATHS.APP_DEST));
|
||||||
|
});
|
13
gulp/build/build-cli.js
Normal file
13
gulp/build/build-cli.js
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
import gulp from 'gulp';
|
||||||
|
import PATHS from './../helpers/src-paths';
|
||||||
|
import sourcemaps from 'gulp-sourcemaps';
|
||||||
|
import babel from 'gulp-babel';
|
||||||
|
|
||||||
|
gulp.task('build-cli', done => {
|
||||||
|
return gulp.src(PATHS.CLI_SRC_JS)
|
||||||
|
.pipe(sourcemaps.init())
|
||||||
|
.pipe(babel())
|
||||||
|
.on('error', done)
|
||||||
|
.pipe(sourcemaps.write('.'))
|
||||||
|
.pipe(gulp.dest('lib'));
|
||||||
|
});
|
21
gulp/build/build-static.js
Normal file
21
gulp/build/build-static.js
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
import gulp from 'gulp';
|
||||||
|
import PATHS from './../helpers/src-paths';
|
||||||
|
|
||||||
|
import babel from 'gulp-babel';
|
||||||
|
import sourcemaps from 'gulp-sourcemaps';
|
||||||
|
|
||||||
|
gulp.task('build-static-not-js', () => {
|
||||||
|
return gulp.src([PATHS.APP_STATIC_ALL, '!**/*.js'])
|
||||||
|
.pipe(gulp.dest(PATHS.APP_STATIC_DEST));
|
||||||
|
});
|
||||||
|
|
||||||
|
gulp.task('build-static-js', done => {
|
||||||
|
return gulp.src(PATHS.APP_STATIC_JS)
|
||||||
|
.pipe(sourcemaps.init())
|
||||||
|
.pipe(babel())
|
||||||
|
.on('error', done)
|
||||||
|
.pipe(sourcemaps.write('.'))
|
||||||
|
.pipe(gulp.dest(PATHS.APP_STATIC_DEST));
|
||||||
|
});
|
||||||
|
|
||||||
|
gulp.task('build-static', ['build-static-js', 'build-static-not-js']);
|
6
gulp/ci.js
Normal file
6
gulp/ci.js
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
import gulp from 'gulp';
|
||||||
|
import runSequence from 'run-sequence';
|
||||||
|
|
||||||
|
gulp.task('ci', callback => {
|
||||||
|
return runSequence('test', 'lint', callback);
|
||||||
|
});
|
13
gulp/helpers/gulp-helpers.js
Normal file
13
gulp/helpers/gulp-helpers.js
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
import shellJs from 'shelljs';
|
||||||
|
|
||||||
|
function shellExec(cmd, silent, callback) {
|
||||||
|
shellJs.exec(cmd, {silent: silent}, (code, stdout, stderr) => {
|
||||||
|
if (code) {
|
||||||
|
callback(JSON.stringify({code, stdout, stderr}));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
callback();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export default {shellExec};
|
22
gulp/helpers/src-paths.js
Normal file
22
gulp/helpers/src-paths.js
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
import path from 'path';
|
||||||
|
|
||||||
|
const paths = {
|
||||||
|
APP_SRC: 'app/src',
|
||||||
|
APP_DEST: 'app/lib',
|
||||||
|
CLI_SRC: 'src',
|
||||||
|
CLI_DEST: 'lib',
|
||||||
|
TEST_SRC: 'test',
|
||||||
|
TEST_DEST: 'built-tests'
|
||||||
|
};
|
||||||
|
|
||||||
|
paths.APP_MAIN_JS = path.join(paths.APP_SRC, '/main.js');
|
||||||
|
paths.APP_ALL = paths.APP_SRC + '/**/*';
|
||||||
|
paths.APP_STATIC_ALL = path.join(paths.APP_SRC, 'static') + '/**/*';
|
||||||
|
paths.APP_STATIC_JS = path.join(paths.APP_SRC, 'static') + '/**/*.js';
|
||||||
|
paths.APP_STATIC_DEST = path.join(paths.APP_DEST, 'static');
|
||||||
|
paths.CLI_SRC_JS = paths.CLI_SRC + '/**/*.js';
|
||||||
|
paths.CLI_DEST_JS = paths.CLI_DEST + '/**/*.js';
|
||||||
|
paths.TEST_SRC_JS = paths.TEST_SRC + '/**/*.js';
|
||||||
|
paths.TEST_DEST_JS = paths.TEST_DEST + '/**/*.js';
|
||||||
|
|
||||||
|
export default paths;
|
14
gulp/release.js
Normal file
14
gulp/release.js
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
import gulp from 'gulp';
|
||||||
|
import runSequence from 'run-sequence';
|
||||||
|
import helpers from './helpers/gulp-helpers';
|
||||||
|
|
||||||
|
const {shellExec} = helpers;
|
||||||
|
|
||||||
|
gulp.task('publish', done => {
|
||||||
|
shellExec('npm publish', false, done);
|
||||||
|
});
|
||||||
|
|
||||||
|
gulp.task('release', callback => {
|
||||||
|
return runSequence('test', 'lint', 'build', 'publish', callback);
|
||||||
|
});
|
||||||
|
|
13
gulp/test.js
Normal file
13
gulp/test.js
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
import gulp from 'gulp';
|
||||||
|
import runSequence from 'run-sequence';
|
||||||
|
import helpers from './helpers/gulp-helpers';
|
||||||
|
|
||||||
|
const {shellExec} = helpers;
|
||||||
|
|
||||||
|
gulp.task('prune', done => {
|
||||||
|
shellExec('npm prune', true, done);
|
||||||
|
});
|
||||||
|
|
||||||
|
gulp.task('test', callback => {
|
||||||
|
return runSequence('prune', 'mocha', callback);
|
||||||
|
});
|
14
gulp/tests/build-tests.js
Normal file
14
gulp/tests/build-tests.js
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
import gulp from 'gulp';
|
||||||
|
import PATHS from './../helpers/src-paths';
|
||||||
|
|
||||||
|
import sourcemaps from 'gulp-sourcemaps';
|
||||||
|
import babel from 'gulp-babel';
|
||||||
|
|
||||||
|
gulp.task('build-tests', done => {
|
||||||
|
return gulp.src(PATHS.TEST_SRC_JS)
|
||||||
|
.pipe(sourcemaps.init())
|
||||||
|
.pipe(babel())
|
||||||
|
.on('error', done)
|
||||||
|
.pipe(sourcemaps.write('.'))
|
||||||
|
.pipe(gulp.dest(PATHS.TEST_DEST));
|
||||||
|
});
|
9
gulp/tests/lint.js
Normal file
9
gulp/tests/lint.js
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
import gulp from 'gulp';
|
||||||
|
import eslint from 'gulp-eslint';
|
||||||
|
|
||||||
|
gulp.task('lint', () => {
|
||||||
|
return gulp.src(['**/*.js', '!node_modules/**', '!app/node_modules/**', '!app/lib/**', '!lib/**', '!built-tests/**', '!coverage/**'])
|
||||||
|
.pipe(eslint())
|
||||||
|
.pipe(eslint.format())
|
||||||
|
.pipe(eslint.failAfterError());
|
||||||
|
});
|
22
gulp/tests/mocha.js
Normal file
22
gulp/tests/mocha.js
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
import gulp from 'gulp';
|
||||||
|
import PATHS from './../helpers/src-paths';
|
||||||
|
|
||||||
|
import istanbul from 'gulp-istanbul';
|
||||||
|
import mocha from 'gulp-mocha';
|
||||||
|
|
||||||
|
gulp.task('mocha', ['build'], done => {
|
||||||
|
gulp.src(PATHS.CLI_DEST_JS)
|
||||||
|
.pipe(istanbul({includeUntested: true}))
|
||||||
|
.on('finish', () => {
|
||||||
|
return gulp.src(PATHS.TEST_DEST_JS, {read: false})
|
||||||
|
.pipe(mocha())
|
||||||
|
.pipe(istanbul.writeReports({
|
||||||
|
dir: './coverage',
|
||||||
|
reporters: ['lcov'],
|
||||||
|
reportOpts: {dir: './coverage'}
|
||||||
|
}))
|
||||||
|
.on('finish', () => {
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
16
gulp/watch.js
Normal file
16
gulp/watch.js
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
import gulp from 'gulp';
|
||||||
|
import PATHS from './helpers/src-paths';
|
||||||
|
|
||||||
|
gulp.task('watch', ['build'], () => {
|
||||||
|
var handleError = function(error) {
|
||||||
|
console.error(error);
|
||||||
|
};
|
||||||
|
gulp.watch(PATHS.APP_ALL, ['build-app'])
|
||||||
|
.on('error', handleError);
|
||||||
|
|
||||||
|
gulp.watch(PATHS.CLI_SRC_JS, ['build-cli'])
|
||||||
|
.on('error', handleError);
|
||||||
|
|
||||||
|
gulp.watch(PATHS.TEST_SRC_JS, ['build-tests'])
|
||||||
|
.on('error', handleError);
|
||||||
|
});
|
|
@ -1,162 +1,9 @@
|
||||||
import gulp from 'gulp';
|
import gulp from 'gulp';
|
||||||
import del from 'del';
|
import requireDir from 'require-dir';
|
||||||
import sourcemaps from 'gulp-sourcemaps';
|
|
||||||
import webpack from 'webpack-stream';
|
|
||||||
import babel from 'gulp-babel';
|
|
||||||
import runSequence from 'run-sequence';
|
|
||||||
import path from 'path';
|
|
||||||
import eslint from 'gulp-eslint';
|
|
||||||
import mocha from 'gulp-mocha';
|
|
||||||
import istanbul from 'gulp-istanbul';
|
|
||||||
import shellJs from 'shelljs';
|
|
||||||
|
|
||||||
const PATHS = setUpPaths();
|
requireDir('./gulp', {
|
||||||
|
recurse: true,
|
||||||
|
duplicates: true
|
||||||
|
});
|
||||||
|
|
||||||
gulp.task('default', ['build']);
|
gulp.task('default', ['build']);
|
||||||
|
|
||||||
gulp.task('build', callback => {
|
|
||||||
runSequence('clean', ['build-cli', 'build-app', 'build-tests'], callback);
|
|
||||||
});
|
|
||||||
|
|
||||||
gulp.task('build-app', ['build-static'], () => {
|
|
||||||
return gulp.src(PATHS.APP_MAIN_JS)
|
|
||||||
.pipe(webpack(require(PATHS.WEBPACK_CONFIG)))
|
|
||||||
.pipe(gulp.dest(PATHS.APP_DEST));
|
|
||||||
});
|
|
||||||
|
|
||||||
gulp.task('clean', callback => {
|
|
||||||
del(PATHS.CLI_DEST).then(() => {
|
|
||||||
del(PATHS.APP_DEST).then(() => {
|
|
||||||
del(PATHS.TEST_DEST).then(() => {
|
|
||||||
callback();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
gulp.task('build-cli', done => {
|
|
||||||
return gulp.src(PATHS.CLI_SRC_JS)
|
|
||||||
.pipe(sourcemaps.init())
|
|
||||||
.pipe(babel())
|
|
||||||
.on('error', done)
|
|
||||||
.pipe(sourcemaps.write('.'))
|
|
||||||
.pipe(gulp.dest('lib'));
|
|
||||||
});
|
|
||||||
|
|
||||||
gulp.task('build-static', ['build-static-js', 'build-static-not-js']);
|
|
||||||
|
|
||||||
gulp.task('build-static-not-js', () => {
|
|
||||||
return gulp.src([PATHS.APP_STATIC_ALL, '!**/*.js'])
|
|
||||||
.pipe(gulp.dest(PATHS.APP_STATIC_DEST));
|
|
||||||
});
|
|
||||||
|
|
||||||
gulp.task('build-static-js', done => {
|
|
||||||
return gulp.src(PATHS.APP_STATIC_JS)
|
|
||||||
.pipe(sourcemaps.init())
|
|
||||||
.pipe(babel())
|
|
||||||
.on('error', done)
|
|
||||||
.pipe(sourcemaps.write('.'))
|
|
||||||
.pipe(gulp.dest(PATHS.APP_STATIC_DEST));
|
|
||||||
});
|
|
||||||
|
|
||||||
gulp.task('watch', ['build'], () => {
|
|
||||||
var handleError = function(error) {
|
|
||||||
console.error(error);
|
|
||||||
};
|
|
||||||
gulp.watch(PATHS.APP_ALL, ['build-app'])
|
|
||||||
.on('error', handleError);
|
|
||||||
|
|
||||||
gulp.watch(PATHS.CLI_SRC_JS, ['build-cli'])
|
|
||||||
.on('error', handleError);
|
|
||||||
|
|
||||||
gulp.watch(PATHS.TEST_SRC_JS, ['build-tests'])
|
|
||||||
.on('error', handleError);
|
|
||||||
});
|
|
||||||
|
|
||||||
gulp.task('publish', done => {
|
|
||||||
shellExec('npm publish', false, done);
|
|
||||||
});
|
|
||||||
|
|
||||||
gulp.task('release', callback => {
|
|
||||||
return runSequence('test', 'lint', 'build', 'publish', callback);
|
|
||||||
});
|
|
||||||
|
|
||||||
gulp.task('lint', () => {
|
|
||||||
return gulp.src(['**/*.js', '!node_modules/**', '!app/node_modules/**', '!app/lib/**', '!lib/**', '!built-tests/**', '!coverage/**'])
|
|
||||||
.pipe(eslint())
|
|
||||||
.pipe(eslint.format())
|
|
||||||
.pipe(eslint.failAfterError());
|
|
||||||
});
|
|
||||||
|
|
||||||
gulp.task('build-tests', done => {
|
|
||||||
return gulp.src(PATHS.TEST_SRC_JS)
|
|
||||||
.pipe(sourcemaps.init())
|
|
||||||
.pipe(babel())
|
|
||||||
.on('error', done)
|
|
||||||
.pipe(sourcemaps.write('.'))
|
|
||||||
.pipe(gulp.dest(PATHS.TEST_DEST));
|
|
||||||
});
|
|
||||||
|
|
||||||
gulp.task('prune', done => {
|
|
||||||
shellExec('npm prune', true, done);
|
|
||||||
});
|
|
||||||
|
|
||||||
gulp.task('test', callback => {
|
|
||||||
return runSequence('prune', 'mocha', callback);
|
|
||||||
});
|
|
||||||
|
|
||||||
gulp.task('mocha', ['build'], done => {
|
|
||||||
gulp.src(PATHS.CLI_DEST_JS)
|
|
||||||
.pipe(istanbul({includeUntested: true}))
|
|
||||||
.on('finish', () => {
|
|
||||||
return gulp.src(PATHS.TEST_DEST_JS, {read: false})
|
|
||||||
.pipe(mocha())
|
|
||||||
.pipe(istanbul.writeReports({
|
|
||||||
dir: './coverage',
|
|
||||||
reporters: ['lcov'],
|
|
||||||
reportOpts: {dir: './coverage'}
|
|
||||||
}))
|
|
||||||
.on('finish', () => {
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
gulp.task('ci', callback => {
|
|
||||||
return runSequence('test', 'lint', callback);
|
|
||||||
});
|
|
||||||
|
|
||||||
function setUpPaths() {
|
|
||||||
const paths = {
|
|
||||||
WEBPACK_CONFIG: './webpack.config.js',
|
|
||||||
APP_SRC: 'app/src',
|
|
||||||
APP_DEST: 'app/lib',
|
|
||||||
CLI_SRC: 'src',
|
|
||||||
CLI_DEST: 'lib',
|
|
||||||
TEST_SRC: 'test',
|
|
||||||
TEST_DEST: 'built-tests'
|
|
||||||
};
|
|
||||||
|
|
||||||
paths.APP_MAIN_JS = path.join(paths.APP_SRC, '/main.js');
|
|
||||||
paths.APP_ALL = paths.APP_SRC + '/**/*';
|
|
||||||
paths.APP_STATIC_ALL = path.join(paths.APP_SRC, 'static') + '/**/*';
|
|
||||||
paths.APP_STATIC_JS = path.join(paths.APP_SRC, 'static') + '/**/*.js';
|
|
||||||
paths.APP_STATIC_DEST = path.join(paths.APP_DEST, 'static');
|
|
||||||
paths.CLI_SRC_JS = paths.CLI_SRC + '/**/*.js';
|
|
||||||
paths.CLI_DEST_JS = paths.CLI_DEST + '/**/*.js';
|
|
||||||
paths.TEST_SRC_JS = paths.TEST_SRC + '/**/*.js';
|
|
||||||
paths.TEST_DEST_JS = paths.TEST_DEST + '/**/*.js';
|
|
||||||
|
|
||||||
return paths;
|
|
||||||
}
|
|
||||||
|
|
||||||
function shellExec(cmd, silent, callback) {
|
|
||||||
shellJs.exec(cmd, {silent: silent}, (code, stdout, stderr) => {
|
|
||||||
if (code) {
|
|
||||||
callback(JSON.stringify({code, stdout, stderr}));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
callback();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -71,6 +71,7 @@
|
||||||
"gulp-mocha": "^2.2.0",
|
"gulp-mocha": "^2.2.0",
|
||||||
"gulp-sourcemaps": "^1.6.0",
|
"gulp-sourcemaps": "^1.6.0",
|
||||||
"lodash": "^4.0.0",
|
"lodash": "^4.0.0",
|
||||||
|
"require-dir": "^0.3.0",
|
||||||
"run-sequence": "^1.1.5",
|
"run-sequence": "^1.1.5",
|
||||||
"shelljs": "^0.5.3",
|
"shelljs": "^0.5.3",
|
||||||
"tmp": "0.0.28",
|
"tmp": "0.0.28",
|
||||||
|
|
Loading…
Reference in New Issue
Block a user