cloudcc-cli 1.3.3 → 1.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +930 -920
- package/bin/build.js +5 -5
- package/bin/buildccbasesdk.js +5 -5
- package/bin/buildccsdk.js +5 -5
- package/bin/buildtag.js +6 -6
- package/bin/create.js +5 -5
- package/bin/publish.js +5 -5
- package/bin/publishh5.js +6 -6
- package/package.json +39 -39
- package/src/buildTag.js +74 -74
- package/src/builderBaseSDK.js +89 -89
- package/src/builderPlugin.js +194 -194
- package/src/builderSDK.js +160 -160
- package/src/creatorTemProject.js +90 -90
- package/src/publishProject.js +258 -239
- package/src/publishProjectH5.js +180 -180
- package/template/generateIDjs +4 -4
- package/template/httpjs +107 -107
- package/template/index.js +65 -65
- package/template/indexvue +343 -343
- package/template/mainjs +16 -16
- package/template/package-lockjson +12154 -12154
- package/template/packagejson +58 -58
- package/template/vueconfigjs +20 -20
- package/test/index.html +14 -14
- package/test/test.js +5 -5
- package/utils/askTool.js +95 -95
- package/utils/changeVersion copy.js +74 -74
- package/utils/changeVersion.js +26 -26
- package/utils/checkVersion.js +90 -90
- package/utils/deploy.js +8 -8
- package/utils/encryption.js +20 -20
- package/utils/http.js +95 -95
- package/utils/md2html.js +88 -88
- package/utils/notifyIM.js +86 -86
- package/utils/pushCode.js +185 -186
- package/utils/test.js +1 -1
- package/utils/trigger.js +15 -15
- package/utils/updatei18n.js +126 -126
package/utils/checkVersion.js
CHANGED
|
@@ -1,90 +1,90 @@
|
|
|
1
|
-
// 导入cli配置文件
|
|
2
|
-
const config = require("../package.json")
|
|
3
|
-
const inquirer = require("inquirer")
|
|
4
|
-
const exec = require('child_process').execSync;
|
|
5
|
-
const chalk = require("chalk")
|
|
6
|
-
/**
|
|
7
|
-
* 检查版本号
|
|
8
|
-
*/
|
|
9
|
-
function checkNpmVersion() {
|
|
10
|
-
let currentVersion = Number(config.version.replace(/\./g, ""));
|
|
11
|
-
let onlineVersionNum
|
|
12
|
-
let onlineVersion = '0.0.1'
|
|
13
|
-
|
|
14
|
-
// 从npm官网获取版本号
|
|
15
|
-
// onlineVersion = exec(`npm view cloudcc-cli version --registry http://registry.npmjs.org`)
|
|
16
|
-
// onlineVersion = onlineVersion.toString("utf8").trim();
|
|
17
|
-
|
|
18
|
-
// 从阿里源获取版本号
|
|
19
|
-
try {
|
|
20
|
-
onlineVersion = exec(`curl -s http://www.npmmirror.com/package/cloudcc-cli`)
|
|
21
|
-
onlineVersion = onlineVersion.toString("utf8").trim().split('img title="')[1].split('" src')[0];
|
|
22
|
-
} catch (e) {
|
|
23
|
-
}
|
|
24
|
-
onlineVersionNum = Number(onlineVersion.replace(/\./g, ""));
|
|
25
|
-
// 如果结果大于0,那么提示升级
|
|
26
|
-
if (onlineVersionNum - currentVersion > 0) {
|
|
27
|
-
console.log();
|
|
28
|
-
console.log(chalk.green("Cloudcc-cli发现新版本!"));
|
|
29
|
-
console.log();
|
|
30
|
-
console.log(chalk.green("当前版本:v" + config.version));
|
|
31
|
-
console.log(chalk.green("最新版本:v" + onlineVersion));
|
|
32
|
-
console.log();
|
|
33
|
-
console.log(chalk.yellow(`如无法自动更新,请使用命令更新:npm install -g cloudcc-cli@${onlineVersion} --registry http://registry.npmmirror.com`));
|
|
34
|
-
return onlineVersion;
|
|
35
|
-
}
|
|
36
|
-
return null;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* 是否升级
|
|
41
|
-
* @returns 对象
|
|
42
|
-
*/
|
|
43
|
-
function askUpdate() {
|
|
44
|
-
console.log();
|
|
45
|
-
const prompt = [{
|
|
46
|
-
type: 'list',
|
|
47
|
-
message: '是否进行自动升级?',
|
|
48
|
-
name: 'update',
|
|
49
|
-
choices: [
|
|
50
|
-
"Yes", 'No'
|
|
51
|
-
],
|
|
52
|
-
}];
|
|
53
|
-
return inquirer.prompt(prompt)
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* 升级cli
|
|
58
|
-
*/
|
|
59
|
-
function update(onlineVersion) {
|
|
60
|
-
console.log()
|
|
61
|
-
console.log(chalk.green("升级中,请稍后..."));
|
|
62
|
-
exec(`npm install -g cloudcc-cli@${onlineVersion} --registry http://registry.npmmirror.com`)
|
|
63
|
-
console.log()
|
|
64
|
-
console.log(chalk.green("升级完成!请重新运行"));
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* 检查更新
|
|
69
|
-
*/
|
|
70
|
-
async function checkUpdate() {
|
|
71
|
-
let onlineVersion;
|
|
72
|
-
try {
|
|
73
|
-
onlineVersion = checkNpmVersion();
|
|
74
|
-
} catch (error) {
|
|
75
|
-
onlineVersion = false;
|
|
76
|
-
}
|
|
77
|
-
if (onlineVersion) {
|
|
78
|
-
let res = await askUpdate()
|
|
79
|
-
if ("Yes" == res.update) {
|
|
80
|
-
update(onlineVersion)
|
|
81
|
-
return true;
|
|
82
|
-
} else {
|
|
83
|
-
return false
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
return false
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
module.exports = { checkUpdate }
|
|
1
|
+
// 导入cli配置文件
|
|
2
|
+
const config = require("../package.json")
|
|
3
|
+
const inquirer = require("inquirer")
|
|
4
|
+
const exec = require('child_process').execSync;
|
|
5
|
+
const chalk = require("chalk")
|
|
6
|
+
/**
|
|
7
|
+
* 检查版本号
|
|
8
|
+
*/
|
|
9
|
+
function checkNpmVersion() {
|
|
10
|
+
let currentVersion = Number(config.version.replace(/\./g, ""));
|
|
11
|
+
let onlineVersionNum
|
|
12
|
+
let onlineVersion = '0.0.1'
|
|
13
|
+
|
|
14
|
+
// 从npm官网获取版本号
|
|
15
|
+
// onlineVersion = exec(`npm view cloudcc-cli version --registry http://registry.npmjs.org`)
|
|
16
|
+
// onlineVersion = onlineVersion.toString("utf8").trim();
|
|
17
|
+
|
|
18
|
+
// 从阿里源获取版本号
|
|
19
|
+
try {
|
|
20
|
+
onlineVersion = exec(`curl -s http://www.npmmirror.com/package/cloudcc-cli`)
|
|
21
|
+
onlineVersion = onlineVersion.toString("utf8").trim().split('img title="')[1].split('" src')[0];
|
|
22
|
+
} catch (e) {
|
|
23
|
+
}
|
|
24
|
+
onlineVersionNum = Number(onlineVersion.replace(/\./g, ""));
|
|
25
|
+
// 如果结果大于0,那么提示升级
|
|
26
|
+
if (onlineVersionNum - currentVersion > 0) {
|
|
27
|
+
console.log();
|
|
28
|
+
console.log(chalk.green("Cloudcc-cli发现新版本!"));
|
|
29
|
+
console.log();
|
|
30
|
+
console.log(chalk.green("当前版本:v" + config.version));
|
|
31
|
+
console.log(chalk.green("最新版本:v" + onlineVersion));
|
|
32
|
+
console.log();
|
|
33
|
+
console.log(chalk.yellow(`如无法自动更新,请使用命令更新:npm install -g cloudcc-cli@${onlineVersion} --registry http://registry.npmmirror.com`));
|
|
34
|
+
return onlineVersion;
|
|
35
|
+
}
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* 是否升级
|
|
41
|
+
* @returns 对象
|
|
42
|
+
*/
|
|
43
|
+
function askUpdate() {
|
|
44
|
+
console.log();
|
|
45
|
+
const prompt = [{
|
|
46
|
+
type: 'list',
|
|
47
|
+
message: '是否进行自动升级?',
|
|
48
|
+
name: 'update',
|
|
49
|
+
choices: [
|
|
50
|
+
"Yes", 'No'
|
|
51
|
+
],
|
|
52
|
+
}];
|
|
53
|
+
return inquirer.prompt(prompt)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* 升级cli
|
|
58
|
+
*/
|
|
59
|
+
function update(onlineVersion) {
|
|
60
|
+
console.log()
|
|
61
|
+
console.log(chalk.green("升级中,请稍后..."));
|
|
62
|
+
exec(`npm install -g cloudcc-cli@${onlineVersion} --registry http://registry.npmmirror.com`)
|
|
63
|
+
console.log()
|
|
64
|
+
console.log(chalk.green("升级完成!请重新运行"));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* 检查更新
|
|
69
|
+
*/
|
|
70
|
+
async function checkUpdate() {
|
|
71
|
+
let onlineVersion;
|
|
72
|
+
try {
|
|
73
|
+
onlineVersion = checkNpmVersion();
|
|
74
|
+
} catch (error) {
|
|
75
|
+
onlineVersion = false;
|
|
76
|
+
}
|
|
77
|
+
if (onlineVersion) {
|
|
78
|
+
let res = await askUpdate()
|
|
79
|
+
if ("Yes" == res.update) {
|
|
80
|
+
update(onlineVersion)
|
|
81
|
+
return true;
|
|
82
|
+
} else {
|
|
83
|
+
return false
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return false
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
module.exports = { checkUpdate }
|
package/utils/deploy.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 版本发布
|
|
3
|
-
*/
|
|
4
|
-
const axios = require("axios")
|
|
5
|
-
module.exports = {
|
|
6
|
-
deploy: (url) => {
|
|
7
|
-
axios.post(url);
|
|
8
|
-
},
|
|
1
|
+
/**
|
|
2
|
+
* 版本发布
|
|
3
|
+
*/
|
|
4
|
+
const axios = require("axios")
|
|
5
|
+
module.exports = {
|
|
6
|
+
deploy: (url) => {
|
|
7
|
+
axios.post(url);
|
|
8
|
+
},
|
|
9
9
|
}
|
package/utils/encryption.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
const CryptoJS = require("crypto-js");
|
|
2
|
-
|
|
3
|
-
const keyCode = "646576636f6e736f6c652d7376633132"
|
|
4
|
-
module.exports = {
|
|
5
|
-
en(word, keyStr = keyCode) {
|
|
6
|
-
let enc = CryptoJS.AES.encrypt(word, CryptoJS.enc.Hex.parse(keyStr), {
|
|
7
|
-
mode: CryptoJS.mode.ECB,
|
|
8
|
-
padding: CryptoJS.pad.Pkcs7
|
|
9
|
-
})
|
|
10
|
-
return enc.ciphertext.toString()
|
|
11
|
-
},
|
|
12
|
-
|
|
13
|
-
de(word, keyStr = keyCode) {
|
|
14
|
-
let dec = CryptoJS.AES.decrypt(CryptoJS.format.Hex.parse(word), CryptoJS.enc.Hex.parse(keyStr), {
|
|
15
|
-
mode: CryptoJS.mode.ECB,
|
|
16
|
-
padding: CryptoJS.pad.Pkcs7
|
|
17
|
-
})
|
|
18
|
-
return CryptoJS.enc.Utf8.stringify(dec)
|
|
19
|
-
}
|
|
20
|
-
};
|
|
1
|
+
const CryptoJS = require("crypto-js");
|
|
2
|
+
|
|
3
|
+
const keyCode = "646576636f6e736f6c652d7376633132"
|
|
4
|
+
module.exports = {
|
|
5
|
+
en(word, keyStr = keyCode) {
|
|
6
|
+
let enc = CryptoJS.AES.encrypt(word, CryptoJS.enc.Hex.parse(keyStr), {
|
|
7
|
+
mode: CryptoJS.mode.ECB,
|
|
8
|
+
padding: CryptoJS.pad.Pkcs7
|
|
9
|
+
})
|
|
10
|
+
return enc.ciphertext.toString()
|
|
11
|
+
},
|
|
12
|
+
|
|
13
|
+
de(word, keyStr = keyCode) {
|
|
14
|
+
let dec = CryptoJS.AES.decrypt(CryptoJS.format.Hex.parse(word), CryptoJS.enc.Hex.parse(keyStr), {
|
|
15
|
+
mode: CryptoJS.mode.ECB,
|
|
16
|
+
padding: CryptoJS.pad.Pkcs7
|
|
17
|
+
})
|
|
18
|
+
return CryptoJS.enc.Utf8.stringify(dec)
|
|
19
|
+
}
|
|
20
|
+
};
|
package/utils/http.js
CHANGED
|
@@ -1,95 +1,95 @@
|
|
|
1
|
-
const axios = require("axios")
|
|
2
|
-
const encry = require("./encryption")
|
|
3
|
-
const service = axios.create({
|
|
4
|
-
timeout: 60000, // request timeout
|
|
5
|
-
headers: {
|
|
6
|
-
'Content-Type': 'application/json; charset=utf-8',
|
|
7
|
-
},
|
|
8
|
-
})
|
|
9
|
-
|
|
10
|
-
// request interceptor
|
|
11
|
-
service.interceptors.request.use(
|
|
12
|
-
config => {
|
|
13
|
-
// config.data = encry.en(JSON.stringify(config.data))
|
|
14
|
-
return config
|
|
15
|
-
},
|
|
16
|
-
error => {
|
|
17
|
-
// Do something with request error
|
|
18
|
-
Promise.reject(error)
|
|
19
|
-
}
|
|
20
|
-
)
|
|
21
|
-
|
|
22
|
-
// response interceptor
|
|
23
|
-
service.interceptors.response.use(
|
|
24
|
-
response => {
|
|
25
|
-
const code = response.data.code || 200
|
|
26
|
-
if (code !== 200) {
|
|
27
|
-
return Promise.reject(null == response.data.msg ? "未知异常" : response.data.msg)
|
|
28
|
-
} else {
|
|
29
|
-
// response.data= JSON.parse(encry.de(response.data));
|
|
30
|
-
return response.data;
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
error => {
|
|
34
|
-
return Promise.reject(error)
|
|
35
|
-
}
|
|
36
|
-
)
|
|
37
|
-
const formateData = (data, header) => {
|
|
38
|
-
if (header) {
|
|
39
|
-
Object.assign(header, { source: "cloudcc_cli" })
|
|
40
|
-
}
|
|
41
|
-
return {
|
|
42
|
-
head: {
|
|
43
|
-
...header
|
|
44
|
-
},
|
|
45
|
-
body: {
|
|
46
|
-
...data
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
module.exports = {
|
|
51
|
-
get: (url, data = {}, responseType = '') => {
|
|
52
|
-
return service({
|
|
53
|
-
url: url,
|
|
54
|
-
method: 'get',
|
|
55
|
-
params: formateData(data),
|
|
56
|
-
responseType: responseType
|
|
57
|
-
})
|
|
58
|
-
},
|
|
59
|
-
post: (url, data = {}, header = { appVersion: "1.0.0" }, responseType = '') => {
|
|
60
|
-
return service({
|
|
61
|
-
url: url,
|
|
62
|
-
method: 'post',
|
|
63
|
-
data: formateData(data, header),
|
|
64
|
-
responseType: responseType
|
|
65
|
-
})
|
|
66
|
-
},
|
|
67
|
-
postParams: (url, data = {}) => {
|
|
68
|
-
return service({
|
|
69
|
-
url: url,
|
|
70
|
-
method: 'post',
|
|
71
|
-
params: data
|
|
72
|
-
})
|
|
73
|
-
},
|
|
74
|
-
patch: (url, data = {}) => {
|
|
75
|
-
return service({
|
|
76
|
-
url: url,
|
|
77
|
-
method: 'patch',
|
|
78
|
-
data: formateData(data)
|
|
79
|
-
})
|
|
80
|
-
},
|
|
81
|
-
delete: (url, data = {}) => {
|
|
82
|
-
return service({
|
|
83
|
-
url: url,
|
|
84
|
-
method: 'delete',
|
|
85
|
-
data: formateData(data)
|
|
86
|
-
})
|
|
87
|
-
},
|
|
88
|
-
put: (url, data = {}) => {
|
|
89
|
-
return service({
|
|
90
|
-
url: url,
|
|
91
|
-
method: 'put',
|
|
92
|
-
data: formateData(data)
|
|
93
|
-
})
|
|
94
|
-
}
|
|
95
|
-
}
|
|
1
|
+
const axios = require("axios")
|
|
2
|
+
const encry = require("./encryption")
|
|
3
|
+
const service = axios.create({
|
|
4
|
+
timeout: 60000, // request timeout
|
|
5
|
+
headers: {
|
|
6
|
+
'Content-Type': 'application/json; charset=utf-8',
|
|
7
|
+
},
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
// request interceptor
|
|
11
|
+
service.interceptors.request.use(
|
|
12
|
+
config => {
|
|
13
|
+
// config.data = encry.en(JSON.stringify(config.data))
|
|
14
|
+
return config
|
|
15
|
+
},
|
|
16
|
+
error => {
|
|
17
|
+
// Do something with request error
|
|
18
|
+
Promise.reject(error)
|
|
19
|
+
}
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
// response interceptor
|
|
23
|
+
service.interceptors.response.use(
|
|
24
|
+
response => {
|
|
25
|
+
const code = response.data.code || 200
|
|
26
|
+
if (code !== 200) {
|
|
27
|
+
return Promise.reject(null == response.data.msg ? "未知异常" : response.data.msg)
|
|
28
|
+
} else {
|
|
29
|
+
// response.data= JSON.parse(encry.de(response.data));
|
|
30
|
+
return response.data;
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
error => {
|
|
34
|
+
return Promise.reject(error)
|
|
35
|
+
}
|
|
36
|
+
)
|
|
37
|
+
const formateData = (data, header) => {
|
|
38
|
+
if (header) {
|
|
39
|
+
Object.assign(header, { source: "cloudcc_cli" })
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
head: {
|
|
43
|
+
...header
|
|
44
|
+
},
|
|
45
|
+
body: {
|
|
46
|
+
...data
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
module.exports = {
|
|
51
|
+
get: (url, data = {}, responseType = '') => {
|
|
52
|
+
return service({
|
|
53
|
+
url: url,
|
|
54
|
+
method: 'get',
|
|
55
|
+
params: formateData(data),
|
|
56
|
+
responseType: responseType
|
|
57
|
+
})
|
|
58
|
+
},
|
|
59
|
+
post: (url, data = {}, header = { appVersion: "1.0.0" }, responseType = '') => {
|
|
60
|
+
return service({
|
|
61
|
+
url: url,
|
|
62
|
+
method: 'post',
|
|
63
|
+
data: formateData(data, header),
|
|
64
|
+
responseType: responseType
|
|
65
|
+
})
|
|
66
|
+
},
|
|
67
|
+
postParams: (url, data = {}) => {
|
|
68
|
+
return service({
|
|
69
|
+
url: url,
|
|
70
|
+
method: 'post',
|
|
71
|
+
params: data
|
|
72
|
+
})
|
|
73
|
+
},
|
|
74
|
+
patch: (url, data = {}) => {
|
|
75
|
+
return service({
|
|
76
|
+
url: url,
|
|
77
|
+
method: 'patch',
|
|
78
|
+
data: formateData(data)
|
|
79
|
+
})
|
|
80
|
+
},
|
|
81
|
+
delete: (url, data = {}) => {
|
|
82
|
+
return service({
|
|
83
|
+
url: url,
|
|
84
|
+
method: 'delete',
|
|
85
|
+
data: formateData(data)
|
|
86
|
+
})
|
|
87
|
+
},
|
|
88
|
+
put: (url, data = {}) => {
|
|
89
|
+
return service({
|
|
90
|
+
url: url,
|
|
91
|
+
method: 'put',
|
|
92
|
+
data: formateData(data)
|
|
93
|
+
})
|
|
94
|
+
}
|
|
95
|
+
}
|
package/utils/md2html.js
CHANGED
|
@@ -1,89 +1,89 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 将md编译为html,并复制到dist/plu
|
|
3
|
-
*/
|
|
4
|
-
const fs = require('fs'); //文件模块
|
|
5
|
-
const path = require('path'); //路径模块
|
|
6
|
-
const marked = require('marked'); //md转html模块
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* 检测文件改动
|
|
10
|
-
*/
|
|
11
|
-
function watchFile(target) {
|
|
12
|
-
fs.watchFile(target, {
|
|
13
|
-
persistent: true, //是否持续监听
|
|
14
|
-
interval: 200, //刷新间隔
|
|
15
|
-
}, (curr, prev) => {
|
|
16
|
-
if (curr.mtime == prev.mtime) { //比较修改时间,判断保存后内容是否真的发生了变化
|
|
17
|
-
return false;
|
|
18
|
-
}
|
|
19
|
-
change()
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* 转换
|
|
24
|
-
* @param {target} 编译文件名称
|
|
25
|
-
* @param {outPath} 保存路径
|
|
26
|
-
*/
|
|
27
|
-
function change(target = "README", outPath = "dist") {
|
|
28
|
-
//读取文件
|
|
29
|
-
const data = fs.readFileSync(target + ".md", 'utf-8')
|
|
30
|
-
const html = marked(data); //将md内容转为html内容
|
|
31
|
-
let template = createTemplate();
|
|
32
|
-
template = template.replace('{{{content}}}', html); //替换html内容占位标记
|
|
33
|
-
|
|
34
|
-
let css = fs.readFileSync(path.join(__dirname) + '/github-markdown.min.css', 'utf8')
|
|
35
|
-
template = template.replace('{{{style}}}', css); //替换css内容占位标记
|
|
36
|
-
createFile(template,
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* 创建页面模板
|
|
41
|
-
* @returns {string} 页面骨架字符串
|
|
42
|
-
*/
|
|
43
|
-
|
|
44
|
-
function createTemplate() {
|
|
45
|
-
const template = `<!DOCTYPE html>
|
|
46
|
-
<html>
|
|
47
|
-
<head>
|
|
48
|
-
<meta charset="utf-8" >
|
|
49
|
-
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
50
|
-
<title>开发日志</title>
|
|
51
|
-
<style>
|
|
52
|
-
.markdown-body {
|
|
53
|
-
box-sizing: border-box;
|
|
54
|
-
min-width: 200px;
|
|
55
|
-
max-width: 980px;
|
|
56
|
-
margin: 0 auto;
|
|
57
|
-
padding: 45px;
|
|
58
|
-
}
|
|
59
|
-
@media (max-width: 767px) {
|
|
60
|
-
.markdown-body {
|
|
61
|
-
padding: 15px;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
{{{style}}}
|
|
65
|
-
</style>
|
|
66
|
-
</head>
|
|
67
|
-
<body>
|
|
68
|
-
<article class="markdown-body">
|
|
69
|
-
{{{content}}}
|
|
70
|
-
</article>
|
|
71
|
-
</body>
|
|
72
|
-
</html>`;
|
|
73
|
-
return template;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* 创建html文件
|
|
78
|
-
* @param {string} content 写入html的文件内容
|
|
79
|
-
*/
|
|
80
|
-
function createFile(content,
|
|
81
|
-
const suffix = 'html'; //文件格式
|
|
82
|
-
const fullName =
|
|
83
|
-
const file = path.join(outPath, fullName); //文件地址
|
|
84
|
-
fs.writeFileSync(file, content, 'utf-8')
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
module.exports = {
|
|
88
|
-
createFile, createTemplate, change, watchFile
|
|
1
|
+
/**
|
|
2
|
+
* 将md编译为html,并复制到dist/plu
|
|
3
|
+
*/
|
|
4
|
+
const fs = require('fs'); //文件模块
|
|
5
|
+
const path = require('path'); //路径模块
|
|
6
|
+
const marked = require('marked'); //md转html模块
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* 检测文件改动
|
|
10
|
+
*/
|
|
11
|
+
function watchFile(target) {
|
|
12
|
+
fs.watchFile(target, {
|
|
13
|
+
persistent: true, //是否持续监听
|
|
14
|
+
interval: 200, //刷新间隔
|
|
15
|
+
}, (curr, prev) => {
|
|
16
|
+
if (curr.mtime == prev.mtime) { //比较修改时间,判断保存后内容是否真的发生了变化
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
change()
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* 转换
|
|
24
|
+
* @param {target} 编译文件名称
|
|
25
|
+
* @param {outPath} 保存路径
|
|
26
|
+
*/
|
|
27
|
+
function change(target = "README", outPath = "dist", outFile = "README") {
|
|
28
|
+
//读取文件
|
|
29
|
+
const data = fs.readFileSync(target + ".md", 'utf-8')
|
|
30
|
+
const html = marked(data); //将md内容转为html内容
|
|
31
|
+
let template = createTemplate();
|
|
32
|
+
template = template.replace('{{{content}}}', html); //替换html内容占位标记
|
|
33
|
+
|
|
34
|
+
let css = fs.readFileSync(path.join(__dirname) + '/github-markdown.min.css', 'utf8')
|
|
35
|
+
template = template.replace('{{{style}}}', css); //替换css内容占位标记
|
|
36
|
+
createFile(template, outPath, outFile);
|
|
37
|
+
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* 创建页面模板
|
|
41
|
+
* @returns {string} 页面骨架字符串
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
function createTemplate() {
|
|
45
|
+
const template = `<!DOCTYPE html>
|
|
46
|
+
<html>
|
|
47
|
+
<head>
|
|
48
|
+
<meta charset="utf-8" >
|
|
49
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
50
|
+
<title>开发日志</title>
|
|
51
|
+
<style>
|
|
52
|
+
.markdown-body {
|
|
53
|
+
box-sizing: border-box;
|
|
54
|
+
min-width: 200px;
|
|
55
|
+
max-width: 980px;
|
|
56
|
+
margin: 0 auto;
|
|
57
|
+
padding: 45px;
|
|
58
|
+
}
|
|
59
|
+
@media (max-width: 767px) {
|
|
60
|
+
.markdown-body {
|
|
61
|
+
padding: 15px;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
{{{style}}}
|
|
65
|
+
</style>
|
|
66
|
+
</head>
|
|
67
|
+
<body>
|
|
68
|
+
<article class="markdown-body">
|
|
69
|
+
{{{content}}}
|
|
70
|
+
</article>
|
|
71
|
+
</body>
|
|
72
|
+
</html>`;
|
|
73
|
+
return template;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* 创建html文件
|
|
78
|
+
* @param {string} content 写入html的文件内容
|
|
79
|
+
*/
|
|
80
|
+
function createFile(content, outPath = "dist", outFile) {
|
|
81
|
+
const suffix = 'html'; //文件格式
|
|
82
|
+
const fullName = outFile + '.' + suffix; //文件全名
|
|
83
|
+
const file = path.join(outPath, fullName); //文件地址
|
|
84
|
+
fs.writeFileSync(file, content, 'utf-8')
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
module.exports = {
|
|
88
|
+
createFile, createTemplate, change, watchFile
|
|
89
89
|
}
|