@cdlab996/lowcode-plugin-code-generator 0.0.0-stage → 2.0.0
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/LICENSE +21 -0
- package/README.md +21 -2
- package/dist/index.cjs +212 -0
- package/dist/index.d.cts +25 -0
- package/dist/index.d.mts +25 -0
- package/dist/index.mjs +189 -0
- package/package.json +64 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023-PRESENT cdLab996<https://github.com/cdLab996>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @cdlab996/lowcode-plugin-code-generator
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Code generation for the LowCode Engine designer: a 出码 button in the top bar
|
|
4
|
+
generates a Vite + Vue project from the current schema with
|
|
5
|
+
[`@cdlab996/lowcode-code-generator`](../../tools/code-generator), shows its
|
|
6
|
+
files and what could not be exported, and downloads it as a zip.
|
|
7
|
+
|
|
8
|
+
```ts
|
|
9
|
+
import { plugins } from '@alilc/lowcode-engine'
|
|
10
|
+
import CodeGenerator from '@cdlab996/lowcode-plugin-code-generator'
|
|
11
|
+
|
|
12
|
+
await plugins.register(CodeGenerator, { vue: 3, name: 'my-app' })
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
| Option | Description |
|
|
16
|
+
| ------ | --------------------------------------------- |
|
|
17
|
+
| `vue` | `2` (Vue 2.7) or `3` (default). |
|
|
18
|
+
| `name` | Package and zip name (default `lowcode-app`). |
|
|
19
|
+
|
|
20
|
+
Component imports come from the materials' code generation manifests: the
|
|
21
|
+
`codegen` field of the asset packages, or the `assets.json` next to a
|
|
22
|
+
package script (written by `@cdlab996/lowcode-material-builder`).
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
// \0rolldown/runtime.js
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
let react = require("react");
|
|
23
|
+
react = __toESM(react, 1);
|
|
24
|
+
let _alifd_next = require("@alifd/next");
|
|
25
|
+
let _alilc_lowcode_plugin_base_monaco_editor = require("@alilc/lowcode-plugin-base-monaco-editor");
|
|
26
|
+
_alilc_lowcode_plugin_base_monaco_editor = __toESM(_alilc_lowcode_plugin_base_monaco_editor, 1);
|
|
27
|
+
require("@alilc/lowcode-plugin-base-monaco-editor/lib/style");
|
|
28
|
+
let _alilc_lowcode_types = require("@alilc/lowcode-types");
|
|
29
|
+
let _cdlab996_lowcode_code_generator = require("@cdlab996/lowcode-code-generator");
|
|
30
|
+
// src/generator-dialog.tsx
|
|
31
|
+
const LANGUAGES = {
|
|
32
|
+
vue: "html",
|
|
33
|
+
js: "javascript",
|
|
34
|
+
json: "json",
|
|
35
|
+
css: "css",
|
|
36
|
+
html: "html",
|
|
37
|
+
md: "markdown",
|
|
38
|
+
yaml: "yaml"
|
|
39
|
+
};
|
|
40
|
+
const styles = {
|
|
41
|
+
root: {
|
|
42
|
+
display: "flex",
|
|
43
|
+
flexDirection: "column",
|
|
44
|
+
gap: 12,
|
|
45
|
+
height: "70vh"
|
|
46
|
+
},
|
|
47
|
+
warnings: {
|
|
48
|
+
margin: 0,
|
|
49
|
+
paddingLeft: 16
|
|
50
|
+
},
|
|
51
|
+
body: {
|
|
52
|
+
display: "flex",
|
|
53
|
+
flex: 1,
|
|
54
|
+
minHeight: 0,
|
|
55
|
+
border: "1px solid #e6e6e6"
|
|
56
|
+
},
|
|
57
|
+
files: {
|
|
58
|
+
width: 260,
|
|
59
|
+
margin: 0,
|
|
60
|
+
padding: "8px 0",
|
|
61
|
+
overflow: "auto",
|
|
62
|
+
listStyle: "none",
|
|
63
|
+
borderRight: "1px solid #e6e6e6"
|
|
64
|
+
},
|
|
65
|
+
file: {
|
|
66
|
+
padding: "4px 12px",
|
|
67
|
+
cursor: "pointer",
|
|
68
|
+
fontSize: 12,
|
|
69
|
+
whiteSpace: "nowrap"
|
|
70
|
+
},
|
|
71
|
+
active: {
|
|
72
|
+
background: "#e8f2ff",
|
|
73
|
+
color: "#0079f2"
|
|
74
|
+
},
|
|
75
|
+
code: {
|
|
76
|
+
flex: 1,
|
|
77
|
+
minWidth: 0
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
function download(files, name) {
|
|
81
|
+
const blob = new Blob([(0, _cdlab996_lowcode_code_generator.toZip)(files)], { type: "application/zip" });
|
|
82
|
+
const url = URL.createObjectURL(blob);
|
|
83
|
+
const link = document.createElement("a");
|
|
84
|
+
link.href = url;
|
|
85
|
+
link.download = `${name}.zip`;
|
|
86
|
+
link.click();
|
|
87
|
+
setTimeout(() => URL.revokeObjectURL(url));
|
|
88
|
+
}
|
|
89
|
+
/** 出码: generates the project of the current schema, previews it and downloads it. */
|
|
90
|
+
function GeneratorButton({ ctx, vue, name, intl }) {
|
|
91
|
+
var _project$files$curren, _LANGUAGES, _current$split$pop;
|
|
92
|
+
const [loading, setLoading] = (0, react.useState)(false);
|
|
93
|
+
const [project, setProject] = (0, react.useState)(null);
|
|
94
|
+
const [current, setCurrent] = (0, react.useState)("");
|
|
95
|
+
const generate = async () => {
|
|
96
|
+
setLoading(true);
|
|
97
|
+
try {
|
|
98
|
+
var _ctx$material$getAsse, _ctx$material$getAsse2, _ref, _paths$find;
|
|
99
|
+
const assets = (_ctx$material$getAsse = (_ctx$material$getAsse2 = ctx.material.getAssets()) === null || _ctx$material$getAsse2 === void 0 ? void 0 : _ctx$material$getAsse2.packages) !== null && _ctx$material$getAsse !== void 0 ? _ctx$material$getAsse : [];
|
|
100
|
+
const result = await (0, _cdlab996_lowcode_code_generator.generateProject)(ctx.project.exportSchema(_alilc_lowcode_types.IPublicEnumTransformStage.Save), {
|
|
101
|
+
vue,
|
|
102
|
+
packages: await (0, _cdlab996_lowcode_code_generator.materialPackages)(assets),
|
|
103
|
+
name,
|
|
104
|
+
format: true
|
|
105
|
+
});
|
|
106
|
+
const paths = Object.keys(result.files);
|
|
107
|
+
setCurrent((_ref = (_paths$find = paths.find((path) => path.startsWith("src/pages/"))) !== null && _paths$find !== void 0 ? _paths$find : paths[0]) !== null && _ref !== void 0 ? _ref : "");
|
|
108
|
+
setProject(result);
|
|
109
|
+
} catch (error) {
|
|
110
|
+
_alifd_next.Message.error(intl("GenerateFailed", { message: error instanceof Error ? error.message : String(error) }));
|
|
111
|
+
} finally {
|
|
112
|
+
setLoading(false);
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
const paths = project ? Object.keys(project.files).sort() : [];
|
|
116
|
+
return /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, /* @__PURE__ */ react.default.createElement(_alifd_next.Button, {
|
|
117
|
+
loading,
|
|
118
|
+
onClick: () => void generate()
|
|
119
|
+
}, intl("Generate")), /* @__PURE__ */ react.default.createElement(_alifd_next.Dialog, {
|
|
120
|
+
title: intl("DialogTitle", { version: vue === 2 ? "2.7" : "3" }),
|
|
121
|
+
visible: !!project,
|
|
122
|
+
style: { width: "90vw" },
|
|
123
|
+
onClose: () => setProject(null),
|
|
124
|
+
footer: /* @__PURE__ */ react.default.createElement(_alifd_next.Button, {
|
|
125
|
+
type: "primary",
|
|
126
|
+
onClick: () => project && download(project.files, name)
|
|
127
|
+
}, intl("DownloadZip"))
|
|
128
|
+
}, project && /* @__PURE__ */ react.default.createElement("div", {
|
|
129
|
+
className: "lowcode-code-generator",
|
|
130
|
+
style: styles.root
|
|
131
|
+
}, project.warnings.length > 0 && /* @__PURE__ */ react.default.createElement(_alifd_next.Message, {
|
|
132
|
+
type: "warning",
|
|
133
|
+
title: intl("Warnings")
|
|
134
|
+
}, /* @__PURE__ */ react.default.createElement("ul", { style: styles.warnings }, project.warnings.map((warning) => /* @__PURE__ */ react.default.createElement("li", { key: warning }, warning)))), /* @__PURE__ */ react.default.createElement("div", { style: styles.body }, /* @__PURE__ */ react.default.createElement("ul", {
|
|
135
|
+
className: "lowcode-code-generator-files",
|
|
136
|
+
style: styles.files
|
|
137
|
+
}, paths.map((path) => /* @__PURE__ */ react.default.createElement("li", {
|
|
138
|
+
key: path,
|
|
139
|
+
style: path === current ? {
|
|
140
|
+
...styles.file,
|
|
141
|
+
...styles.active
|
|
142
|
+
} : styles.file,
|
|
143
|
+
onClick: () => setCurrent(path)
|
|
144
|
+
}, path))), /* @__PURE__ */ react.default.createElement("div", { style: styles.code }, /* @__PURE__ */ react.default.createElement(_alilc_lowcode_plugin_base_monaco_editor.default, {
|
|
145
|
+
key: current,
|
|
146
|
+
value: (_project$files$curren = project.files[current]) !== null && _project$files$curren !== void 0 ? _project$files$curren : "",
|
|
147
|
+
language: (_LANGUAGES = LANGUAGES[(_current$split$pop = current.split(".").pop()) !== null && _current$split$pop !== void 0 ? _current$split$pop : ""]) !== null && _LANGUAGES !== void 0 ? _LANGUAGES : "plaintext",
|
|
148
|
+
height: "100%",
|
|
149
|
+
style: { height: "100%" },
|
|
150
|
+
options: {
|
|
151
|
+
readOnly: true,
|
|
152
|
+
minimap: { enabled: false },
|
|
153
|
+
automaticLayout: true
|
|
154
|
+
}
|
|
155
|
+
}))))));
|
|
156
|
+
}
|
|
157
|
+
// src/locale/en-US.json
|
|
158
|
+
var en_US_default = {
|
|
159
|
+
Generate: "Export code",
|
|
160
|
+
GenerateFailed: "Code generation failed: {message}",
|
|
161
|
+
DialogTitle: "Export code (Vue {version})",
|
|
162
|
+
DownloadZip: "Download zip",
|
|
163
|
+
Warnings: "Not exported, or to be handled by hand"
|
|
164
|
+
};
|
|
165
|
+
// src/locale/zh-CN.json
|
|
166
|
+
var zh_CN_default = {
|
|
167
|
+
Generate: "出码",
|
|
168
|
+
GenerateFailed: "出码失败:{message}",
|
|
169
|
+
DialogTitle: "出码(Vue {version})",
|
|
170
|
+
DownloadZip: "下载 zip",
|
|
171
|
+
Warnings: "以下内容未导出或需要手动处理"
|
|
172
|
+
};
|
|
173
|
+
// src/locale/index.ts
|
|
174
|
+
/** Messages of the plugin in the engine locale. */
|
|
175
|
+
function createIntl(ctx) {
|
|
176
|
+
return ctx.common.utils.createIntl({
|
|
177
|
+
"en-US": en_US_default,
|
|
178
|
+
"zh-CN": zh_CN_default
|
|
179
|
+
}).intl;
|
|
180
|
+
}
|
|
181
|
+
// src/index.tsx
|
|
182
|
+
const PluginCodeGenerator = (ctx, options = {}) => {
|
|
183
|
+
return { init() {
|
|
184
|
+
var _options$vue, _options$name;
|
|
185
|
+
ctx.skeleton.add({
|
|
186
|
+
area: "topArea",
|
|
187
|
+
type: "Widget",
|
|
188
|
+
name: "codeGenerator",
|
|
189
|
+
props: { align: "right" },
|
|
190
|
+
content: (0, react.createElement)(GeneratorButton, {
|
|
191
|
+
ctx,
|
|
192
|
+
vue: (_options$vue = options.vue) !== null && _options$vue !== void 0 ? _options$vue : 3,
|
|
193
|
+
name: (_options$name = options.name) !== null && _options$name !== void 0 ? _options$name : "lowcode-app",
|
|
194
|
+
intl: createIntl(ctx)
|
|
195
|
+
})
|
|
196
|
+
});
|
|
197
|
+
} };
|
|
198
|
+
};
|
|
199
|
+
PluginCodeGenerator.pluginName = "PluginCodeGenerator";
|
|
200
|
+
PluginCodeGenerator.meta = { preferenceDeclaration: {
|
|
201
|
+
title: "PluginCodeGenerator Plugin Parameter Definition",
|
|
202
|
+
properties: [{
|
|
203
|
+
key: "vue",
|
|
204
|
+
type: "number",
|
|
205
|
+
description: "Vue version: 2 or 3"
|
|
206
|
+
}, {
|
|
207
|
+
key: "name",
|
|
208
|
+
type: "string",
|
|
209
|
+
description: "Name of the generated package"
|
|
210
|
+
}]
|
|
211
|
+
} };
|
|
212
|
+
module.exports = PluginCodeGenerator;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { IPublicModelPluginContext } from "@alilc/lowcode-types";
|
|
2
|
+
import { VueVersion } from "@cdlab996/lowcode-code-generator";
|
|
3
|
+
export interface Options {
|
|
4
|
+
/** Vue version of the generated project (default 3). */
|
|
5
|
+
vue?: VueVersion;
|
|
6
|
+
/** Name of the generated package and zip (default `lowcode-app`). */
|
|
7
|
+
name?: string;
|
|
8
|
+
}
|
|
9
|
+
declare function PluginCodeGenerator(ctx: IPublicModelPluginContext, options?: Options): {
|
|
10
|
+
init(): void;
|
|
11
|
+
};
|
|
12
|
+
declare namespace PluginCodeGenerator {
|
|
13
|
+
var pluginName: string;
|
|
14
|
+
var meta: {
|
|
15
|
+
preferenceDeclaration: {
|
|
16
|
+
title: string;
|
|
17
|
+
properties: {
|
|
18
|
+
key: string;
|
|
19
|
+
type: string;
|
|
20
|
+
description: string;
|
|
21
|
+
}[];
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export { PluginCodeGenerator as default };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { IPublicModelPluginContext } from "@alilc/lowcode-types";
|
|
2
|
+
import { VueVersion } from "@cdlab996/lowcode-code-generator";
|
|
3
|
+
export interface Options {
|
|
4
|
+
/** Vue version of the generated project (default 3). */
|
|
5
|
+
vue?: VueVersion;
|
|
6
|
+
/** Name of the generated package and zip (default `lowcode-app`). */
|
|
7
|
+
name?: string;
|
|
8
|
+
}
|
|
9
|
+
declare function PluginCodeGenerator(ctx: IPublicModelPluginContext, options?: Options): {
|
|
10
|
+
init(): void;
|
|
11
|
+
};
|
|
12
|
+
declare namespace PluginCodeGenerator {
|
|
13
|
+
var pluginName: string;
|
|
14
|
+
var meta: {
|
|
15
|
+
preferenceDeclaration: {
|
|
16
|
+
title: string;
|
|
17
|
+
properties: {
|
|
18
|
+
key: string;
|
|
19
|
+
type: string;
|
|
20
|
+
description: string;
|
|
21
|
+
}[];
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export { PluginCodeGenerator as default };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import React, { createElement, useState } from "react";
|
|
2
|
+
import { Button, Dialog, Message } from "@alifd/next";
|
|
3
|
+
import MonacoEditor from "@alilc/lowcode-plugin-base-monaco-editor";
|
|
4
|
+
import "@alilc/lowcode-plugin-base-monaco-editor/lib/style";
|
|
5
|
+
import { IPublicEnumTransformStage } from "@alilc/lowcode-types";
|
|
6
|
+
import { generateProject, materialPackages, toZip } from "@cdlab996/lowcode-code-generator";
|
|
7
|
+
// src/generator-dialog.tsx
|
|
8
|
+
const LANGUAGES = {
|
|
9
|
+
vue: "html",
|
|
10
|
+
js: "javascript",
|
|
11
|
+
json: "json",
|
|
12
|
+
css: "css",
|
|
13
|
+
html: "html",
|
|
14
|
+
md: "markdown",
|
|
15
|
+
yaml: "yaml"
|
|
16
|
+
};
|
|
17
|
+
const styles = {
|
|
18
|
+
root: {
|
|
19
|
+
display: "flex",
|
|
20
|
+
flexDirection: "column",
|
|
21
|
+
gap: 12,
|
|
22
|
+
height: "70vh"
|
|
23
|
+
},
|
|
24
|
+
warnings: {
|
|
25
|
+
margin: 0,
|
|
26
|
+
paddingLeft: 16
|
|
27
|
+
},
|
|
28
|
+
body: {
|
|
29
|
+
display: "flex",
|
|
30
|
+
flex: 1,
|
|
31
|
+
minHeight: 0,
|
|
32
|
+
border: "1px solid #e6e6e6"
|
|
33
|
+
},
|
|
34
|
+
files: {
|
|
35
|
+
width: 260,
|
|
36
|
+
margin: 0,
|
|
37
|
+
padding: "8px 0",
|
|
38
|
+
overflow: "auto",
|
|
39
|
+
listStyle: "none",
|
|
40
|
+
borderRight: "1px solid #e6e6e6"
|
|
41
|
+
},
|
|
42
|
+
file: {
|
|
43
|
+
padding: "4px 12px",
|
|
44
|
+
cursor: "pointer",
|
|
45
|
+
fontSize: 12,
|
|
46
|
+
whiteSpace: "nowrap"
|
|
47
|
+
},
|
|
48
|
+
active: {
|
|
49
|
+
background: "#e8f2ff",
|
|
50
|
+
color: "#0079f2"
|
|
51
|
+
},
|
|
52
|
+
code: {
|
|
53
|
+
flex: 1,
|
|
54
|
+
minWidth: 0
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
function download(files, name) {
|
|
58
|
+
const blob = new Blob([toZip(files)], { type: "application/zip" });
|
|
59
|
+
const url = URL.createObjectURL(blob);
|
|
60
|
+
const link = document.createElement("a");
|
|
61
|
+
link.href = url;
|
|
62
|
+
link.download = `${name}.zip`;
|
|
63
|
+
link.click();
|
|
64
|
+
setTimeout(() => URL.revokeObjectURL(url));
|
|
65
|
+
}
|
|
66
|
+
/** 出码: generates the project of the current schema, previews it and downloads it. */
|
|
67
|
+
function GeneratorButton({ ctx, vue, name, intl }) {
|
|
68
|
+
var _project$files$curren, _LANGUAGES, _current$split$pop;
|
|
69
|
+
const [loading, setLoading] = useState(false);
|
|
70
|
+
const [project, setProject] = useState(null);
|
|
71
|
+
const [current, setCurrent] = useState("");
|
|
72
|
+
const generate = async () => {
|
|
73
|
+
setLoading(true);
|
|
74
|
+
try {
|
|
75
|
+
var _ctx$material$getAsse, _ctx$material$getAsse2, _ref, _paths$find;
|
|
76
|
+
const assets = (_ctx$material$getAsse = (_ctx$material$getAsse2 = ctx.material.getAssets()) === null || _ctx$material$getAsse2 === void 0 ? void 0 : _ctx$material$getAsse2.packages) !== null && _ctx$material$getAsse !== void 0 ? _ctx$material$getAsse : [];
|
|
77
|
+
const result = await generateProject(ctx.project.exportSchema(IPublicEnumTransformStage.Save), {
|
|
78
|
+
vue,
|
|
79
|
+
packages: await materialPackages(assets),
|
|
80
|
+
name,
|
|
81
|
+
format: true
|
|
82
|
+
});
|
|
83
|
+
const paths = Object.keys(result.files);
|
|
84
|
+
setCurrent((_ref = (_paths$find = paths.find((path) => path.startsWith("src/pages/"))) !== null && _paths$find !== void 0 ? _paths$find : paths[0]) !== null && _ref !== void 0 ? _ref : "");
|
|
85
|
+
setProject(result);
|
|
86
|
+
} catch (error) {
|
|
87
|
+
Message.error(intl("GenerateFailed", { message: error instanceof Error ? error.message : String(error) }));
|
|
88
|
+
} finally {
|
|
89
|
+
setLoading(false);
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
const paths = project ? Object.keys(project.files).sort() : [];
|
|
93
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(Button, {
|
|
94
|
+
loading,
|
|
95
|
+
onClick: () => void generate()
|
|
96
|
+
}, intl("Generate")), /* @__PURE__ */ React.createElement(Dialog, {
|
|
97
|
+
title: intl("DialogTitle", { version: vue === 2 ? "2.7" : "3" }),
|
|
98
|
+
visible: !!project,
|
|
99
|
+
style: { width: "90vw" },
|
|
100
|
+
onClose: () => setProject(null),
|
|
101
|
+
footer: /* @__PURE__ */ React.createElement(Button, {
|
|
102
|
+
type: "primary",
|
|
103
|
+
onClick: () => project && download(project.files, name)
|
|
104
|
+
}, intl("DownloadZip"))
|
|
105
|
+
}, project && /* @__PURE__ */ React.createElement("div", {
|
|
106
|
+
className: "lowcode-code-generator",
|
|
107
|
+
style: styles.root
|
|
108
|
+
}, project.warnings.length > 0 && /* @__PURE__ */ React.createElement(Message, {
|
|
109
|
+
type: "warning",
|
|
110
|
+
title: intl("Warnings")
|
|
111
|
+
}, /* @__PURE__ */ React.createElement("ul", { style: styles.warnings }, project.warnings.map((warning) => /* @__PURE__ */ React.createElement("li", { key: warning }, warning)))), /* @__PURE__ */ React.createElement("div", { style: styles.body }, /* @__PURE__ */ React.createElement("ul", {
|
|
112
|
+
className: "lowcode-code-generator-files",
|
|
113
|
+
style: styles.files
|
|
114
|
+
}, paths.map((path) => /* @__PURE__ */ React.createElement("li", {
|
|
115
|
+
key: path,
|
|
116
|
+
style: path === current ? {
|
|
117
|
+
...styles.file,
|
|
118
|
+
...styles.active
|
|
119
|
+
} : styles.file,
|
|
120
|
+
onClick: () => setCurrent(path)
|
|
121
|
+
}, path))), /* @__PURE__ */ React.createElement("div", { style: styles.code }, /* @__PURE__ */ React.createElement(MonacoEditor, {
|
|
122
|
+
key: current,
|
|
123
|
+
value: (_project$files$curren = project.files[current]) !== null && _project$files$curren !== void 0 ? _project$files$curren : "",
|
|
124
|
+
language: (_LANGUAGES = LANGUAGES[(_current$split$pop = current.split(".").pop()) !== null && _current$split$pop !== void 0 ? _current$split$pop : ""]) !== null && _LANGUAGES !== void 0 ? _LANGUAGES : "plaintext",
|
|
125
|
+
height: "100%",
|
|
126
|
+
style: { height: "100%" },
|
|
127
|
+
options: {
|
|
128
|
+
readOnly: true,
|
|
129
|
+
minimap: { enabled: false },
|
|
130
|
+
automaticLayout: true
|
|
131
|
+
}
|
|
132
|
+
}))))));
|
|
133
|
+
}
|
|
134
|
+
// src/locale/en-US.json
|
|
135
|
+
var en_US_default = {
|
|
136
|
+
Generate: "Export code",
|
|
137
|
+
GenerateFailed: "Code generation failed: {message}",
|
|
138
|
+
DialogTitle: "Export code (Vue {version})",
|
|
139
|
+
DownloadZip: "Download zip",
|
|
140
|
+
Warnings: "Not exported, or to be handled by hand"
|
|
141
|
+
};
|
|
142
|
+
// src/locale/zh-CN.json
|
|
143
|
+
var zh_CN_default = {
|
|
144
|
+
Generate: "出码",
|
|
145
|
+
GenerateFailed: "出码失败:{message}",
|
|
146
|
+
DialogTitle: "出码(Vue {version})",
|
|
147
|
+
DownloadZip: "下载 zip",
|
|
148
|
+
Warnings: "以下内容未导出或需要手动处理"
|
|
149
|
+
};
|
|
150
|
+
// src/locale/index.ts
|
|
151
|
+
/** Messages of the plugin in the engine locale. */
|
|
152
|
+
function createIntl(ctx) {
|
|
153
|
+
return ctx.common.utils.createIntl({
|
|
154
|
+
"en-US": en_US_default,
|
|
155
|
+
"zh-CN": zh_CN_default
|
|
156
|
+
}).intl;
|
|
157
|
+
}
|
|
158
|
+
// src/index.tsx
|
|
159
|
+
const PluginCodeGenerator = (ctx, options = {}) => {
|
|
160
|
+
return { init() {
|
|
161
|
+
var _options$vue, _options$name;
|
|
162
|
+
ctx.skeleton.add({
|
|
163
|
+
area: "topArea",
|
|
164
|
+
type: "Widget",
|
|
165
|
+
name: "codeGenerator",
|
|
166
|
+
props: { align: "right" },
|
|
167
|
+
content: createElement(GeneratorButton, {
|
|
168
|
+
ctx,
|
|
169
|
+
vue: (_options$vue = options.vue) !== null && _options$vue !== void 0 ? _options$vue : 3,
|
|
170
|
+
name: (_options$name = options.name) !== null && _options$name !== void 0 ? _options$name : "lowcode-app",
|
|
171
|
+
intl: createIntl(ctx)
|
|
172
|
+
})
|
|
173
|
+
});
|
|
174
|
+
} };
|
|
175
|
+
};
|
|
176
|
+
PluginCodeGenerator.pluginName = "PluginCodeGenerator";
|
|
177
|
+
PluginCodeGenerator.meta = { preferenceDeclaration: {
|
|
178
|
+
title: "PluginCodeGenerator Plugin Parameter Definition",
|
|
179
|
+
properties: [{
|
|
180
|
+
key: "vue",
|
|
181
|
+
type: "number",
|
|
182
|
+
description: "Vue version: 2 or 3"
|
|
183
|
+
}, {
|
|
184
|
+
key: "name",
|
|
185
|
+
type: "string",
|
|
186
|
+
description: "Name of the generated package"
|
|
187
|
+
}]
|
|
188
|
+
} };
|
|
189
|
+
export { PluginCodeGenerator as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,67 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cdlab996/lowcode-plugin-code-generator",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Code generation for the LowCode Engine designer: Vue 2.7 / Vue 3 projects from the current schema.",
|
|
6
|
+
"author": "wudi <wuchendi96@gmail.com>",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"homepage": "https://github.com/wuchendi/lowcode-engine-vue/tree/main/packages/plugins/code-generator",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/wuchendi/lowcode-engine-vue.git",
|
|
12
|
+
"directory": "packages/plugins/code-generator"
|
|
13
|
+
},
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/wuchendi/lowcode-engine-vue/issues"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"lowcode",
|
|
19
|
+
"lowcode-engine",
|
|
20
|
+
"lowcode-plugin"
|
|
21
|
+
],
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"require": {
|
|
25
|
+
"types": "./dist/index.d.cts",
|
|
26
|
+
"default": "./dist/index.cjs"
|
|
27
|
+
},
|
|
28
|
+
"import": {
|
|
29
|
+
"types": "./dist/index.d.mts",
|
|
30
|
+
"default": "./dist/index.mjs"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"main": "./dist/index.cjs",
|
|
35
|
+
"module": "./dist/index.mjs",
|
|
36
|
+
"types": "./dist/index.d.mts",
|
|
37
|
+
"files": [
|
|
38
|
+
"dist",
|
|
39
|
+
"README.md",
|
|
40
|
+
"LICENSE"
|
|
41
|
+
],
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"@alifd/next": "*",
|
|
44
|
+
"@alilc/lowcode-types": "^1.0.0",
|
|
45
|
+
"react": ">=16"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@alifd/next": "^1.27.34",
|
|
49
|
+
"@alilc/lowcode-types": "^1.3.4",
|
|
50
|
+
"@cdlab996/lowcode-tsconfig": "1.0.0",
|
|
51
|
+
"@types/react": "^16.14.70",
|
|
52
|
+
"react": "^16.14.0",
|
|
53
|
+
"tsdown": "^0.23.7"
|
|
54
|
+
},
|
|
55
|
+
"publishConfig": {
|
|
56
|
+
"access": "public",
|
|
57
|
+
"registry": "https://registry.npmjs.org/"
|
|
58
|
+
},
|
|
59
|
+
"dependencies": {
|
|
60
|
+
"@alilc/lowcode-plugin-base-monaco-editor": "^1.1.2",
|
|
61
|
+
"@cdlab996/lowcode-code-generator": "2.0.0"
|
|
62
|
+
},
|
|
63
|
+
"scripts": {
|
|
64
|
+
"build": "tsdown",
|
|
65
|
+
"lint:type": "tsc -p ./tsconfig.json --noEmit"
|
|
66
|
+
}
|
|
6
67
|
}
|