2019-01-27 06:47:43 +02:00
|
|
|
import * as gulp from 'gulp';
|
|
|
|
import * as fs from 'fs';
|
2023-01-13 14:56:30 +02:00
|
|
|
import {promises as fsp} from 'fs';
|
2019-12-31 18:27:38 +02:00
|
|
|
import * as path from 'path';
|
|
|
|
import * as util from 'util';
|
2019-01-27 06:47:43 +02:00
|
|
|
import * as zip from 'gulp-zip';
|
|
|
|
import * as ts from 'gulp-typescript';
|
2023-12-03 10:38:29 +02:00
|
|
|
import * as sourcemaps from 'gulp-sourcemaps';
|
2019-12-31 18:27:38 +02:00
|
|
|
import * as xml2js from 'xml2js';
|
|
|
|
import * as child_process from 'child_process';
|
2022-04-04 19:37:31 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
2019-01-27 06:47:43 +02:00
|
|
|
// @ts-ignore
|
2019-12-21 19:14:28 +02:00
|
|
|
import * as jeditor from 'gulp-json-editor';
|
2023-01-13 14:56:30 +02:00
|
|
|
import {XLIFF} from 'xlf-google-translate';
|
|
|
|
import {PrivateConfigClass} from './src/common/config/private/Config';
|
|
|
|
import {ConfigClassBuilder} from 'typeconfig/src/decorators/builders/ConfigClassBuilder';
|
2019-01-27 06:47:43 +02:00
|
|
|
|
2019-12-31 18:27:38 +02:00
|
|
|
const execPr = util.promisify(child_process.exec);
|
2019-01-27 06:47:43 +02:00
|
|
|
|
|
|
|
const translationFolder = 'translate';
|
|
|
|
const tsBackendProject = ts.createProject('tsconfig.json');
|
2022-04-04 19:37:31 +02:00
|
|
|
declare const process: NodeJS.Process;
|
2019-01-27 06:47:43 +02:00
|
|
|
|
2019-12-22 01:04:52 +02:00
|
|
|
const getSwitch = (name: string, def: string = null): string => {
|
2019-12-21 19:14:28 +02:00
|
|
|
name = '--' + name;
|
|
|
|
for (let i = 0; i < process.argv.length; i++) {
|
|
|
|
if (process.argv[i].startsWith(name + '=')) {
|
|
|
|
return process.argv[i].replace(name + '=', '').trim();
|
|
|
|
}
|
2019-12-22 01:04:52 +02:00
|
|
|
if (process.argv[i].startsWith(name)) {
|
|
|
|
if (i + 1 < process.argv.length) {
|
|
|
|
return process.argv[i + 1].trim();
|
|
|
|
}
|
|
|
|
return 'true';
|
2019-12-21 19:14:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return def;
|
|
|
|
};
|
|
|
|
|
2021-04-18 16:54:34 +02:00
|
|
|
gulp.task('build-backend', (): any =>
|
2022-04-04 19:37:31 +02:00
|
|
|
gulp
|
|
|
|
.src(['src/common/**/*.ts', 'src/backend/**/*.ts', 'benchmark/**/*.ts'], {
|
2023-12-03 10:38:29 +02:00
|
|
|
base: '.'
|
2022-04-04 19:37:31 +02:00
|
|
|
})
|
2023-12-03 10:38:29 +02:00
|
|
|
.pipe(sourcemaps.init())
|
2019-01-27 06:47:43 +02:00
|
|
|
.pipe(tsBackendProject())
|
2023-12-03 10:38:29 +02:00
|
|
|
.pipe(sourcemaps.write('.', {includeContent: false}))
|
|
|
|
.pipe(gulp.dest('./release'))
|
2022-04-04 19:37:31 +02:00
|
|
|
);
|
2019-01-27 06:47:43 +02:00
|
|
|
|
2022-04-04 19:37:31 +02:00
|
|
|
const createDynamicTranslationFile = async (
|
|
|
|
language: string
|
|
|
|
): Promise<void> => {
|
2019-12-31 18:27:38 +02:00
|
|
|
// load
|
|
|
|
const folder = './src/frontend/' + translationFolder;
|
2022-04-04 19:37:31 +02:00
|
|
|
const data: string = await fsp.readFile(
|
|
|
|
path.join(folder, `messages.${language}.xlf`),
|
|
|
|
'utf-8'
|
|
|
|
);
|
2019-12-31 18:27:38 +02:00
|
|
|
const translationXml: XLIFF.Root = await xml2js.parseStringPromise(data);
|
|
|
|
|
2023-12-03 10:38:29 +02:00
|
|
|
// clean translations, keep only .ts translations
|
2021-04-18 15:48:35 +02:00
|
|
|
const hasTsTranslation = (cg: XLIFF.ContextGroup): boolean =>
|
2022-04-04 19:37:31 +02:00
|
|
|
cg.context.findIndex(
|
|
|
|
(c: any): boolean =>
|
|
|
|
c.$['context-type'] === 'sourcefile' && c._.endsWith('.ts')
|
|
|
|
) !== -1;
|
2019-12-31 18:27:38 +02:00
|
|
|
const translations = translationXml.xliff.file[0].body[0]['trans-unit'];
|
2022-04-04 19:37:31 +02:00
|
|
|
const filtered = translations.filter(
|
|
|
|
(tr): boolean => tr['context-group'].findIndex(hasTsTranslation) !== -1
|
|
|
|
);
|
2021-04-18 15:48:35 +02:00
|
|
|
filtered.forEach((tr): boolean => delete tr['context-group']);
|
2019-12-31 18:27:38 +02:00
|
|
|
translationXml.xliff.file[0].body[0]['trans-unit'] = filtered;
|
|
|
|
|
|
|
|
// save
|
2021-01-04 12:11:55 +02:00
|
|
|
const builder = new xml2js.Builder();
|
2019-12-31 18:27:38 +02:00
|
|
|
const xml = builder.buildObject(translationXml);
|
|
|
|
await fsp.writeFile(path.join(folder, `ts-only-msg.${language}.xlf`), xml);
|
|
|
|
};
|
|
|
|
|
2022-04-04 19:37:31 +02:00
|
|
|
const removeDynamicTranslationFile = async (
|
|
|
|
language: string
|
|
|
|
): Promise<void> => {
|
|
|
|
const translationFile = path.join(
|
|
|
|
'./src/frontend/',
|
|
|
|
translationFolder,
|
|
|
|
`ts-only-msg.${language}.xlf`
|
|
|
|
);
|
2019-12-31 18:27:38 +02:00
|
|
|
fsp.unlink(translationFile);
|
|
|
|
};
|
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
const setDynTransFileAtAppModule = async (language: string): Promise<void> => {
|
2019-12-31 18:27:38 +02:00
|
|
|
const file = './src/frontend/app/app.module.ts';
|
|
|
|
let data: string = await fsp.readFile(file, 'utf-8');
|
|
|
|
const from = 'messages.${locale}.xlf';
|
|
|
|
const to = `ts-only-msg.${language}.xlf`;
|
|
|
|
data = data.replace(from, to);
|
|
|
|
await fsp.writeFile(file, data);
|
|
|
|
};
|
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
const resetAppModule = async (language: string): Promise<void> => {
|
2019-12-31 18:27:38 +02:00
|
|
|
const file = './src/frontend/app/app.module.ts';
|
|
|
|
let data: string = await fsp.readFile(file, 'utf-8');
|
|
|
|
const from = 'messages.${locale}.xlf';
|
|
|
|
const to = `ts-only-msg.${language}.xlf`;
|
|
|
|
data = data.replace(to, from);
|
|
|
|
await fsp.writeFile(file, data);
|
|
|
|
};
|
|
|
|
|
2022-04-04 19:37:31 +02:00
|
|
|
const createFrontendTask = (
|
|
|
|
type: string,
|
|
|
|
script: string
|
|
|
|
): void => {
|
2021-04-18 15:48:35 +02:00
|
|
|
gulp.task(type, async (cb): Promise<void> => {
|
2019-12-31 18:27:38 +02:00
|
|
|
try {
|
2023-01-13 14:56:30 +02:00
|
|
|
const {stdout, stderr} = await execPr(script);
|
2019-12-31 18:27:38 +02:00
|
|
|
console.log(stdout);
|
|
|
|
console.error(stderr);
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
2021-04-17 18:32:32 +02:00
|
|
|
cb(e);
|
2019-12-31 18:27:38 +02:00
|
|
|
}
|
2019-01-27 06:47:43 +02:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
const getLanguages = (): any[] | string[] => {
|
2019-12-10 11:44:35 +02:00
|
|
|
if (!fs.existsSync('./src/frontend/' + translationFolder)) {
|
2019-01-27 06:47:43 +02:00
|
|
|
return [];
|
|
|
|
}
|
2019-12-10 11:44:35 +02:00
|
|
|
const dirCont = fs.readdirSync('./src/frontend/' + translationFolder);
|
2021-04-18 15:48:35 +02:00
|
|
|
const files: string[] = dirCont.filter((elm): any => {
|
2023-01-10 21:38:26 +02:00
|
|
|
return elm.match(/.*\.[a-zA-Z]+(-[a-zA-Z]+)?\.(xlf)/gi);
|
2019-01-27 06:47:43 +02:00
|
|
|
});
|
2019-12-08 01:33:50 +02:00
|
|
|
|
|
|
|
// get languages to filter
|
|
|
|
let languageFilter: string[] = null;
|
2019-12-21 19:14:28 +02:00
|
|
|
if (getSwitch('languages')) {
|
|
|
|
languageFilter = getSwitch('languages').split(',');
|
2019-12-08 01:33:50 +02:00
|
|
|
}
|
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
let languages = files.map((f: string): string => {
|
2019-01-27 06:47:43 +02:00
|
|
|
return f.split('.')[1];
|
|
|
|
});
|
2019-12-08 01:33:50 +02:00
|
|
|
|
|
|
|
if (languageFilter !== null) {
|
2021-04-18 15:48:35 +02:00
|
|
|
languages = languages.filter((l): boolean => {
|
2019-12-08 01:33:50 +02:00
|
|
|
return languageFilter.indexOf(l) !== -1;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return languages;
|
2019-01-27 06:47:43 +02:00
|
|
|
};
|
|
|
|
|
2022-04-04 19:37:31 +02:00
|
|
|
gulp.task(
|
|
|
|
'build-frontend',
|
|
|
|
((): any => {
|
|
|
|
const tasks = [];
|
|
|
|
createFrontendTask(
|
|
|
|
'build-frontend-release default',
|
2023-03-12 01:11:39 +02:00
|
|
|
'ng build --configuration production --no-progress --output-path=./release/dist'
|
2022-04-04 19:37:31 +02:00
|
|
|
);
|
|
|
|
tasks.push('build-frontend-release default');
|
|
|
|
return gulp.series(...tasks);
|
|
|
|
})()
|
|
|
|
);
|
|
|
|
|
|
|
|
gulp.task('copy-static', (): any =>
|
|
|
|
gulp
|
|
|
|
.src(
|
|
|
|
[
|
|
|
|
'src/backend/model/diagnostics/blank.jpg',
|
|
|
|
'README.md',
|
|
|
|
// 'package-lock.json', should not add, it keeps optional packages optional even with --force-opt-packages.
|
|
|
|
'LICENSE',
|
|
|
|
],
|
2023-01-13 14:56:30 +02:00
|
|
|
{base: '.'}
|
2022-04-04 19:37:31 +02:00
|
|
|
)
|
|
|
|
.pipe(gulp.dest('./release'))
|
|
|
|
);
|
|
|
|
|
|
|
|
gulp.task('copy-package', (): any =>
|
|
|
|
gulp
|
2023-01-13 14:56:30 +02:00
|
|
|
.src(['package.json'], {base: '.'})
|
2022-04-04 19:37:31 +02:00
|
|
|
.pipe(
|
|
|
|
jeditor(
|
|
|
|
(json: {
|
|
|
|
devDependencies: { [key: string]: string };
|
|
|
|
scripts: { [key: string]: string };
|
|
|
|
dependencies: { [key: string]: string };
|
|
|
|
optionalDependencies: { [key: string]: string };
|
|
|
|
buildTime: string;
|
|
|
|
buildCommitHash: string;
|
|
|
|
}): {
|
|
|
|
devDependencies: { [p: string]: string };
|
|
|
|
scripts: { [p: string]: string };
|
|
|
|
dependencies: { [p: string]: string };
|
|
|
|
optionalDependencies: { [p: string]: string };
|
|
|
|
buildTime: string;
|
|
|
|
buildCommitHash: string;
|
|
|
|
} => {
|
|
|
|
delete json.devDependencies;
|
2023-01-13 14:56:30 +02:00
|
|
|
json.scripts = {start: 'node ./src/backend/index.js'};
|
2022-04-04 19:37:31 +02:00
|
|
|
|
|
|
|
if (getSwitch('skip-opt-packages')) {
|
|
|
|
const skipPackages = getSwitch('skip-opt-packages')
|
|
|
|
.replace(new RegExp(' ', 'g'), ',')
|
|
|
|
.split(',');
|
|
|
|
for (const pkg of skipPackages) {
|
|
|
|
for (const key of Object.keys(json.optionalDependencies)) {
|
|
|
|
if (key.indexOf(pkg) !== -1) {
|
|
|
|
delete json.optionalDependencies[key];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-12-21 19:14:28 +02:00
|
|
|
}
|
2019-01-27 06:47:43 +02:00
|
|
|
|
2022-04-04 19:37:31 +02:00
|
|
|
if (getSwitch('force-opt-packages')) {
|
|
|
|
for (const key of Object.keys(json.optionalDependencies)) {
|
|
|
|
json.dependencies[key] = json.optionalDependencies[key];
|
|
|
|
}
|
|
|
|
delete json.optionalDependencies;
|
|
|
|
}
|
|
|
|
json.buildTime = new Date().toISOString();
|
|
|
|
|
|
|
|
try {
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
|
|
json.buildCommitHash = require('child_process')
|
|
|
|
.execSync('git rev-parse HEAD')
|
|
|
|
.toString()
|
|
|
|
.trim();
|
|
|
|
// eslint-disable-next-line no-empty
|
2023-01-13 14:56:30 +02:00
|
|
|
} catch (e) {
|
|
|
|
}
|
2022-04-04 19:37:31 +02:00
|
|
|
|
|
|
|
return json;
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.pipe(gulp.dest('./release'))
|
|
|
|
);
|
2019-01-27 06:47:43 +02:00
|
|
|
|
2021-04-18 16:54:34 +02:00
|
|
|
gulp.task('zip-release', (): any =>
|
2022-04-04 19:37:31 +02:00
|
|
|
gulp
|
2023-01-13 14:56:30 +02:00
|
|
|
.src(['release/**/*'], {base: './release'})
|
2019-01-27 06:47:43 +02:00
|
|
|
.pipe(zip('pigallery2.zip'))
|
2022-04-04 19:37:31 +02:00
|
|
|
.pipe(gulp.dest('.'))
|
|
|
|
);
|
|
|
|
|
2019-01-27 06:47:43 +02:00
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
const simpleBuild = (isProd: boolean): any => {
|
2019-01-27 06:47:43 +02:00
|
|
|
const tasks = [];
|
2021-04-17 18:32:32 +02:00
|
|
|
let cmd = 'ng build ';
|
2019-01-27 06:47:43 +02:00
|
|
|
if (isProd) {
|
2023-03-12 01:11:39 +02:00
|
|
|
cmd += ' --configuration production --no-extract-licenses ';
|
2019-01-27 06:47:43 +02:00
|
|
|
}
|
2023-01-13 14:56:30 +02:00
|
|
|
createFrontendTask('build-frontend default', cmd);
|
2021-04-17 18:32:32 +02:00
|
|
|
tasks.push('build-frontend default');
|
2019-01-27 06:47:43 +02:00
|
|
|
return gulp.series(...tasks);
|
|
|
|
};
|
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
gulp.task('extract-locale', async (cb): Promise<any> => {
|
2019-01-27 06:47:43 +02:00
|
|
|
console.log('creating source translation file: locale.source.xlf');
|
2019-12-31 18:27:38 +02:00
|
|
|
try {
|
|
|
|
{
|
2023-01-13 14:56:30 +02:00
|
|
|
const {stdout, stderr} = await execPr(
|
2022-04-04 19:37:31 +02:00
|
|
|
'ng extract-i18n --out-file=locale.source.xlf --format=xlf',
|
2023-01-13 14:56:30 +02:00
|
|
|
{maxBuffer: 1024 * 1024}
|
2022-04-04 19:37:31 +02:00
|
|
|
);
|
2019-12-31 18:27:38 +02:00
|
|
|
console.log(stdout);
|
|
|
|
console.error(stderr);
|
|
|
|
}
|
|
|
|
cb();
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
|
|
|
return cb(e);
|
|
|
|
}
|
2019-01-27 06:47:43 +02:00
|
|
|
});
|
|
|
|
|
2022-04-04 19:37:31 +02:00
|
|
|
const translate = async (
|
|
|
|
list: any[],
|
|
|
|
cb: (err?: any) => void
|
|
|
|
): Promise<void> => {
|
2019-12-31 18:27:38 +02:00
|
|
|
try {
|
|
|
|
const localsStr = '"[\\"' + list.join('\\",\\"') + '\\"]"';
|
2023-01-13 14:56:30 +02:00
|
|
|
const {stdout, stderr} = await execPr(
|
2022-04-04 19:37:31 +02:00
|
|
|
'xlf-google-translate ' +
|
2023-01-13 14:56:30 +02:00
|
|
|
'--source-lang="en" ' +
|
|
|
|
'--source-file="./locale.source.xlf" ' +
|
|
|
|
'--destination-filename="messages" ' +
|
|
|
|
'--destination-folder="./src/frontend/"' +
|
|
|
|
translationFolder +
|
|
|
|
' --destination-languages=' +
|
|
|
|
localsStr
|
2022-04-04 19:37:31 +02:00
|
|
|
);
|
2019-12-31 18:27:38 +02:00
|
|
|
console.log(stdout);
|
|
|
|
console.error(stderr);
|
|
|
|
cb();
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
|
|
|
return cb(e);
|
|
|
|
}
|
2019-01-27 06:47:43 +02:00
|
|
|
};
|
2021-04-18 15:48:35 +02:00
|
|
|
const merge = async (list: any[], cb: (err?: any) => void): Promise<void> => {
|
2019-12-31 18:27:38 +02:00
|
|
|
try {
|
|
|
|
const localsStr = '"[\\"' + list.join('\\",\\"') + '\\"]"';
|
2022-04-04 19:37:31 +02:00
|
|
|
const command =
|
|
|
|
'xlf-google-translate ' +
|
2019-12-31 18:27:38 +02:00
|
|
|
'--method="extend-only" ' +
|
|
|
|
'--source-lang="en" ' +
|
|
|
|
'--source-file="./locale.source.xlf" ' +
|
|
|
|
'--destination-filename="messages" ' +
|
2022-04-04 19:37:31 +02:00
|
|
|
'--destination-folder="./src/frontend/' +
|
|
|
|
translationFolder +
|
|
|
|
'" ' +
|
|
|
|
'--destination-languages=' +
|
|
|
|
localsStr;
|
2021-04-17 18:32:32 +02:00
|
|
|
console.log(command);
|
2023-01-13 14:56:30 +02:00
|
|
|
const {stdout, stderr} = await execPr(command);
|
2019-12-31 18:27:38 +02:00
|
|
|
console.log(stdout);
|
|
|
|
console.error(stderr);
|
|
|
|
cb();
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
|
|
|
return cb(e);
|
|
|
|
}
|
2019-07-21 15:14:12 +02:00
|
|
|
};
|
2019-01-27 06:47:43 +02:00
|
|
|
|
2021-04-18 16:54:34 +02:00
|
|
|
gulp.task('update-translation-only', (cb): void => {
|
2020-01-03 21:28:03 +02:00
|
|
|
translate(getLanguages(), cb).catch(console.error);
|
2019-01-27 06:47:43 +02:00
|
|
|
});
|
2021-04-18 16:54:34 +02:00
|
|
|
gulp.task('merge-translation-only', (cb): void => {
|
2020-01-03 21:28:03 +02:00
|
|
|
merge(getLanguages(), cb).catch(console.error);
|
2019-07-21 15:14:12 +02:00
|
|
|
});
|
2019-01-27 06:47:43 +02:00
|
|
|
|
2022-04-04 19:37:31 +02:00
|
|
|
gulp.task(
|
|
|
|
'update-translation',
|
|
|
|
gulp.series('extract-locale', 'update-translation-only')
|
|
|
|
);
|
2019-07-21 15:14:12 +02:00
|
|
|
|
2022-04-04 19:37:31 +02:00
|
|
|
gulp.task(
|
|
|
|
'merge-new-translation',
|
|
|
|
gulp.series('extract-locale', 'merge-translation-only')
|
|
|
|
);
|
2019-01-27 06:47:43 +02:00
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
gulp.task('add-translation-only', (cb): any => {
|
2019-01-27 06:47:43 +02:00
|
|
|
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) {
|
2022-04-04 19:37:31 +02:00
|
|
|
console.error(
|
2023-01-13 14:56:30 +02:00
|
|
|
'Error: set language with \'--\' e.g: npm run add-translation -- --en'
|
2022-04-04 19:37:31 +02:00
|
|
|
);
|
2019-01-27 06:47:43 +02:00
|
|
|
return cb();
|
|
|
|
}
|
|
|
|
if (languages.indexOf(lng) !== -1) {
|
2022-04-04 19:37:31 +02:00
|
|
|
console.error(
|
2023-01-13 14:56:30 +02:00
|
|
|
'Error: language already exists, can\'t add. These language(s) already exist(s): ' +
|
|
|
|
languages
|
2022-04-04 19:37:31 +02:00
|
|
|
);
|
2019-01-27 06:47:43 +02:00
|
|
|
return cb();
|
|
|
|
}
|
|
|
|
translate([lng], cb);
|
|
|
|
});
|
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
gulp.task('generate-man', async (cb): Promise<void> => {
|
2021-04-17 18:32:32 +02:00
|
|
|
const defCFG = ConfigClassBuilder.attachInterface(new PrivateConfigClass());
|
2020-02-07 14:59:36 +02:00
|
|
|
defCFG.Server.sessionSecret = [];
|
2020-01-28 19:36:52 +02:00
|
|
|
let txt = '# Pigallery 2 man page\n';
|
2022-04-04 19:37:31 +02:00
|
|
|
txt +=
|
|
|
|
'pigallery2 uses [typeconfig](https://github.com/bpatrik/typeconfig) for configuration\n\n';
|
2020-01-28 19:36:52 +02:00
|
|
|
txt += '`npm start -- --help` prints the following:\n\n';
|
2022-04-04 19:37:31 +02:00
|
|
|
txt +=
|
|
|
|
'```\n' +
|
|
|
|
ConfigClassBuilder.attachPrivateInterface(defCFG).__printMan() +
|
|
|
|
'```';
|
2020-02-07 14:59:36 +02:00
|
|
|
txt += '\n\n ### `config.json` sample:\n';
|
|
|
|
txt += '```json\n' + JSON.stringify(defCFG, null, 4) + '```';
|
2020-01-28 19:36:52 +02:00
|
|
|
await fsp.writeFile('MANPAGE.md', txt);
|
|
|
|
cb();
|
|
|
|
});
|
2019-01-27 06:47:43 +02:00
|
|
|
|
2023-04-08 01:00:05 +02:00
|
|
|
// this is a workaround for bundle hash is not considering localization
|
|
|
|
// so all the js files would have the same name and caching would not be possible to use
|
|
|
|
// prefixing main.js with localization to force reload
|
|
|
|
// see: https://github.com/angular/angular-cli/issues/17416
|
|
|
|
gulp.task('localize-bundles', async (cb): Promise<void> => {
|
|
|
|
const bundlesToUpdate = ['main'];
|
|
|
|
const foldersToCheck = ['./dist', './release/dist'];
|
|
|
|
for (let f = 0; f < foldersToCheck.length; ++f) {
|
|
|
|
const folder = foldersToCheck[f];
|
|
|
|
if (!fs.existsSync(folder)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
const builds = fs.readdirSync(folder);
|
|
|
|
|
|
|
|
for (let i = 0; i < builds.length; ++i) {
|
|
|
|
const dir = path.join(folder, builds[i]);
|
|
|
|
const indexhtmlPath = path.join(dir, 'index.html');
|
|
|
|
|
|
|
|
let indexhtml = fs.readFileSync(indexhtmlPath, 'utf8');
|
|
|
|
|
|
|
|
for (let j = 0; j < bundlesToUpdate.length; ++j) {
|
|
|
|
|
|
|
|
const rgx = new RegExp('<script src="' + bundlesToUpdate[j], 'g');
|
|
|
|
indexhtml = indexhtml.replace(rgx, '<script src="' + builds[i] + '.' + bundlesToUpdate[j]);
|
|
|
|
fs.readdirSync(folder);
|
|
|
|
|
|
|
|
const fileToRename = fs.readdirSync(dir)
|
|
|
|
.find(fl => fl.startsWith(bundlesToUpdate[j]) && fl.endsWith('js'));
|
|
|
|
if (!fileToRename) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
fs.renameSync(path.join(dir, fileToRename), path.join(dir, builds[i] + '.' + fileToRename));
|
|
|
|
}
|
|
|
|
fs.writeFileSync(indexhtmlPath, indexhtml, 'utf8');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cb();
|
|
|
|
});
|
|
|
|
|
2022-04-04 19:37:31 +02:00
|
|
|
gulp.task(
|
|
|
|
'add-translation',
|
|
|
|
gulp.series('extract-locale', 'add-translation-only')
|
|
|
|
);
|
2019-01-27 06:47:43 +02:00
|
|
|
|
|
|
|
gulp.task('build-dev', simpleBuild(false));
|
2023-04-08 01:00:05 +02:00
|
|
|
gulp.task('build-prod', gulp.series(simpleBuild(true), 'localize-bundles'));
|
|
|
|
|
|
|
|
gulp.task(
|
|
|
|
'create-release',
|
|
|
|
gulp.series(
|
|
|
|
'build-frontend',
|
|
|
|
'localize-bundles',
|
|
|
|
'build-backend',
|
|
|
|
'copy-static',
|
|
|
|
'copy-package',
|
|
|
|
'zip-release'
|
|
|
|
)
|
|
|
|
);
|