Last active
June 5, 2023 20:28
-
-
Save mrgrain/db41783b66d80d85afb2a58b14949d18 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env node | |
const { spawnSync } = require("node:child_process"); | |
const fs = require("node:fs"); | |
const path = require("node:path"); | |
const spawny = (command) => { | |
const [cmd, ...rest] = command.split(" "); | |
console.log(command); | |
spawnSync(cmd, rest, { stdio: 'inherit', cwd: process.cwd() }); | |
} | |
const npxProjen = () => spawny('npx projen default') | |
const rcJsName = process.argv.slice(2).at(0) ?? ".projenrc.js"; | |
const rcTsName = '.projenrc.ts'; | |
const rcFilePath = path.join(process.cwd(), rcJsName); | |
/** | |
* Add projenrcTs: true to your project. | |
*/ | |
const rcFileBuffer = fs.readFileSync(rcFilePath, { encoding: 'utf8' }).split('\n'); | |
const nameLine = rcFileBuffer.findIndex((l) => l.match(/name\:.*,/)) | |
rcFileBuffer.splice(nameLine + 1, 0, ' projenrcTs: true,') | |
fs.writeFileSync(rcFilePath, rcFileBuffer.join('\n')); | |
/** | |
* Run npx projen. | |
*/ | |
npxProjen(); | |
/** | |
* Rename .projenrc.js to .projenrc.ts. | |
*/ | |
const newRcFilePath = path.join(process.cwd(), rcTsName); | |
fs.renameSync(rcFilePath, newRcFilePath); | |
/** | |
* Update requires to imports. | |
*/ | |
spawny(`npx --yes [email protected] ${rcTsName}`) | |
/** | |
* Run npx projen. | |
*/ | |
npxProjen(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment