@vtj/local 0.12.66 → 0.12.68

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/dist/index.cjs CHANGED
@@ -41,10 +41,11 @@ var __publicField$3 = (obj, key, value) => {
41
41
  return value;
42
42
  };
43
43
  class JsonRepository {
44
- constructor(path$1, platform = "web") {
44
+ constructor(options) {
45
45
  __publicField$3(this, "path");
46
- const dir = platform === "uniapp" ? "src/.vtj" : ".vtj";
47
- this.path = path.resolve(dir, path$1);
46
+ const { dir = ".vtj", platform = "web", category } = options;
47
+ const _dir = platform === "uniapp" ? `src/${dir}` : dir;
48
+ this.path = path.resolve(_dir, category);
48
49
  }
49
50
  exist(name) {
50
51
  const filePath = path.join(this.path, `${name}.json`);
@@ -93,10 +94,11 @@ var __publicField$2 = (obj, key, value) => {
93
94
  return value;
94
95
  };
95
96
  class VueRepository {
96
- constructor(platform = "web") {
97
+ constructor(options) {
97
98
  __publicField$2(this, "path");
98
- const dir = platform === "uniapp" ? "src/pages" : ".vtj/vue";
99
- this.path = path.resolve(dir);
99
+ const { dir = ".vtj/vue", platform = "web" } = options;
100
+ const _dir = platform === "uniapp" ? `src/pages` : dir;
101
+ this.path = path.resolve(_dir);
100
102
  }
101
103
  exist(name) {
102
104
  const filePath = path.join(this.path, `${name}.vue`);
@@ -137,7 +139,7 @@ class StaticRepository {
137
139
  constructor(options) {
138
140
  this.options = options;
139
141
  __publicField$1(this, "path");
140
- this.path = path.resolve(this.options.staticDir, this.options.vtjDir);
142
+ this.path = path.resolve(this.options.staticDir, this.options.vtjStaticDir);
141
143
  }
142
144
  exist(name) {
143
145
  const filePath = path.join(this.path, name);
@@ -166,7 +168,7 @@ class StaticRepository {
166
168
  filename: name,
167
169
  filepath: path.join(
168
170
  this.options.staticBase,
169
- this.options.vtjDir,
171
+ this.options.vtjStaticDir,
170
172
  name
171
173
  ).replace(/\\/g, "/")
172
174
  };
@@ -186,7 +188,7 @@ class StaticRepository {
186
188
  filename: file.originalFilename,
187
189
  filepath: path.join(
188
190
  this.options.staticBase,
189
- this.options.vtjDir,
191
+ this.options.vtjStaticDir,
190
192
  file.originalFilename
191
193
  ).replace(/\\/g, "/")
192
194
  });
@@ -215,7 +217,7 @@ class StaticRepository {
215
217
  filename: file.originalFilename,
216
218
  filepath: path.join(
217
219
  this.options.staticBase,
218
- this.options.vtjDir,
220
+ this.options.vtjStaticDir,
219
221
  file.originalFilename
220
222
  ).replace(/\\/g, "/")
221
223
  });
@@ -533,9 +535,13 @@ async function getUniConfig(dsl) {
533
535
 
534
536
  let isInit = false;
535
537
  let _platform = "web";
536
- async function saveLogs(e) {
538
+ async function saveLogs(e, opts) {
537
539
  const name = `error-${node.timestamp()}`;
538
- const logs = new JsonRepository("logs", _platform);
540
+ const logs = new JsonRepository({
541
+ platform: _platform,
542
+ dir: opts.vtjDir,
543
+ category: "logs"
544
+ });
539
545
  const json = JSON.parse(JSON.stringify(e));
540
546
  return logs.save(name, json);
541
547
  }
@@ -581,7 +587,11 @@ async function init(_body, opts) {
581
587
  const description = vtj.description || pkg.description || "";
582
588
  const platform = vtj.platform || "web";
583
589
  _platform = platform;
584
- const repository = new JsonRepository("projects", _platform);
590
+ const repository = new JsonRepository({
591
+ platform: _platform,
592
+ dir: opts.vtjDir,
593
+ category: "projects"
594
+ });
585
595
  let dsl = repository.get(id);
586
596
  const plugins = pluginPepository.getPlugins();
587
597
  if (dsl) {
@@ -617,8 +627,12 @@ async function init(_body, opts) {
617
627
  return success(dsl);
618
628
  }
619
629
  }
620
- async function saveProject(dsl, type) {
621
- const repository = new JsonRepository("projects", dsl.platform);
630
+ async function saveProject(dsl, type, opts) {
631
+ const repository = new JsonRepository({
632
+ platform: dsl.platform || "web",
633
+ dir: opts.vtjDir,
634
+ category: "projects"
635
+ });
622
636
  if (repository.exist(dsl.id)) {
623
637
  const ret = repository.save(dsl.id, dsl);
624
638
  if (dsl.platform === "uniapp") {
@@ -629,13 +643,21 @@ async function saveProject(dsl, type) {
629
643
  return fail("\u9879\u76EE\u6587\u4EF6\u4E0D\u5B58\u5728");
630
644
  }
631
645
  }
632
- async function saveFile(dsl) {
633
- const repository = new JsonRepository("files", _platform);
646
+ async function saveFile(dsl, opts) {
647
+ const repository = new JsonRepository({
648
+ platform: _platform,
649
+ dir: opts.vtjDir,
650
+ category: "files"
651
+ });
634
652
  const ret = repository.save(dsl.id, dsl);
635
653
  return success(ret);
636
654
  }
637
- async function getFile(id) {
638
- const repository = new JsonRepository("files", _platform);
655
+ async function getFile(id, opts) {
656
+ const repository = new JsonRepository({
657
+ platform: _platform,
658
+ dir: opts.vtjDir,
659
+ category: "files"
660
+ });
639
661
  const json = repository.get(id);
640
662
  if (json) {
641
663
  return success(json);
@@ -643,13 +665,21 @@ async function getFile(id) {
643
665
  return fail("\u6587\u4EF6\u4E0D\u5B58\u5728");
644
666
  }
645
667
  }
646
- async function removeFile(id) {
647
- const repository = new JsonRepository("files", _platform);
668
+ async function removeFile(id, opts) {
669
+ const repository = new JsonRepository({
670
+ platform: _platform,
671
+ dir: opts.vtjDir,
672
+ category: "files"
673
+ });
648
674
  const ret = repository.remove(id);
649
675
  return success(ret);
650
676
  }
651
- async function getHistory(id) {
652
- const repository = new JsonRepository("histories", _platform);
677
+ async function getHistory(id, opts) {
678
+ const repository = new JsonRepository({
679
+ platform: _platform,
680
+ dir: opts.vtjDir,
681
+ category: "histories"
682
+ });
653
683
  const json = repository.get(id);
654
684
  if (json) {
655
685
  return success(json);
@@ -657,20 +687,36 @@ async function getHistory(id) {
657
687
  return success({});
658
688
  }
659
689
  }
660
- async function saveHistory(file) {
661
- const repository = new JsonRepository("histories", _platform);
690
+ async function saveHistory(file, opts) {
691
+ const repository = new JsonRepository({
692
+ platform: _platform,
693
+ dir: opts.vtjDir,
694
+ category: "histories"
695
+ });
662
696
  const ret = repository.save(file.id, file);
663
697
  return success(ret);
664
698
  }
665
- async function removeHistory(id) {
666
- const repository = new JsonRepository("histories", _platform);
667
- const items = new JsonRepository(`histories/${id}`, _platform);
699
+ async function removeHistory(id, opts) {
700
+ const repository = new JsonRepository({
701
+ platform: _platform,
702
+ dir: opts.vtjDir,
703
+ category: "histories"
704
+ });
705
+ const items = new JsonRepository({
706
+ platform: _platform,
707
+ dir: opts.vtjDir,
708
+ category: `histories/${id}`
709
+ });
668
710
  items.clear();
669
711
  repository.remove(id);
670
712
  return success(true);
671
713
  }
672
- async function getHistoryItem(fId, id) {
673
- const repository = new JsonRepository(`histories/${fId}`, _platform);
714
+ async function getHistoryItem(fId, id, opts) {
715
+ const repository = new JsonRepository({
716
+ platform: _platform,
717
+ dir: opts.vtjDir,
718
+ category: `histories/${fId}`
719
+ });
674
720
  const json = repository.get(id);
675
721
  if (json) {
676
722
  return success(json);
@@ -678,28 +724,48 @@ async function getHistoryItem(fId, id) {
678
724
  return fail("\u6587\u4EF6\u4E0D\u5B58\u5728");
679
725
  }
680
726
  }
681
- async function saveHistoryItem(fId, item) {
682
- const repository = new JsonRepository(`histories/${fId}`, _platform);
727
+ async function saveHistoryItem(fId, item, opts) {
728
+ const repository = new JsonRepository({
729
+ platform: _platform,
730
+ dir: opts.vtjDir,
731
+ category: `histories/${fId}`
732
+ });
683
733
  repository.save(item.id, item);
684
734
  return success(true);
685
735
  }
686
- async function removeHistoryItem(fId, ids) {
687
- const repository = new JsonRepository(`histories/${fId}`, _platform);
736
+ async function removeHistoryItem(fId, ids, opts) {
737
+ const repository = new JsonRepository({
738
+ platform: _platform,
739
+ dir: opts.vtjDir,
740
+ category: `histories/${fId}`
741
+ });
688
742
  ids.forEach((id) => {
689
743
  repository.remove(id);
690
744
  });
691
745
  return success(true);
692
746
  }
693
- async function saveMaterials(project, materials) {
694
- const repository = new JsonRepository("materials", _platform);
747
+ async function saveMaterials(project, materials, opts) {
748
+ const repository = new JsonRepository({
749
+ platform: _platform,
750
+ dir: opts.vtjDir,
751
+ category: "materials"
752
+ });
695
753
  repository.save(project.id, materials);
696
754
  return success(true);
697
755
  }
698
- async function publishFile(project, file, componentMap) {
699
- const materialsRepository = new JsonRepository("materials", project.platform);
756
+ async function publishFile(project, file, componentMap, opts) {
757
+ const materialsRepository = new JsonRepository({
758
+ platform: _platform,
759
+ dir: opts.vtjDir,
760
+ category: "materials"
761
+ });
700
762
  const materials = materialsRepository.get(project.id);
701
763
  componentMap = componentMap || new Map(Object.entries(materials || {}));
702
- const fileRepository = new JsonRepository("files", project.platform);
764
+ const fileRepository = new JsonRepository({
765
+ platform: project.platform || _platform,
766
+ dir: opts.vtjDir,
767
+ category: "files"
768
+ });
703
769
  const dsl = fileRepository.get(file.id);
704
770
  if (dsl) {
705
771
  const content = await coder.generator(
@@ -709,39 +775,49 @@ async function publishFile(project, file, componentMap) {
709
775
  project.platform
710
776
  ).catch((e) => {
711
777
  try {
712
- saveLogs({
713
- dsl,
714
- componentMap,
715
- dependencies: project.dependencies,
716
- message: e.message,
717
- stack: e.stack
718
- });
778
+ saveLogs(
779
+ {
780
+ dsl,
781
+ componentMap,
782
+ dependencies: project.dependencies,
783
+ message: e.message,
784
+ stack: e.stack
785
+ },
786
+ opts
787
+ );
719
788
  } catch (e2) {
720
789
  }
721
790
  throw e;
722
791
  });
723
- const vueRepository = new VueRepository(_platform);
792
+ const vueRepository = new VueRepository({
793
+ platform: _platform,
794
+ dir: opts.vtjRawDir
795
+ });
724
796
  vueRepository.save(file.id, content);
725
797
  return success(true);
726
798
  } else {
727
799
  return fail("\u6587\u4EF6\u4E0D\u5B58\u5728");
728
800
  }
729
801
  }
730
- async function publish(project) {
802
+ async function publish(project, opts) {
731
803
  const { pages = [], blocks = [] } = project;
732
- const materialsRepository = new JsonRepository("materials", project.platform);
804
+ const materialsRepository = new JsonRepository({
805
+ platform: project.platform || _platform,
806
+ dir: opts.vtjDir,
807
+ category: "materials"
808
+ });
733
809
  const materials = materialsRepository.get(project.id);
734
810
  const componentMap = new Map(
735
811
  Object.entries(materials)
736
812
  );
737
813
  for (const block of blocks) {
738
814
  if (!block.fromType || block.fromType === "Schema") {
739
- await publishFile(project, block, componentMap);
815
+ await publishFile(project, block, componentMap, opts);
740
816
  }
741
817
  }
742
818
  for (const page of pages) {
743
819
  if (!page.raw) {
744
- await publishFile(project, page, componentMap);
820
+ await publishFile(project, page, componentMap, opts);
745
821
  }
746
822
  }
747
823
  if (project.platform === "uniapp") {
@@ -758,8 +834,12 @@ async function genUniConfig(project, injectPages = false) {
758
834
  await uniRepository.saveApp(project);
759
835
  return success(true);
760
836
  }
761
- async function genVueContent(project, dsl) {
762
- const materialsRepository = new JsonRepository("materials", project.platform);
837
+ async function genVueContent(project, dsl, opts) {
838
+ const materialsRepository = new JsonRepository({
839
+ platform: project.platform || _platform,
840
+ dir: opts.vtjDir,
841
+ category: "materials"
842
+ });
763
843
  const materials = materialsRepository.get(project.id);
764
844
  const componentMap = new Map(
765
845
  Object.entries(materials || {})
@@ -782,14 +862,20 @@ async function parseVue(options) {
782
862
  });
783
863
  return success(errors ? errors : dsl);
784
864
  }
785
- async function createRawPage(file) {
786
- const repository = new VueRepository(_platform);
865
+ async function createRawPage(file, opts) {
866
+ const repository = new VueRepository({
867
+ platform: _platform,
868
+ dir: opts.vtjRawDir
869
+ });
787
870
  const page = await coder.createEmptyPage(file);
788
871
  repository.save(file.id, page);
789
872
  return success(true);
790
873
  }
791
- async function removeRawPage(id) {
792
- const repository = new VueRepository(_platform);
874
+ async function removeRawPage(id, opts) {
875
+ const repository = new VueRepository({
876
+ platform: _platform,
877
+ dir: opts.vtjRawDir
878
+ });
793
879
  repository.remove(id);
794
880
  return success(true);
795
881
  }
@@ -822,65 +908,65 @@ const controller = {
822
908
  },
823
909
  getExtension: getExtension,
824
910
  init: init,
825
- saveProject: async (req) => {
911
+ saveProject: async (req, opts) => {
826
912
  const project = req.data;
827
- return saveProject(project, req.query?.type);
913
+ return saveProject(project, req.query?.type, opts);
828
914
  },
829
- saveFile: async (req) => {
915
+ saveFile: async (req, opts) => {
830
916
  const file = req.data;
831
- return saveFile(file);
917
+ return saveFile(file, opts);
832
918
  },
833
- getFile: async (req) => {
919
+ getFile: async (req, opts) => {
834
920
  const id = req.data;
835
- return getFile(id);
921
+ return getFile(id, opts);
836
922
  },
837
- removeFile: async (req) => {
923
+ removeFile: async (req, opts) => {
838
924
  const id = req.data;
839
- return removeFile(id);
925
+ return removeFile(id, opts);
840
926
  },
841
- getHistory: async (req) => {
927
+ getHistory: async (req, opts) => {
842
928
  const id = req.data;
843
- return getHistory(id);
929
+ return getHistory(id, opts);
844
930
  },
845
- saveHistory: async (req) => {
931
+ saveHistory: async (req, opts) => {
846
932
  const file = req.data;
847
- return saveHistory(file);
933
+ return saveHistory(file, opts);
848
934
  },
849
- removeHistory: async (req) => {
935
+ removeHistory: async (req, opts) => {
850
936
  const id = req.data;
851
- return removeHistory(id);
937
+ return removeHistory(id, opts);
852
938
  },
853
- getHistoryItem: async (req) => {
939
+ getHistoryItem: async (req, opts) => {
854
940
  const { fId, id } = req.data || {};
855
- return getHistoryItem(fId, id);
941
+ return getHistoryItem(fId, id, opts);
856
942
  },
857
- saveHistoryItem: async (req) => {
943
+ saveHistoryItem: async (req, opts) => {
858
944
  const { fId, item } = req.data || {};
859
- return saveHistoryItem(fId, item);
945
+ return saveHistoryItem(fId, item, opts);
860
946
  },
861
- removeHistoryItem: async (req) => {
947
+ removeHistoryItem: async (req, opts) => {
862
948
  const { fId, ids = [] } = req.data || {};
863
- return removeHistoryItem(fId, ids);
949
+ return removeHistoryItem(fId, ids, opts);
864
950
  },
865
- saveMaterials: async (req) => {
951
+ saveMaterials: async (req, opts) => {
866
952
  const { project, materials } = req.data || {};
867
- return saveMaterials(project, materials);
953
+ return saveMaterials(project, materials, opts);
868
954
  },
869
- publishFile: async (req) => {
955
+ publishFile: async (req, opts) => {
870
956
  const { project, file } = req.data || {};
871
- const result = await publishFile(project, file);
957
+ const result = await publishFile(project, file, void 0, opts);
872
958
  if (project.platform === "uniapp") {
873
959
  await genUniConfig(project, true);
874
960
  }
875
961
  return result;
876
962
  },
877
- publish: async (req) => {
963
+ publish: async (req, opts) => {
878
964
  const project = req.data || {};
879
- return publish(project);
965
+ return publish(project, opts);
880
966
  },
881
- genVueContent: async (req) => {
967
+ genVueContent: async (req, opts) => {
882
968
  const { project, dsl } = req.data || {};
883
- return genVueContent(project, dsl);
969
+ return genVueContent(project, dsl, opts);
884
970
  },
885
971
  parseVue: async (req) => {
886
972
  const { id, name, source, project } = req.data || {};
@@ -891,28 +977,40 @@ const controller = {
891
977
  project
892
978
  });
893
979
  },
894
- createRawPage: async (req) => {
980
+ createRawPage: async (req, opts) => {
895
981
  const file = req.data;
896
- return createRawPage(file);
982
+ return createRawPage(file, opts);
897
983
  },
898
- removeRawPage: async (req) => {
984
+ removeRawPage: async (req, opts) => {
899
985
  const id = req.data;
900
- return removeRawPage(id);
986
+ return removeRawPage(id, opts);
901
987
  },
902
988
  getStaticFiles: async (_req, opts) => {
903
- return getStaticFiles(opts);
989
+ return getStaticFiles({
990
+ staticBase: opts.staticBase,
991
+ staticDir: opts.staticDir,
992
+ vtjStaticDir: opts.vtjStaticDir
993
+ });
904
994
  },
905
995
  removeStaticFile: async (req, opts) => {
906
996
  const name = req.data?.name;
907
- return removeStaticFile(name, opts);
997
+ return removeStaticFile(name, {
998
+ staticBase: opts.staticBase,
999
+ staticDir: opts.staticDir,
1000
+ vtjStaticDir: opts.vtjStaticDir
1001
+ });
908
1002
  },
909
1003
  clearStaticFiles: async (_req, opts) => {
910
- return clearStaticFiles(opts);
1004
+ return clearStaticFiles({
1005
+ staticBase: opts.staticBase,
1006
+ staticDir: opts.staticDir,
1007
+ vtjStaticDir: opts.vtjStaticDir
1008
+ });
911
1009
  },
912
1010
  uploader: async (req, opts) => {
913
1011
  if (!opts)
914
1012
  return fail("\u5F02\u5E38\u9519\u8BEF");
915
- const uploadDir = path.resolve(opts.staticDir, opts.vtjDir);
1013
+ const uploadDir = path.resolve(opts.staticDir, opts.vtjStaticDir);
916
1014
  const form = formidable__default({
917
1015
  keepExtensions: true,
918
1016
  multiples: true,
@@ -920,14 +1018,20 @@ const controller = {
920
1018
  uploadDir
921
1019
  });
922
1020
  return await new Promise((reslove) => {
923
- form.parse(req, (err, _fields, files) => {
1021
+ form.parse(req, async (err, _fields, files) => {
924
1022
  if (err) {
925
1023
  reslove(fail("\u5F02\u5E38\u9519\u8BEF", err));
926
1024
  return;
927
1025
  }
928
1026
  const tempFiles = files.files || [];
929
- const result = uploadStaticFiles(tempFiles, opts);
930
- reslove(result);
1027
+ const result = await uploadStaticFiles(tempFiles, {
1028
+ staticBase: opts.staticBase,
1029
+ staticDir: opts.staticDir,
1030
+ vtjStaticDir: opts.vtjStaticDir
1031
+ });
1032
+ setTimeout(() => {
1033
+ reslove(result);
1034
+ }, 200);
931
1035
  });
932
1036
  });
933
1037
  }
@@ -969,7 +1073,7 @@ const router = async (req, opts) => {
969
1073
  stack: e?.stack
970
1074
  }
971
1075
  };
972
- await saveLogs(info);
1076
+ await saveLogs(info, opts);
973
1077
  return fail("\u5F02\u5E38\u9519\u8BEF", e?.message, e?.stack);
974
1078
  }
975
1079
  }
@@ -1249,6 +1353,8 @@ function createDevTools(options = {}) {
1249
1353
  link: true,
1250
1354
  linkOptions: null,
1251
1355
  vtjDir: ".vtj",
1356
+ vtjStaticDir: ".vtj",
1357
+ vtjRawDir: ".vtj/vue",
1252
1358
  packagesDir: "../../packages",
1253
1359
  devMode: false,
1254
1360
  uploader: "/uploader.json",
package/dist/index.d.cts CHANGED
@@ -10,6 +10,8 @@ interface DevToolsOptions {
10
10
  link: boolean | string;
11
11
  linkOptions: LinkOptions | null;
12
12
  vtjDir: string;
13
+ vtjStaticDir: string;
14
+ vtjRawDir: string;
13
15
  packagesDir: string;
14
16
  devMode: boolean;
15
17
  uploader: string;
package/dist/index.d.mts CHANGED
@@ -10,6 +10,8 @@ interface DevToolsOptions {
10
10
  link: boolean | string;
11
11
  linkOptions: LinkOptions | null;
12
12
  vtjDir: string;
13
+ vtjStaticDir: string;
14
+ vtjRawDir: string;
13
15
  packagesDir: string;
14
16
  devMode: boolean;
15
17
  uploader: string;
package/dist/index.d.ts CHANGED
@@ -10,6 +10,8 @@ interface DevToolsOptions {
10
10
  link: boolean | string;
11
11
  linkOptions: LinkOptions | null;
12
12
  vtjDir: string;
13
+ vtjStaticDir: string;
14
+ vtjRawDir: string;
13
15
  packagesDir: string;
14
16
  devMode: boolean;
15
17
  uploader: string;
package/dist/index.mjs CHANGED
@@ -34,10 +34,11 @@ var __publicField$3 = (obj, key, value) => {
34
34
  return value;
35
35
  };
36
36
  class JsonRepository {
37
- constructor(path, platform = "web") {
37
+ constructor(options) {
38
38
  __publicField$3(this, "path");
39
- const dir = platform === "uniapp" ? "src/.vtj" : ".vtj";
40
- this.path = resolve(dir, path);
39
+ const { dir = ".vtj", platform = "web", category } = options;
40
+ const _dir = platform === "uniapp" ? `src/${dir}` : dir;
41
+ this.path = resolve(_dir, category);
41
42
  }
42
43
  exist(name) {
43
44
  const filePath = join(this.path, `${name}.json`);
@@ -86,10 +87,11 @@ var __publicField$2 = (obj, key, value) => {
86
87
  return value;
87
88
  };
88
89
  class VueRepository {
89
- constructor(platform = "web") {
90
+ constructor(options) {
90
91
  __publicField$2(this, "path");
91
- const dir = platform === "uniapp" ? "src/pages" : ".vtj/vue";
92
- this.path = resolve(dir);
92
+ const { dir = ".vtj/vue", platform = "web" } = options;
93
+ const _dir = platform === "uniapp" ? `src/pages` : dir;
94
+ this.path = resolve(_dir);
93
95
  }
94
96
  exist(name) {
95
97
  const filePath = join(this.path, `${name}.vue`);
@@ -130,7 +132,7 @@ class StaticRepository {
130
132
  constructor(options) {
131
133
  this.options = options;
132
134
  __publicField$1(this, "path");
133
- this.path = resolve(this.options.staticDir, this.options.vtjDir);
135
+ this.path = resolve(this.options.staticDir, this.options.vtjStaticDir);
134
136
  }
135
137
  exist(name) {
136
138
  const filePath = join(this.path, name);
@@ -159,7 +161,7 @@ class StaticRepository {
159
161
  filename: name,
160
162
  filepath: join(
161
163
  this.options.staticBase,
162
- this.options.vtjDir,
164
+ this.options.vtjStaticDir,
163
165
  name
164
166
  ).replace(/\\/g, "/")
165
167
  };
@@ -179,7 +181,7 @@ class StaticRepository {
179
181
  filename: file.originalFilename,
180
182
  filepath: join(
181
183
  this.options.staticBase,
182
- this.options.vtjDir,
184
+ this.options.vtjStaticDir,
183
185
  file.originalFilename
184
186
  ).replace(/\\/g, "/")
185
187
  });
@@ -208,7 +210,7 @@ class StaticRepository {
208
210
  filename: file.originalFilename,
209
211
  filepath: join(
210
212
  this.options.staticBase,
211
- this.options.vtjDir,
213
+ this.options.vtjStaticDir,
212
214
  file.originalFilename
213
215
  ).replace(/\\/g, "/")
214
216
  });
@@ -526,9 +528,13 @@ async function getUniConfig(dsl) {
526
528
 
527
529
  let isInit = false;
528
530
  let _platform = "web";
529
- async function saveLogs(e) {
531
+ async function saveLogs(e, opts) {
530
532
  const name = `error-${timestamp()}`;
531
- const logs = new JsonRepository("logs", _platform);
533
+ const logs = new JsonRepository({
534
+ platform: _platform,
535
+ dir: opts.vtjDir,
536
+ category: "logs"
537
+ });
532
538
  const json = JSON.parse(JSON.stringify(e));
533
539
  return logs.save(name, json);
534
540
  }
@@ -574,7 +580,11 @@ async function init(_body, opts) {
574
580
  const description = vtj.description || pkg.description || "";
575
581
  const platform = vtj.platform || "web";
576
582
  _platform = platform;
577
- const repository = new JsonRepository("projects", _platform);
583
+ const repository = new JsonRepository({
584
+ platform: _platform,
585
+ dir: opts.vtjDir,
586
+ category: "projects"
587
+ });
578
588
  let dsl = repository.get(id);
579
589
  const plugins = pluginPepository.getPlugins();
580
590
  if (dsl) {
@@ -610,8 +620,12 @@ async function init(_body, opts) {
610
620
  return success(dsl);
611
621
  }
612
622
  }
613
- async function saveProject(dsl, type) {
614
- const repository = new JsonRepository("projects", dsl.platform);
623
+ async function saveProject(dsl, type, opts) {
624
+ const repository = new JsonRepository({
625
+ platform: dsl.platform || "web",
626
+ dir: opts.vtjDir,
627
+ category: "projects"
628
+ });
615
629
  if (repository.exist(dsl.id)) {
616
630
  const ret = repository.save(dsl.id, dsl);
617
631
  if (dsl.platform === "uniapp") {
@@ -622,13 +636,21 @@ async function saveProject(dsl, type) {
622
636
  return fail("\u9879\u76EE\u6587\u4EF6\u4E0D\u5B58\u5728");
623
637
  }
624
638
  }
625
- async function saveFile(dsl) {
626
- const repository = new JsonRepository("files", _platform);
639
+ async function saveFile(dsl, opts) {
640
+ const repository = new JsonRepository({
641
+ platform: _platform,
642
+ dir: opts.vtjDir,
643
+ category: "files"
644
+ });
627
645
  const ret = repository.save(dsl.id, dsl);
628
646
  return success(ret);
629
647
  }
630
- async function getFile(id) {
631
- const repository = new JsonRepository("files", _platform);
648
+ async function getFile(id, opts) {
649
+ const repository = new JsonRepository({
650
+ platform: _platform,
651
+ dir: opts.vtjDir,
652
+ category: "files"
653
+ });
632
654
  const json = repository.get(id);
633
655
  if (json) {
634
656
  return success(json);
@@ -636,13 +658,21 @@ async function getFile(id) {
636
658
  return fail("\u6587\u4EF6\u4E0D\u5B58\u5728");
637
659
  }
638
660
  }
639
- async function removeFile(id) {
640
- const repository = new JsonRepository("files", _platform);
661
+ async function removeFile(id, opts) {
662
+ const repository = new JsonRepository({
663
+ platform: _platform,
664
+ dir: opts.vtjDir,
665
+ category: "files"
666
+ });
641
667
  const ret = repository.remove(id);
642
668
  return success(ret);
643
669
  }
644
- async function getHistory(id) {
645
- const repository = new JsonRepository("histories", _platform);
670
+ async function getHistory(id, opts) {
671
+ const repository = new JsonRepository({
672
+ platform: _platform,
673
+ dir: opts.vtjDir,
674
+ category: "histories"
675
+ });
646
676
  const json = repository.get(id);
647
677
  if (json) {
648
678
  return success(json);
@@ -650,20 +680,36 @@ async function getHistory(id) {
650
680
  return success({});
651
681
  }
652
682
  }
653
- async function saveHistory(file) {
654
- const repository = new JsonRepository("histories", _platform);
683
+ async function saveHistory(file, opts) {
684
+ const repository = new JsonRepository({
685
+ platform: _platform,
686
+ dir: opts.vtjDir,
687
+ category: "histories"
688
+ });
655
689
  const ret = repository.save(file.id, file);
656
690
  return success(ret);
657
691
  }
658
- async function removeHistory(id) {
659
- const repository = new JsonRepository("histories", _platform);
660
- const items = new JsonRepository(`histories/${id}`, _platform);
692
+ async function removeHistory(id, opts) {
693
+ const repository = new JsonRepository({
694
+ platform: _platform,
695
+ dir: opts.vtjDir,
696
+ category: "histories"
697
+ });
698
+ const items = new JsonRepository({
699
+ platform: _platform,
700
+ dir: opts.vtjDir,
701
+ category: `histories/${id}`
702
+ });
661
703
  items.clear();
662
704
  repository.remove(id);
663
705
  return success(true);
664
706
  }
665
- async function getHistoryItem(fId, id) {
666
- const repository = new JsonRepository(`histories/${fId}`, _platform);
707
+ async function getHistoryItem(fId, id, opts) {
708
+ const repository = new JsonRepository({
709
+ platform: _platform,
710
+ dir: opts.vtjDir,
711
+ category: `histories/${fId}`
712
+ });
667
713
  const json = repository.get(id);
668
714
  if (json) {
669
715
  return success(json);
@@ -671,28 +717,48 @@ async function getHistoryItem(fId, id) {
671
717
  return fail("\u6587\u4EF6\u4E0D\u5B58\u5728");
672
718
  }
673
719
  }
674
- async function saveHistoryItem(fId, item) {
675
- const repository = new JsonRepository(`histories/${fId}`, _platform);
720
+ async function saveHistoryItem(fId, item, opts) {
721
+ const repository = new JsonRepository({
722
+ platform: _platform,
723
+ dir: opts.vtjDir,
724
+ category: `histories/${fId}`
725
+ });
676
726
  repository.save(item.id, item);
677
727
  return success(true);
678
728
  }
679
- async function removeHistoryItem(fId, ids) {
680
- const repository = new JsonRepository(`histories/${fId}`, _platform);
729
+ async function removeHistoryItem(fId, ids, opts) {
730
+ const repository = new JsonRepository({
731
+ platform: _platform,
732
+ dir: opts.vtjDir,
733
+ category: `histories/${fId}`
734
+ });
681
735
  ids.forEach((id) => {
682
736
  repository.remove(id);
683
737
  });
684
738
  return success(true);
685
739
  }
686
- async function saveMaterials(project, materials) {
687
- const repository = new JsonRepository("materials", _platform);
740
+ async function saveMaterials(project, materials, opts) {
741
+ const repository = new JsonRepository({
742
+ platform: _platform,
743
+ dir: opts.vtjDir,
744
+ category: "materials"
745
+ });
688
746
  repository.save(project.id, materials);
689
747
  return success(true);
690
748
  }
691
- async function publishFile(project, file, componentMap) {
692
- const materialsRepository = new JsonRepository("materials", project.platform);
749
+ async function publishFile(project, file, componentMap, opts) {
750
+ const materialsRepository = new JsonRepository({
751
+ platform: _platform,
752
+ dir: opts.vtjDir,
753
+ category: "materials"
754
+ });
693
755
  const materials = materialsRepository.get(project.id);
694
756
  componentMap = componentMap || new Map(Object.entries(materials || {}));
695
- const fileRepository = new JsonRepository("files", project.platform);
757
+ const fileRepository = new JsonRepository({
758
+ platform: project.platform || _platform,
759
+ dir: opts.vtjDir,
760
+ category: "files"
761
+ });
696
762
  const dsl = fileRepository.get(file.id);
697
763
  if (dsl) {
698
764
  const content = await generator(
@@ -702,39 +768,49 @@ async function publishFile(project, file, componentMap) {
702
768
  project.platform
703
769
  ).catch((e) => {
704
770
  try {
705
- saveLogs({
706
- dsl,
707
- componentMap,
708
- dependencies: project.dependencies,
709
- message: e.message,
710
- stack: e.stack
711
- });
771
+ saveLogs(
772
+ {
773
+ dsl,
774
+ componentMap,
775
+ dependencies: project.dependencies,
776
+ message: e.message,
777
+ stack: e.stack
778
+ },
779
+ opts
780
+ );
712
781
  } catch (e2) {
713
782
  }
714
783
  throw e;
715
784
  });
716
- const vueRepository = new VueRepository(_platform);
785
+ const vueRepository = new VueRepository({
786
+ platform: _platform,
787
+ dir: opts.vtjRawDir
788
+ });
717
789
  vueRepository.save(file.id, content);
718
790
  return success(true);
719
791
  } else {
720
792
  return fail("\u6587\u4EF6\u4E0D\u5B58\u5728");
721
793
  }
722
794
  }
723
- async function publish(project) {
795
+ async function publish(project, opts) {
724
796
  const { pages = [], blocks = [] } = project;
725
- const materialsRepository = new JsonRepository("materials", project.platform);
797
+ const materialsRepository = new JsonRepository({
798
+ platform: project.platform || _platform,
799
+ dir: opts.vtjDir,
800
+ category: "materials"
801
+ });
726
802
  const materials = materialsRepository.get(project.id);
727
803
  const componentMap = new Map(
728
804
  Object.entries(materials)
729
805
  );
730
806
  for (const block of blocks) {
731
807
  if (!block.fromType || block.fromType === "Schema") {
732
- await publishFile(project, block, componentMap);
808
+ await publishFile(project, block, componentMap, opts);
733
809
  }
734
810
  }
735
811
  for (const page of pages) {
736
812
  if (!page.raw) {
737
- await publishFile(project, page, componentMap);
813
+ await publishFile(project, page, componentMap, opts);
738
814
  }
739
815
  }
740
816
  if (project.platform === "uniapp") {
@@ -751,8 +827,12 @@ async function genUniConfig(project, injectPages = false) {
751
827
  await uniRepository.saveApp(project);
752
828
  return success(true);
753
829
  }
754
- async function genVueContent(project, dsl) {
755
- const materialsRepository = new JsonRepository("materials", project.platform);
830
+ async function genVueContent(project, dsl, opts) {
831
+ const materialsRepository = new JsonRepository({
832
+ platform: project.platform || _platform,
833
+ dir: opts.vtjDir,
834
+ category: "materials"
835
+ });
756
836
  const materials = materialsRepository.get(project.id);
757
837
  const componentMap = new Map(
758
838
  Object.entries(materials || {})
@@ -775,14 +855,20 @@ async function parseVue(options) {
775
855
  });
776
856
  return success(errors ? errors : dsl);
777
857
  }
778
- async function createRawPage(file) {
779
- const repository = new VueRepository(_platform);
858
+ async function createRawPage(file, opts) {
859
+ const repository = new VueRepository({
860
+ platform: _platform,
861
+ dir: opts.vtjRawDir
862
+ });
780
863
  const page = await createEmptyPage(file);
781
864
  repository.save(file.id, page);
782
865
  return success(true);
783
866
  }
784
- async function removeRawPage(id) {
785
- const repository = new VueRepository(_platform);
867
+ async function removeRawPage(id, opts) {
868
+ const repository = new VueRepository({
869
+ platform: _platform,
870
+ dir: opts.vtjRawDir
871
+ });
786
872
  repository.remove(id);
787
873
  return success(true);
788
874
  }
@@ -815,65 +901,65 @@ const controller = {
815
901
  },
816
902
  getExtension: getExtension,
817
903
  init: init,
818
- saveProject: async (req) => {
904
+ saveProject: async (req, opts) => {
819
905
  const project = req.data;
820
- return saveProject(project, req.query?.type);
906
+ return saveProject(project, req.query?.type, opts);
821
907
  },
822
- saveFile: async (req) => {
908
+ saveFile: async (req, opts) => {
823
909
  const file = req.data;
824
- return saveFile(file);
910
+ return saveFile(file, opts);
825
911
  },
826
- getFile: async (req) => {
912
+ getFile: async (req, opts) => {
827
913
  const id = req.data;
828
- return getFile(id);
914
+ return getFile(id, opts);
829
915
  },
830
- removeFile: async (req) => {
916
+ removeFile: async (req, opts) => {
831
917
  const id = req.data;
832
- return removeFile(id);
918
+ return removeFile(id, opts);
833
919
  },
834
- getHistory: async (req) => {
920
+ getHistory: async (req, opts) => {
835
921
  const id = req.data;
836
- return getHistory(id);
922
+ return getHistory(id, opts);
837
923
  },
838
- saveHistory: async (req) => {
924
+ saveHistory: async (req, opts) => {
839
925
  const file = req.data;
840
- return saveHistory(file);
926
+ return saveHistory(file, opts);
841
927
  },
842
- removeHistory: async (req) => {
928
+ removeHistory: async (req, opts) => {
843
929
  const id = req.data;
844
- return removeHistory(id);
930
+ return removeHistory(id, opts);
845
931
  },
846
- getHistoryItem: async (req) => {
932
+ getHistoryItem: async (req, opts) => {
847
933
  const { fId, id } = req.data || {};
848
- return getHistoryItem(fId, id);
934
+ return getHistoryItem(fId, id, opts);
849
935
  },
850
- saveHistoryItem: async (req) => {
936
+ saveHistoryItem: async (req, opts) => {
851
937
  const { fId, item } = req.data || {};
852
- return saveHistoryItem(fId, item);
938
+ return saveHistoryItem(fId, item, opts);
853
939
  },
854
- removeHistoryItem: async (req) => {
940
+ removeHistoryItem: async (req, opts) => {
855
941
  const { fId, ids = [] } = req.data || {};
856
- return removeHistoryItem(fId, ids);
942
+ return removeHistoryItem(fId, ids, opts);
857
943
  },
858
- saveMaterials: async (req) => {
944
+ saveMaterials: async (req, opts) => {
859
945
  const { project, materials } = req.data || {};
860
- return saveMaterials(project, materials);
946
+ return saveMaterials(project, materials, opts);
861
947
  },
862
- publishFile: async (req) => {
948
+ publishFile: async (req, opts) => {
863
949
  const { project, file } = req.data || {};
864
- const result = await publishFile(project, file);
950
+ const result = await publishFile(project, file, void 0, opts);
865
951
  if (project.platform === "uniapp") {
866
952
  await genUniConfig(project, true);
867
953
  }
868
954
  return result;
869
955
  },
870
- publish: async (req) => {
956
+ publish: async (req, opts) => {
871
957
  const project = req.data || {};
872
- return publish(project);
958
+ return publish(project, opts);
873
959
  },
874
- genVueContent: async (req) => {
960
+ genVueContent: async (req, opts) => {
875
961
  const { project, dsl } = req.data || {};
876
- return genVueContent(project, dsl);
962
+ return genVueContent(project, dsl, opts);
877
963
  },
878
964
  parseVue: async (req) => {
879
965
  const { id, name, source, project } = req.data || {};
@@ -884,28 +970,40 @@ const controller = {
884
970
  project
885
971
  });
886
972
  },
887
- createRawPage: async (req) => {
973
+ createRawPage: async (req, opts) => {
888
974
  const file = req.data;
889
- return createRawPage(file);
975
+ return createRawPage(file, opts);
890
976
  },
891
- removeRawPage: async (req) => {
977
+ removeRawPage: async (req, opts) => {
892
978
  const id = req.data;
893
- return removeRawPage(id);
979
+ return removeRawPage(id, opts);
894
980
  },
895
981
  getStaticFiles: async (_req, opts) => {
896
- return getStaticFiles(opts);
982
+ return getStaticFiles({
983
+ staticBase: opts.staticBase,
984
+ staticDir: opts.staticDir,
985
+ vtjStaticDir: opts.vtjStaticDir
986
+ });
897
987
  },
898
988
  removeStaticFile: async (req, opts) => {
899
989
  const name = req.data?.name;
900
- return removeStaticFile(name, opts);
990
+ return removeStaticFile(name, {
991
+ staticBase: opts.staticBase,
992
+ staticDir: opts.staticDir,
993
+ vtjStaticDir: opts.vtjStaticDir
994
+ });
901
995
  },
902
996
  clearStaticFiles: async (_req, opts) => {
903
- return clearStaticFiles(opts);
997
+ return clearStaticFiles({
998
+ staticBase: opts.staticBase,
999
+ staticDir: opts.staticDir,
1000
+ vtjStaticDir: opts.vtjStaticDir
1001
+ });
904
1002
  },
905
1003
  uploader: async (req, opts) => {
906
1004
  if (!opts)
907
1005
  return fail("\u5F02\u5E38\u9519\u8BEF");
908
- const uploadDir = resolve(opts.staticDir, opts.vtjDir);
1006
+ const uploadDir = resolve(opts.staticDir, opts.vtjStaticDir);
909
1007
  const form = formidable({
910
1008
  keepExtensions: true,
911
1009
  multiples: true,
@@ -913,14 +1011,20 @@ const controller = {
913
1011
  uploadDir
914
1012
  });
915
1013
  return await new Promise((reslove) => {
916
- form.parse(req, (err, _fields, files) => {
1014
+ form.parse(req, async (err, _fields, files) => {
917
1015
  if (err) {
918
1016
  reslove(fail("\u5F02\u5E38\u9519\u8BEF", err));
919
1017
  return;
920
1018
  }
921
1019
  const tempFiles = files.files || [];
922
- const result = uploadStaticFiles(tempFiles, opts);
923
- reslove(result);
1020
+ const result = await uploadStaticFiles(tempFiles, {
1021
+ staticBase: opts.staticBase,
1022
+ staticDir: opts.staticDir,
1023
+ vtjStaticDir: opts.vtjStaticDir
1024
+ });
1025
+ setTimeout(() => {
1026
+ reslove(result);
1027
+ }, 200);
924
1028
  });
925
1029
  });
926
1030
  }
@@ -962,7 +1066,7 @@ const router = async (req, opts) => {
962
1066
  stack: e?.stack
963
1067
  }
964
1068
  };
965
- await saveLogs(info);
1069
+ await saveLogs(info, opts);
966
1070
  return fail("\u5F02\u5E38\u9519\u8BEF", e?.message, e?.stack);
967
1071
  }
968
1072
  }
@@ -1242,6 +1346,8 @@ function createDevTools(options = {}) {
1242
1346
  link: true,
1243
1347
  linkOptions: null,
1244
1348
  vtjDir: ".vtj",
1349
+ vtjStaticDir: ".vtj",
1350
+ vtjRawDir: ".vtj/vue",
1245
1351
  packagesDir: "../../packages",
1246
1352
  devMode: false,
1247
1353
  uploader: "/uploader.json",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vtj/local",
3
3
  "private": false,
4
- "version": "0.12.66",
4
+ "version": "0.12.68",
5
5
  "type": "module",
6
6
  "keywords": [
7
7
  "低代码引擎",
@@ -22,16 +22,16 @@
22
22
  "license": "MIT",
23
23
  "dependencies": {
24
24
  "formidable": "~3.5.1",
25
- "@vtj/coder": "~0.12.66",
26
- "@vtj/core": "~0.12.66",
27
- "@vtj/parser": "~0.12.66",
28
- "@vtj/node": "~0.12.4"
25
+ "@vtj/coder": "~0.12.68",
26
+ "@vtj/core": "~0.12.68",
27
+ "@vtj/node": "~0.12.4",
28
+ "@vtj/parser": "~0.12.68"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@types/formidable": "~3.4.5",
32
32
  "unbuild": "~2.0.0",
33
33
  "vite": "~6.3.0",
34
- "@vtj/cli": "~0.12.9"
34
+ "@vtj/cli": "~0.12.10"
35
35
  },
36
36
  "exports": {
37
37
  ".": {