Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split copy-res into two phases during yarn start #26593

Merged
merged 3 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@
"build:bundle-stats": "webpack --progress --mode production --json > webpack-stats.json",
"build:module_system": "tsc --project ./tsconfig.module_system.json && node ./lib/module_system/scripts/install.js",
"dist": "scripts/package.sh",
"start": "yarn build:module_system && concurrently --kill-others-on-fail --prefix \"{time} [{name}]\" -n res,element-js \"yarn start:res\" \"yarn start:js\"",
"start": "concurrently --kill-others-on-fail --prefix \"{time} [{name}]\" -n modules,res,jitsi \"yarn build:module_system\" \"yarn build:res\" \"yarn build:jitsi\" && concurrently --kill-others-on-fail --prefix \"{time} [{name}]\" -n res,element-js \"yarn start:res\" \"yarn start:js\"",
"start:https": "concurrently --kill-others-on-fail --prefix \"{time} [{name}]\" -n res,element-js \"yarn start:res\" \"yarn start:js --https\"",
"start:res": "yarn build:jitsi && ts-node scripts/copy-res.ts -w",
"start:res": "ts-node scripts/copy-res.ts -w",
"start:js": "webpack serve --output-path webapp --mode development",
"lint": "yarn lint:types && yarn lint:js && yarn lint:style",
"lint:js": "yarn lint:js:src && yarn lint:js:module_system",
Expand Down
23 changes: 15 additions & 8 deletions scripts/copy-res.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ function next(i: number, err?: Error): void {
createCpx(path, dest).copy(errCheck);
};
chokidar
.watch(source)
.watch(source, { ignoreInitial: true })
.on("ready", () => {
logWatch(source);
cb();
Expand All @@ -107,7 +107,7 @@ function next(i: number, err?: Error): void {
}
}

function genLangFile(lang: string, dest: string): string {
function prepareLangFile(lang: string, dest: string): [filename: string, json: string] {
const reactSdkFile = REACT_I18N_BASE_PATH + lang + ".json";
const riotWebFile = I18N_BASE_PATH + lang + ".json";

Expand All @@ -128,12 +128,14 @@ function genLangFile(lang: string, dest: string): string {
const digest = loaderUtils.getHashDigest(jsonBuffer, null, "hex", 7);
const filename = `${lang}.${digest}.json`;

return [filename, json];
}

function genLangFile(dest: string, filename: string, json: string) {
fs.writeFileSync(dest + filename, json);
if (verbose) {
console.log("Generated language file: " + filename);
}

return filename;
}

function genLangList(langFileMap: Record<string, string>): void {
Expand Down Expand Up @@ -176,15 +178,16 @@ function watchLanguage(lang: string, dest: string, langFileMap: Record<string, s
clearTimeout(makeLangDebouncer);
}
makeLangDebouncer = setTimeout(() => {
const filename = genLangFile(lang, dest);
const [filename, json] = prepareLangFile(lang, dest);
genLangFile(dest, filename, json);
langFileMap[lang] = filename;
genLangList(langFileMap);
}, 500);
};

[reactSdkFile, riotWebFile].forEach(function (f) {
chokidar
.watch(f)
.watch(f, { ignoreInitial: true })
.on("ready", () => {
logWatch(f);
})
Expand All @@ -197,14 +200,18 @@ function watchLanguage(lang: string, dest: string, langFileMap: Record<string, s
// language resources
const I18N_DEST = "webapp/i18n/";
const I18N_FILENAME_MAP = INCLUDE_LANGS.reduce<Record<string, string>>((m, l) => {
const filename = genLangFile(l, I18N_DEST);
const [filename, json] = prepareLangFile(l, I18N_DEST);
if (!watch) {
genLangFile(I18N_DEST, filename, json);
}
m[l] = filename;
return m;
}, {});
genLangList(I18N_FILENAME_MAP);

if (watch) {
INCLUDE_LANGS.forEach((l) => watchLanguage(l, I18N_DEST, I18N_FILENAME_MAP));
} else {
genLangList(I18N_FILENAME_MAP);
}

// non-language resources
Expand Down
Loading