| #!/usr/bin/env node |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| import assert from 'node:assert'; |
| import {parseArgs} from 'node:util'; |
|
|
| import {readFile, loadDefaultSettings, applySettings} from '../src/utility.mjs'; |
|
|
| const options = { |
| 'expand-macros': {type: 'boolean'}, |
| help: {type: 'boolean', short: 'h'}, |
| }; |
| const {values, positionals} = parseArgs({options, allowPositionals: true}); |
|
|
| if (values.help) { |
| console.log(`\ |
| Run JS preprocessor / macro processor on an input file |
| |
| Usage: preprocessor.mjs <settings.json> <input-file> [--expand-macros]`); |
| process.exit(0); |
| } |
|
|
| loadDefaultSettings(); |
|
|
| assert(positionals.length == 2, 'Script requires 2 arguments'); |
|
|
| |
| let settingsFile = positionals[0]; |
| assert(settingsFile, 'settings file not specified'); |
| if (settingsFile == '-') { |
| |
| settingsFile = 0; |
| } |
| const userSettings = JSON.parse(readFile(settingsFile)); |
| applySettings(userSettings); |
|
|
| const inputFile = positionals[1]; |
|
|
| |
| |
| |
| const parseTools = await import('../src/parseTools.mjs'); |
| await import('../src/modules.mjs'); |
|
|
| let output = parseTools.preprocess(inputFile); |
| if (values['expand-macros']) { |
| output = parseTools.processMacros(output, inputFile); |
| } |
| process.stdout.write(output); |
|
|