UNPKG

2.03 kBJavaScriptView Raw
1// #!/usr/bin/env node
2var mkdirp = require('mkdirp')
3var nps = require('path')
4var child = require('child_process')
5var cp = require('copy-dir')
6var chalk = require('chalk')
7
8var fs = require('../lib/lib/utils/fs')
9var _console = require('../lib/lib/utils/console').default
10
11var resPath = nps.join(__dirname, 'res')
12
13//
14// init picidae project
15// 1. check [path] is whether exited, mkdir path
16// 2. check $path/picidae.config.js is whether exited
17// 3.1. if $path/picidae.config.js is existed, exit 1
18// 3.2. if $path/picidae.config.js isn't existed, entry step 4
19// 4. create $path/picidae.config.js
20// 5. log the recommended theme
21//
22module.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 // child.execSync('npm link ' + nps.join(__dirname, '..'), { cwd: path })
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