|
@@ -8,13 +8,29 @@ import { SVG, cleanupSVG, parseColors, runSVGO } from "@iconify/tools";
|
|
|
|
|
|
import {
|
|
import {
|
|
S3Client,
|
|
S3Client,
|
|
- PutObjectCommand,
|
|
|
|
ListObjectsCommand,
|
|
ListObjectsCommand,
|
|
GetObjectCommand,
|
|
GetObjectCommand,
|
|
- DeleteObjectsCommand,
|
|
|
|
} from "@aws-sdk/client-s3";
|
|
} from "@aws-sdk/client-s3";
|
|
-import { pathsToTree } from "../utils/s3Helper";
|
|
|
|
|
|
+import fs from "node:fs";
|
|
|
|
+import path from "node:path";
|
|
|
|
+import { exec } from "child_process";
|
|
|
|
|
|
|
|
+const DOC_BASE_PATH = "pages";
|
|
|
|
+
|
|
|
|
+// 执行 git restore 命令
|
|
|
|
+await new Promise((resolve, reject) =>
|
|
|
|
+ exec(`git restore ${DOC_BASE_PATH}`, (error, stdout, stderr) => {
|
|
|
|
+ if (error) {
|
|
|
|
+ console.error(`执行 git restore 时出错: ${error.message}`);
|
|
|
|
+ reject(stderr);
|
|
|
|
+ }
|
|
|
|
+ console.log(`git restore 输出结果: ${stdout}`);
|
|
|
|
+ resolve(stdout);
|
|
|
|
+ })
|
|
|
|
+);
|
|
|
|
+process.exit();
|
|
|
|
+
|
|
|
|
+// 从S3构建pages里面的markdown文件
|
|
const s3 = new S3Client({
|
|
const s3 = new S3Client({
|
|
credentials: {
|
|
credentials: {
|
|
accessKeyId: process.env.VITE_AWS_S3_ACCESS_KEY_ID!,
|
|
accessKeyId: process.env.VITE_AWS_S3_ACCESS_KEY_ID!,
|
|
@@ -26,15 +42,39 @@ const command = new ListObjectsCommand({
|
|
Bucket: process.env.VITE_DOCS_LIST_BUCKET,
|
|
Bucket: process.env.VITE_DOCS_LIST_BUCKET,
|
|
});
|
|
});
|
|
const { Contents: contents } = await s3.send(command);
|
|
const { Contents: contents } = await s3.send(command);
|
|
-const docsTree = pathsToTree(contents!.map((f) => f.Key!));
|
|
|
|
-console.log(docsTree)
|
|
|
|
|
|
+console.log(contents);
|
|
process.exit();
|
|
process.exit();
|
|
|
|
+await fs.emptyDir(DOC_BASE_PATH, { recursive: true });
|
|
|
|
+await Promise.all(
|
|
|
|
+ contents!.map((content) => {
|
|
|
|
+ return new Promise(async (resolve, reject) => {
|
|
|
|
+ try {
|
|
|
|
+ const command = new GetObjectCommand({
|
|
|
|
+ Bucket: process.env.VITE_DOCS_LIST_BUCKET,
|
|
|
|
+ Key: content.Key,
|
|
|
|
+ ResponseCacheControl: "no-cache",
|
|
|
|
+ });
|
|
|
|
+ const file = await s3.send(command);
|
|
|
|
+ const writePath = path.join(DOC_BASE_PATH, content.Key!);
|
|
|
|
+ const directory = path.dirname(writePath);
|
|
|
|
+ fs.mkdirSync(directory, { recursive: true });
|
|
|
|
+ fs.writeFileSync(writePath, await file.Body!.transformToString());
|
|
|
|
+ resolve(content.Key);
|
|
|
|
+ } catch (e) {
|
|
|
|
+ reject(e);
|
|
|
|
+ }
|
|
|
|
+ fs.writeFile;
|
|
|
|
+ });
|
|
|
|
+ })
|
|
|
|
+);
|
|
|
|
+
|
|
|
|
+// 构建sideBar数据
|
|
|
|
|
|
// https://vitepress.dev/reference/site-config
|
|
// https://vitepress.dev/reference/site-config
|
|
export default defineConfig({
|
|
export default defineConfig({
|
|
title: "CocoBlockly帮助文档",
|
|
title: "CocoBlockly帮助文档",
|
|
description: "Cococlass help documents",
|
|
description: "Cococlass help documents",
|
|
- srcDir: "pages",
|
|
|
|
|
|
+ srcDir: DOC_BASE_PATH,
|
|
// themeConfig: {
|
|
// themeConfig: {
|
|
// search: {
|
|
// search: {
|
|
// provider: "local",
|
|
// provider: "local",
|