-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
executable file
·46 lines (40 loc) · 1.15 KB
/
Copy pathmain.js
File metadata and controls
executable file
·46 lines (40 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#! /usr/bin/env node
const templateRepo = 'https://github.com/<username>/<repo-name>.git';
const { exec } = require('child_process');
const { promisify } = require('util');
const promiseExec = promisify(exec);
const run = ({ cmd, msg }) =>
promiseExec(cmd).then(() => {
console.log(msg);
});
const [binPath, mainScriptPath, projectName, newOrigin] = process.argv;
if (!projectName) throw new Error('Missing project name');
const task = {
createFolder: {
cmd: `mkdir ${projectName}`,
msg: `Created repo folder: ${projectName}`,
},
cloneRepo: {
cmd: `cd ${projectName} && git clone ${templateRepo} .`,
msg: `Cloned template repo: ${templateRepo}`,
},
removeOrigin: {
cmd: `cd ${projectName} && git remote rm origin`,
msg: `Removed origin: ${templateRepo}`,
},
addNewOrigin: {
cmd: `cd ${projectName} && git remote add origin ${newOrigin}`,
msg: `Added new origin: ${newOrigin}`,
},
};
run(task.createFolder)
.then(() => run(task.cloneRepo))
.then(() => run(task.removeOrigin))
.then(() => {
if (newOrigin) {
run(task.addNewOrigin);
}
})
.catch((error) => {
console.log('Error:', error);
});