Created
February 9, 2023 12:50
-
-
Save gambitier/81d7b29ed27367c6a4a0444582f7be2e 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
| import { exec as exec_child_process } from 'child_process'; | |
| const exec = util.promisify(exec_child_process); | |
| async function initGitRepo(dest: string) { | |
| try { | |
| const command = 'git init'; | |
| const { stdout, stderr } = await exec(command, { | |
| cwd: dest | |
| }); | |
| console.log(`stdout: ${stdout}`); | |
| console.error(`stderr: ${stderr}`); | |
| } catch (err) { | |
| console.error(`exec error: ${err}`); | |
| } | |
| const gitignoreContent = readFileSync( | |
| path.join(__dirname, 'src', 'git', '.gitignore.sample') | |
| ); | |
| writeFileSync(path.join(dest, '.gitignore'), gitignoreContent); | |
| try { | |
| const gitAdd = 'git add .'; | |
| const { stdout, stderr } = await exec(gitAdd, { | |
| cwd: dest | |
| }); | |
| console.log(`stdout: ${stdout}`); | |
| console.error(`stderr: ${stderr}`); | |
| } catch (err) { | |
| console.error(`exec error: ${err}`); | |
| } | |
| try { | |
| const gitCommit = 'git commit -m "initial commit"'; | |
| const { stdout, stderr } = await exec(gitCommit, { | |
| cwd: dest | |
| }); | |
| console.log(`stdout: ${stdout}`); | |
| console.error(`stderr: ${stderr}`); | |
| } catch (err) { | |
| console.error(`exec error: ${err}`); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment