@vtj/local 0.9.29 → 0.10.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/package.json CHANGED
@@ -1,30 +1,30 @@
1
1
  {
2
2
  "name": "@vtj/local",
3
3
  "private": false,
4
- "version": "0.9.29",
4
+ "version": "0.10.0",
5
5
  "type": "module",
6
6
  "dependencies": {
7
7
  "formidable": "~3.5.1",
8
- "@vtj/coder": "~0.9.29",
9
- "@vtj/node": "~0.9.6",
10
- "@vtj/core": "~0.9.29"
8
+ "@vtj/core": "~0.10.0",
9
+ "@vtj/coder": "~0.10.0",
10
+ "@vtj/node": "~0.10.0",
11
+ "@vtj/parser": "~0.10.0"
11
12
  },
12
13
  "devDependencies": {
13
14
  "@types/formidable": "~3.4.5",
14
15
  "unbuild": "~2.0.0",
15
16
  "vite": "~6.0.6",
16
- "vitest": "~2.1.1",
17
- "@vtj/cli": "~0.9.8"
17
+ "@vtj/cli": "~0.10.0"
18
18
  },
19
19
  "exports": {
20
20
  ".": {
21
21
  "types": "./dist/index.d.ts",
22
22
  "import": "./dist/index.mjs",
23
- "require": "./dist/index.mjs"
23
+ "require": "./dist/index.cjs"
24
24
  },
25
25
  "./*": "./*"
26
26
  },
27
- "main": "./dist/index.mjs",
27
+ "main": "./dist/index.cjs",
28
28
  "module": "./dist/index.mjs",
29
29
  "types": "./dist/index.d.ts",
30
30
  "files": [
@@ -1,6 +0,0 @@
1
- import { type ApiRequest, type ApiResponse } from './shared';
2
- import type { DevToolsOptions } from './plugin';
3
- export interface Controller {
4
- [index: string]: (req: ApiRequest, opts: DevToolsOptions) => Promise<ApiResponse>;
5
- }
6
- export declare const router: (req: any, opts: DevToolsOptions) => Promise<ApiResponse>;
@@ -1,130 +0,0 @@
1
- import formidable from "formidable";
2
- import { fail } from "./shared.mjs";
3
- import * as service from "./service.mjs";
4
- import { resolve } from "path";
5
- const controller = {
6
- notMatch: async (_req) => {
7
- return fail("\u627E\u4E0D\u5230\u5904\u7406\u7A0B\u5E8F");
8
- },
9
- getExtension: service.getExtension,
10
- init: service.init,
11
- saveProject: async (req) => {
12
- const project = req.data;
13
- return service.saveProject(project);
14
- },
15
- saveFile: async (req) => {
16
- const file = req.data;
17
- return service.saveFile(file);
18
- },
19
- getFile: async (req) => {
20
- const id = req.data;
21
- return service.getFile(id);
22
- },
23
- removeFile: async (req) => {
24
- const id = req.data;
25
- return service.removeFile(id);
26
- },
27
- getHistory: async (req) => {
28
- const id = req.data;
29
- return service.getHistory(id);
30
- },
31
- saveHistory: async (req) => {
32
- const file = req.data;
33
- return service.saveHistory(file);
34
- },
35
- removeHistory: async (req) => {
36
- const id = req.data;
37
- return service.removeHistory(id);
38
- },
39
- getHistoryItem: async (req) => {
40
- const { fId, id } = req.data || {};
41
- return service.getHistoryItem(fId, id);
42
- },
43
- saveHistoryItem: async (req) => {
44
- const { fId, item } = req.data || {};
45
- return service.saveHistoryItem(fId, item);
46
- },
47
- removeHistoryItem: async (req) => {
48
- const { fId, ids = [] } = req.data || {};
49
- return service.removeHistoryItem(fId, ids);
50
- },
51
- saveMaterials: async (req) => {
52
- const { project, materials } = req.data || {};
53
- return service.saveMaterials(project, materials);
54
- },
55
- publishFile: async (req) => {
56
- const { project, file } = req.data || {};
57
- return service.publishFile(project, file);
58
- },
59
- publish: async (req) => {
60
- const project = req.data || {};
61
- return service.publish(project);
62
- },
63
- genVueContent: async (req) => {
64
- const { project, dsl } = req.data || {};
65
- return service.genVueContent(project, dsl);
66
- },
67
- createRawPage: async (req) => {
68
- const file = req.data;
69
- return service.createRawPage(file);
70
- },
71
- removeRawPage: async (req) => {
72
- const id = req.data;
73
- return service.removeRawPage(id);
74
- },
75
- getStaticFiles: async (_req, opts) => {
76
- return service.getStaticFiles(opts);
77
- },
78
- removeStaticFile: async (req, opts) => {
79
- const name = req.data?.name;
80
- return service.removeStaticFile(name, opts);
81
- },
82
- clearStaticFiles: async (_req, opts) => {
83
- return service.clearStaticFiles(opts);
84
- },
85
- uploader: async (req, opts) => {
86
- if (!opts) return fail("\u5F02\u5E38\u9519\u8BEF");
87
- const uploadDir = resolve(opts.staticDir, opts.vtjDir);
88
- const form = formidable({
89
- keepExtensions: true,
90
- multiples: true,
91
- createDirsFromUploads: true,
92
- uploadDir
93
- });
94
- return await new Promise((reslove) => {
95
- form.parse(req, (err, _fields, files) => {
96
- if (err) {
97
- reslove(fail("\u5F02\u5E38\u9519\u8BEF", err));
98
- return;
99
- }
100
- const tempFiles = files.files || [];
101
- const result = service.uploadStaticFiles(tempFiles, opts);
102
- reslove(result);
103
- });
104
- });
105
- }
106
- };
107
- export const router = async (req, opts) => {
108
- const body = req.body || {};
109
- const reqUrl = req.url || "";
110
- const uploaderPath = `${opts.baseURL}${opts.uploader}`;
111
- const isUploader = reqUrl.startsWith(uploaderPath);
112
- if (isUploader) {
113
- return await controller.uploader(req, opts);
114
- } else {
115
- const handler = controller[body.type] || controller.notMatch;
116
- try {
117
- return await handler(body, opts);
118
- } catch (e) {
119
- const info = {
120
- input: body,
121
- error: {
122
- message: e?.message,
123
- stack: e?.stack
124
- }
125
- };
126
- await service.saveLogs(info);
127
- return fail("\u5F02\u5E38\u9519\u8BEF", e?.message, e?.stack);
128
- }
129
- }
130
- };
package/dist/plugin.mjs DELETED
@@ -1,321 +0,0 @@
1
- import {
2
- copyPlugin,
3
- staticPlugin
4
- } from "@vtj/cli";
5
- import { pathExistsSync, readJsonSync } from "@vtj/node";
6
- import { join, resolve } from "path";
7
- import bodyParser from "body-parser";
8
- import { router } from "./controller.mjs";
9
- import { CLIENT_DIR } from "./shared.mjs";
10
- const setApis = (server, options) => {
11
- server.middlewares.use((req, res, next) => {
12
- const reqUrl = req.url || "";
13
- if (reqUrl.startsWith(options.baseURL)) {
14
- bodyParser.json({ type: "application/json", limit: "50000kb" })(
15
- req,
16
- res,
17
- next
18
- );
19
- } else {
20
- next();
21
- }
22
- });
23
- server.middlewares.use(async (req, res, next) => {
24
- const reqUrl = req.url || "";
25
- if (reqUrl.startsWith(options.baseURL)) {
26
- const data = await router(req, options);
27
- res.writeHead(200, { "Content-Type": "application/json" });
28
- res.end(JSON.stringify(data));
29
- } else {
30
- next();
31
- }
32
- });
33
- };
34
- const apiServerPlugin = function(options) {
35
- return {
36
- name: "vtj-api-plugin",
37
- apply: "serve",
38
- configureServer(server) {
39
- setApis(server, options);
40
- },
41
- configurePreviewServer(server) {
42
- return () => {
43
- setApis(server, options);
44
- };
45
- }
46
- };
47
- };
48
- const linkPlugin = function(options) {
49
- const {
50
- entry = "/index.html",
51
- href = "",
52
- serveOnly = true
53
- } = options.linkOptions || {};
54
- let config;
55
- return {
56
- name: "vtj-link-plugin",
57
- apply: serveOnly ? "serve" : void 0,
58
- configResolved(resolvedConfig) {
59
- config = resolvedConfig;
60
- },
61
- transformIndexHtml(html, ctx) {
62
- if (html.includes("__VTJ_LINK__")) {
63
- return html;
64
- }
65
- if (options.link) {
66
- if (ctx.path !== entry) {
67
- return html;
68
- }
69
- const link = typeof options.link === "string" ? options.link : `${CLIENT_DIR}/entry/index.js`;
70
- const url = `${config.base}${link}`;
71
- return html.replace(
72
- /<\/body>/,
73
- `
74
- <script>window.__VTJ_LINK__ = { href: '${href}' }<\/script>
75
- <script src="${url}"><\/script></body>
76
- `
77
- );
78
- }
79
- return html;
80
- }
81
- };
82
- };
83
- const hmPlugin = function(options) {
84
- const { hm } = options;
85
- return {
86
- name: "vtj-hm-plugin",
87
- transformIndexHtml(html) {
88
- return html.replace(
89
- /<\/body>/,
90
- `
91
- <script>
92
- (function () {
93
- window._hmt = window._hmt || [];
94
- const hm = document.createElement('script');
95
- hm.src = 'https://hm.baidu.com/hm.js?${hm}';
96
- var s = document.getElementsByTagName('script')[0];
97
- s.parentNode.insertBefore(hm, s);
98
- })();
99
- <\/script>
100
- `
101
- );
102
- }
103
- };
104
- };
105
- const aliasPlugin = function(options) {
106
- return {
107
- name: "vtj-alias-plugin",
108
- config(config) {
109
- const { root = process.cwd() } = config || {};
110
- const vtjDir = join(root, options.vtjDir);
111
- const packagesDir = join(root, options.packagesDir);
112
- const devAlias = options.devMode && process.env.NODE_ENV === "development" ? {
113
- "@vtj/ui/dist/style.css": join(
114
- packagesDir,
115
- "ui/src/style/index.scss"
116
- ),
117
- "@vtj/icons/dist/style.css": join(
118
- packagesDir,
119
- "icons/src/style.scss"
120
- ),
121
- "@vtj/designer/dist/style.css": join(
122
- packagesDir,
123
- "designer/src/style/index.scss"
124
- ),
125
- "@vtj/base": join(packagesDir, "base/src"),
126
- "@vtj/utils": join(packagesDir, "utils/src/index.ts"),
127
- "@vtj/icons/svg": join(packagesDir, "icons/dist/svg.ts"),
128
- "@vtj/icons": join(packagesDir, "icons/src"),
129
- "@vtj/ui": join(packagesDir, "ui/src"),
130
- "@vtj/charts": join(packagesDir, "charts/src"),
131
- "@vtj/core": join(packagesDir, "core/src"),
132
- "@vtj/designer": join(packagesDir, "designer/src"),
133
- "@vtj/renderer": join(packagesDir, "renderer/src"),
134
- "@vtj/coder": join(packagesDir, "coder/src")
135
- } : {};
136
- if (config.resolve) {
137
- let alias = config.resolve.alias || {};
138
- if (Array.isArray(alias)) {
139
- alias.push({
140
- find: "$vtj",
141
- replacement: vtjDir
142
- });
143
- alias.push(
144
- ...Object.entries(devAlias).map(([find, replacement]) => ({
145
- find,
146
- replacement
147
- }))
148
- );
149
- } else {
150
- Object.assign(alias, {
151
- $vtj: vtjDir,
152
- ...devAlias
153
- });
154
- }
155
- config.resolve.alias = alias;
156
- } else {
157
- config.resolve = {
158
- alias: {
159
- $vtj: vtjDir,
160
- ...devAlias
161
- }
162
- };
163
- }
164
- }
165
- };
166
- };
167
- export function parsePresetPlugins(options) {
168
- const {
169
- presetPlugins = [],
170
- pluginNodeModulesDir = "node_modules",
171
- staticBase
172
- } = options;
173
- const pkg = readJsonSync(resolve("./package.json"));
174
- const { devDependencies, dependencies } = pkg || {};
175
- const deps = Object.keys({ ...devDependencies, ...dependencies }).filter(
176
- (name) => presetPlugins.some((regex) => name.startsWith(regex))
177
- );
178
- const copies = [];
179
- const staticDirs = [];
180
- for (const dep of deps) {
181
- const dist = join(pluginNodeModulesDir, dep, "dist");
182
- if (pathExistsSync(dist)) {
183
- copies.push({
184
- from: dist,
185
- to: "@vtj/plugins",
186
- emptyDir: false
187
- });
188
- staticDirs.push({
189
- path: `${staticBase}@vtj/plugins`,
190
- dir: dist
191
- });
192
- }
193
- }
194
- return {
195
- copies,
196
- staticDirs
197
- };
198
- }
199
- export function createDevTools(options = {}) {
200
- const opts = {
201
- baseURL: `/${CLIENT_DIR}/api`,
202
- copy: true,
203
- server: true,
204
- staticBase: "/",
205
- staticDir: "public",
206
- link: true,
207
- linkOptions: null,
208
- vtjDir: ".vtj",
209
- packagesDir: "../../packages",
210
- devMode: false,
211
- uploader: "/uploader.json",
212
- packageName: "@vtj/pro",
213
- nodeModulesDir: "node_modules",
214
- presetPlugins: ["@newpearl/plugin-", "@vtj/plugin-"],
215
- pluginNodeModulesDir: "node_modules",
216
- extensionDir: "",
217
- materialDirs: [],
218
- hm: "42f2469b4aa27c3f8978f634c0c19d24",
219
- ...options
220
- };
221
- const plugins = [aliasPlugin(opts)];
222
- const proPath = `${opts.nodeModulesDir}/${opts.packageName}/dist`;
223
- const materialsPath1 = `${opts.nodeModulesDir}/@vtj/materials/dist`;
224
- const materialsPath2 = `${opts.nodeModulesDir}/${opts.packageName}/${materialsPath1}`;
225
- const materialDirs = opts.materialDirs.map((n) => {
226
- return `${opts.pluginNodeModulesDir}/${n}/dist`;
227
- });
228
- if (opts.copy) {
229
- const copyOptions = [];
230
- if (pathExistsSync(materialsPath1)) {
231
- copyOptions.push({
232
- from: materialsPath1,
233
- to: "@vtj/materials",
234
- emptyDir: true
235
- });
236
- } else if (pathExistsSync(materialsPath2)) {
237
- copyOptions.push({
238
- from: materialsPath2,
239
- to: "@vtj/materials",
240
- emptyDir: true
241
- });
242
- } else {
243
- console.warn(
244
- "\n @vtj/materials is not installed, please install it first.\n"
245
- );
246
- }
247
- materialDirs.forEach((form) => {
248
- copyOptions.push({
249
- from: form,
250
- to: "@vtj/materials",
251
- emptyDir: false
252
- });
253
- });
254
- if (opts.extensionDir && pathExistsSync(opts.extensionDir)) {
255
- copyOptions.push({
256
- from: opts.extensionDir,
257
- to: "@vtj/extension",
258
- emptyDir: true
259
- });
260
- }
261
- if (copyOptions.length > 0) {
262
- plugins.push(copyPlugin(copyOptions));
263
- }
264
- }
265
- if (opts.server) {
266
- plugins.push(apiServerPlugin(opts));
267
- const staticOptions = [];
268
- if (pathExistsSync(proPath)) {
269
- staticOptions.push({
270
- path: `${opts.staticBase}${CLIENT_DIR}`,
271
- dir: proPath
272
- });
273
- }
274
- if (pathExistsSync(materialsPath1)) {
275
- staticOptions.push({
276
- path: `${opts.staticBase}@vtj/materials`,
277
- dir: materialsPath1
278
- });
279
- } else if (pathExistsSync(materialsPath2)) {
280
- staticOptions.push({
281
- path: `${opts.staticBase}@vtj/materials`,
282
- dir: materialsPath2
283
- });
284
- } else {
285
- console.warn(
286
- "\n @vtj/materials is not installed, please install it first.\n"
287
- );
288
- }
289
- materialDirs.forEach((dir) => {
290
- staticOptions.push({
291
- path: `${opts.staticBase}@vtj/materials`,
292
- dir
293
- });
294
- });
295
- if (opts.extensionDir && pathExistsSync(opts.extensionDir)) {
296
- staticOptions.push({
297
- path: `${opts.staticBase}@vtj/extension`,
298
- dir: opts.extensionDir
299
- });
300
- }
301
- if (staticOptions.length > 0) {
302
- plugins.push(staticPlugin(staticOptions));
303
- }
304
- }
305
- if (opts.presetPlugins && opts.presetPlugins.length) {
306
- const { copies, staticDirs } = parsePresetPlugins(opts);
307
- if (copies.length) {
308
- plugins.push(copyPlugin(copies));
309
- }
310
- if (staticDirs.length) {
311
- plugins.push(staticPlugin(staticDirs));
312
- }
313
- }
314
- if (!!opts.link) {
315
- plugins.push(linkPlugin(opts));
316
- }
317
- if (opts.hm) {
318
- plugins.push(hmPlugin(opts));
319
- }
320
- return plugins;
321
- }
@@ -1,4 +0,0 @@
1
- export * from './json';
2
- export * from './vue';
3
- export * from './static';
4
- export * from './plugins';
@@ -1,4 +0,0 @@
1
- export * from "./json.mjs";
2
- export * from "./vue.mjs";
3
- export * from "./static.mjs";
4
- export * from "./plugins.mjs";
@@ -1,9 +0,0 @@
1
- export declare class JsonRepository {
2
- private path;
3
- constructor(path: string);
4
- exist(name: string): any;
5
- save(name: string, json: any): boolean;
6
- get(name: string): any;
7
- remove(name: string): boolean;
8
- clear(): boolean;
9
- }
@@ -1,52 +0,0 @@
1
- import { resolve, join } from "path";
2
- import {
3
- writeJsonSync,
4
- pathExistsSync,
5
- readJsonSync,
6
- removeSync,
7
- ensureFileSync
8
- } from "@vtj/node";
9
- export class JsonRepository {
10
- path;
11
- constructor(path) {
12
- this.path = resolve(".vtj", path);
13
- }
14
- exist(name) {
15
- const filePath = join(this.path, `${name}.json`);
16
- return pathExistsSync(filePath);
17
- }
18
- save(name, json) {
19
- const filePath = join(this.path, `${name}.json`);
20
- if (!this.exist(name)) {
21
- ensureFileSync(filePath);
22
- }
23
- writeJsonSync(filePath, json, {
24
- spaces: 2,
25
- EOL: "\n"
26
- });
27
- return true;
28
- }
29
- get(name) {
30
- const filePath = join(this.path, `${name}.json`);
31
- if (pathExistsSync(filePath)) {
32
- return readJsonSync(filePath);
33
- } else {
34
- return void 0;
35
- }
36
- }
37
- remove(name) {
38
- const filePath = join(this.path, `${name}.json`);
39
- if (pathExistsSync(filePath)) {
40
- removeSync(filePath);
41
- return true;
42
- }
43
- return false;
44
- }
45
- clear() {
46
- if (pathExistsSync(this.path)) {
47
- removeSync(this.path);
48
- return true;
49
- }
50
- return false;
51
- }
52
- }
@@ -1,10 +0,0 @@
1
- import { type BlockFile } from '@vtj/core';
2
- import type { DevToolsOptions } from '../plugin';
3
- export declare class PluginRepository {
4
- private pkg;
5
- private opts;
6
- private deps;
7
- constructor(pkg: any, opts: DevToolsOptions);
8
- getName(dep: string): Capitalize<string>;
9
- getPlugins(): BlockFile[];
10
- }
@@ -1,67 +0,0 @@
1
- import { join } from "path";
2
- import {
3
- pathExistsSync,
4
- readdirSync,
5
- readJsonSync,
6
- upperFirstCamelCase
7
- } from "@vtj/node";
8
- export class PluginRepository {
9
- constructor(pkg, opts) {
10
- this.pkg = pkg;
11
- this.opts = opts;
12
- const { devDependencies, dependencies } = pkg || {};
13
- const { presetPlugins } = opts;
14
- this.deps = Object.keys({ ...devDependencies, ...dependencies }).filter(
15
- (name) => presetPlugins.some((regex) => name.startsWith(regex))
16
- );
17
- }
18
- deps = [];
19
- getName(dep) {
20
- const { presetPlugins } = this.opts;
21
- let name = dep;
22
- for (const regex of presetPlugins) {
23
- name = name.replace(regex, "x-");
24
- }
25
- return upperFirstCamelCase(name);
26
- }
27
- getPlugins() {
28
- const { vtj = {} } = this.pkg;
29
- const { pluginNodeModulesDir = "node_modules", staticBase = "/" } = this.opts;
30
- const plugins = (vtj.plugins || []).map((n) => {
31
- n.type = "block";
32
- n.fromType = "Plugin";
33
- n.preset = true;
34
- n.category = "\u63D2\u4EF6\u533A\u5757";
35
- return n;
36
- });
37
- const ext = [".css", ".js", ".json"];
38
- for (const dep of this.deps) {
39
- const dist = join(pluginNodeModulesDir, dep, "dist");
40
- if (pathExistsSync(dist)) {
41
- const pkg = readJsonSync(
42
- join(pluginNodeModulesDir, dep, "package.json")
43
- );
44
- const files = readdirSync(dist, { recursive: true, encoding: "utf-8" });
45
- const urls = files.filter((url) => ext.some((n) => url.endsWith(n))).map(
46
- (url) => `${staticBase}@vtj/plugins/${url.replace(/\\/gi, "/")}`
47
- );
48
- const { description } = pkg || "";
49
- const name = upperFirstCamelCase(dep);
50
- if (files.length) {
51
- plugins.push({
52
- type: "block",
53
- fromType: "Plugin",
54
- preset: true,
55
- id: dep,
56
- name: this.getName(dep),
57
- title: description || name,
58
- library: name,
59
- urls: urls.join(","),
60
- category: "\u63D2\u4EF6\u533A\u5757"
61
- });
62
- }
63
- }
64
- }
65
- return plugins;
66
- }
67
- }
@@ -1,17 +0,0 @@
1
- import formidable from 'formidable';
2
- export interface StaticRepositoryOptions {
3
- staticBase: string;
4
- staticDir: string;
5
- vtjDir: string;
6
- }
7
- export declare class StaticRepository {
8
- private options;
9
- private path;
10
- constructor(options: StaticRepositoryOptions);
11
- exist(name: string): any;
12
- remove(name: string): boolean;
13
- clear(): boolean;
14
- getAllFiles(): any;
15
- validate(files: formidable.File[]): false | never[];
16
- save(files: formidable.File[]): never[];
17
- }