-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
47 lines (39 loc) · 1.16 KB
/
index.js
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
47
#! /usr/bin/env node
const { spawn } = require('child_process');
const name = process.argv[2];
if (!name || name.match(/[<>:"\/\\|?*\x00-\x1F]/)) {
return console.log(`
Invalid directory name.
Usage: create-typescript-express-api name-of-api
`);
}
const repoURL = 'https://github.com/dewhurstwill/typescript-express-api-starter.git';
runCommand('git', ['clone', repoURL, name])
.then(() => {
return runCommand('rm', ['-rf', `${name}/.git`]);
}).then(() => {
console.log('Installing dependencies...');
return runCommand('yarn', ['install'], {
cwd: process.cwd() + '/' + name
});
}).then(() => {
console.log('Done! 🏁');
console.log('');
console.log('To get started:');
console.log('cd', name);
console.log('yarn run start:dev');
});
function runCommand(command, args, options = undefined) {
const spawned = spawn(command, args, options);
return new Promise((resolve) => {
spawned.stdout.on('data', (data) => {
console.log(data.toString());
});
spawned.stderr.on('data', (data) => {
console.error(data.toString());
});
spawned.on('close', () => {
resolve();
});
});
}