forked from docsifyjs/docsify-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.js
60 lines (48 loc) · 1.78 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
'use strict'
const fs = require('fs')
const cp = require('cp-file').sync
const chalk = require('chalk')
const util = require('../util/index')
var exists = util.exists
var cwd = util.cwd
var pwd = util.pwd
var resolve = util.resolve
var read = util.read
var replace = function (file, tpl, replace) {
fs.writeFileSync(file, read(file).replace(tpl, replace), 'utf-8')
}
var PKG = util.pkg()
module.exports = function (path, local, theme) {
path = path || '.'
var msg = '\n' + chalk.green('Initialization succeeded!') + ' Please run ' +
chalk.inverse(`docsify serve ${path}`) + '\n'
path = cwd(path)
var target = function (file) {
return resolve(path, file)
}
var readme = exists(cwd('README.md')) || pwd('template/README.md')
var main = pwd('template/index.html')
if (local) {
main = pwd('template/index.local.html')
var vendor = exists(cwd('node_modules/docsify')) || pwd('../node_modules/docsify')
cp(resolve(vendor, 'lib/docsify.min.js'), target('vendor/docsify.js'))
cp(resolve(vendor, `lib/themes/${theme}.css`), target(`vendor/themes/${theme}.css`))
}
var filename = 'index.html'
cp(readme, target('README.md'))
cp(main, target(filename))
cp(pwd('template/.nojekyll'), target('.nojekyll'))
replace(target(filename), 'vue.css', `${theme}.css`)
if (PKG.name) {
replace(target(filename), 'Document', PKG.name + (PKG.description ? (' - ' + PKG.description) : ''))
replace(target(filename), 'name: \'\',', `name: '${PKG.name}',`)
}
if (PKG.description) {
replace(target(filename), 'Description', PKG.description)
}
if (PKG.repository) {
const repo = (PKG.repository.url || PKG.repository).replace(/\.git$/g, '').replace(/^git\+/g, '')
replace(target(filename), 'repo: \'\'', `repo: '${repo}'`)
}
console.log(msg)
}