@giteeteam/apps-cli 0.4.0 → 0.4.2

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.
Files changed (2) hide show
  1. package/dist/index.js +3 -746
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -12,10 +12,7 @@ var esbuild$1 = require('esbuild');
12
12
  var pluginNodeResolve = require('@rollup/plugin-node-resolve');
13
13
  var commonjs = require('@rollup/plugin-commonjs');
14
14
  var ora = require('ora');
15
- var yaml = require('yaml');
16
- var Ajv = require('ajv');
17
- var AjvKeywords = require('ajv-keywords');
18
- var lodash = require('lodash');
15
+ var appsManifest = require('@giteeteam/apps-manifest');
19
16
  var inquirer = require('inquirer');
20
17
  var simpleGit = require('simple-git');
21
18
  var chalk = require('chalk');
@@ -32,8 +29,6 @@ var archiver__default = /*#__PURE__*/_interopDefaultLegacy(archiver);
32
29
  var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
33
30
  var commonjs__default = /*#__PURE__*/_interopDefaultLegacy(commonjs);
34
31
  var ora__default = /*#__PURE__*/_interopDefaultLegacy(ora);
35
- var Ajv__default = /*#__PURE__*/_interopDefaultLegacy(Ajv);
36
- var AjvKeywords__default = /*#__PURE__*/_interopDefaultLegacy(AjvKeywords);
37
32
  var inquirer__default = /*#__PURE__*/_interopDefaultLegacy(inquirer);
38
33
  var simpleGit__default = /*#__PURE__*/_interopDefaultLegacy(simpleGit);
39
34
  var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);
@@ -41,7 +36,7 @@ var execa__default = /*#__PURE__*/_interopDefaultLegacy(execa);
41
36
  var child_process__default = /*#__PURE__*/_interopDefaultLegacy(child_process);
42
37
  var chokidar__default = /*#__PURE__*/_interopDefaultLegacy(chokidar);
43
38
 
44
- var version = "0.4.0";
39
+ var version = "0.4.2";
45
40
 
46
41
  const packageApp = async ({ outputDir, manifest, copyFiles }) => {
47
42
  const { resources } = manifest;
@@ -214,748 +209,10 @@ const execActionWithSpinner = async (message, action) => {
214
209
  spinner.succeed(message.succeed);
215
210
  };
216
211
 
217
- var $id$b = "http://proxima.com/schemas/all.json";
218
- var type$b = "object";
219
- var properties$7 = {
220
- app: {
221
- $ref: "app.json"
222
- },
223
- modules: {
224
- $ref: "modules/index.json"
225
- },
226
- resources: {
227
- $ref: "resources.json"
228
- },
229
- tables: {
230
- $ref: "tables.json"
231
- },
232
- locales: {
233
- $ref: "locales.json"
234
- }
235
- };
236
- var required$7 = [
237
- "app"
238
- ];
239
- var additionalProperties$4 = false;
240
- var allSchema = {
241
- $id: $id$b,
242
- type: type$b,
243
- properties: properties$7,
244
- required: required$7,
245
- additionalProperties: additionalProperties$4
246
- };
247
-
248
- var $id$a = "http://proxima.com/schemas/app.json";
249
- var type$a = "object";
250
- var required$6 = [
251
- "name",
252
- "key",
253
- "version"
254
- ];
255
- var properties$6 = {
256
- key: {
257
- type: "string",
258
- regexp: "/^[a-z][a-z0-9_]*$/gi"
259
- },
260
- name: {
261
- type: "string"
262
- },
263
- version: {
264
- type: "string"
265
- }
266
- };
267
- var appSchema = {
268
- $id: $id$a,
269
- type: type$a,
270
- required: required$6,
271
- properties: properties$6
272
- };
273
-
274
- var $id$9 = "http://proxima.com/schemas/modules/index.json";
275
- var type$9 = "object";
276
- var patternProperties$1 = {
277
- "^(adminPage|itemPanel|itemActivity|appPage|viewAction)$": {
278
- type: "array",
279
- uniqueItems: true,
280
- uniqueItemProperties: [
281
- "key"
282
- ],
283
- minItems: 1,
284
- additionalItems: true,
285
- items: [
286
- {
287
- $ref: "frontend/base.json"
288
- }
289
- ]
290
- },
291
- "^(webtrigger)$": {
292
- type: "array",
293
- uniqueItems: true,
294
- uniqueItemProperties: [
295
- "key"
296
- ],
297
- minItems: 1,
298
- additionalItems: true,
299
- items: [
300
- {
301
- $ref: "trigger/webtrigger.json"
302
- }
303
- ]
304
- },
305
- "^(trigger)$": {
306
- type: "array",
307
- uniqueItems: true,
308
- uniqueItemProperties: [
309
- "key"
310
- ],
311
- minItems: 1,
312
- additionalItems: true,
313
- items: [
314
- {
315
- $ref: "trigger/base.json"
316
- }
317
- ]
318
- },
319
- "^(function)$": {
320
- type: "array",
321
- uniqueItems: true,
322
- uniqueItemProperties: [
323
- "key"
324
- ],
325
- minItems: 1,
326
- additionalItems: true,
327
- items: [
328
- {
329
- $ref: "function/base.json"
330
- }
331
- ]
332
- },
333
- "^(customFieldType)$": {
334
- type: "array",
335
- uniqueItems: true,
336
- uniqueItemProperties: [
337
- "key"
338
- ],
339
- minItems: 1,
340
- additionalItems: true,
341
- items: [
342
- {
343
- $ref: "custom-field/type.json"
344
- }
345
- ]
346
- },
347
- "^(customField)$": {
348
- type: "array",
349
- uniqueItems: true,
350
- uniqueItemProperties: [
351
- "key"
352
- ],
353
- minItems: 1,
354
- additionalItems: true,
355
- items: [
356
- {
357
- $ref: "custom-field/field.json"
358
- }
359
- ]
360
- }
361
- };
362
- var additionalProperties$3 = true;
363
- var minProperties$1 = 1;
364
- var modulesSchema = {
365
- $id: $id$9,
366
- type: type$9,
367
- patternProperties: patternProperties$1,
368
- additionalProperties: additionalProperties$3,
369
- minProperties: minProperties$1
370
- };
371
-
372
- var type$8 = "object";
373
- var $id$8 = "http://proxima.com/schemas/modules/frontend/base.json";
374
- var additionalProperties$2 = true;
375
- var properties$5 = {
376
- key: {
377
- type: "string"
378
- },
379
- resource: {
380
- type: "string"
381
- },
382
- title: {
383
- type: "string"
384
- },
385
- loadType: {
386
- type: "string"
387
- },
388
- route: {
389
- type: "string"
390
- }
391
- };
392
- var required$5 = [
393
- "key",
394
- "resource",
395
- "title"
396
- ];
397
- var frontendBaseSchema = {
398
- type: type$8,
399
- $id: $id$8,
400
- additionalProperties: additionalProperties$2,
401
- properties: properties$5,
402
- required: required$5
403
- };
404
-
405
- var type$7 = "object";
406
- var $id$7 = "http://proxima.com/schemas/modules/trigger/base.json";
407
- var properties$4 = {
408
- key: {
409
- type: "string"
410
- },
411
- events: {
412
- type: "array",
413
- uniqueItems: true,
414
- minItems: 1,
415
- additionalItems: true,
416
- items: [
417
- {
418
- type: "string"
419
- }
420
- ]
421
- },
422
- "function": {
423
- type: "string"
424
- }
425
- };
426
- var required$4 = [
427
- "key",
428
- "events",
429
- "function"
430
- ];
431
- var triggerSchema = {
432
- type: type$7,
433
- $id: $id$7,
434
- properties: properties$4,
435
- required: required$4
436
- };
437
-
438
- var type$6 = "object";
439
- var $id$6 = "http://proxima.com/schemas/modules/trigger/webtrigger.json";
440
- var properties$3 = {
441
- key: {
442
- type: "string"
443
- },
444
- "function": {
445
- type: "string"
446
- }
447
- };
448
- var required$3 = [
449
- "key",
450
- "function"
451
- ];
452
- var webtriggerSchema = {
453
- type: type$6,
454
- $id: $id$6,
455
- properties: properties$3,
456
- required: required$3
457
- };
458
-
459
- var type$5 = "object";
460
- var $id$5 = "http://proxima.com/schemas/modules/function/base.json";
461
- var properties$2 = {
462
- key: {
463
- type: "string"
464
- },
465
- handler: {
466
- type: "string"
467
- }
468
- };
469
- var required$2 = [
470
- "key",
471
- "handler"
472
- ];
473
- var functionSchema = {
474
- type: type$5,
475
- $id: $id$5,
476
- properties: properties$2,
477
- required: required$2
478
- };
479
-
480
- var type$4 = "object";
481
- var $id$4 = "http://proxima.com/schemas/modules/custom-field/field.json";
482
- var additionalProperties$1 = true;
483
- var properties$1 = {
484
- key: {
485
- type: "string"
486
- },
487
- name: {
488
- type: "string"
489
- },
490
- type: {
491
- type: "string"
492
- }
493
- };
494
- var required$1 = [
495
- "key",
496
- "name",
497
- "type"
498
- ];
499
- var customFieldSchema = {
500
- type: type$4,
501
- $id: $id$4,
502
- additionalProperties: additionalProperties$1,
503
- properties: properties$1,
504
- required: required$1
505
- };
506
-
507
- var type$3 = "object";
508
- var $id$3 = "http://proxima.com/schemas/modules/custom-field/type.json";
509
- var properties = {
510
- key: {
511
- type: "string"
512
- },
513
- name: {
514
- type: "string"
515
- },
516
- resource: {
517
- type: "string"
518
- }
519
- };
520
- var required = [
521
- "key",
522
- "name"
523
- ];
524
- var customFieldTypeSchema = {
525
- type: type$3,
526
- $id: $id$3,
527
- properties: properties,
528
- required: required
529
- };
530
-
531
- var $id$2 = "http://proxima.com/schemas/resources.json";
532
- var type$2 = "array";
533
- var minItems$1 = 1;
534
- var uniqueItems$1 = true;
535
- var uniqueItemProperties$1 = [
536
- "key"
537
- ];
538
- var items$1 = {
539
- type: "object",
540
- properties: {
541
- key: {
542
- type: "string"
543
- },
544
- path: {
545
- type: "string"
546
- }
547
- },
548
- required: [
549
- "key",
550
- "path"
551
- ]
552
- };
553
- var resourcesSchema = {
554
- $id: $id$2,
555
- type: type$2,
556
- minItems: minItems$1,
557
- uniqueItems: uniqueItems$1,
558
- uniqueItemProperties: uniqueItemProperties$1,
559
- items: items$1
560
- };
561
-
562
- var $id$1 = "http://proxima.com/schemas/tables.json";
563
- var type$1 = "array";
564
- var minItems = 1;
565
- var uniqueItems = true;
566
- var uniqueItemProperties = [
567
- "className"
568
- ];
569
- var items = {
570
- type: "object",
571
- properties: {
572
- className: {
573
- type: "string",
574
- regexp: {
575
- pattern: "(^_([a-zA-Z0-9]_?)*$)|(^[a-zA-Z](_?[a-zA-Z0-9])*_?$)",
576
- flags: "i"
577
- }
578
- },
579
- fields: {
580
- type: "object",
581
- patternProperties: {
582
- "(^_([a-zA-Z0-9]_?)*$)|(^[a-zA-Z](_?[a-zA-Z0-9])*_?$)": {
583
- type: "object",
584
- anyOf: [
585
- {
586
- type: "object",
587
- properties: {
588
- type: {
589
- type: "string",
590
- "enum": [
591
- "Pointer",
592
- "Relation"
593
- ]
594
- },
595
- targetClass: {
596
- type: "string",
597
- regexp: {
598
- pattern: "(^_([a-zA-Z0-9]_?)*$)|(^[a-zA-Z](_?[a-zA-Z0-9])*_?$)",
599
- flags: "i"
600
- }
601
- },
602
- isAppClass: {
603
- type: "boolean",
604
- "default": false
605
- }
606
- },
607
- required: [
608
- "type",
609
- "targetClass"
610
- ]
611
- },
612
- {
613
- type: "object",
614
- properties: {
615
- type: {
616
- type: "string",
617
- "const": "String"
618
- },
619
- defaultValue: {
620
- type: "string"
621
- }
622
- },
623
- required: [
624
- "type"
625
- ]
626
- },
627
- {
628
- type: "object",
629
- properties: {
630
- type: {
631
- type: "string",
632
- "const": "Boolean"
633
- },
634
- defaultValue: {
635
- type: "boolean"
636
- }
637
- },
638
- required: [
639
- "type"
640
- ]
641
- },
642
- {
643
- type: "object",
644
- properties: {
645
- type: {
646
- type: "string",
647
- "const": "Number"
648
- },
649
- defaultValue: {
650
- type: "number"
651
- }
652
- },
653
- required: [
654
- "type"
655
- ]
656
- },
657
- {
658
- type: "object",
659
- properties: {
660
- type: {
661
- type: "string",
662
- "const": "Object"
663
- },
664
- defaultValue: {
665
- type: "object"
666
- }
667
- },
668
- required: [
669
- "type"
670
- ]
671
- },
672
- {
673
- type: "object",
674
- properties: {
675
- type: {
676
- type: "string",
677
- "const": "Array"
678
- },
679
- defaultValue: {
680
- type: "array"
681
- }
682
- },
683
- required: [
684
- "type"
685
- ]
686
- },
687
- {
688
- type: "object",
689
- properties: {
690
- type: {
691
- type: "string",
692
- "enum": [
693
- "Date",
694
- "File"
695
- ]
696
- }
697
- },
698
- required: [
699
- "type"
700
- ]
701
- }
702
- ]
703
- }
704
- },
705
- additionalProperties: false
706
- }
707
- },
708
- required: [
709
- "className",
710
- "fields"
711
- ]
712
- };
713
- var tablesSchema = {
714
- $id: $id$1,
715
- type: type$1,
716
- minItems: minItems,
717
- uniqueItems: uniqueItems,
718
- uniqueItemProperties: uniqueItemProperties,
719
- items: items
720
- };
721
-
722
- var $id = "http://proxima.com/schemas/locales.json";
723
- var type = "object";
724
- var patternProperties = {
725
- "^(en-US|zh-CN)$": {
726
- type: "object",
727
- additionalProperties: true
728
- }
729
- };
730
- var additionalProperties = true;
731
- var minProperties = 1;
732
- var localesSchema = {
733
- $id: $id,
734
- type: type,
735
- patternProperties: patternProperties,
736
- additionalProperties: additionalProperties,
737
- minProperties: minProperties
738
- };
739
-
740
- const validateResource = (json) => {
741
- const errors = [];
742
- const frontendModules = ['adminPage', 'itemPanel', 'itemActivity', 'appPage'];
743
- const modules = lodash.get(json, 'modules') || {};
744
- const resourcesEntries = lodash.keyBy(lodash.get(json, 'resources'), 'key');
745
- const functionEntries = lodash.keyBy(lodash.get(json, 'modules.function'), 'key');
746
- const customFieldTypeEntries = lodash.keyBy(lodash.get(json, 'modules.customFieldType'), 'key');
747
- const moduleKeys = {};
748
- Object.keys(modules).forEach(moduleKey => {
749
- const module = lodash.get(modules, moduleKey);
750
- if (!module)
751
- return;
752
- const isFrontendModule = frontendModules.indexOf(moduleKey) > -1;
753
- Array.from(module).forEach(({ resource, function: functionRef, type, key }, index) => {
754
- const path = `/modules/${moduleKey}/${index}`;
755
- if (moduleKeys[key]) {
756
- errors.push({
757
- path,
758
- message: `Key '${key}' has already exits! `,
759
- });
760
- }
761
- else {
762
- moduleKeys[key] = true;
763
- }
764
- if (isFrontendModule) {
765
- if (resource && !lodash.get(resourcesEntries, resource)) {
766
- errors.push({
767
- path,
768
- message: `Resource '${resource}' not found! `,
769
- });
770
- }
771
- }
772
- else if (moduleKey === 'trigger' || moduleKey === 'webtrigger') {
773
- if (functionRef && !lodash.get(functionEntries, functionRef)) {
774
- errors.push({
775
- path,
776
- message: `Function '${functionRef}' not found! `,
777
- });
778
- }
779
- }
780
- else if (moduleKey === 'customField' && lodash.startsWith(type, '_self:')) {
781
- const fieldTypeRef = type === null || type === void 0 ? void 0 : type.slice(6);
782
- if (fieldTypeRef && !lodash.get(customFieldTypeEntries, fieldTypeRef)) {
783
- errors.push({
784
- path,
785
- message: `FieldType '${fieldTypeRef}' not found! `,
786
- });
787
- }
788
- }
789
- });
790
- });
791
- return {
792
- pass: errors.length === 0,
793
- errors,
794
- };
795
- };
796
- const validateFactory = (schema) => {
797
- const ajv = new Ajv__default["default"]({
798
- // https://github.com/ajv-validator/ajv/issues/1417
799
- strictTuples: false,
800
- allowMatchingProperties: false,
801
- schemas: [
802
- allSchema,
803
- appSchema,
804
- modulesSchema,
805
- frontendBaseSchema,
806
- triggerSchema,
807
- webtriggerSchema,
808
- functionSchema,
809
- customFieldSchema,
810
- customFieldTypeSchema,
811
- resourcesSchema,
812
- tablesSchema,
813
- localesSchema,
814
- ],
815
- });
816
- AjvKeywords__default["default"](ajv);
817
- return (json) => {
818
- const validate = ajv.getSchema(schema);
819
- const pass = validate === null || validate === void 0 ? void 0 : validate(json);
820
- const errors = validate === null || validate === void 0 ? void 0 : validate.errors;
821
- return {
822
- pass,
823
- errors: errors
824
- ? lodash.map(errors, error => ({
825
- path: error.instancePath,
826
- message: error.message,
827
- }))
828
- : null,
829
- };
830
- };
831
- };
832
- const validateAll = (json) => {
833
- const { pass: schemaPass, errors } = validateFactory('http://proxima.com/schemas/all.json')(json);
834
- if (!schemaPass) {
835
- return { pass: schemaPass, errors };
836
- }
837
- // 校验一下需要的引用是否存在
838
- return validateResource(json);
839
- };
840
- validateFactory('http://proxima.com/schemas/app.json');
841
- validateFactory('http://proxima.com/schemas/modules/index.json');
842
- validateFactory('http://proxima.com/schemas/resources.json');
843
- validateFactory('http://proxima.com/schemas/tables.json');
844
- validateFactory('http://proxima.com/schemas/locales.json');
845
-
846
- class Manifest {
847
- constructor(manifestString) {
848
- this.manifest = yaml.parse(manifestString);
849
- this.manifestString = manifestString;
850
- }
851
- get resources() {
852
- return this.manifest.resources;
853
- }
854
- get app() {
855
- return this.manifest.app;
856
- }
857
- get tables() {
858
- return this.manifest.tables;
859
- }
860
- getManifest() {
861
- return this.manifest;
862
- }
863
- getManifestString() {
864
- return this.manifestString;
865
- }
866
- /**
867
- * 获取所有自定义事项类型
868
- */
869
- getCustomItemType() {
870
- const { modules } = this.manifest;
871
- return modules.customItemType || [];
872
- }
873
- /**
874
- * 获取所有自定义字段类型
875
- */
876
- getCustomFieldType() {
877
- const { modules } = this.manifest;
878
- return modules.customFieldType || [];
879
- }
880
- /**
881
- * 获取所有自定义字段
882
- */
883
- getCustomField() {
884
- const { modules } = this.manifest;
885
- return modules.customField || [];
886
- }
887
- /**
888
- * 根据key获取执行的function
889
- * @param key
890
- * @returns
891
- */
892
- getFunctionByKey(key) {
893
- const functionKey = this.getFunctionKeyByKey(key);
894
- if (functionKey) {
895
- return this.getFunctionByFunctionKey(functionKey);
896
- }
897
- }
898
- /**
899
- * 根据functionKey获取执行的function
900
- * @param functionKey
901
- * @returns
902
- */
903
- getFunctionByFunctionKey(functionKey) {
904
- var _a, _b;
905
- return (_b = (_a = this.manifest.modules) === null || _a === void 0 ? void 0 : _a.function) === null || _b === void 0 ? void 0 : _b.find(f => f.key === functionKey);
906
- }
907
- /**
908
- * 根据key获取执行的functionKey
909
- * @param key
910
- * @returns
911
- */
912
- getFunctionKeyByKey(key) {
913
- var _a, _b, _c;
914
- const { modules } = this.manifest;
915
- for (const k in modules) {
916
- if (k === 'function') {
917
- continue;
918
- }
919
- else if (k === 'importer') {
920
- // importer扩展点需要判断function和validate
921
- if (key === ((_a = modules[k]) === null || _a === void 0 ? void 0 : _a.function) || key === ((_b = modules[k]) === null || _b === void 0 ? void 0 : _b.validate)) {
922
- return key;
923
- }
924
- }
925
- else if (Array.isArray(modules[k])) {
926
- const targetModule = (_c = modules[k]) === null || _c === void 0 ? void 0 : _c.find(v => v.key === key);
927
- if (targetModule) {
928
- return targetModule.function;
929
- }
930
- }
931
- }
932
- }
933
- /**
934
- * 获取function下的文件列表
935
- * @returns
936
- */
937
- getFunctionFiles() {
938
- var _a, _b;
939
- const fileNames = new Set();
940
- (_b = (_a = this.manifest.modules) === null || _a === void 0 ? void 0 : _a.function) === null || _b === void 0 ? void 0 : _b.forEach(({ handler }) => {
941
- const filename = handler.split('.')[0];
942
- fileNames.add(filename);
943
- });
944
- return [...fileNames];
945
- }
946
- /**
947
- * 校验manifest
948
- * @returns
949
- */
950
- validate() {
951
- return validateAll(this.getManifest());
952
- }
953
- }
954
-
955
212
  const getManifest = async () => {
956
213
  const manifestFile = path__default["default"].resolve('manifest.yml');
957
214
  const strBuffer = await fse__default["default"].readFile(manifestFile);
958
- return new Manifest(strBuffer.toString());
215
+ return new appsManifest.Manifest(strBuffer.toString());
959
216
  };
960
217
 
961
218
  var run$2 = async ({ outputDir, inputDir, prod, copyFiles, zip }) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@giteeteam/apps-cli",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "description": "Giteeteam Apps cli",
5
5
  "keywords": [
6
6
  "typescript",
@@ -38,9 +38,9 @@
38
38
  "registry": "https://registry.npmjs.org/"
39
39
  },
40
40
  "dependencies": {
41
- "@giteeteam/apps-manifest": "^0.2.1",
41
+ "@giteeteam/apps-manifest": "^0.3.0",
42
42
  "@rollup/plugin-commonjs": "^22.0.0",
43
- "@rollup/plugin-node-resolve": "^15.0.1",
43
+ "@rollup/plugin-node-resolve": "13.3.0",
44
44
  "archiver": "^5.3.1",
45
45
  "chalk": "^4.1.2",
46
46
  "chokidar": "^3.5.3",