openxiangda 1.0.44 → 1.0.45
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/package.json
CHANGED
|
@@ -17,6 +17,8 @@ import { loadConfig, rootDir } from "./utils/load-config.mjs";
|
|
|
17
17
|
import { getContentType, getCacheControl } from "./utils/mime-types.mjs";
|
|
18
18
|
import { createOSSClient, uploadWithRetry, ensureBucketCors } from "./utils/oss-client.mjs";
|
|
19
19
|
import { createProgressTracker } from "./utils/progress.mjs";
|
|
20
|
+
import { discoverPages } from "./utils/pages.mjs";
|
|
21
|
+
import { buildUploadPatterns } from "./utils/publish-oss-patterns.mjs";
|
|
20
22
|
|
|
21
23
|
const args = minimist(process.argv.slice(2).filter((arg) => arg !== "--"));
|
|
22
24
|
const dryRun = Boolean(args["dry-run"]);
|
|
@@ -58,18 +60,11 @@ if (
|
|
|
58
60
|
|
|
59
61
|
const client = dryRun ? null : createOSSClient(config.oss);
|
|
60
62
|
|
|
61
|
-
/**
|
|
62
|
-
* 构建文件扫描 glob 模式
|
|
63
|
-
* @returns {string} glob 模式
|
|
64
|
-
*/
|
|
65
|
-
function buildPattern() {
|
|
66
|
-
if (targetForm) return `{form-runtime/**/*,forms/${targetForm}/**/*}`;
|
|
67
|
-
if (targetPage) return `{page-runtime/**/*,pages/${targetPage}/**/*}`;
|
|
68
|
-
return "{form-runtime,page-runtime,forms,pages}/**/*";
|
|
69
|
-
}
|
|
70
|
-
|
|
71
63
|
const distDir = path.resolve(rootDir, "dist");
|
|
72
|
-
const files = (await glob(
|
|
64
|
+
const files = (await glob(
|
|
65
|
+
await buildUploadPatterns({ targetForm, targetPage, discoverPages }),
|
|
66
|
+
{ cwd: distDir, nodir: true },
|
|
67
|
+
)).filter(
|
|
73
68
|
(file) => !file.endsWith("/build-cache.json"),
|
|
74
69
|
);
|
|
75
70
|
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export function getPageUploadPatterns(targetPage, pages = []) {
|
|
2
|
+
const names = new Set([targetPage].filter(Boolean));
|
|
3
|
+
for (const page of pages) {
|
|
4
|
+
const code = page?.config?.code;
|
|
5
|
+
if (page?.dirName === targetPage || code === targetPage) {
|
|
6
|
+
if (page.dirName) names.add(page.dirName);
|
|
7
|
+
if (code) names.add(code);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
return ["page-runtime/**/*", ...[...names].map((name) => `pages/${name}/**/*`)];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export async function buildUploadPatterns({ targetForm, targetPage, discoverPages }) {
|
|
14
|
+
if (targetForm) return ["form-runtime/**/*", `forms/${targetForm}/**/*`];
|
|
15
|
+
if (targetPage) {
|
|
16
|
+
const pages = discoverPages ? await discoverPages() : [];
|
|
17
|
+
return getPageUploadPatterns(targetPage, pages);
|
|
18
|
+
}
|
|
19
|
+
return ["{form-runtime,page-runtime,forms,pages}/**/*"];
|
|
20
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { buildUploadPatterns, getPageUploadPatterns } from "./publish-oss-patterns.mjs";
|
|
4
|
+
|
|
5
|
+
describe("publish oss upload patterns", () => {
|
|
6
|
+
it("uploads both page dir name and page config code assets", () => {
|
|
7
|
+
expect(
|
|
8
|
+
getPageUploadPatterns("runtime-workbench", [
|
|
9
|
+
{
|
|
10
|
+
dirName: "runtime-workbench",
|
|
11
|
+
config: { code: "runtime_workbench" },
|
|
12
|
+
},
|
|
13
|
+
]),
|
|
14
|
+
).toEqual([
|
|
15
|
+
"page-runtime/**/*",
|
|
16
|
+
"pages/runtime-workbench/**/*",
|
|
17
|
+
"pages/runtime_workbench/**/*",
|
|
18
|
+
]);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("resolves page config code when target page is already code", async () => {
|
|
22
|
+
await expect(
|
|
23
|
+
buildUploadPatterns({
|
|
24
|
+
targetForm: "",
|
|
25
|
+
targetPage: "runtime_workbench",
|
|
26
|
+
discoverPages: async () => [
|
|
27
|
+
{
|
|
28
|
+
dirName: "runtime-workbench",
|
|
29
|
+
config: { code: "runtime_workbench" },
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
}),
|
|
33
|
+
).resolves.toEqual([
|
|
34
|
+
"page-runtime/**/*",
|
|
35
|
+
"pages/runtime_workbench/**/*",
|
|
36
|
+
"pages/runtime-workbench/**/*",
|
|
37
|
+
]);
|
|
38
|
+
});
|
|
39
|
+
});
|