This repository has been archived by the owner on Dec 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate.js
61 lines (52 loc) · 1.91 KB
/
create.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
#!/usr/bin/env node
const fs = require('fs');
const path = require('path');
const child_process = require('child_process');
function copyFolderSync(from, to) {
fs.mkdirSync(to);
fs.readdirSync(from).forEach(element => {
if (element.indexOf('node_modules') != -1) return;
if (element.indexOf(process.argv[2]) != -1) return;
if (element.indexOf('create.js') != -1) return;
if (element.indexOf('package-lock.json') != -1) return;
if (fs.lstatSync(path.join(from, element)).isFile()) {
fs.copyFileSync(path.join(from, element), path.join(to, element));
} else {
copyFolderSync(path.join(from, element), path.join(to, element));
}
});
}
function log() {
let argstr = '';
for (const arg of arguments) {
argstr += arg
.replace(/(\$RES)/g, '\x1b[0m')
.replace(/(\$COL)/g, '\x1b[0m\x1b[36m')
.replace(/(\$UND)/g, '\x1b[4m')
+ ' ';
}
console.log('\x1b[36m[pjs]', argstr, '\x1b[0m')
}
const start = Date.now();
log(`Creating $RES$UND${process.argv[2]}$COL in $RES$UND${process.cwd()}$RES`);
const installpath = path.dirname(process.argv[1]);
const fspath = `${process.cwd()}/${process.argv[2]}/`;
log('Copying files...');
copyFolderSync(installpath, fspath);
log('Setting up $RES$UNDpackage.json$COL...');
const pkgcontent = JSON.parse(fs.readFileSync(fspath + 'package.json'));
pkgcontent.name = process.argv[2];
pkgcontent.description = process.argv[2];
delete pkgcontent.author;
delete pkgcontent.license;
delete pkgcontent.bin;
fs.writeFileSync(fspath + 'package.json', JSON.stringify(pkgcontent, undefined, 4));
log('Running $RES$UNDnpm install$COL...');
child_process.execSync('npm install', {
cwd: fspath
});
log(`Finished in $RES$UND${Date.now() - start}ms$RES`);
console.log('');
console.log('');
console.log('');
log(`Run $RES$UNDnpm run dev$RES to start the development server`);