1 |
|
2 | var mkdirp = require('mkdirp')
|
3 | var nps = require('path')
|
4 | var child = require('child_process')
|
5 | var cp = require('copy-dir')
|
6 | var chalk = require('chalk')
|
7 |
|
8 | var fs = require('../lib/lib/utils/fs')
|
9 | var _console = require('../lib/lib/utils/console').default
|
10 |
|
11 | var resPath = nps.join(__dirname, 'res')
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | module.exports = function (path) {
|
23 | path = path || process.cwd()
|
24 | path = nps.resolve(path)
|
25 | if (fs.isFile(path)) {
|
26 | _console.error('The File ' + chalk.yellow('(' + nps.relative(process.cwd(), path) + ')') + ' has already existed')
|
27 | process.exit(1)
|
28 | }
|
29 | !fs.existsSync(path) && mkdirp.sync(path)
|
30 |
|
31 | var configFilename = nps.join(path, 'picidae.config.js')
|
32 | if (fs.existsSync(configFilename)) {
|
33 | _console.error('The Config File ' + chalk.yellow('(' + nps.relative(process.cwd(), configFilename) + ')') + ' has already existed')
|
34 | process.exit(1)
|
35 | }
|
36 |
|
37 | console.log(' running: ', chalk.yellow.bold('npm init -y'))
|
38 | child.execSync('npm init -y', { cwd: path })
|
39 |
|
40 | cp.sync(resPath, path)
|
41 |
|
42 | var preappend = ''
|
43 | if (path !== process.cwd()) {
|
44 | preappend = 'cd ' + nps.relative(process.cwd(), path) + ' && '
|
45 | }
|
46 |
|
47 |
|
48 | console.log([
|
49 | chalk.cyan('\n Thanks for you using picidae 🐦\n'),
|
50 | ' We recommend using the theme `picidae-theme-grass`',
|
51 | ' By running: ',
|
52 | ' ' + chalk.green.bold('`' + preappend + 'picidae use picidae-theme-grass && picidae start`'),
|
53 | ' And some other vendor likes ' + chalk.green.bold('`picidae use picidae-commander-gh-pages`')
|
54 | ].join('\n'))
|
55 |
|
56 | process.exit()
|
57 | }
|
58 |
|
59 |
|