From 1eefb07eba5c6664f8f09c3a5fa4da6f6741df73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E5=91=98=E5=B0=8F=E5=A2=A8?= <2291200076@qq.com> Date: Mon, 30 Jan 2023 15:20:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0CSDN=E7=8C=BF=E5=A6=82?= =?UTF-8?q?=E6=84=8Flinux-command=E6=8E=A5=E5=8F=A3=E7=88=AC=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- linux-command/.gitignore | 2 ++ linux-command/README.md | 1 + linux-command/index.js | 55 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 linux-command/.gitignore create mode 100644 linux-command/README.md create mode 100644 linux-command/index.js 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