Tired of manually writing BabelJS generation code for JavaScript? You're not alone.
Given a JS file, babelJS-gen-gen generates a TypeScript program that generates the BabelJS generation code to generate this file.
- Clone this repository
npm installin the repo root
- Something to compile/run TypeScript (recommended: either
tscorts-node) nodejs(ensure the version is new enough to natively support ESM)npm
The arguments to babeljs-gen-gen are as follows:
file_to_gengen: the JS file to generate generation code for- optional
gen_full_script: iftrue, the output is a runnable TypeScript program that will generate the JS and print it to console. The default behaviour is to generate only the generation code (for easy pasting into your own program). - optional
output_file: if specified, output the generation code to this file. The default behaviour is to print to console.
There are some examples of JS files and corresponding generated generation code in the Examples directory.
file.jsis the sample input JS filesample_output.tsis the corresponding generated generation script
To recreate: ts-node gen_babel_gencode.ts --file_to_gengen Example/file.js --gen_full_script true
Running ts-node Example/sample_output.ts will print the same code as contained in file.js.
babel_core_lib_index.jsis the sample input JS file, taken from the compiled babel core package'slib/index.jsfile.babel_core_lib_output.tsis the corresponding generated generation script
To recreate: ts-node gen_babel_gencode.ts --file_to_gengen Example/babel_core_lib_index.js --gen_full_script true
Running ts-node Example/babel_core_lib_output.ts will print the same code (modulo a few formatting improvements) as contained in babel_core_lib_index.js.
ts-node gen_babel_gencode.ts --file_to_gengen file.js --gen_full_script true --output_file output.js
ts-node gen_babel_gencode.ts --file_to_gengen file.js --output_file output.js
ts-node gen_babel_gencode.ts --file_to_gengen file.js
npm run build # equivalent to tsc *.ts
node gen_babel_gencode.js --file_to_gengen file.js --gen_full_script true --output_file output.js
node gen_babel_gencode.js --file_to_gengen file.js --output_file output.js
node gen_babel_gencode.js --file_to_gengen file.js