12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- var gulp = require('gulp');
- var $ = require('gulp-load-plugins')();
- var path = require('path');
- var del = require('del');
- var distPath = path.resolve('./dist');
- var version = '';
- var versionPath = '';
- var env = '';
- (function () {
- var d = new Date();
- version = (d.getFullYear().toString().slice(2))
- + ((d.getMonth() + 1) >= 10 ? (d.getMonth() + 1) : '0' + (d.getMonth() + 1))
- + (d.getDate() >= 10 ? d.getDate() : '0' + d.getDate());
- versionPath = distPath + '/' + version;
- })();
- gulp.task('build', $.shell.task([ 'node build/build.js' ]));
- gulp.task('create:versionPath', ['build'], function () {
- return gulp.src(`${distPath}/static/**/*`)
- .pipe(gulp.dest(`${versionPath}/static/`))
- });
- gulp.task('replace:cdnUrl', ['create:versionPath'], function () {
- return gulp.src(`${versionPath}/static/js/manifest.js`)
- .pipe($.replace(/"\.\/"/g, 'window.SITE_CONFIG.cdnUrl + "/"'))
- .pipe(gulp.dest(`${versionPath}/static/js/`))
- });
- gulp.task('replace:staticFileName', ['create:versionPath'], function () {
- return gulp.src(`${versionPath}/static/config/index-${env}.js`)
- .pipe($.replace(/window.SITE_CONFIG.staticFileName = \'.*\'/g, `window.SITE_CONFIG.staticFileName = \'${version}\'`))
- .pipe(gulp.dest(`${versionPath}/static/config/`))
- });
- gulp.task('concat:config', ['replace:staticFileName'], function () {
- return gulp.src([`${versionPath}/static/config/index-${env}.js`, `${versionPath}/static/config/init.js`])
- .pipe($.concat('index.js'))
- .pipe(gulp.dest(`${distPath}/config/`))
- });
- gulp.task('clean', function () {
- return del([versionPath])
- });
- gulp.task('default', ['clean'], function () {
-
- env = process.env.npm_config_qa ? 'qa' : process.env.npm_config_uat ? 'uat' : 'prod'
-
- gulp.start(['replace:cdnUrl', 'replace:staticFileName', 'concat:config'], function () {
-
- del([`${distPath}/static`, `${versionPath}/static/config`])
- })
- });
|