From 8ed202b53db88e4f460ee3ccf975c7d2e4171cb5 Mon Sep 17 00:00:00 2001 From: "Patrik J. Braun" Date: Sat, 26 Jan 2019 23:47:43 -0500 Subject: [PATCH] fixing tests --- benchmark/README.md | 2 +- benchmark/index.ts | 2 +- gulpfile.js | 195 -------------------------------------------- gulpfile.ts | 179 ++++++++++++++++++++++++++++++++++++++++ package.json | 78 +++++++++--------- 5 files changed, 221 insertions(+), 235 deletions(-) delete mode 100644 gulpfile.js create mode 100644 gulpfile.ts diff --git a/benchmark/README.md b/benchmark/README.md index e2491173..27b1c430 100644 --- a/benchmark/README.md +++ b/benchmark/README.md @@ -2,7 +2,7 @@ These results are created mostly for development, but I'm making them public for curious users. -## PiGallery2 v1.5.8, 06.01.2019 +## PiGallery2 v1.5.8, 26.01.2019 **System**: Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz, 16GB Ram, SHDD: 1TB, 5400 rpm **Gallery**: directories: 0 media: 341, faces: 39 diff --git a/benchmark/index.ts b/benchmark/index.ts index 9a1b975d..b2aaf471 100644 --- a/benchmark/index.ts +++ b/benchmark/index.ts @@ -20,7 +20,7 @@ const printLine = (text: string) => { const printHeader = async () => { const dt = new Date(); printLine('## PiGallery2 v' + require('./../package.json').version + - ', ' + Utils.zeroPrefix(dt.getDay(), 2) + + ', ' + Utils.zeroPrefix(dt.getDate(), 2) + '.' + Utils.zeroPrefix(dt.getMonth() + 1, 2) + '.' + dt.getFullYear()); printLine('**System**: ' + config.system); diff --git a/gulpfile.js b/gulpfile.js deleted file mode 100644 index a1d23dfc..00000000 --- a/gulpfile.js +++ /dev/null @@ -1,195 +0,0 @@ -var ts = require('gulp-typescript'); -var gulp = require('gulp'); -var zip = require('gulp-zip'); -var fs = require('fs'); -var runSequence = require('run-sequence'); -var jsonModify = require('gulp-json-modify'); -var exec = require('child_process').exec; - -var translationFolder = "translate"; -var tsBackendProject = ts.createProject('tsconfig.json'); -gulp.task('build-backend', function () { - return gulp.src([ - "common/**/*.ts", - "backend/**/*.ts"], {base: "."}) - .pipe(tsBackendProject()) - .js - .pipe(gulp.dest("./release")) - -}); -var createFrontendTask = function (type, script) { - gulp.task(type, function (cb) { - exec(script, function (err, stdout, stderr) { - console.log(stdout); - console.log(stderr); - cb(err); - }); - }); -}; - -gulp.task('build-frontend', function (done) { - var languages = getLanguages().filter(function (l) { - return l !== "en"; - }); - var tasks = []; - createFrontendTask('build-frontend-release default', - "ng build --aot --prod --output-path=./release/dist --no-progress --i18n-locale=en" + - " --i18n-format xlf --i18n-file frontend/" + translationFolder + "/messages.en.xlf" + - " --i18n-missing-translation warning"); - tasks.push('build-frontend-release default'); - for (var i = 0; i < languages.length; i++) { - createFrontendTask('build-frontend-release ' + languages[i], - "ng build --aot --prod --output-path=./release/dist/" + languages[i] + - " --no-progress --i18n-locale=" + languages[i] + - " --i18n-format xlf --i18n-file frontend/" + translationFolder + "/messages." + languages[i] + ".xlf" + - " --i18n-missing-translation warning"); - tasks.push('build-frontend-release ' + languages[i]); - } - tasks.push(function () { - done(); - }); - - runSequence.apply(this, tasks); - -}); - -gulp.task('copy-static', function () { - return gulp.src([ - "backend/model/diagnostics/blank.jpg", - "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')); -}); - - -gulp.task('zip-release', function () { - return gulp.src(['release/**/*'], {base: "./release"}) - .pipe(zip('pigallery2.zip')) - .pipe(gulp.dest('.')); -}); - -gulp.task('build-release', function (done) { - runSequence('build-frontend', 'build-backend', 'copy-static', 'copy-package', 'zip-release', function () { - done(); - }); -}); - -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] - }); -}; - -var simpleBuild = function (isProd) { - return function (done) { - var languages = getLanguages().filter(function (l) { - return l !== "en"; - }); - var tasks = []; - var cmd = "ng build --aot "; - if (isProd) { - cmd += " --prod --no-extract-licenses " - } - createFrontendTask('build-frontend default', cmd + "--output-path=./dist --no-progress --no-progress --i18n-locale en" + - " --i18n-format=xlf --i18n-file=frontend/" + translationFolder + "/messages.en.xlf" + " --i18n-missing-translation warning"); - tasks.push('build-frontend default'); - for (var i = 0; i < languages.length; i++) { - createFrontendTask('build-frontend ' + languages[i], cmd + "--output-path=./dist/" + languages[i] + " --no-progress --i18n-locale " + languages[i] + - " --i18n-format=xlf --i18n-file=frontend/" + translationFolder + "/messages." + languages[i] + ".xlf" + " --i18n-missing-translation warning"); - tasks.push('build-frontend ' + languages[i]); - } - tasks.push(function () { - done(); - }); - - runSequence.apply(this, tasks); - }; -}; - -gulp.task("extract-locale", function (cb) { - console.log("creating source translation file: locale.source.xlf"); - exec('ng xi18n --out-file=./../locale.source.xlf --i18n-format=xlf --i18n-locale=en', {maxBuffer: 1024 * 1024}, function (err, stdout, stderr) { - console.log(stdout); - console.log(stderr); - if (err) { - return cb(err); - } - exec('ngx-extractor -i frontend/**/*.ts -f xlf --out-file locale.source.xlf', function (err, stdout, stderr) { - console.log(stdout); - console.log(stderr); - cb(err); - }); - }); -}); - -var translate = function (list, cb) { - var localsStr = '"[\\"' + list.join('\\",\\"') + '\\"]"'; - 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(); - }); -}); - - -gulp.task('build-dev', simpleBuild(false)); -gulp.task('build-prod', simpleBuild(true)); diff --git a/gulpfile.ts b/gulpfile.ts new file mode 100644 index 00000000..09e1d033 --- /dev/null +++ b/gulpfile.ts @@ -0,0 +1,179 @@ +import * as gulp from 'gulp'; +import * as fs from 'fs'; +import * as zip from 'gulp-zip'; +import * as ts from 'gulp-typescript'; +// @ts-ignore +import * as jsonModify from 'gulp-json-modify'; + + +const exec = require('child_process').exec; + +const translationFolder = 'translate'; +const tsBackendProject = ts.createProject('tsconfig.json'); + +gulp.task('build-backend', function () { + return gulp.src([ + 'common/**/*.ts', + 'backend/**/*.ts'], {base: '.'}) + .pipe(tsBackendProject()) + .js + .pipe(gulp.dest('./release')); + +}); + +const handleError = (cb: (err: any) => void) => { + return (err: any, stdout: string, stderr: string) => { + console.log(stdout); + console.log(stderr); + cb(err); + }; +}; + +const createFrontendTask = (type: string, script: string) => { + gulp.task(type, (cb) => { + exec(script, handleError(cb)); + }); +}; + +const getLanguages = () => { + if (!fs.existsSync('./frontend/' + translationFolder)) { + return []; + } + const dirCont = fs.readdirSync('./frontend/' + translationFolder); + const files: string[] = dirCont.filter((elm) => { + return elm.match(/.*\.[a-zA-Z]+\.(xlf)/ig); + }); + return files.map((f: string) => { + return f.split('.')[1]; + }); +}; + +gulp.task('build-frontend', (() => { + const languages = getLanguages().filter((l) => { + return l !== 'en'; + }); + const tasks = []; + createFrontendTask('build-frontend-release default', + 'ng build --aot --prod --output-path=./release/dist --no-progress --i18n-locale=en' + + ' --i18n-format xlf --i18n-file frontend/' + translationFolder + '/messages.en.xlf' + + ' --i18n-missing-translation warning'); + tasks.push('build-frontend-release default'); + for (let i = 0; i < languages.length; i++) { + createFrontendTask('build-frontend-release ' + languages[i], + 'ng build --aot --prod --output-path=./release/dist/' + languages[i] + + ' --no-progress --i18n-locale=' + languages[i] + + ' --i18n-format xlf --i18n-file frontend/' + translationFolder + '/messages.' + languages[i] + '.xlf' + + ' --i18n-missing-translation warning'); + tasks.push('build-frontend-release ' + languages[i]); + } + return gulp.series(...tasks); +})()); + +gulp.task('copy-static', function () { + return gulp.src([ + 'backend/model/diagnostics/blank.jpg', + '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')); +}); + + +gulp.task('zip-release', function () { + return gulp.src(['release/**/*'], {base: './release'}) + .pipe(zip('pigallery2.zip')) + .pipe(gulp.dest('.')); +}); + +gulp.task('build-release', gulp.series('build-frontend', 'build-backend', 'copy-static', 'copy-package', 'zip-release')); + + +const simpleBuild = (isProd: boolean) => { + const languages = getLanguages().filter(function (l) { + return l !== 'en'; + }); + const tasks = []; + let cmd = 'ng build --aot '; + if (isProd) { + cmd += ' --prod --no-extract-licenses '; + } + createFrontendTask('build-frontend default', cmd + '--output-path=./dist --no-progress --no-progress --i18n-locale en' + + ' --i18n-format=xlf --i18n-file=frontend/' + translationFolder + '/messages.en.xlf' + ' --i18n-missing-translation warning'); + tasks.push('build-frontend default'); + for (let i = 0; i < languages.length; i++) { + createFrontendTask('build-frontend ' + languages[i], cmd + + '--output-path=./dist/' + languages[i] + + ' --no-progress --i18n-locale ' + languages[i] + + ' --i18n-format=xlf --i18n-file=frontend/' + translationFolder + + '/messages.' + languages[i] + '.xlf' + ' --i18n-missing-translation warning'); + tasks.push('build-frontend ' + languages[i]); + } + return gulp.series(...tasks); +}; + +gulp.task('extract-locale', (cb) => { + console.log('creating source translation file: locale.source.xlf'); + exec('ng xi18n --out-file=./../locale.source.xlf --i18n-format=xlf --i18n-locale=en', + {maxBuffer: 1024 * 1024}, (error: any, stdOut: string, stdErr: string) => { + console.log(stdOut); + console.log(stdErr); + if (error) { + return cb(error); + } + exec('ngx-extractor -i frontend/**/*.ts -f xlf --out-file locale.source.xlf', + handleError(cb)); + }); +}); + +const translate = (list: any[], cb: (err: any) => void) => { + const localsStr = '"[\\"' + list.join('\\",\\"') + '\\"]"'; + exec('xlf-google-translate --source-lang="en" --source-file="./locale.source.xlf" --destination-folder="./frontend/"' + + translationFolder + ' --destination-languages=' + localsStr, + handleError(cb)); +}; + +gulp.task('update-translation-only', function (cb) { + translate(getLanguages(), cb); +}); + +gulp.task('update-translation', gulp.series('extract-locale', 'update-translation-only')); + + +gulp.task('add-translation-only', (cb) => { + const languages = getLanguages(); + let lng = null; + for (let 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', gulp.series('extract-locale', 'add-translation-only')); + + +gulp.task('build-dev', simpleBuild(false)); +gulp.task('build-prod', simpleBuild(true)); diff --git a/package.json b/package.json index 63bc4285..fb23df45 100644 --- a/package.json +++ b/package.json @@ -30,58 +30,60 @@ "cookie-parser": "1.4.3", "cookie-session": "2.0.0-beta.3", "ejs": "2.6.1", - "exifreader": "2.5.0", + "exifreader": "2.6.0", "express": "4.16.4", "fluent-ffmpeg": "2.1.2", - "image-size": "0.6.3", + "image-size": "0.7.1", "jdataview": "2.5.0", "jimp": "0.6.0", "locale": "0.1.0", - "reflect-metadata": "0.1.12", - "sqlite3": "4.0.4", + "reflect-metadata": "0.1.13", + "sqlite3": "4.0.6", "ts-exif-parser": "0.1.4", "ts-node-iptc": "1.0.11", "typeconfig": "1.0.7", - "typeorm": "0.2.11", - "winston": "2.4.2", + "typeorm": "0.2.12", + "winston": "2.4.4", "xmldom": "0.1.27" }, "devDependencies": { - "@angular-devkit/build-angular": "0.11.4", - "@angular-devkit/build-optimizer": "0.11.4", - "@angular/animations": "7.1.4", - "@angular/cli": "7.1.4", - "@angular/common": "7.1.4", - "@angular/compiler": "7.1.4", - "@angular/compiler-cli": "7.1.4", - "@angular/core": "7.1.4", - "@angular/forms": "7.1.4", - "@angular/http": "7.1.4", - "@angular/language-service": "7.1.4", - "@angular/platform-browser": "7.1.4", - "@angular/platform-browser-dynamic": "7.1.4", - "@angular/router": "7.1.4", + "@angular-devkit/build-angular": "0.12.3", + "@angular-devkit/build-optimizer": "0.12.3", + "@angular/animations": "7.2.2", + "@angular/cli": "7.2.3", + "@angular/common": "7.2.2", + "@angular/compiler": "7.2.2", + "@angular/compiler-cli": "7.2.2", + "@angular/core": "7.2.2", + "@angular/forms": "7.2.2", + "@angular/http": "7.2.2", + "@angular/language-service": "7.2.2", + "@angular/platform-browser": "7.2.2", + "@angular/platform-browser-dynamic": "7.2.2", + "@angular/router": "7.2.2", "@ngx-translate/i18n-polyfill": "1.0.0", "@types/bcryptjs": "2.4.2", "@types/chai": "4.1.7", "@types/cookie-parser": "1.4.1", "@types/cookie-session": "2.0.36", "@types/ejs": "2.6.1", - "@types/express": "4.16.0", + "@types/express": "4.16.1", "@types/fluent-ffmpeg": "2.1.9", "@types/gm": "1.18.2", - "@types/image-size": "0.0.29", - "@types/jasmine": "3.3.5", + "@types/gulp": "^4.0.5", + "@types/gulp-zip": "^4.0.0", + "@types/image-size": "0.7.0", + "@types/jasmine": "3.3.8", "@types/node": "10.12.18", - "@types/sharp": "0.21.0", - "@types/winston": "2.3.9", + "@types/sharp": "0.21.2", + "@types/winston": "2.4.4", "@yaga/leaflet-ng2": "1.0.0", "bootstrap": "4.1.3", "chai": "4.2.0", "codelyzer": "4.5.0", - "core-js": "2.6.1", + "core-js": "2.6.3", "ejs-loader": "0.3.1", - "gulp": "3.9.1", + "gulp": "4.0.0", "gulp-json-modify": "1.0.2", "gulp-typescript": "5.0.0", "gulp-zip": "4.2.0", @@ -89,8 +91,8 @@ "intl": "1.2.5", "jasmine-core": "3.3.0", "jasmine-spec-reporter": "4.2.1", - "jw-bootstrap-switch-ng2": "2.0.2", - "karma": "3.1.4", + "jw-bootstrap-switch-ng2": "2.0.4", + "karma": "4.0.0", "karma-chrome-launcher": "2.2.0", "karma-cli": "2.0.0", "karma-coverage-istanbul-reporter": "2.0.4", @@ -106,18 +108,18 @@ "ngx-clipboard": "11.1.9", "ngx-toastr": "9.1.1", "open-iconic": "1.1.1", - "protractor": "5.4.1", - "remap-istanbul": "0.12.0", - "rimraf": "2.6.2", + "protractor": "5.4.2", + "remap-istanbul": "0.13.0", + "rimraf": "2.6.3", "run-sequence": "2.2.1", "rxjs": "6.3.3", "rxjs-compat": "^6.3.3", "ts-helpers": "1.1.2", - "ts-node": "7.0.1", - "tslint": "5.12.0", - "typescript": "3.1.6", + "ts-node": "8.0.2", + "tslint": "5.12.1", + "typescript": "3.2.4", "xlf-google-translate": "1.0.0-beta.13", - "zone.js": "0.8.26" + "zone.js": "0.8.29" }, "resolutions": { "natives": "1.1.3" @@ -125,10 +127,10 @@ "optionalDependencies": { "@ffmpeg-installer/ffmpeg": "1.0.17", "@ffprobe-installer/ffprobe": "1.0.9", - "bcrypt": "3.0.2", + "bcrypt": "3.0.3", "gm": "1.23.1", "mysql": "2.16.0", - "sharp": "0.21.1" + "sharp": "0.21.3" }, "engines": { "node": ">= 6.9 <11.0"