diff --git a/linux-command/.gitignore b/linux-command/.gitignore new file mode 100644 index 0000000..47a6a82 --- /dev/null +++ b/linux-command/.gitignore @@ -0,0 +1,2 @@ +commands/* +list.json diff --git a/linux-command/README.md b/linux-command/README.md new file mode 100644 index 0000000..1c78e58 --- /dev/null +++ b/linux-command/README.md @@ -0,0 +1 @@ +Api是从 CSDN猿如意 的插件中扒出来的 \ No newline at end of file diff --git a/linux-command/index.js b/linux-command/index.js new file mode 100644 index 0000000..f39d3eb --- /dev/null +++ b/linux-command/index.js @@ -0,0 +1,55 @@ +const fs = require('fs'); +const path = require('path'); +const os = require('os'); +const { getApiResult } = require('../utils/requestUtils'); + +const url = { + list: 'https://cdn-static-devbit.csdn.net/devbit-static/plugin/linux-command/dist/data.min.json', + content: (command) => `https://cdn-static-devbit.csdn.net/devbit-static/plugin/linux-command/command/${command}.md` +} + +async function get_list() { + let saveFilePath = './list.json' + if (fs.existsSync(saveFilePath) && fs.statSync(saveFilePath).isFile()) { + console.log('File exists') + let list = fs.readFileSync(saveFilePath, 'utf8') + let list_data = JSON.parse(list) + return list_data + } else { + console.log('File not exists') + let list = await getApiResult(url.list) + let list_data = JSON.parse(list) + fs.writeFileSync(saveFilePath, JSON.stringify(list_data, null, 4)) + return list_data + } +} + +async function get_content_by_command(command) { + // console.log(element) + let saveFilePath = `./commands/${command}.md` + if (fs.existsSync(saveFilePath) && fs.statSync(saveFilePath).isFile()) { + console.log(`[${command}] File exists, skip ...`) + } else { + console.log(`[${command}] File not exists, get content ...`) + let content = await getApiResult(url.content(command)) + fs.writeFileSync(saveFilePath, content) + } +} + +async function main() { + let list = await get_list() + let commands = Object.keys(list) + // console.log(commands.join(', ')) + + let folderPath = './commands' + if (!fs.existsSync(folderPath) || !fs.statSync(folderPath).isDirectory()) { + fs.mkdirSync(folderPath, { recursive: true }) + } + + for (let i = 0; i < commands.length; i++) { + const element = commands[i] + get_content_by_command(element) + } +} + +main() \ No newline at end of file