generated from unchainedshop/create
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.js
executable file
·98 lines (73 loc) · 2.59 KB
/
init.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env node
var fs = require('fs');
var path = require('path');
const ignoreFileList = ['.env', 'package-lock.json'];
const ignoreFolderList = ['node_modules', '.git'];
function copyFileSync( source, target ) {
if (ignoreFileList.includes(path.basename(source))) {
return
}
var targetFile = target;
//if target is a directory a new file with the same name will be created
if ( fs.existsSync( target ) ) {
if ( fs.lstatSync( target ).isDirectory() ) {
targetFile = path.join( target, path.basename( source ) );
}
}
console.log('creating', targetFile);
fs.writeFileSync(targetFile, fs.readFileSync(source));
}
function copyFolderRecursiveSync( source, target, depth = 0 ) {
if (ignoreFolderList.includes(path.basename(source))) {
return
}
var files = [];
//check if folder needs to be created or integrated
var targetFolder = depth === 0 ? target : path.join( target, path.basename( source ) );
if ( !fs.existsSync( targetFolder ) ) {
fs.mkdirSync( targetFolder );
}
//copy
if ( fs.lstatSync( source ).isDirectory() ) {
files = fs.readdirSync( source );
files.forEach( function ( file ) {
var curSource = path.join( source, file );
if ( fs.lstatSync( curSource ).isDirectory() ) {
copyFolderRecursiveSync( curSource, targetFolder, depth + 1);
} else {
copyFileSync( curSource, targetFolder );
}
} );
}
}
const start = new Date();
console.log(`
Initializing
_____ _____ _____ _____ _____ _____ _____ _____ ____
| | | | | | | | _ | | | | __| \\
| | | | | | --| | |- -| | | | __| | |
|_____|_|___|_____|__|__|__|__|_____|_|___|_____|____/
...
`);
fs.readdir(process.cwd(), function(err, files) {
if (err) {
// some sort of error
} else {
if (files.length) {
console.log('Error: Current working directory not empty. Run this command inside of an empty directory.')
} else {
copyFolderRecursiveSync(__dirname, path.join(process.cwd(), '.'));
const finish = new Date();
console.log(`
Finished in ${finish-start} milliseconds.
To get started run:
$ npm run install-all
$ npm run dev
- Open a web browser at http://localhost:3000 to see the front-end
- Open a web browser at http://localhost:4010 to see the control panel. Login with username: admin@localhost / password: password
- Open a web browser at http://localhost:4010/graphql to see the Unchained GraphQL Playground
Have fun!
` );
}
}
});