summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2017-01-12 18:53:52 +0900
committersyuilo <syuilotan@yahoo.co.jp>2017-01-12 18:53:52 +0900
commit66dbfaae9b99971f837abb9cd28c3ce002c74cc0 (patch)
treea072b757a3503590f210059f44e413bd10aea7aa
parentUpdate dependencies :rocket: (diff)
downloadmisskey-66dbfaae9b99971f837abb9cd28c3ce002c74cc0.tar.gz
misskey-66dbfaae9b99971f837abb9cd28c3ce002c74cc0.tar.bz2
misskey-66dbfaae9b99971f837abb9cd28c3ce002c74cc0.zip
Refactor
-rw-r--r--gulpfile.ts120
-rw-r--r--package.json1
2 files changed, 63 insertions, 58 deletions
diff --git a/gulpfile.ts b/gulpfile.ts
index 677225c398..bc8c3569f1 100644
--- a/gulpfile.ts
+++ b/gulpfile.ts
@@ -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)
+ const commit = await prominence(git).getLastCommit();
- // スペースでインデントされてないとエラーが出る
- .transform(transformify((source, file) => {
- if (file.substr(-4) !== '.tag') return source;
- return source.replace(/\t/g, ' ');
- }))
+ // Get all app scripts
+ const files = await promiseify(glob)('./src/web/app/*/script.js');
- .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}'`)
- ;
- }))
+ // 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, ' ');
+ }))
- .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')));
+ .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}'`)
+ ;
+ }))
- if (isProduction) {
- bundle = bundle
- .pipe(buffer())
- // ↓ https://github.com/mishoo/UglifyJS2/issues/448
- .pipe(babel({
- presets: ['es2015']
- }))
- .pipe(uglify({
- compress: true
- }));
+ .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
- .pipe(gulp.dest('./built/web/resources/'));
- });
+ if (isProduction) {
+ 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', () => {
diff --git a/package.json b/package.json
index 41a6fec7d4..6a56f67a69 100644
--- a/package.json
+++ b/package.json
@@ -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",