-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
executable file
·49 lines (39 loc) · 1.28 KB
/
cli.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
#!/usr/bin/env node
const {program} = require('commander');
const fs = require('fs');
const path = require('path');
const { exec, execSync } = require('child_process');
program
.command('init')
.description('Initialize Nodebox')
.action(async () => {
console.log('Initializing Nodebox...');
execSync('npm install express');
copyDirSync('node_modules/nodebox-framework/testsite/', '.');
console.log('Test Site copied.');
console.log('updating package.json...');
const data = fs.readFileSync('package.json', 'utf8');
const jsonData = JSON.parse(data);
jsonData['scripts']['start'] = 'node index.js';
const updatedJsonString = JSON.stringify(jsonData, null, 2);
fs.writeFileSync('package.json', updatedJsonString);
console.log('...done.');
console.log('To start site, run: npm start');
});
function copyDirSync(src, dest) {
let entries = fs.readdirSync(src, { withFileTypes: true });
// Ensure the destination directory exists
if (!fs.existsSync(dest)) {
fs.mkdirSync(dest, { recursive: true });
}
for (let entry of entries) {
let srcPath = path.join(src, entry.name);
let destPath = path.join(dest, entry.name);
if (entry.isDirectory()) {
copyDirSync(srcPath, destPath);
} else {
fs.copyFileSync(srcPath, destPath);
}
}
}
program.parse(process.argv);