openxiangda 1.0.44 → 1.0.46

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openxiangda",
3
- "version": "1.0.44",
3
+ "version": "1.0.46",
4
4
  "description": "OpenXiangda CLI, workspace build tools, runtime SDK, and form components.",
5
5
  "private": false,
6
6
  "bin": {
@@ -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(buildPattern(), { cwd: distDir, nodir: true })).filter(
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
 
@@ -159,6 +159,7 @@ async function sendToApi(apiPayload, config, accessToken) {
159
159
  ? {
160
160
  schema: apiPayload.schema,
161
161
  packages: apiPayload.packages,
162
+ formType: apiPayload.formType,
162
163
  }
163
164
  : {
164
165
  userId: config.userId,
@@ -166,6 +167,7 @@ async function sendToApi(apiPayload, config, accessToken) {
166
167
  formUuid: apiPayload.formUuid,
167
168
  schema: apiPayload.schema,
168
169
  packages: apiPayload.packages,
170
+ formType: apiPayload.formType,
169
171
  },
170
172
  ),
171
173
  });
@@ -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
+ });
@@ -72,6 +72,9 @@ export function transformToApiFormat(schema, formName = "unknown") {
72
72
  validateFormSchema(schema, formName);
73
73
 
74
74
  const { formMeta, fields } = schema;
75
+ const formType = normalizeFormType(
76
+ formMeta.formType || schema.template?.formType,
77
+ );
75
78
  const componentNodes = fields.map(createFormComponentNode);
76
79
  const pageSchema = {
77
80
  version: "2.0",
@@ -88,12 +91,21 @@ export function transformToApiFormat(schema, formName = "unknown") {
88
91
  return {
89
92
  formUuid: formMeta.formUuid,
90
93
  appType: formMeta.appType,
94
+ formType,
91
95
  fieldCount: componentNodes.length,
92
96
  schema: JSON.stringify(pageSchema),
93
97
  packages: JSON.stringify({}),
94
98
  };
95
99
  }
96
100
 
101
+ export function normalizeFormType(formType) {
102
+ const normalized = String(formType || "").trim().toLowerCase();
103
+ if (["process", "workflow", "flow", "flowform", "processform"].includes(normalized)) {
104
+ return "process";
105
+ }
106
+ return "receipt";
107
+ }
108
+
97
109
  export function assertSchemaSyncResult(body, expectedFieldCount) {
98
110
  if (body?.code !== 200) {
99
111
  throw new Error(
@@ -35,6 +35,7 @@ describe("schema-transform", () => {
35
35
  const schema = JSON.parse(payload.schema);
36
36
  const nodes = schema.componentsTree[0].children;
37
37
 
38
+ expect(payload.formType).toBe("receipt");
38
39
  expect(payload.fieldCount).toBe(2);
39
40
  expect(nodes[0].props).toMatchObject({
40
41
  fieldId: "customer_name",
@@ -48,6 +49,36 @@ describe("schema-transform", () => {
48
49
  });
49
50
  });
50
51
 
52
+ it("normalizes process form type from form meta or template", () => {
53
+ const fromMeta = transformToApiFormat(
54
+ {
55
+ formMeta: {
56
+ formUuid: "FORM_PROCESS_META",
57
+ appType: "APP_1",
58
+ title: "审批表单",
59
+ formType: "process",
60
+ },
61
+ fields: [{ fieldId: "title", componentName: "TextField", label: "标题" }],
62
+ },
63
+ "process-meta",
64
+ );
65
+ const fromTemplate = transformToApiFormat(
66
+ {
67
+ formMeta: {
68
+ formUuid: "FORM_PROCESS_TEMPLATE",
69
+ appType: "APP_1",
70
+ title: "审批表单",
71
+ },
72
+ template: { formType: "workflow" },
73
+ fields: [{ fieldId: "title", componentName: "TextField", label: "标题" }],
74
+ },
75
+ "process-template",
76
+ );
77
+
78
+ expect(fromMeta.formType).toBe("process");
79
+ expect(fromTemplate.formType).toBe("process");
80
+ });
81
+
51
82
  it("rejects duplicate field ids and empty fields", () => {
52
83
  expect(() =>
53
84
  transformToApiFormat(
@@ -57,8 +57,10 @@ export type OpenXiangdaFormSchemaInput = {
57
57
  formUuid: string;
58
58
  appType: string;
59
59
  title: string;
60
+ formType?: "receipt" | "process";
60
61
  };
61
62
  fields: FieldDefinition[];
63
+ template?: Record<string, unknown>;
62
64
  };
63
65
 
64
66
  export function option(value: string, label = value): FormOption {
@@ -72,6 +74,10 @@ export function options(values: string[]): FormOption[] {
72
74
  export function createFormSchema(input: OpenXiangdaFormSchemaInput) {
73
75
  return defineFormSchema({
74
76
  formMeta: input.formMeta,
77
+ template: {
78
+ ...(input.template || {}),
79
+ ...(input.formMeta.formType === "process" ? { formType: "process" } : {}),
80
+ },
75
81
  fields: input.fields.map(normalizeField),
76
82
  layout: input.fields.map((field) => ({
77
83
  id: `layout_${field.fieldId}`,