Created
January 15, 2023 03:46
-
-
Save simonpai/881ca35d7e32c39bae4f82bd95125b62 to your computer and use it in GitHub Desktop.
tsconfig.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { writeFile } from 'fs/promises'; | |
import { resolve } from 'path'; | |
import glob from 'fast-glob'; | |
const cwd = process.env.PWD; | |
async function outputConfigJson(file) { | |
const outputFile = file.replace(/\.js$/, '.json'); | |
// use import() so both CJS and ESM work | |
let config = await import(resolve(cwd, file)); | |
// accept default export to make it easier with ESM | |
await writeFile(outputFile, JSON.stringify(config.default || config, undefined, 2)); | |
} | |
// you can choose your match pattern | |
const files = await glob('tsconfig*.js', { cwd }); | |
await Promise.all(files.map(outputConfigJson)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"scripts": { | |
"build:clean": "npx rimraf dist", | |
"build:config": "node ./build-tsconfig.mjs", | |
"build:tsc": "npx tsc -p tsconfig.json", | |
"build": "npm run build:clean && npm run build:config && npm run build:tsc" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default { | |
// ... | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment