forked from w3cj/create-express-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
executable file
·52 lines (44 loc) · 1.3 KB
/
index.js
File metadata and controls
executable file
·52 lines (44 loc) · 1.3 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
47
48
49
50
51
52
#! /usr/bin/env node
const spawn = require('child_process').spawn;
const name = process.argv[2];
if (!name || name.match(/[<>:"\/\\|?*\x00-\x1F]/)) {
return console.log(`
Invalid directory name.
Usage: create-express-api name-of-api
`);
}
const repoURL = 'https://github.com/w3cj/express-api-starter.git';
runCommand('git', ['clone', repoURL, name])
.then(() => {
return runCommand('rm', ['-rf', `${name}/.git`]);
}).then(() => {
console.log('Installing dependencies...');
return runCommand('npm', ['install'], {
cwd: process.cwd() + '/' + name
});
}).then(() => {
console.log('Done! 🏁');
console.log('');
console.log('To get started:');
console.log('cd', name);
console.log('npm run dev');
});
function runCommand(command, args, options = undefined) {
var windowsEnvironment = process.platform === "win32";
if (command === 'npm' && windowsEnvironment) {
var command = 'npm.cmd'
// var command = process.execPath
}
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();
});
});
}