mirror of
https://github.com/142vip/408CSFamily.git
synced 2026-02-03 02:23:38 +08:00
feat: 新增markdown转思维导图脚本,导航栏改版
This commit is contained in:
@@ -5,54 +5,53 @@
|
||||
const {join} = require('path')
|
||||
const cwd = join(__dirname, '..')
|
||||
process.env.PATH = `${join(cwd, 'node_modules', '.bin')}:${process.env.PATH}`
|
||||
const {exec,exit} = require('shelljs');
|
||||
const {exec, exit} = require('shelljs');
|
||||
|
||||
/**
|
||||
* 监听进程
|
||||
* - 退出进程
|
||||
*/
|
||||
process.on('exit', () => {
|
||||
exit()
|
||||
exit()
|
||||
})
|
||||
|
||||
/**
|
||||
* 执行shell指令
|
||||
* @param commands
|
||||
*/
|
||||
exports.execShell = async commands => {
|
||||
let runCommands=[]
|
||||
if(typeof commands ==='string'){
|
||||
runCommands.push(commands)
|
||||
}
|
||||
let runCommands = []
|
||||
if (typeof commands === 'string') {
|
||||
runCommands.push(commands)
|
||||
}
|
||||
|
||||
// 批量执行
|
||||
if(Array.isArray(commands)){
|
||||
runCommands=commands
|
||||
}
|
||||
// 批量执行
|
||||
if (Array.isArray(commands)) {
|
||||
runCommands = commands
|
||||
}
|
||||
|
||||
for (let index=0;index<runCommands.length;index++) {
|
||||
const command=runCommands[index]
|
||||
const count=index+1
|
||||
console.log(`>>>command(${count}):\n${command} \n<<<command(${count})--start === \n`)
|
||||
// await syncExec(command)
|
||||
const execResult=await exec(command)
|
||||
for (let index = 0; index < runCommands.length; index++) {
|
||||
const command = runCommands[index]
|
||||
const count = index + 1
|
||||
console.log(`>>>command(${count}):\n${command} \n<<<command(${count})--start === \n`)
|
||||
// await syncExec(command)
|
||||
const execResult = await exec(command)
|
||||
|
||||
console.log(`\n<<<command(${count})--ending === `)
|
||||
// 指令异常,不执行后续指令
|
||||
if(execResult.code!==0){
|
||||
break;
|
||||
}
|
||||
console.log(`\n<<<command(${count})--ending === `)
|
||||
// 指令异常,不执行后续指令
|
||||
if (execResult.code !== 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 脚本基础设置
|
||||
*/
|
||||
exports.BaseSetting={
|
||||
successLogger:"\033[36m",
|
||||
errorLogger:"\033[1;31m",
|
||||
warnLogger:"\033[1;33m",
|
||||
exports.BaseSetting = {
|
||||
successLogger: "\033[36m",
|
||||
errorLogger: "\033[1;31m",
|
||||
warnLogger: "\033[1;33m",
|
||||
// 定义时间
|
||||
currentTime:'$(date "+%Y-%m-%d %H:%M:%S")'
|
||||
currentTime: '$(date "+%Y-%m-%d %H:%M:%S")'
|
||||
}
|
||||
|
||||
|
||||
56
scripts/mark-map
Executable file
56
scripts/mark-map
Executable file
@@ -0,0 +1,56 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
* 将思维导图的md格式转化为html,提供在线预览
|
||||
* 链接:https://www.npmjs.com/package/markmap-cli
|
||||
*/
|
||||
const {execShell} = require("./.exec");
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const markMapPath = path.join(__dirname, '../', 'docs/manuscripts/mark-map')
|
||||
const markMapHtmlPath = path.join(__dirname, '../', 'docs/.vuepress/public/mark-map')
|
||||
|
||||
|
||||
/**
|
||||
* 扫面目录
|
||||
*/
|
||||
function scanDirectory(directory, fileType) {
|
||||
const fileList = fs.readdirSync(directory)
|
||||
|
||||
return fileList
|
||||
.map(file => {
|
||||
const filePath = path.join(directory, file);
|
||||
const fileExtension = path.extname(file).toLowerCase();
|
||||
|
||||
if (fileExtension === `.${fileType.toLowerCase()}`) {
|
||||
return filePath
|
||||
}
|
||||
})
|
||||
// 过滤空
|
||||
.filter(c => c != null)
|
||||
}
|
||||
|
||||
|
||||
(async () => {
|
||||
/**
|
||||
* 第一步: 清空站点思维导图文件存放目录
|
||||
*/
|
||||
const delHtmlDir = `rm -rf ${path.join(markMapHtmlPath, '*')}`
|
||||
|
||||
/**
|
||||
* 第二步: 将md文档转化为思维导图网页
|
||||
*/
|
||||
const mdList = scanDirectory(markMapPath, 'md')
|
||||
const mdToHtmlCmdStr = mdList.map(md => `markmap --no-open ${md}`).join(' && ')
|
||||
|
||||
|
||||
/**
|
||||
* 第三步: 根据文件类型将思维导图网页文件移动到站点指定目录
|
||||
*
|
||||
*/
|
||||
const mdHtmlByFileType = path.join(markMapPath, '*.html')
|
||||
const moveHtmlCmdStr = `mv -f ${mdHtmlByFileType} ${markMapHtmlPath}`
|
||||
|
||||
await execShell([delHtmlDir, mdToHtmlCmdStr, moveHtmlCmdStr])
|
||||
|
||||
})()
|
||||
35
scripts/test
35
scripts/test
@@ -1,35 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
* 脚本测试
|
||||
* 链接:https://github.com/enquirer/enquirer
|
||||
*/
|
||||
// const {execShell} = require("./.exec");
|
||||
|
||||
(async() => {
|
||||
const { AutoComplete } = require('enquirer')
|
||||
|
||||
const prompt = new AutoComplete({
|
||||
name: 'flavor',
|
||||
message: 'Pick your favorite flavor',
|
||||
limit: 10,
|
||||
initial: 2,
|
||||
choices: [
|
||||
'Almond',
|
||||
'Apple',
|
||||
'Banana',
|
||||
'Blackberry',
|
||||
'Blueberry',
|
||||
'Cherry',
|
||||
'Chocolate',
|
||||
'Cinnamon',
|
||||
'Coconut',
|
||||
'Cranberry',
|
||||
'Grape'
|
||||
]
|
||||
})
|
||||
|
||||
prompt.run()
|
||||
.then(answer => console.log('Answer:', answer))
|
||||
.catch(console.error)
|
||||
})()
|
||||
Reference in New Issue
Block a user