Created
July 12, 2019 05:24
-
-
Save dschinkel/abf05616a84c6e460d28d97a857669e1 to your computer and use it in GitHub Desktop.
Gulp v4 Build
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const gulp = require('gulp'), | |
less = require('gulp-less'), | |
babel = require("gulp-babel"), | |
shell = require('gulp-shell'), | |
mocha = require('gulp-mocha'), | |
rename = require('gulp-rename'), | |
bro = require('gulp-bro'), | |
del = require('del'), | |
{ series, dest, src } = require('gulp'); | |
require('dotenv').config(); | |
const config = { | |
watch: { | |
src: './src/*.js' | |
}, | |
test: { | |
path: { | |
specs: './test/specs/*-spec.js' | |
}, | |
mocha: { | |
reporter: 'spec' | |
} | |
} | |
}; | |
function precompile(cb) { | |
src('./src/client/less/*.less') | |
.pipe(less({ | |
compress: true | |
})) | |
.pipe(gulp.dest('./build/client/css')); | |
cb(); | |
} | |
function clean() { | |
return del(['build', 'distribute']); | |
} | |
function transpile() { | |
return src(['./src/**/*.js', '!./src/client/less/*.js']) | |
.pipe(babel()) | |
.pipe(gulp.dest("build")); | |
} | |
function copyBuild(){ | |
return src(['src/shared/**/*.json']).pipe(dest('build/shared')); | |
} | |
function copyExt() { | |
return src(['ext/**/*']).pipe(dest('dist/client/lib')); | |
} | |
function copyData() { | |
return src(['src/shared/**']).pipe(dest('dist/shared')); | |
} | |
function copyAssets() { | |
return src(['src/client/assets/**']).pipe(dest('dist/client/lib/assets')); | |
} | |
function copyStyles() { | |
return src(['./build/client/css/*.css']).pipe(dest('dist/client/lib/css')); | |
} | |
function copyFeed() { | |
return src(['feed.xml']).pipe(dest('dist/client')); | |
} | |
function copyBuildAndDist() { | |
return src(['build/server.js', 'build/api.js', 'build/shared', 'src/**/index.html', 'package.json']).pipe(dest('dist')); | |
} | |
function link(cb) { | |
shell.task(['ln -s ' + process.cwd() + '/node_modules ' + process.cwd() + '/dist/node_modules']); | |
cb(); | |
} | |
function tar(cb){ | |
shell.task(['tar -C dist -cf we-do-tdd.tar ./']); | |
cb(); | |
} | |
function bundle() { | |
return src('build/client/index.js') | |
.pipe(bro({ | |
transform: [ | |
[ 'uglifyify', { global: true } ] | |
] | |
})) | |
.pipe(rename('app.bundle.js')) | |
.pipe(dest('dist/client/scripts/')); | |
} | |
function createDist() { | |
return src(['./'], { allowEmpty: true }).pipe(dest('dist/client/scripts')); | |
} | |
function specFontEnd() { | |
process.env.PORT = 8001; | |
return src(['build/test/spec/frontend/**/*-spec.js'], {read: false}) | |
.pipe(mocha({ | |
reporter: config.test.mocha.reporter, | |
ui: 'bdd' | |
})); | |
} | |
function specBackEnd() { | |
process.env.PORT = 8001; | |
return src(['build/test/spec/backend/**/*-spec.js'], {read: false}) | |
.pipe(mocha({ | |
reporter: config.test.mocha.reporter, | |
ui: 'bdd' | |
})); | |
} | |
function specAll() { | |
process.env.PORT = 8001; | |
return src(['build/test/spec/**/*-spec.js'], {read: false}) | |
.pipe(mocha({ | |
reporter: config.test.mocha.reporter, | |
ui: 'bdd' | |
})); | |
} | |
exports.build = series(clean, transpile, copyBuild); | |
exports.distribute = series( | |
clean, | |
transpile, | |
copyBuild, | |
createDist, | |
copyBuildAndDist, | |
copyExt, | |
link, | |
bundle, | |
precompile, | |
copyData, | |
copyAssets, | |
copyStyles, | |
copyFeed, | |
tar); | |
exports.clean = clean; | |
exports.precompile = precompile; | |
exports.transpile = transpile; | |
exports.copyBuild = copyBuild; | |
exports.copyExt = copyExt; | |
exports.copyData = copyData; | |
exports.copyAssets = copyAssets; | |
exports.copyStyles = copyStyles; | |
exports.copyFeed = copyFeed; | |
exports.copyBuildAndDist = copyBuildAndDist; | |
exports.bundle = bundle; | |
exports.createDist = createDist; | |
exports.specFontEnd = specFontEnd; | |
exports.specBackEnd = specBackEnd; | |
exports.specAll = specAll; | |
exports.default = link; | |
exports.default = tar; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment