-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
64 lines (55 loc) · 1.89 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#! /usr/bin/env node
const child_process = require('child_process');
const path = require('path');
const fs = require('fs');
const deleteFolderRecursive = function(directoryPath) {
if (fs.existsSync(directoryPath)) {
fs.readdirSync(directoryPath).forEach((file, index) => {
const curPath = path.join(directoryPath, file);
if (fs.lstatSync(curPath).isDirectory()) {
// recurse
deleteFolderRecursive(curPath);
} else {
// delete file
fs.unlinkSync(curPath);
}
});
fs.rmdirSync(directoryPath);
}
};
if (process.argv.length < 3) {
console.log('You have to provide a name to your app.');
console.log('For example :');
console.log(' npx create-cloudgate-app my-app');
process.exit(1);
}
const projectName = process.argv[2];
const currentPath = process.cwd();
const projectPath = path.join(currentPath, projectName);
const git_repo = "https://github.com/elestio/cloudgate-app";
try {
fs.mkdirSync(projectPath);
} catch (err) {
if (err.code === 'EEXIST') {
console.log(`The folder ${projectName} already exist in the current directory, please give it another name.`);
} else {
console.log(err);
}
process.exit(1);
}
async function main() {
try {
console.log('Downloading files...');
child_process.execSync(`git clone --depth 1 ${git_repo} ${projectPath}`);
process.chdir(projectPath);
console.log('Installing dependencies...');
child_process.execSync('npm install --loglevel=error');
deleteFolderRecursive(projectPath + "/.git");
deleteFolderRecursive(projectPath + "/node_modules/aws-sdk");
console.log('Your new project is ready');
console.log('type: cd ' + projectName + " && ./run.sh");
} catch (error) {
console.log(error);
}
}
main();