@vtj/local 0.9.30 → 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.
@@ -1,93 +0,0 @@
1
- import { resolve, join } from "path";
2
- import { pathExistsSync, removeSync, readdirSync, moveSync } from "@vtj/node";
3
- export class StaticRepository {
4
- constructor(options) {
5
- this.options = options;
6
- this.path = resolve(this.options.staticDir, this.options.vtjDir);
7
- }
8
- path;
9
- exist(name) {
10
- const filePath = join(this.path, name);
11
- return pathExistsSync(filePath);
12
- }
13
- remove(name) {
14
- const filePath = join(this.path, name);
15
- if (pathExistsSync(filePath)) {
16
- removeSync(filePath);
17
- return true;
18
- }
19
- return false;
20
- }
21
- clear() {
22
- if (pathExistsSync(this.path)) {
23
- removeSync(this.path);
24
- return true;
25
- }
26
- return false;
27
- }
28
- getAllFiles() {
29
- if (pathExistsSync(this.path)) {
30
- const files = readdirSync(this.path) || [];
31
- return files.map((name) => {
32
- return {
33
- filename: name,
34
- filepath: join(
35
- this.options.staticBase,
36
- this.options.vtjDir,
37
- name
38
- ).replace(/\\/g, "/")
39
- };
40
- });
41
- }
42
- return [];
43
- }
44
- validate(files) {
45
- let isExists = false;
46
- const result = [];
47
- for (let file of files) {
48
- if (file.originalFilename) {
49
- const filePath = join(this.path, file.originalFilename);
50
- if (pathExistsSync(filePath)) {
51
- isExists = true;
52
- result.push({
53
- filename: file.originalFilename,
54
- filepath: join(
55
- this.options.staticBase,
56
- this.options.vtjDir,
57
- file.originalFilename
58
- ).replace(/\\/g, "/")
59
- });
60
- break;
61
- }
62
- }
63
- }
64
- if (isExists) {
65
- for (let file of files) {
66
- if (file.filepath) {
67
- if (pathExistsSync(file.filepath)) {
68
- removeSync(file.filepath);
69
- }
70
- }
71
- }
72
- }
73
- return isExists ? result : false;
74
- }
75
- save(files) {
76
- const result = [];
77
- for (let file of files) {
78
- if (file.filepath && file.originalFilename) {
79
- const filePath = join(this.path, file.originalFilename);
80
- moveSync(file.filepath, filePath, { overwrite: true });
81
- result.push({
82
- filename: file.originalFilename,
83
- filepath: join(
84
- this.options.staticBase,
85
- this.options.vtjDir,
86
- file.originalFilename
87
- ).replace(/\\/g, "/")
88
- });
89
- }
90
- }
91
- return result;
92
- }
93
- }
@@ -1,8 +0,0 @@
1
- export declare class VueRepository {
2
- private path;
3
- constructor();
4
- exist(name: string): any;
5
- save(name: string, content: any): boolean;
6
- remove(name: string): boolean;
7
- clear(): boolean;
8
- }
@@ -1,40 +0,0 @@
1
- import { resolve, join } from "path";
2
- import {
3
- pathExistsSync,
4
- removeSync,
5
- outputFileSync,
6
- ensureFileSync
7
- } from "@vtj/node";
8
- export class VueRepository {
9
- path;
10
- constructor() {
11
- this.path = resolve(".vtj/vue");
12
- }
13
- exist(name) {
14
- const filePath = join(this.path, `${name}.vue`);
15
- return pathExistsSync(filePath);
16
- }
17
- save(name, content) {
18
- const filePath = join(this.path, `${name}.vue`);
19
- if (!this.exist(name)) {
20
- ensureFileSync(filePath);
21
- }
22
- outputFileSync(filePath, content, "utf-8");
23
- return true;
24
- }
25
- remove(name) {
26
- const filePath = join(this.path, `${name}.vue`);
27
- if (pathExistsSync(filePath)) {
28
- removeSync(filePath);
29
- return true;
30
- }
31
- return false;
32
- }
33
- clear() {
34
- if (pathExistsSync(this.path)) {
35
- removeSync(this.path);
36
- return true;
37
- }
38
- return false;
39
- }
40
- }
package/dist/service.d.ts DELETED
@@ -1,29 +0,0 @@
1
- import { type ProjectSchema, type BlockSchema, type HistorySchema, type HistoryItem, type MaterialDescription, type PageFile, type BlockFile } from '@vtj/core';
2
- import formidable from 'formidable';
3
- import { type ApiRequest } from './shared';
4
- import { type StaticRepositoryOptions } from './repository';
5
- import type { DevToolsOptions } from './plugin';
6
- export declare function notMatch(_req: ApiRequest): Promise<import("./shared").ApiResponse>;
7
- export declare function saveLogs(e: any): Promise<boolean>;
8
- export declare function getExtension(_body: any, opts: DevToolsOptions): Promise<import("./shared").ApiResponse>;
9
- export declare function init(_body: any, opts: DevToolsOptions): Promise<import("./shared").ApiResponse>;
10
- export declare function saveProject(dsl: ProjectSchema): Promise<import("./shared").ApiResponse>;
11
- export declare function saveFile(dsl: BlockSchema): Promise<import("./shared").ApiResponse>;
12
- export declare function getFile(id: string): Promise<import("./shared").ApiResponse>;
13
- export declare function removeFile(id: string): Promise<import("./shared").ApiResponse>;
14
- export declare function getHistory(id: string): Promise<import("./shared").ApiResponse>;
15
- export declare function saveHistory(file: HistorySchema): Promise<import("./shared").ApiResponse>;
16
- export declare function removeHistory(id: string): Promise<import("./shared").ApiResponse>;
17
- export declare function getHistoryItem(fId: string, id: string): Promise<import("./shared").ApiResponse>;
18
- export declare function saveHistoryItem(fId: string, item: HistoryItem): Promise<import("./shared").ApiResponse>;
19
- export declare function removeHistoryItem(fId: string, ids: string[]): Promise<import("./shared").ApiResponse>;
20
- export declare function saveMaterials(project: ProjectSchema, materials: Record<string, MaterialDescription>): Promise<import("./shared").ApiResponse>;
21
- export declare function publishFile(project: ProjectSchema, file: PageFile | BlockFile, componentMap?: Map<string, MaterialDescription>): Promise<import("./shared").ApiResponse>;
22
- export declare function publish(project: ProjectSchema): Promise<import("./shared").ApiResponse>;
23
- export declare function genVueContent(project: ProjectSchema, dsl: BlockSchema): Promise<import("./shared").ApiResponse>;
24
- export declare function createRawPage(file: PageFile): Promise<import("./shared").ApiResponse>;
25
- export declare function removeRawPage(id: string): Promise<import("./shared").ApiResponse>;
26
- export declare function uploadStaticFiles(files: formidable.File[], options: StaticRepositoryOptions): Promise<import("./shared").ApiResponse>;
27
- export declare function removeStaticFile(filename: string, options: StaticRepositoryOptions): Promise<import("./shared").ApiResponse>;
28
- export declare function getStaticFiles(options: StaticRepositoryOptions): Promise<import("./shared").ApiResponse>;
29
- export declare function clearStaticFiles(options: StaticRepositoryOptions): Promise<import("./shared").ApiResponse>;
package/dist/service.mjs DELETED
@@ -1,253 +0,0 @@
1
- import {
2
- ProjectModel
3
- } from "@vtj/core";
4
- import { resolve } from "path";
5
- import { readJsonSync, upperFirstCamelCase, timestamp, merge } from "@vtj/node";
6
- import { generator, createEmptyPage } from "@vtj/coder";
7
- import { fail, success } from "./shared.mjs";
8
- import {
9
- JsonRepository,
10
- VueRepository,
11
- StaticRepository,
12
- PluginRepository
13
- } from "./repository/index.mjs";
14
- let isInit = false;
15
- export async function notMatch(_req) {
16
- return fail("\u627E\u4E0D\u5230\u5904\u7406\u7A0B\u5E8F");
17
- }
18
- export async function saveLogs(e) {
19
- const name = `error-${timestamp()}`;
20
- const logs = new JsonRepository("logs");
21
- const json = JSON.parse(JSON.stringify(e));
22
- return logs.save(name, json);
23
- }
24
- export async function getExtension(_body, opts) {
25
- const root = resolve("./");
26
- const pkg = readJsonSync(resolve(root, "package.json"));
27
- const { vtj = {} } = pkg || {};
28
- const adapters = {
29
- remote: "https://lcdp.vtj.pro",
30
- access: {
31
- auth: "/auth.html",
32
- privateKey: "MIIBOgIBAAJBAKoIzmn1FYQ1YOhOBw9EhABxZ+PySAIaydI+zdhoKflrdgJ4A5E4/5gbQmRpk09hPWG8nvX7h+l/QLU8kXxAIBECAwEAAQJAAlgpxQY6sByLsXqzJcthC8LSGsLf2JEJkHwlnpwFqlEV8UCkoINpuZ2Wzl+aftURu5rIfAzRCQBvHmeOTW9/zQIhAO5ufWDmnSLyfAAsNo5JRNpVuLFCFodR8Xm+ulDlosR/AiEAtpAltyP9wmCABKG/v/hrtTr3mcvFNGCjoGa9bUAok28CIHbrVs9w1ijrBlvTsXYwJw46uP539uKRRT4ymZzlm9QjAiB+1KH/G9f9pEEL9rtaSOG7JF5D0JcOjlze4MGVFs+ZrQIhALKOUFBNr2zEsyJIjw2PlvEucdlG77UniszjXTROHSPd"
33
- }
34
- };
35
- const extension = {
36
- ...vtj.extension || {},
37
- history: vtj.history || "hash",
38
- base: vtj.base || "/",
39
- pageRouteName: vtj.pageRouteName || "page",
40
- __BASE_PATH__: opts.staticBase,
41
- __adapters__: merge({}, adapters, vtj.adapters || {})
42
- };
43
- return success(extension);
44
- }
45
- export async function init(_body, opts) {
46
- const root = resolve("./");
47
- const pkg = readJsonSync(resolve(root, "package.json"));
48
- const repository = new JsonRepository("projects");
49
- const pluginPepository = new PluginRepository(pkg, opts);
50
- const { vtj = {} } = pkg || {};
51
- const id = vtj.id || pkg.name;
52
- const name = vtj.name || pkg.description || upperFirstCamelCase(id);
53
- const description = vtj.description || pkg.description || "";
54
- const platform = vtj.platform || "web";
55
- let dsl = repository.get(id);
56
- const plugins = pluginPepository.getPlugins();
57
- if (dsl) {
58
- const blocks = (dsl.blocks || []).filter((n) => !n.preset);
59
- dsl.blocks = plugins.concat(blocks);
60
- Object.assign(dsl, { id, name, description, platform });
61
- if (!isInit) {
62
- isInit = true;
63
- repository.save(id, dsl);
64
- }
65
- dsl.__BASE_PATH__ = opts.staticBase;
66
- return success(dsl);
67
- } else {
68
- const model = new ProjectModel({
69
- id,
70
- name,
71
- description,
72
- platform,
73
- blocks: plugins
74
- });
75
- dsl = model.toDsl();
76
- repository.save(id, dsl);
77
- dsl.__BASE_PATH__ = opts.staticBase;
78
- return success(dsl);
79
- }
80
- }
81
- export async function saveProject(dsl) {
82
- const repository = new JsonRepository("projects");
83
- if (repository.exist(dsl.id)) {
84
- const ret = repository.save(dsl.id, dsl);
85
- return success(ret);
86
- } else {
87
- return fail("\u9879\u76EE\u6587\u4EF6\u4E0D\u5B58\u5728");
88
- }
89
- }
90
- export async function saveFile(dsl) {
91
- const repository = new JsonRepository("files");
92
- const ret = repository.save(dsl.id, dsl);
93
- return success(ret);
94
- }
95
- export async function getFile(id) {
96
- const repository = new JsonRepository("files");
97
- const json = repository.get(id);
98
- if (json) {
99
- return success(json);
100
- } else {
101
- return fail("\u6587\u4EF6\u4E0D\u5B58\u5728");
102
- }
103
- }
104
- export async function removeFile(id) {
105
- const repository = new JsonRepository("files");
106
- const ret = repository.remove(id);
107
- return success(ret);
108
- }
109
- export async function getHistory(id) {
110
- const repository = new JsonRepository("histories");
111
- const json = repository.get(id);
112
- if (json) {
113
- return success(json);
114
- } else {
115
- return success({});
116
- }
117
- }
118
- export async function saveHistory(file) {
119
- const repository = new JsonRepository("histories");
120
- const ret = repository.save(file.id, file);
121
- return success(ret);
122
- }
123
- export async function removeHistory(id) {
124
- const repository = new JsonRepository("histories");
125
- const items = new JsonRepository(`histories/${id}`);
126
- items.clear();
127
- repository.remove(id);
128
- return success(true);
129
- }
130
- export async function getHistoryItem(fId, id) {
131
- const repository = new JsonRepository(`histories/${fId}`);
132
- const json = repository.get(id);
133
- if (json) {
134
- return success(json);
135
- } else {
136
- return fail("\u6587\u4EF6\u4E0D\u5B58\u5728");
137
- }
138
- }
139
- export async function saveHistoryItem(fId, item) {
140
- const repository = new JsonRepository(`histories/${fId}`);
141
- repository.save(item.id, item);
142
- return success(true);
143
- }
144
- export async function removeHistoryItem(fId, ids) {
145
- const repository = new JsonRepository(`histories/${fId}`);
146
- ids.forEach((id) => {
147
- repository.remove(id);
148
- });
149
- return success(true);
150
- }
151
- export async function saveMaterials(project, materials) {
152
- const repository = new JsonRepository("materials");
153
- repository.save(project.id, materials);
154
- return success(true);
155
- }
156
- export async function publishFile(project, file, componentMap) {
157
- const materialsRepository = new JsonRepository("materials");
158
- const materials = materialsRepository.get(project.id);
159
- componentMap = componentMap || new Map(Object.entries(materials || {}));
160
- const fileRepository = new JsonRepository("files");
161
- const dsl = fileRepository.get(file.id);
162
- if (dsl) {
163
- const content = await generator(
164
- dsl,
165
- componentMap,
166
- project.dependencies
167
- ).catch((e) => {
168
- try {
169
- saveLogs({
170
- dsl,
171
- componentMap,
172
- dependencies: project.dependencies,
173
- message: e.message,
174
- stack: e.stack
175
- });
176
- } catch (e2) {
177
- }
178
- throw e;
179
- });
180
- const vueRepository = new VueRepository();
181
- vueRepository.save(file.id, content);
182
- return success(true);
183
- } else {
184
- return fail("\u6587\u4EF6\u4E0D\u5B58\u5728");
185
- }
186
- }
187
- export async function publish(project) {
188
- const { pages = [], blocks = [] } = project;
189
- const materialsRepository = new JsonRepository("materials");
190
- const materials = materialsRepository.get(project.id);
191
- const componentMap = new Map(
192
- Object.entries(materials)
193
- );
194
- for (const block of blocks) {
195
- if (!block.fromType || block.fromType === "Schema") {
196
- await publishFile(project, block, componentMap);
197
- }
198
- }
199
- for (const page of pages) {
200
- if (!page.raw) {
201
- await publishFile(project, page, componentMap);
202
- }
203
- }
204
- return success(true);
205
- }
206
- export async function genVueContent(project, dsl) {
207
- const materialsRepository = new JsonRepository("materials");
208
- const materials = materialsRepository.get(project.id);
209
- const componentMap = new Map(
210
- Object.entries(materials)
211
- );
212
- const content = await generator(
213
- dsl,
214
- componentMap,
215
- project.dependencies
216
- ).catch((e) => {
217
- throw e;
218
- });
219
- return success(content);
220
- }
221
- export async function createRawPage(file) {
222
- const repository = new VueRepository();
223
- const page = await createEmptyPage(file);
224
- repository.save(file.id, page);
225
- return success(true);
226
- }
227
- export async function removeRawPage(id) {
228
- const repository = new VueRepository();
229
- repository.remove(id);
230
- return success(true);
231
- }
232
- export async function uploadStaticFiles(files, options) {
233
- const repository = new StaticRepository(options);
234
- const error = repository.validate(files);
235
- if (error) {
236
- return fail("\u6587\u4EF6\u540D\u79F0\u5DF2\u5B58\u5728", error);
237
- }
238
- const res = repository.save(files);
239
- return success(res);
240
- }
241
- export async function removeStaticFile(filename, options) {
242
- const repository = new StaticRepository(options);
243
- const ret = repository.remove(filename);
244
- return ret ? success(true) : fail("\u5220\u9664\u5931\u8D25");
245
- }
246
- export async function getStaticFiles(options) {
247
- const repository = new StaticRepository(options);
248
- return success(repository.getAllFiles());
249
- }
250
- export async function clearStaticFiles(options) {
251
- const repository = new StaticRepository(options);
252
- return success(repository.clear());
253
- }
package/dist/shared.d.ts DELETED
@@ -1,18 +0,0 @@
1
- export interface ApiRequest {
2
- type: string;
3
- data: any;
4
- }
5
- export interface ApiResponse {
6
- code: number;
7
- msg: string;
8
- data: any;
9
- stack?: any;
10
- success: boolean;
11
- }
12
- export declare enum Result {
13
- Success = 0,
14
- Fail = 1
15
- }
16
- export declare const success: (data: any) => ApiResponse;
17
- export declare const fail: (msg: string, data?: any, stack?: any) => ApiResponse;
18
- export declare const CLIENT_DIR = "__vtj__";
package/dist/shared.mjs DELETED
@@ -1,23 +0,0 @@
1
- export var Result = /* @__PURE__ */ ((Result2) => {
2
- Result2[Result2["Success"] = 0] = "Success";
3
- Result2[Result2["Fail"] = 1] = "Fail";
4
- return Result2;
5
- })(Result || {});
6
- export const success = (data) => {
7
- return {
8
- code: 0 /* Success */,
9
- msg: "success",
10
- data,
11
- success: true
12
- };
13
- };
14
- export const fail = (msg, data = null, stack = null) => {
15
- return {
16
- code: 1 /* Fail */,
17
- msg,
18
- data,
19
- stack,
20
- success: false
21
- };
22
- };
23
- export const CLIENT_DIR = "__vtj__";