Skip to content

Commit c2880e9

Browse files
authored
[FSSDK-10985] Implement log message file generator (#974)
1 parent bbe7a5b commit c2880e9

File tree

4 files changed

+52
-2
lines changed

4 files changed

+52
-2
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,6 @@ dist/
1212
.DS_STORE
1313

1414
browserstack.err
15-
local.log
15+
local.log
16+
17+
**/*.gen.ts

message_generator.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import path from 'path';
2+
import { writeFile } from 'fs/promises';
3+
4+
const generate = async () => {
5+
const inp = process.argv.slice(2);
6+
for(const filePath of inp) {
7+
console.log('generating messages for: ', filePath);
8+
const parsedPath = path.parse(filePath);
9+
const fileName = parsedPath.name;
10+
const dirName = parsedPath.dir;
11+
const ext = parsedPath.ext;
12+
13+
const genFilePath = path.join(dirName, `${fileName}.gen${ext}`);
14+
console.log('generated file path: ', genFilePath);
15+
const exports = await import(filePath);
16+
const messages : Array<any> = [];
17+
18+
let genOut = '';
19+
20+
Object.keys(exports).forEach((key, i) => {
21+
const msg = exports[key];
22+
genOut += `export const ${key} = '${i}';\n`;
23+
messages.push(exports[key])
24+
});
25+
26+
genOut += `export const messages = ${JSON.stringify(messages, null, 2)};`
27+
await writeFile(genFilePath, genOut, 'utf-8');
28+
};
29+
}
30+
31+
generate().then(() => {
32+
console.log('successfully generated messages');
33+
}).catch((e) => {
34+
console.error(e);
35+
process.exit(1);
36+
});

package-lock.json

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@
8888
"coveralls": "nyc --reporter=lcov npm test",
8989
"prepare": "npm run build",
9090
"prepublishOnly": "npm test && npm run test-ci",
91-
"postbuild:win": "@powershell copy \"dist/index.lite.d.ts\" \"dist/optimizely.lite.es.d.ts\" && @powershell copy \"dist/index.lite.d.ts\" \"dist/optimizely.lite.es.min.d.ts\" && @powershell copy \"dist/index.lite.d.ts\" \"dist/optimizely.lite.min.d.ts\""
91+
"postbuild:win": "@powershell copy \"dist/index.lite.d.ts\" \"dist/optimizely.lite.es.d.ts\" && @powershell copy \"dist/index.lite.d.ts\" \"dist/optimizely.lite.es.min.d.ts\" && @powershell copy \"dist/index.lite.d.ts\" \"dist/optimizely.lite.min.d.ts\"",
92+
"genmsg": "jiti message_generator ./lib/error_messages.ts"
9293
},
9394
"repository": {
9495
"type": "git",
@@ -132,6 +133,7 @@
132133
"eslint-config-prettier": "^6.10.0",
133134
"eslint-plugin-prettier": "^3.1.2",
134135
"happy-dom": "^14.12.3",
136+
"jiti": "^2.4.1",
135137
"json-loader": "^0.5.4",
136138
"karma": "^6.4.0",
137139
"karma-browserstack-launcher": "^1.5.1",

0 commit comments

Comments
 (0)