2017-06-03 04:31:51 +08:00
|
|
|
var ts = require('gulp-typescript');
|
|
|
|
var gulp = require('gulp');
|
2017-06-03 05:21:05 +08:00
|
|
|
var zip = require('gulp-zip');
|
2017-12-25 07:42:25 +08:00
|
|
|
var fs = require('fs');
|
2017-06-03 04:31:51 +08:00
|
|
|
var runSequence = require('run-sequence');
|
2017-07-12 04:10:36 +08:00
|
|
|
var jsonModify = require('gulp-json-modify');
|
|
|
|
var exec = require('child_process').exec;
|
2017-06-03 04:31:51 +08:00
|
|
|
|
2017-10-20 01:27:02 +08:00
|
|
|
var tsBackendProject = ts.createProject('tsconfig.json');
|
2017-07-12 04:10:36 +08:00
|
|
|
gulp.task('build-backend', function () {
|
|
|
|
return gulp.src([
|
|
|
|
"common/**/*.ts",
|
|
|
|
"backend/**/*.ts"], {base: "."})
|
2017-10-20 00:08:07 +08:00
|
|
|
.pipe(tsBackendProject())
|
2017-07-12 04:10:36 +08:00
|
|
|
.js
|
|
|
|
.pipe(gulp.dest("./release"))
|
2017-06-03 04:31:51 +08:00
|
|
|
|
|
|
|
});
|
2017-12-25 07:42:25 +08:00
|
|
|
var createFornendTask = function (tpye, script) {
|
2018-02-04 08:50:42 +08:00
|
|
|
//console.log(tpye, script);
|
2017-12-25 07:42:25 +08:00
|
|
|
gulp.task(tpye, function (cb) {
|
|
|
|
exec(script, function (err, stdout, stderr) {
|
|
|
|
console.log(stdout);
|
|
|
|
console.log(stderr);
|
|
|
|
cb(err);
|
|
|
|
});
|
2017-07-12 04:10:36 +08:00
|
|
|
});
|
2017-12-25 07:42:25 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
gulp.task('build-frontend', function (done) {
|
|
|
|
var dirCont = fs.readdirSync("./frontend/locale");
|
|
|
|
var files = dirCont.filter(function (elm) {
|
|
|
|
return elm.match(/.*\.[a-zA-Z]+\.(xlf)/ig);
|
|
|
|
});
|
|
|
|
var languages = files.map(function (f) {
|
|
|
|
return f.split(".")[1]
|
|
|
|
});
|
|
|
|
var tasks = [];
|
2018-01-21 09:36:38 +08:00
|
|
|
createFornendTask('build-frontend-release default', "ng build --aot -prod --output-path=./release/dist --no-progress");
|
|
|
|
tasks.push('build-frontend-release default');
|
2017-12-25 07:42:25 +08:00
|
|
|
for (var i = 0; i < files.length; i++) {
|
2018-02-04 08:50:42 +08:00
|
|
|
createFornendTask('build-frontend-release ' + languages[i], "ng build --aot -prod --output-path=./release/dist/" + languages[i] + " --no-progress --locale=" + languages[i] + " --i18n-format xlf --i18n-file frontend/locale/" + files[i] + " --missing-translation warning");
|
2018-01-21 09:36:38 +08:00
|
|
|
tasks.push('build-frontend-release ' + languages[i]);
|
2017-12-25 07:42:25 +08:00
|
|
|
}
|
|
|
|
tasks.push(function () {
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
runSequence.apply(this, tasks);
|
|
|
|
|
2017-07-12 04:10:36 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('copy-static', function () {
|
|
|
|
return gulp.src([
|
|
|
|
"README.md",
|
|
|
|
"LICENSE"], {base: "."})
|
|
|
|
.pipe(gulp.dest('./release'));
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('copy-package', function () {
|
|
|
|
return gulp.src([
|
|
|
|
"package.json"], {base: "."})
|
|
|
|
.pipe(jsonModify({
|
|
|
|
key: 'devDependencies',
|
|
|
|
value: {}
|
|
|
|
}))
|
|
|
|
.pipe(jsonModify({
|
|
|
|
key: 'scripts',
|
|
|
|
value: {"start": "node ./backend/index.js"}
|
|
|
|
}))
|
|
|
|
.pipe(gulp.dest('./release'));
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2017-06-03 05:21:05 +08:00
|
|
|
gulp.task('zip-release', function () {
|
2017-07-12 04:23:07 +08:00
|
|
|
return gulp.src(['release/**/*'], {base: "./release"})
|
2017-07-12 04:10:36 +08:00
|
|
|
.pipe(zip('pigallery2.zip'))
|
|
|
|
.pipe(gulp.dest('.'));
|
2017-06-03 05:21:05 +08:00
|
|
|
});
|
2017-06-03 04:31:51 +08:00
|
|
|
|
|
|
|
gulp.task('build-release', function (done) {
|
2017-07-12 04:10:36 +08:00
|
|
|
runSequence('build-frontend', 'build-backend', 'copy-static', 'copy-package', 'zip-release', function () {
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2017-12-25 07:42:25 +08:00
|
|
|
|
2018-01-07 22:11:05 +08:00
|
|
|
var simpleBuild = function (isProd) {
|
|
|
|
return function (done) {
|
|
|
|
var dirCont = fs.readdirSync("./frontend/locale");
|
|
|
|
var files = dirCont.filter(function (elm) {
|
|
|
|
return elm.match(/.*\.[a-zA-Z]+\.(xlf)/ig);
|
|
|
|
});
|
|
|
|
var languages = files.map(function (f) {
|
|
|
|
return f.split(".")[1]
|
|
|
|
});
|
|
|
|
var tasks = [];
|
|
|
|
var cmd = "ng build ";
|
|
|
|
if (isProd) {
|
|
|
|
cmd += " -prod "
|
|
|
|
}
|
2018-01-21 09:36:38 +08:00
|
|
|
createFornendTask('build-frontend default', cmd + "--output-path=./dist --no-progress");
|
|
|
|
tasks.push('build-frontend default');
|
2018-01-07 22:11:05 +08:00
|
|
|
for (var i = 0; i < files.length; i++) {
|
2018-02-04 08:50:42 +08:00
|
|
|
createFornendTask('build-frontend ' + languages[i], cmd + "--output-path=./dist/" + languages[i] + " --no-progress --locale " + languages[i] + " --i18n-format=xlf --i18n-file=frontend/locale/" + files[i] + " --missing-translation warning");
|
2018-01-21 09:36:38 +08:00
|
|
|
tasks.push('build-frontend ' + languages[i]);
|
2018-01-07 22:11:05 +08:00
|
|
|
}
|
|
|
|
tasks.push(function () {
|
|
|
|
done();
|
|
|
|
});
|
2017-12-25 07:42:25 +08:00
|
|
|
|
2018-01-07 22:11:05 +08:00
|
|
|
runSequence.apply(this, tasks);
|
|
|
|
};
|
|
|
|
};
|
2017-12-25 07:42:25 +08:00
|
|
|
|
2018-01-07 22:11:05 +08:00
|
|
|
gulp.task('build-dev', simpleBuild(false));
|
|
|
|
gulp.task('build-prod', simpleBuild(true));
|