2017-06-02 22:31:51 +02:00
|
|
|
var ts = require('gulp-typescript');
|
|
|
|
var gulp = require('gulp');
|
2017-06-02 23:21:05 +02:00
|
|
|
var zip = require('gulp-zip');
|
2017-12-25 01:42:25 +02:00
|
|
|
var fs = require('fs');
|
2017-06-02 22:31:51 +02:00
|
|
|
var runSequence = require('run-sequence');
|
2017-07-11 22:10:36 +02:00
|
|
|
var jsonModify = require('gulp-json-modify');
|
|
|
|
var exec = require('child_process').exec;
|
2017-06-02 22:31:51 +02:00
|
|
|
|
2018-03-30 02:30:23 +02:00
|
|
|
var translationFolder = "translate";
|
2017-10-19 19:27:02 +02:00
|
|
|
var tsBackendProject = ts.createProject('tsconfig.json');
|
2017-07-11 22:10:36 +02:00
|
|
|
gulp.task('build-backend', function () {
|
|
|
|
return gulp.src([
|
|
|
|
"common/**/*.ts",
|
|
|
|
"backend/**/*.ts"], {base: "."})
|
2017-10-19 18:08:07 +02:00
|
|
|
.pipe(tsBackendProject())
|
2017-07-11 22:10:36 +02:00
|
|
|
.js
|
|
|
|
.pipe(gulp.dest("./release"))
|
2017-06-02 22:31:51 +02:00
|
|
|
|
|
|
|
});
|
2018-03-30 02:30:23 +02:00
|
|
|
var createFrontendTask = function (type, script) {
|
|
|
|
gulp.task(type, function (cb) {
|
2017-12-25 01:42:25 +02:00
|
|
|
exec(script, function (err, stdout, stderr) {
|
|
|
|
console.log(stdout);
|
|
|
|
console.log(stderr);
|
|
|
|
cb(err);
|
|
|
|
});
|
2017-07-11 22:10:36 +02:00
|
|
|
});
|
2017-12-25 01:42:25 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
gulp.task('build-frontend', function (done) {
|
2018-05-12 18:19:51 +02:00
|
|
|
var languages = getLanguages().filter(function (l) {
|
|
|
|
return l !== "en";
|
|
|
|
});
|
2017-12-25 01:42:25 +02:00
|
|
|
var tasks = [];
|
2018-05-04 00:23:48 +02:00
|
|
|
createFrontendTask('build-frontend-release default',
|
|
|
|
"ng build --aot -prod --output-path=./release/dist --no-progress --locale=en" +
|
|
|
|
" --i18n-format xlf --i18n-file frontend/" + translationFolder + "/messages.en.xlf" +
|
|
|
|
" --missing-translation warning");
|
2018-01-21 03:36:38 +02:00
|
|
|
tasks.push('build-frontend-release default');
|
2018-03-30 02:30:23 +02:00
|
|
|
for (var i = 0; i < languages.length; i++) {
|
2018-05-04 00:23:48 +02:00
|
|
|
createFrontendTask('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/" + translationFolder + "/messages." + languages[i] + ".xlf" +
|
|
|
|
" --missing-translation warning");
|
2018-01-21 03:36:38 +02:00
|
|
|
tasks.push('build-frontend-release ' + languages[i]);
|
2017-12-25 01:42:25 +02:00
|
|
|
}
|
|
|
|
tasks.push(function () {
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
runSequence.apply(this, tasks);
|
|
|
|
|
2017-07-11 22:10:36 +02: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-02 23:21:05 +02:00
|
|
|
gulp.task('zip-release', function () {
|
2017-07-11 22:23:07 +02:00
|
|
|
return gulp.src(['release/**/*'], {base: "./release"})
|
2017-07-11 22:10:36 +02:00
|
|
|
.pipe(zip('pigallery2.zip'))
|
|
|
|
.pipe(gulp.dest('.'));
|
2017-06-02 23:21:05 +02:00
|
|
|
});
|
2017-06-02 22:31:51 +02:00
|
|
|
|
|
|
|
gulp.task('build-release', function (done) {
|
2017-07-11 22:10:36 +02:00
|
|
|
runSequence('build-frontend', 'build-backend', 'copy-static', 'copy-package', 'zip-release', function () {
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2017-12-25 01:42:25 +02:00
|
|
|
|
2018-03-30 02:30:23 +02:00
|
|
|
var getLanguages = function () {
|
|
|
|
if (!fs.existsSync("./frontend/" + translationFolder)) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
var dirCont = fs.readdirSync("./frontend/" + translationFolder);
|
|
|
|
var files = dirCont.filter(function (elm) {
|
|
|
|
return elm.match(/.*\.[a-zA-Z]+\.(xlf)/ig);
|
|
|
|
});
|
|
|
|
return files.map(function (f) {
|
|
|
|
return f.split(".")[1]
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2018-01-07 16:11:05 +02:00
|
|
|
var simpleBuild = function (isProd) {
|
|
|
|
return function (done) {
|
2018-05-12 18:19:51 +02:00
|
|
|
var languages = getLanguages().filter(function (l) {
|
|
|
|
return l !== "en";
|
|
|
|
});
|
2018-01-07 16:11:05 +02:00
|
|
|
var tasks = [];
|
2018-03-30 23:59:43 +02:00
|
|
|
var cmd = "ng build --aot ";
|
2018-01-07 16:11:05 +02:00
|
|
|
if (isProd) {
|
|
|
|
cmd += " -prod "
|
|
|
|
}
|
2018-03-30 23:59:43 +02:00
|
|
|
createFrontendTask('build-frontend default', cmd + "--output-path=./dist --no-progress --no-progress --locale en" +
|
|
|
|
" --i18n-format=xlf --i18n-file=frontend/" + translationFolder + "/messages.en.xlf" + " --missing-translation warning");
|
2018-01-21 03:36:38 +02:00
|
|
|
tasks.push('build-frontend default');
|
2018-03-30 02:30:23 +02:00
|
|
|
for (var i = 0; i < languages.length; i++) {
|
|
|
|
createFrontendTask('build-frontend ' + languages[i], cmd + "--output-path=./dist/" + languages[i] + " --no-progress --locale " + languages[i] +
|
|
|
|
" --i18n-format=xlf --i18n-file=frontend/" + translationFolder + "/messages." + languages[i] + ".xlf" + " --missing-translation warning");
|
2018-01-21 03:36:38 +02:00
|
|
|
tasks.push('build-frontend ' + languages[i]);
|
2018-01-07 16:11:05 +02:00
|
|
|
}
|
|
|
|
tasks.push(function () {
|
|
|
|
done();
|
|
|
|
});
|
2017-12-25 01:42:25 +02:00
|
|
|
|
2018-01-07 16:11:05 +02:00
|
|
|
runSequence.apply(this, tasks);
|
|
|
|
};
|
|
|
|
};
|
2017-12-25 01:42:25 +02:00
|
|
|
|
2018-03-30 02:30:23 +02:00
|
|
|
gulp.task("extract-locale", function (cb) {
|
|
|
|
console.log("creating source translation file: locale.source.xlf");
|
|
|
|
exec('ng xi18n -of ./../locale.source.xlf -f xlf --locale en', function (err, stdout, stderr) {
|
|
|
|
console.log(stdout);
|
|
|
|
console.log(stderr);
|
|
|
|
if (err) {
|
|
|
|
return cb(err);
|
|
|
|
}
|
|
|
|
exec('ngx-extractor -i frontend/**/*.ts -f xlf -o locale.source.xlf', function (err, stdout, stderr) {
|
|
|
|
console.log(stdout);
|
|
|
|
console.log(stderr);
|
|
|
|
cb(err);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
var translate = function (list, cb) {
|
|
|
|
var localsStr = '"[\\"' + list.join('\\",\\"') + '\\"]"';
|
|
|
|
console.log(localsStr);
|
|
|
|
exec('xlf-google-translate --source-lang="en" --source-file="./locale.source.xlf" --destination-folder="./frontend/"' +
|
|
|
|
translationFolder + ' --destination-languages=' + localsStr, function (err, stdout, stderr) {
|
|
|
|
console.log(stdout);
|
|
|
|
console.log(stderr);
|
|
|
|
cb(err);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
gulp.task("update-translation-only", function (cb) {
|
|
|
|
translate(getLanguages(), cb)
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task("update-translation", function (done) {
|
|
|
|
runSequence('extract-locale', 'update-translation-only', function () {
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
gulp.task("add-translation-only", function (cb) {
|
|
|
|
var languages = getLanguages();
|
|
|
|
var lng = null;
|
|
|
|
for (var i = 0; i < process.argv.length - 1; i++) {
|
|
|
|
if (process.argv[i] === "add-translation") {
|
|
|
|
lng = process.argv[i + 1].replace("--", "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (lng == null) {
|
|
|
|
console.error("Error: set language with '--' e.g: npm run add-translation -- --en");
|
|
|
|
return cb();
|
|
|
|
}
|
|
|
|
if (languages.indexOf(lng) !== -1) {
|
|
|
|
console.error("Error: language already exists, can't add. These language(s) already exist(s): " + languages);
|
|
|
|
return cb();
|
|
|
|
}
|
|
|
|
translate([lng], cb)
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
gulp.task("add-translation", function (done) {
|
|
|
|
runSequence('extract-locale', 'add-translation-only', function () {
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2018-01-07 16:11:05 +02:00
|
|
|
gulp.task('build-dev', simpleBuild(false));
|
|
|
|
gulp.task('build-prod', simpleBuild(true));
|