Skip to content

Commit

Permalink
[FSSDK-10985] Implement log message file generator (#974)
Browse files Browse the repository at this point in the history
  • Loading branch information
raju-opti authored Dec 11, 2024
1 parent bbe7a5b commit c2880e9
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ dist/
.DS_STORE

browserstack.err
local.log
local.log

**/*.gen.ts
36 changes: 36 additions & 0 deletions message_generator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import path from 'path';
import { writeFile } from 'fs/promises';

const generate = async () => {
const inp = process.argv.slice(2);
for(const filePath of inp) {
console.log('generating messages for: ', filePath);
const parsedPath = path.parse(filePath);
const fileName = parsedPath.name;
const dirName = parsedPath.dir;
const ext = parsedPath.ext;

const genFilePath = path.join(dirName, `${fileName}.gen${ext}`);
console.log('generated file path: ', genFilePath);
const exports = await import(filePath);
const messages : Array<any> = [];

let genOut = '';

Object.keys(exports).forEach((key, i) => {
const msg = exports[key];
genOut += `export const ${key} = '${i}';\n`;
messages.push(exports[key])
});

genOut += `export const messages = ${JSON.stringify(messages, null, 2)};`
await writeFile(genFilePath, genOut, 'utf-8');
};
}

generate().then(() => {
console.log('successfully generated messages');
}).catch((e) => {
console.error(e);
process.exit(1);
});
10 changes: 10 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@
"coveralls": "nyc --reporter=lcov npm test",
"prepare": "npm run build",
"prepublishOnly": "npm test && npm run test-ci",
"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\""
"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\"",
"genmsg": "jiti message_generator ./lib/error_messages.ts"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -132,6 +133,7 @@
"eslint-config-prettier": "^6.10.0",
"eslint-plugin-prettier": "^3.1.2",
"happy-dom": "^14.12.3",
"jiti": "^2.4.1",
"json-loader": "^0.5.4",
"karma": "^6.4.0",
"karma-browserstack-launcher": "^1.5.1",
Expand Down

0 comments on commit c2880e9

Please sign in to comment.