Skip to content

[FSSDK-10985] Implement log message file generator #974

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

Merged
merged 2 commits into from
Dec 11, 2024
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: 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
Loading