Refactor
This commit is contained in:
parent
05e563db8f
commit
66dbfaae9b
120
gulpfile.ts
120
gulpfile.ts
|
@ -25,6 +25,8 @@ import pug = require('gulp-pug');
|
||||||
import git = require('git-last-commit');
|
import git = require('git-last-commit');
|
||||||
import * as rimraf from 'rimraf';
|
import * as rimraf from 'rimraf';
|
||||||
import * as escapeHtml from 'escape-html';
|
import * as escapeHtml from 'escape-html';
|
||||||
|
import prominence = require('prominence');
|
||||||
|
import promiseify = require('promiseify');
|
||||||
|
|
||||||
const env = process.env.NODE_ENV;
|
const env = process.env.NODE_ENV;
|
||||||
const isProduction = env === 'production';
|
const isProduction = env === 'production';
|
||||||
|
@ -175,75 +177,77 @@ gulp.task('build:client', [
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
gulp.task('build:client:scripts', done => {
|
gulp.task('build:client:scripts', async (done) => {
|
||||||
gutil.log('スクリプトを構築します...');
|
gutil.log('スクリプトを構築します...');
|
||||||
|
|
||||||
// Get commit info
|
// Get commit info
|
||||||
git.getLastCommit((err, commit) => {
|
const commit = await prominence(git).getLastCommit();
|
||||||
glob('./src/web/app/*/script.js', (err, files) => {
|
|
||||||
const tasks = files.map(entry => {
|
|
||||||
let bundle =
|
|
||||||
browserify({
|
|
||||||
entries: [entry]
|
|
||||||
})
|
|
||||||
.transform(ls)
|
|
||||||
.transform(aliasify, aliasifyConfig)
|
|
||||||
|
|
||||||
// スペースでインデントされてないとエラーが出る
|
// Get all app scripts
|
||||||
.transform(transformify((source, file) => {
|
const files = await promiseify(glob)('./src/web/app/*/script.js');
|
||||||
if (file.substr(-4) !== '.tag') return source;
|
|
||||||
return source.replace(/\t/g, ' ');
|
|
||||||
}))
|
|
||||||
|
|
||||||
.transform(transformify((source, file) => {
|
// Compile for each scripts
|
||||||
return source
|
const tasks = files.map(entry => {
|
||||||
.replace(/VERSION/g, `'${commit ? commit.hash : 'null'}'`)
|
let bundle =
|
||||||
.replace(/\$theme\-color\-foreground/g, '#fff')
|
browserify({
|
||||||
.replace(/\$theme\-color/g, config.themeColor)
|
entries: [entry]
|
||||||
.replace(/CONFIG\.theme-color/g, `'${config.themeColor}'`)
|
})
|
||||||
.replace(/CONFIG\.themeColor/g, `'${config.themeColor}'`)
|
.transform(ls)
|
||||||
.replace(/CONFIG\.api\.url/g, `'${config.scheme}://api.${config.host}'`)
|
.transform(aliasify, aliasifyConfig)
|
||||||
.replace(/CONFIG\.urls\.about/g, `'${config.scheme}://about.${config.host}'`)
|
|
||||||
.replace(/CONFIG\.urls\.dev/g, `'${config.scheme}://dev.${config.host}'`)
|
|
||||||
.replace(/CONFIG\.url/g, `'${config.url}'`)
|
|
||||||
.replace(/CONFIG\.host/g, `'${config.host}'`)
|
|
||||||
.replace(/CONFIG\.recaptcha\.siteKey/g, `'${config.recaptcha.siteKey}'`)
|
|
||||||
;
|
|
||||||
}))
|
|
||||||
|
|
||||||
.transform(riotify, {
|
// スペースでインデントされてないとエラーが出る
|
||||||
type: 'livescript',
|
.transform(transformify((source, file) => {
|
||||||
expr: false,
|
if (file.substr(-4) !== '.tag') return source;
|
||||||
compact: true,
|
return source.replace(/\t/g, ' ');
|
||||||
parserOptions: {
|
}))
|
||||||
style: {
|
|
||||||
compress: true,
|
|
||||||
rawDefine: config
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.bundle()
|
|
||||||
.pipe(source(entry.replace('./src/web/app/', './').replace('.ls', '.js')));
|
|
||||||
|
|
||||||
if (isProduction) {
|
.transform(transformify((source, file) => {
|
||||||
bundle = bundle
|
return source
|
||||||
.pipe(buffer())
|
.replace(/VERSION/g, `'${commit ? commit.hash : 'null'}'`)
|
||||||
// ↓ https://github.com/mishoo/UglifyJS2/issues/448
|
.replace(/\$theme\-color\-foreground/g, '#fff')
|
||||||
.pipe(babel({
|
.replace(/\$theme\-color/g, config.themeColor)
|
||||||
presets: ['es2015']
|
.replace(/CONFIG\.theme-color/g, `'${config.themeColor}'`)
|
||||||
}))
|
.replace(/CONFIG\.themeColor/g, `'${config.themeColor}'`)
|
||||||
.pipe(uglify({
|
.replace(/CONFIG\.api\.url/g, `'${config.scheme}://api.${config.host}'`)
|
||||||
compress: true
|
.replace(/CONFIG\.urls\.about/g, `'${config.scheme}://about.${config.host}'`)
|
||||||
}));
|
.replace(/CONFIG\.urls\.dev/g, `'${config.scheme}://dev.${config.host}'`)
|
||||||
|
.replace(/CONFIG\.url/g, `'${config.url}'`)
|
||||||
|
.replace(/CONFIG\.host/g, `'${config.host}'`)
|
||||||
|
.replace(/CONFIG\.recaptcha\.siteKey/g, `'${config.recaptcha.siteKey}'`)
|
||||||
|
;
|
||||||
|
}))
|
||||||
|
|
||||||
|
.transform(riotify, {
|
||||||
|
type: 'livescript',
|
||||||
|
expr: false,
|
||||||
|
compact: true,
|
||||||
|
parserOptions: {
|
||||||
|
style: {
|
||||||
|
compress: true,
|
||||||
|
rawDefine: config
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
.bundle()
|
||||||
|
.pipe(source(entry.replace('./src/web/app/', './').replace('.ls', '.js')));
|
||||||
|
|
||||||
return bundle
|
if (isProduction) {
|
||||||
.pipe(gulp.dest('./built/web/resources/'));
|
bundle = bundle
|
||||||
});
|
.pipe(buffer())
|
||||||
|
// ↓ https://github.com/mishoo/UglifyJS2/issues/448
|
||||||
|
.pipe(babel({
|
||||||
|
presets: ['es2015']
|
||||||
|
}))
|
||||||
|
.pipe(uglify({
|
||||||
|
compress: true
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
es.merge(tasks).on('end', done);
|
return bundle
|
||||||
});
|
.pipe(gulp.dest('./built/web/resources/'));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
es.merge(tasks).on('end', done);
|
||||||
});
|
});
|
||||||
|
|
||||||
gulp.task('build:client:styles', () => {
|
gulp.task('build:client:styles', () => {
|
||||||
|
|
|
@ -109,6 +109,7 @@
|
||||||
"nyaize": "0.0.2",
|
"nyaize": "0.0.2",
|
||||||
"page": "1.7.1",
|
"page": "1.7.1",
|
||||||
"prominence": "0.2.0",
|
"prominence": "0.2.0",
|
||||||
|
"promiseify": "0.2.0",
|
||||||
"pug": "2.0.0-beta6",
|
"pug": "2.0.0-beta6",
|
||||||
"ratelimiter": "2.1.3",
|
"ratelimiter": "2.1.3",
|
||||||
"recaptcha-promise": "0.1.2",
|
"recaptcha-promise": "0.1.2",
|
||||||
|
|
Loading…
Reference in New Issue