@vtj/local 0.8.18 → 0.8.20

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.
@@ -1,6 +1,6 @@
1
1
  import { type ApiRequest, type ApiResponse } from './shared';
2
2
  import type { DevToolsOptions } from './plugin';
3
3
  export interface Controller {
4
- [index: string]: (req: ApiRequest, opts?: DevToolsOptions) => Promise<ApiResponse>;
4
+ [index: string]: (req: ApiRequest, opts: DevToolsOptions) => Promise<ApiResponse>;
5
5
  }
6
6
  export declare const router: (req: any, opts: DevToolsOptions) => Promise<ApiResponse>;
package/dist/plugin.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { type Plugin } from 'vite';
2
+ import { type CopyPluginOption, type StaticPluginOption } from '@vtj/cli';
2
3
  export interface DevToolsOptions {
3
4
  baseURL: string;
4
5
  copy: boolean;
@@ -13,6 +14,7 @@ export interface DevToolsOptions {
13
14
  uploader: string;
14
15
  packageName: string;
15
16
  nodeModulesDir: string;
17
+ presetPlugins: RegExp[];
16
18
  hm?: string;
17
19
  }
18
20
  export interface LinkOptions {
@@ -20,4 +22,8 @@ export interface LinkOptions {
20
22
  href?: string;
21
23
  serveOnly?: boolean;
22
24
  }
25
+ export declare function parsePresetPlugins(options: DevToolsOptions): {
26
+ copies: CopyPluginOption[];
27
+ staticDirs: StaticPluginOption[];
28
+ };
23
29
  export declare function createDevTools(options?: Partial<DevToolsOptions>): Plugin<any>[];
package/dist/plugin.mjs CHANGED
@@ -2,8 +2,8 @@ import {
2
2
  copyPlugin,
3
3
  staticPlugin
4
4
  } from "@vtj/cli";
5
- import { pathExistsSync } from "@vtj/node";
6
- import { join } from "path";
5
+ import { pathExistsSync, readJsonSync } from "@vtj/node";
6
+ import { join, resolve } from "path";
7
7
  import bodyParser from "body-parser";
8
8
  import { router } from "./controller.mjs";
9
9
  const setApis = (server, options) => {
@@ -139,6 +139,38 @@ const aliasPlugin = function(options) {
139
139
  }
140
140
  };
141
141
  };
142
+ export function parsePresetPlugins(options) {
143
+ const {
144
+ presetPlugins = [],
145
+ nodeModulesDir = "node_modules",
146
+ staticBase
147
+ } = options;
148
+ const pkg = readJsonSync(resolve("./package.json"));
149
+ const { devDependencies, dependencies } = pkg || {};
150
+ const deps = Object.keys({ ...devDependencies, ...dependencies }).filter(
151
+ (name) => presetPlugins.some((regex) => regex.test(name))
152
+ );
153
+ const copies = [];
154
+ const staticDirs = [];
155
+ for (const dep of deps) {
156
+ const dist = join(nodeModulesDir, dep, "dist");
157
+ if (pathExistsSync(dist)) {
158
+ copies.push({
159
+ from: dist,
160
+ to: "@vtj/plugins",
161
+ emptyDir: false
162
+ });
163
+ staticDirs.push({
164
+ path: `${staticBase}@vtj/plugins`,
165
+ dir: dist
166
+ });
167
+ }
168
+ }
169
+ return {
170
+ copies,
171
+ staticDirs
172
+ };
173
+ }
142
174
  export function createDevTools(options = {}) {
143
175
  const opts = {
144
176
  baseURL: "/vtj/local/repository",
@@ -154,6 +186,7 @@ export function createDevTools(options = {}) {
154
186
  uploader: "/uploader.json",
155
187
  packageName: "@vtj/pro",
156
188
  nodeModulesDir: "node_modules",
189
+ presetPlugins: [/^\@newpearl\/plugin\-/gi, /^\@vtj\/plugin\-/gi],
157
190
  hm: "42f2469b4aa27c3f8978f634c0c19d24",
158
191
  ...options
159
192
  };
@@ -212,6 +245,15 @@ export function createDevTools(options = {}) {
212
245
  plugins.push(staticPlugin(staticOptions));
213
246
  }
214
247
  }
248
+ if (opts.presetPlugins && opts.presetPlugins.length) {
249
+ const { copies, staticDirs } = parsePresetPlugins(opts);
250
+ if (copies.length) {
251
+ plugins.push(copyPlugin(copies));
252
+ }
253
+ if (staticDirs.length) {
254
+ plugins.push(staticPlugin(staticDirs));
255
+ }
256
+ }
215
257
  if (!!opts.link) {
216
258
  plugins.push(linkPlugin(opts));
217
259
  }
@@ -1,3 +1,4 @@
1
1
  export * from './json';
2
2
  export * from './vue';
3
3
  export * from './static';
4
+ export * from './plugins';
@@ -1,3 +1,4 @@
1
1
  export * from "./json.mjs";
2
2
  export * from "./vue.mjs";
3
3
  export * from "./static.mjs";
4
+ export * from "./plugins.mjs";
@@ -0,0 +1,9 @@
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
+ getPlugins(): BlockFile[];
9
+ }
@@ -0,0 +1,55 @@
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) => regex.test(name))
16
+ );
17
+ }
18
+ deps = [];
19
+ getPlugins() {
20
+ const { vtj = {} } = this.pkg;
21
+ const { nodeModulesDir = "node_modules", staticBase = "/" } = this.opts;
22
+ const plugins = (vtj.plugins || []).map((n) => {
23
+ n.type = "block";
24
+ n.fromType = "Plugin";
25
+ n.preset = true;
26
+ return n;
27
+ });
28
+ const ext = [".css", ".js", ".json"];
29
+ for (const dep of this.deps) {
30
+ const dist = join(nodeModulesDir, dep, "dist");
31
+ if (pathExistsSync(dist)) {
32
+ const pkg = readJsonSync(join(nodeModulesDir, dep, "package.json"));
33
+ const files = readdirSync(dist, { recursive: true, encoding: "utf-8" });
34
+ const urls = files.filter((url) => ext.some((n) => url.endsWith(n))).map(
35
+ (url) => `${staticBase}@vtj/plugins/${url.replace(/\\/gi, "/")}`
36
+ );
37
+ const { description } = pkg || "";
38
+ const name = upperFirstCamelCase(dep);
39
+ if (files.length) {
40
+ plugins.push({
41
+ type: "block",
42
+ fromType: "Plugin",
43
+ preset: true,
44
+ id: dep,
45
+ name,
46
+ title: description || name,
47
+ library: name,
48
+ urls: urls.join(",")
49
+ });
50
+ }
51
+ }
52
+ }
53
+ return plugins;
54
+ }
55
+ }
package/dist/service.d.ts CHANGED
@@ -2,10 +2,11 @@ import { type ProjectSchema, type BlockSchema, type HistorySchema, type HistoryI
2
2
  import formidable from 'formidable';
3
3
  import { type ApiRequest } from './shared';
4
4
  import { type StaticRepositoryOptions } from './repository';
5
+ import type { DevToolsOptions } from './plugin';
5
6
  export declare function notMatch(_req: ApiRequest): Promise<import("./shared").ApiResponse>;
6
7
  export declare function saveLogs(e: any): Promise<boolean>;
7
8
  export declare function getExtension(): Promise<import("./shared").ApiResponse>;
8
- export declare function init(): Promise<import("./shared").ApiResponse>;
9
+ export declare function init(_body: any, opts: DevToolsOptions): Promise<import("./shared").ApiResponse>;
9
10
  export declare function saveProject(dsl: ProjectSchema): Promise<import("./shared").ApiResponse>;
10
11
  export declare function saveFile(dsl: BlockSchema): Promise<import("./shared").ApiResponse>;
11
12
  export declare function getFile(id: string): Promise<import("./shared").ApiResponse>;
package/dist/service.mjs CHANGED
@@ -8,8 +8,10 @@ import { fail, success } from "./shared.mjs";
8
8
  import {
9
9
  JsonRepository,
10
10
  VueRepository,
11
- StaticRepository
11
+ StaticRepository,
12
+ PluginRepository
12
13
  } from "./repository/index.mjs";
14
+ let isInit = false;
13
15
  export async function notMatch(_req) {
14
16
  return fail("\u627E\u4E0D\u5230\u5904\u7406\u7A0B\u5E8F");
15
17
  }
@@ -25,19 +27,23 @@ export async function getExtension() {
25
27
  const { vtj = {} } = pkg || {};
26
28
  return success(vtj.extension || null);
27
29
  }
28
- export async function init() {
30
+ export async function init(_body, opts) {
29
31
  const root = resolve("./");
30
32
  const pkg = readJsonSync(resolve(root, "package.json"));
31
33
  const repository = new JsonRepository("projects");
34
+ const pluginPepository = new PluginRepository(pkg, opts);
32
35
  const { vtj = {} } = pkg || {};
33
36
  const id = vtj.id || pkg.name;
34
37
  const name = vtj.name || pkg.description || upperFirstCamelCase(id);
35
38
  const description = vtj.description || pkg.description || "";
36
39
  let dsl = repository.get(id);
40
+ const plugins = pluginPepository.getPlugins();
37
41
  if (dsl) {
38
- const oId = dsl.id;
42
+ const blocks = (dsl.blocks || []).filter((n) => !n.preset);
43
+ dsl.blocks = plugins.concat(blocks);
39
44
  Object.assign(dsl, { id, name, description });
40
- if (oId !== id) {
45
+ if (!isInit) {
46
+ isInit = true;
41
47
  repository.save(id, dsl);
42
48
  }
43
49
  return success(dsl);
@@ -45,7 +51,8 @@ export async function init() {
45
51
  const model = new ProjectModel({
46
52
  id,
47
53
  name,
48
- description
54
+ description,
55
+ blocks: plugins
49
56
  });
50
57
  dsl = model.toDsl();
51
58
  repository.save(id, dsl);
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@vtj/local",
3
3
  "private": false,
4
- "version": "0.8.18",
4
+ "version": "0.8.20",
5
5
  "type": "module",
6
6
  "dependencies": {
7
7
  "formidable": "~3.5.1",
8
- "@vtj/coder": "~0.8.18",
9
- "@vtj/core": "~0.8.18",
8
+ "@vtj/coder": "~0.8.20",
9
+ "@vtj/core": "~0.8.20",
10
10
  "@vtj/node": "~0.8.2"
11
11
  },
12
12
  "devDependencies": {
@@ -14,7 +14,7 @@
14
14
  "unbuild": "~2.0.0",
15
15
  "vite": "~5.2.6",
16
16
  "vitest": "~1.5.0",
17
- "@vtj/cli": "~0.8.5"
17
+ "@vtj/cli": "~0.8.7"
18
18
  },
19
19
  "exports": {
20
20
  ".": {