-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
56 lines (43 loc) · 1.56 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
#!/usr/bin/env node
var path = require('path')
var fs = require('fs')
var chalk = require('chalk')
var spawn = require('cross-spawn')
var pathExists = require('path-exists')
function success(msg) {
console.log(chalk.green(`Success: ${msg}`))
}
function error(msg) {
console.log(chalk.red(`Error: ${msg}`))
}
function copyRecursiveSync(src, dest) {
var exists = fs.existsSync(src)
var stats = exists && fs.statSync(src)
var isDirectory = exists && stats.isDirectory()
if (exists && isDirectory) {
fs.mkdirSync(dest)
fs.readdirSync(src).forEach(function(childItemName) {
copyRecursiveSync(path.join(src, childItemName), path.join(dest, childItemName))
})
} else {
fs.createReadStream(src).pipe(fs.createWriteStream(dest))
}
}
function run() {
var option = process.argv.slice(2)
var baseDir = process.cwd()
var projectName = option[0]
if (!projectName) return error('no project name provided, try `create-dhl-app <project>` instead.')
if (pathExists.sync(projectName)) return error(`folder ${projectName} exist.`)
if (process.version.slice(1).split('.')[0] < 6) return error(`Node version should be v6.x.`)
var dist = path.join(baseDir, projectName)
copyRecursiveSync(path.join(__dirname, 'template'), dist)
fs.renameSync(dist + '/gitignore', dist + '/.gitignore')
success(`Created ${dist}.`)
//console.log('Installing packages.... This might take a couple minutes.')
// spawn('npm', ['install'], {
// stdio: 'inherit',
// cwd: dist
// })
}
run()