Skip to content
Snippets Groups Projects
Commit 66dbfaae authored by syuilo's avatar syuilo
Browse files

Refactor

parent 05e563db
No related branches found
No related tags found
No related merge requests found
......@@ -25,6 +25,8 @@ import pug = require('gulp-pug');
import git = require('git-last-commit');
import * as rimraf from 'rimraf';
import * as escapeHtml from 'escape-html';
import prominence = require('prominence');
import promiseify = require('promiseify');
const env = process.env.NODE_ENV;
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('スクリプトを構築します...');
// Get commit info
git.getLastCommit((err, commit) => {
glob('./src/web/app/*/script.js', (err, files) => {
const tasks = files.map(entry => {
let bundle =
browserify({
entries: [entry]
})
.transform(ls)
.transform(aliasify, aliasifyConfig)
// スペースでインデントされてないとエラーが出る
.transform(transformify((source, file) => {
if (file.substr(-4) !== '.tag') return source;
return source.replace(/\t/g, ' ');
}))
.transform(transformify((source, file) => {
return source
.replace(/VERSION/g, `'${commit ? commit.hash : 'null'}'`)
.replace(/\$theme\-color\-foreground/g, '#fff')
.replace(/\$theme\-color/g, config.themeColor)
.replace(/CONFIG\.theme-color/g, `'${config.themeColor}'`)
.replace(/CONFIG\.themeColor/g, `'${config.themeColor}'`)
.replace(/CONFIG\.api\.url/g, `'${config.scheme}://api.${config.host}'`)
.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')));
if (isProduction) {
bundle = bundle
.pipe(buffer())
// ↓ https://github.com/mishoo/UglifyJS2/issues/448
.pipe(babel({
presets: ['es2015']
}))
.pipe(uglify({
compress: true
}));
}
const commit = await prominence(git).getLastCommit();
// Get all app scripts
const files = await promiseify(glob)('./src/web/app/*/script.js');
// Compile for each scripts
const tasks = files.map(entry => {
let bundle =
browserify({
entries: [entry]
})
.transform(ls)
.transform(aliasify, aliasifyConfig)
// スペースでインデントされてないとエラーが出る
.transform(transformify((source, file) => {
if (file.substr(-4) !== '.tag') return source;
return source.replace(/\t/g, ' ');
}))
return bundle
.pipe(gulp.dest('./built/web/resources/'));
});
.transform(transformify((source, file) => {
return source
.replace(/VERSION/g, `'${commit ? commit.hash : 'null'}'`)
.replace(/\$theme\-color\-foreground/g, '#fff')
.replace(/\$theme\-color/g, config.themeColor)
.replace(/CONFIG\.theme-color/g, `'${config.themeColor}'`)
.replace(/CONFIG\.themeColor/g, `'${config.themeColor}'`)
.replace(/CONFIG\.api\.url/g, `'${config.scheme}://api.${config.host}'`)
.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}'`)
;
}))
es.merge(tasks).on('end', done);
});
.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')));
if (isProduction) {
bundle = bundle
.pipe(buffer())
// ↓ https://github.com/mishoo/UglifyJS2/issues/448
.pipe(babel({
presets: ['es2015']
}))
.pipe(uglify({
compress: true
}));
}
return bundle
.pipe(gulp.dest('./built/web/resources/'));
});
es.merge(tasks).on('end', done);
});
gulp.task('build:client:styles', () => {
......
......@@ -109,6 +109,7 @@
"nyaize": "0.0.2",
"page": "1.7.1",
"prominence": "0.2.0",
"promiseify": "0.2.0",
"pug": "2.0.0-beta6",
"ratelimiter": "2.1.3",
"recaptcha-promise": "0.1.2",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment