-
Notifications
You must be signed in to change notification settings - Fork 843
Expand file tree
/
Copy pathcopymd.cjs
More file actions
85 lines (80 loc) · 2.33 KB
/
copymd.cjs
File metadata and controls
85 lines (80 loc) · 2.33 KB
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
const targetBaseUrl = `${process.cwd()}/site_docs`
const fse = require('fs-extra')
const copyFile = (from, to) => {
fse
.copy(from, to)
.then(() => {
console.log('success!>', to)
})
.catch((err) => {
console.error(err)
})
}
const removeFile = async (url) => {
return new Promise((res, rej) => {
fse.remove(url, (err) => {
if (err) {
throw err
}
res(true)
})
})
}
const copy = async () => {
let configPath = `src/config.json`
let configPkgPath = `package.json`
let nutuiDocsConfigPath = `${targetBaseUrl}/config.json`
// 判断 site_docs 文件是否存在根路径中
const existsRoot = await fse.pathExists(targetBaseUrl)
if (existsRoot) await removeFile(targetBaseUrl)
// 复制所有组件
const fromConfig = await fse.readJson(configPath)
fromConfig.nav.forEach(({ packages }) => {
packages.forEach((item) => {
if (item.show !== false) {
let cmpName = item.name.toLowerCase()
let docpath = `src/packages/__VUE/${cmpName}/doc.md`
let docEnPath = `src/packages/__VUE/${cmpName}/doc.en-US.md`
let doctaropath = `src/packages/__VUE/${cmpName}/doc.taro.md`
fse.readFile(docpath, (err, data) => {
if (!err) {
copyFile(docpath, `${targetBaseUrl}/docs/${cmpName}/doc.md`)
}
})
fse.readFile(docEnPath, (err, data) => {
if (!err) {
copyFile(docEnPath, `${targetBaseUrl}/docs/${cmpName}/doc.en-US.md`)
}
})
fse.readFile(doctaropath, (err, data) => {
if (!err) {
copyFile(doctaropath, `${targetBaseUrl}/docs/${cmpName}/doc.taro.md`)
}
})
}
})
})
// 复制 config.json
const fromPkgConfig = await fse.readJson(configPkgPath)
const obj = {
version: '',
nav: [],
docs: []
}
fse.outputJSON(nutuiDocsConfigPath, obj, () => {
const docsConfig = fse.readJson(nutuiDocsConfigPath)
docsConfig.version = fromPkgConfig.version
docsConfig.nav = fromConfig.nav
docsConfig.docs = fromConfig.docs
docsConfig.demoUrl = 'https://nutui.jd.com/3x/demo.html#'
fse
.writeJson(nutuiDocsConfigPath, docsConfig, {
spaces: 2
})
.then(() => {
console.log(`${fromPkgConfig.version} success!`)
})
})
}
// copy(reactBaseUrl, 'react');
copy()