definition-generator-framework 1.12.5 → 1.12.6

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 (49) hide show
  1. package/dist/framework/definition-component.d.ts +11 -9
  2. package/dist/framework/definition-component.js +18 -18
  3. package/dist/framework/definition-generator.d.ts +6 -5
  4. package/dist/framework/definition-generator.js +16 -18
  5. package/dist/framework/file-content-generator/file-content-generator.js +1 -1
  6. package/dist/framework/file-content-generator/file-content-generator.test.js +49 -49
  7. package/dist/framework/framework.d.ts +14 -13
  8. package/dist/framework/framework.data.d.ts +3 -3
  9. package/dist/framework/framework.data.js +13 -7
  10. package/dist/framework/framework.js +36 -33
  11. package/dist/framework/framework.model.d.ts +15 -15
  12. package/dist/framework/framework.model.js +3 -3
  13. package/dist/helpers/common-functions/common-functions.js +1 -1
  14. package/dist/helpers/common-functions/common-functions.spec.js +48 -48
  15. package/dist/helpers/duplicate-helper/duplicate-helper.spec.js +52 -52
  16. package/dist/helpers/output-helper/output-helper.d.ts +26 -26
  17. package/dist/helpers/output-helper/output-helper.js +127 -107
  18. package/dist/helpers/output-helper/output-helper.spec.d.ts +22 -22
  19. package/dist/helpers/output-helper/output-helper.spec.js +223 -211
  20. package/dist/helpers/output-helper/output-helper.test.d.ts +22 -22
  21. package/dist/helpers/output-helper/output-helper.test.js +224 -212
  22. package/dist/helpers/raw-definition-helper/raw-definition.helper.spec.js +133 -125
  23. package/dist/helpers/validator/custom-validator-helper/custom-validator.helper.spec.d.ts +1 -1
  24. package/dist/helpers/validator/custom-validator-helper/custom-validator.helper.spec.js +174 -156
  25. package/dist/helpers/validator/custom-validators/image.custom-validator.d.ts +6 -6
  26. package/dist/helpers/validator/custom-validators/image.custom-validator.js +40 -39
  27. package/dist/helpers/validator/custom-validators/unique-name-group.custom-validator.d.ts +4 -4
  28. package/dist/helpers/validator/custom-validators/unique-name-group.custom-validator.js +29 -29
  29. package/dist/helpers/validator/joi-custom-validators.spec.js +284 -240
  30. package/dist/helpers/validator/validator.spec.js +313 -303
  31. package/dist/pipeline/1-select-definitions-helper.d.ts +13 -13
  32. package/dist/pipeline/1-select-definitions-helper.js +68 -72
  33. package/dist/pipeline/1-select-definitions.helper.test.js +40 -40
  34. package/dist/pipeline/1-select-definitions.spec.js +131 -131
  35. package/dist/pipeline/2-structure-parser.helper.spec.js +266 -266
  36. package/dist/pipeline/parsers/array-parser.spec.js +116 -113
  37. package/dist/pipeline/parsers/object-parser.spec.js +159 -153
  38. package/dist/pipeline/parsers/primitive-parser.spec.js +67 -67
  39. package/dist/pre-made-components/assets/3-font.js +4 -4
  40. package/dist/pre-made-components/events/1-event.d.ts +1 -1
  41. package/dist/pre-made-components/events/1-event.js +157 -125
  42. package/dist/pre-made-components/events/2-event-test.d.ts +8 -8
  43. package/dist/pre-made-components/events/2-event-test.js +156 -119
  44. package/dist/pre-made-components/events/2-script-test.js +0 -1
  45. package/dist/pre-made-components/events/event-setup.d.ts +10 -5
  46. package/dist/pre-made-components/events/event-setup.js +15 -15
  47. package/dist/pre-made-components/events/script-setup.d.ts +5 -3
  48. package/dist/pre-made-components/events/script-setup.js +11 -11
  49. package/package.json +5 -10
@@ -1,54 +1,54 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const duplicate_helper_1 = require("./duplicate-helper");
4
- const mocks_1 = require("../../_mocks/mocks");
5
- const context_1 = require("../../framework/context");
1
+ 'use strict';
2
+ Object.defineProperty(exports, '__esModule', { value: true });
3
+ const duplicate_helper_1 = require('./duplicate-helper');
4
+ const mocks_1 = require('../../_mocks/mocks');
5
+ const context_1 = require('../../framework/context');
6
6
  describe('Duplicate Helper', () => {
7
- test('should handle single entry', () => {
8
- (0, mocks_1.resetContext)();
9
- let helper = new duplicate_helper_1.DuplicateHelper('ASSET: Name');
10
- expect(helper.newEntry('identifier', mocks_1.SampleLocation1)).toBeTruthy();
11
- helper.logDuplicateErrors();
12
- expect(context_1.Context.errorLogs).toStrictEqual([]);
13
- });
14
- test('should detect duplicate', () => {
15
- (0, mocks_1.resetContext)();
16
- let helper = new duplicate_helper_1.DuplicateHelper('ASSET: Name');
17
- expect(helper.newEntry('identifier', mocks_1.SampleLocation1)).toBeTruthy();
18
- expect(helper.newEntry('identifier', mocks_1.SampleLocation2)).toBeFalsy();
19
- helper.logDuplicateErrors();
20
- expect(context_1.Context.errorLogs).toStrictEqual([
21
- {
22
- description: 'Value should be singular! Group: "ASSET: Name", Value: "identifier"',
23
- location: mocks_1.SampleLocation1
24
- },
25
- {
26
- description: 'Value should be singular! Group: "ASSET: Name", Value: "identifier"',
27
- location: mocks_1.SampleLocation2
28
- }
29
- ]);
30
- });
31
- test('should detect multiple duplicate', () => {
32
- (0, mocks_1.resetContext)();
33
- let helper = new duplicate_helper_1.DuplicateHelper('ASSET: Name');
34
- expect(helper.newEntry('identifier', mocks_1.SampleLocation1)).toBeTruthy();
35
- expect(helper.newEntry('identifier', mocks_1.SampleLocation2)).toBeFalsy();
36
- expect(helper.newEntry('identifier', mocks_1.SampleLocation3)).toBeFalsy();
37
- helper.logDuplicateErrors();
38
- expect(context_1.Context.errorLogs).toStrictEqual([
39
- {
40
- description: 'Value should be singular! Group: "ASSET: Name", Value: "identifier"',
41
- location: mocks_1.SampleLocation1
42
- },
43
- {
44
- description: 'Value should be singular! Group: "ASSET: Name", Value: "identifier"',
45
- location: mocks_1.SampleLocation2
46
- },
47
- {
48
- description: 'Value should be singular! Group: "ASSET: Name", Value: "identifier"',
49
- location: mocks_1.SampleLocation3
50
- }
51
- ]);
52
- });
7
+ test('should handle single entry', () => {
8
+ (0, mocks_1.resetContext)();
9
+ let helper = new duplicate_helper_1.DuplicateHelper('ASSET: Name');
10
+ expect(helper.newEntry('identifier', mocks_1.SampleLocation1)).toBeTruthy();
11
+ helper.logDuplicateErrors();
12
+ expect(context_1.Context.errorLogs).toStrictEqual([]);
13
+ });
14
+ test('should detect duplicate', () => {
15
+ (0, mocks_1.resetContext)();
16
+ let helper = new duplicate_helper_1.DuplicateHelper('ASSET: Name');
17
+ expect(helper.newEntry('identifier', mocks_1.SampleLocation1)).toBeTruthy();
18
+ expect(helper.newEntry('identifier', mocks_1.SampleLocation2)).toBeFalsy();
19
+ helper.logDuplicateErrors();
20
+ expect(context_1.Context.errorLogs).toStrictEqual([
21
+ {
22
+ description: 'Value should be singular! Group: "ASSET: Name", Value: "identifier"',
23
+ location: mocks_1.SampleLocation1
24
+ },
25
+ {
26
+ description: 'Value should be singular! Group: "ASSET: Name", Value: "identifier"',
27
+ location: mocks_1.SampleLocation2
28
+ }
29
+ ]);
30
+ });
31
+ test('should detect multiple duplicate', () => {
32
+ (0, mocks_1.resetContext)();
33
+ let helper = new duplicate_helper_1.DuplicateHelper('ASSET: Name');
34
+ expect(helper.newEntry('identifier', mocks_1.SampleLocation1)).toBeTruthy();
35
+ expect(helper.newEntry('identifier', mocks_1.SampleLocation2)).toBeFalsy();
36
+ expect(helper.newEntry('identifier', mocks_1.SampleLocation3)).toBeFalsy();
37
+ helper.logDuplicateErrors();
38
+ expect(context_1.Context.errorLogs).toStrictEqual([
39
+ {
40
+ description: 'Value should be singular! Group: "ASSET: Name", Value: "identifier"',
41
+ location: mocks_1.SampleLocation1
42
+ },
43
+ {
44
+ description: 'Value should be singular! Group: "ASSET: Name", Value: "identifier"',
45
+ location: mocks_1.SampleLocation2
46
+ },
47
+ {
48
+ description: 'Value should be singular! Group: "ASSET: Name", Value: "identifier"',
49
+ location: mocks_1.SampleLocation3
50
+ }
51
+ ]);
52
+ });
53
53
  });
54
- //# sourceMappingURL=duplicate-helper.spec.js.map
54
+ //# sourceMappingURL=duplicate-helper.spec.js.map
@@ -1,30 +1,30 @@
1
1
  declare class OutputHelperClass {
2
- generateArrayOutput(options: {
3
- preText?: string;
4
- variableName: string;
5
- variableType: string;
6
- variable: any[];
7
- filePath?: string;
8
- assetUrl?: string;
9
- replaceMap?: {
10
- target: string;
11
- replace: string;
12
- }[];
13
- }): Promise<string>;
14
- generateOutput(options: {
15
- preText?: string;
16
- variableName: string;
17
- variableType?: string;
18
- variable: any;
19
- replaceMap?: {
20
- target: string;
21
- replace: string;
22
- }[];
23
- }): Promise<string>;
24
- private convertToRelativePath;
25
- private replaceOutput;
26
- private format;
27
- private stringify;
2
+ generateArrayOutput(options: {
3
+ preText?: string;
4
+ variableName: string;
5
+ variableType: string;
6
+ variable: any[];
7
+ filePath?: string;
8
+ assetUrl?: string;
9
+ replaceMap?: {
10
+ target: string;
11
+ replace: string;
12
+ }[];
13
+ }): Promise<string>;
14
+ generateOutput(options: {
15
+ preText?: string;
16
+ variableName: string;
17
+ variableType?: string;
18
+ variable: any;
19
+ replaceMap?: {
20
+ target: string;
21
+ replace: string;
22
+ }[];
23
+ }): Promise<string>;
24
+ private convertToRelativePath;
25
+ private replaceOutput;
26
+ private format;
27
+ private stringify;
28
28
  }
29
29
  export declare const OutputHelper: OutputHelperClass;
30
30
  export {};
@@ -1,123 +1,143 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
1
+ 'use strict';
2
+ var __createBinding =
3
+ (this && this.__createBinding) ||
4
+ (Object.create
5
+ ? function (o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ('get' in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = {
10
+ enumerable: true,
11
+ get: function () {
12
+ return m[k];
13
+ }
14
+ };
15
+ }
16
+ Object.defineProperty(o, k2, desc);
17
+ }
18
+ : function (o, m, k, k2) {
19
+ if (k2 === undefined) k2 = k;
20
+ o[k2] = m[k];
21
+ });
22
+ var __setModuleDefault =
23
+ (this && this.__setModuleDefault) ||
24
+ (Object.create
25
+ ? function (o, v) {
26
+ Object.defineProperty(o, 'default', { enumerable: true, value: v });
27
+ }
28
+ : function (o, v) {
29
+ o['default'] = v;
30
+ });
31
+ var __importStar =
32
+ (this && this.__importStar) ||
33
+ function (mod) {
19
34
  if (mod && mod.__esModule) return mod;
20
35
  var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
36
+ if (mod != null)
37
+ for (var k in mod) if (k !== 'default' && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
38
  __setModuleDefault(result, mod);
23
39
  return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
40
+ };
41
+ var __importDefault =
42
+ (this && this.__importDefault) ||
43
+ function (mod) {
44
+ return mod && mod.__esModule ? mod : { default: mod };
45
+ };
46
+ Object.defineProperty(exports, '__esModule', { value: true });
29
47
  exports.OutputHelper = void 0;
30
- const prettier = __importStar(require("prettier"));
31
- const path_1 = __importDefault(require("path"));
32
- const context_1 = require("../../framework/context");
33
- const helpers_lib_1 = require("helpers-lib");
48
+ const prettier = __importStar(require('prettier'));
49
+ const path_1 = __importDefault(require('path'));
50
+ const context_1 = require('../../framework/context');
51
+ const helpers_lib_1 = require('helpers-lib');
34
52
  class OutputHelperClass {
35
- async generateArrayOutput(options) {
36
- let output = '';
37
- if (options.preText) {
38
- output += `${options.preText}\n\n`;
39
- }
40
- let assetsReplaceMap;
41
- if (options.assetUrl) {
42
- if (!options.filePath) {
43
- throw new Error('filePath is required when using assetUrl');
44
- }
45
- let urls = options.variable.map(item => {
46
- let url = helpers_lib_1.JsonHelper.deepFind(item, options.assetUrl);
47
- if (!url) {
48
- throw new Error(`OutputHelperClass: Asset url is not found in the given variable! item: "${JSON.stringify(item)}", assetUrl: "${options.assetUrl}"`);
49
- }
50
- return url;
51
- });
52
- let assetUrlToNameMap = new Map();
53
- urls.forEach(url => {
54
- if (!assetUrlToNameMap.has(url)) {
55
- let name = `asset${assetUrlToNameMap.size}`;
56
- assetUrlToNameMap.set(url, name);
57
- }
58
- });
59
- let imports = Array.from(assetUrlToNameMap, ([key, value]) => ({ name: value, url: key }))
60
- .map(item => `import ${item.name} from '${this.convertToRelativePath(options.filePath, item.url)}';`)
61
- .join('\n');
62
- output += imports + '\n\n';
63
- assetsReplaceMap = urls.reduce((map, url) => [...map, { target: `"${url}"`, replace: assetUrlToNameMap.get(url) }], []);
64
- }
65
- if (options.variable.reduce) {
66
- let content = options.variable.reduce((acc, item, index) => `${acc}${index !== 0 ? ',' : ''}${this.stringify(item)}`, '');
67
- output += `export const ${options.variableName}: ${options.variableType} = [${content}];`;
68
- }
69
- else {
70
- console.error(`Given variable is not an array, do you mean to use "generateOutput()", for the variable "${options.variableName}"?`);
71
- }
72
- if (assetsReplaceMap) {
73
- output = this.replaceOutput(output, assetsReplaceMap);
74
- }
75
- if (options.replaceMap) {
76
- output = this.replaceOutput(output, options.replaceMap);
77
- }
78
- return this.format(output);
53
+ async generateArrayOutput(options) {
54
+ let output = '';
55
+ if (options.preText) {
56
+ output += `${options.preText}\n\n`;
79
57
  }
80
- async generateOutput(options) {
81
- let output = '';
82
- if (options.preText) {
83
- output += `${options.preText}\n\n`;
84
- }
85
- if (options.variableType) {
86
- output += `export const ${options.variableName}: ${options.variableType} = ${this.stringify(options.variable)}`;
58
+ let assetsReplaceMap;
59
+ if (options.assetUrl) {
60
+ if (!options.filePath) {
61
+ throw new Error('filePath is required when using assetUrl');
62
+ }
63
+ let urls = options.variable.map(item => {
64
+ let url = helpers_lib_1.JsonHelper.deepFind(item, options.assetUrl);
65
+ if (!url) {
66
+ throw new Error(
67
+ `OutputHelperClass: Asset url is not found in the given variable! item: "${JSON.stringify(item)}", assetUrl: "${options.assetUrl}"`
68
+ );
87
69
  }
88
- else {
89
- output += `export const ${options.variableName} = ${this.stringify(options.variable)}`;
70
+ return url;
71
+ });
72
+ let assetUrlToNameMap = new Map();
73
+ urls.forEach(url => {
74
+ if (!assetUrlToNameMap.has(url)) {
75
+ let name = `asset${assetUrlToNameMap.size}`;
76
+ assetUrlToNameMap.set(url, name);
90
77
  }
91
- if (options.replaceMap) {
92
- output = this.replaceOutput(output, options.replaceMap);
93
- }
94
- return this.format(output);
78
+ });
79
+ let imports = Array.from(assetUrlToNameMap, ([key, value]) => ({ name: value, url: key }))
80
+ .map(item => `import ${item.name} from '${this.convertToRelativePath(options.filePath, item.url)}';`)
81
+ .join('\n');
82
+ output += imports + '\n\n';
83
+ assetsReplaceMap = urls.reduce((map, url) => [...map, { target: `"${url}"`, replace: assetUrlToNameMap.get(url) }], []);
84
+ }
85
+ if (options.variable.reduce) {
86
+ let content = options.variable.reduce((acc, item, index) => `${acc}${index !== 0 ? ',' : ''}${this.stringify(item)}`, '');
87
+ output += `export const ${options.variableName}: ${options.variableType} = [${content}];`;
88
+ } else {
89
+ console.error(
90
+ `Given variable is not an array, do you mean to use "generateOutput()", for the variable "${options.variableName}"?`
91
+ );
92
+ }
93
+ if (assetsReplaceMap) {
94
+ output = this.replaceOutput(output, assetsReplaceMap);
95
95
  }
96
- convertToRelativePath(filePath, relativePathFromRoot) {
97
- let fromPath = context_1.Context.outputPath + filePath.substring(0, filePath.lastIndexOf('/'));
98
- let toPath = context_1.Context.config.projectRoot + relativePathFromRoot.substring(1);
99
- return path_1.default.relative(fromPath, toPath).replace(/\\/g, '/');
96
+ if (options.replaceMap) {
97
+ output = this.replaceOutput(output, options.replaceMap);
100
98
  }
101
- replaceOutput(output, replaceMap) {
102
- replaceMap.forEach(item => {
103
- output = output.replace(new RegExp(item.target, 'g'), item.replace);
104
- });
105
- return output;
99
+ return this.format(output);
100
+ }
101
+ async generateOutput(options) {
102
+ let output = '';
103
+ if (options.preText) {
104
+ output += `${options.preText}\n\n`;
106
105
  }
107
- async format(str) {
108
- return prettier.format(str, {
109
- parser: 'typescript',
110
- trailingComma: 'none',
111
- tabWidth: 2,
112
- printWidth: 130,
113
- singleQuote: true,
114
- arrowParens: 'avoid'
115
- });
106
+ if (options.variableType) {
107
+ output += `export const ${options.variableName}: ${options.variableType} = ${this.stringify(options.variable)}`;
108
+ } else {
109
+ output += `export const ${options.variableName} = ${this.stringify(options.variable)}`;
116
110
  }
117
- stringify(obj) {
118
- // eslint-disable-next-line no-null/no-null
119
- return JSON.stringify(obj, (k, v) => (v === undefined ? null : v)).replace(/null/gm, 'undefined');
111
+ if (options.replaceMap) {
112
+ output = this.replaceOutput(output, options.replaceMap);
120
113
  }
114
+ return this.format(output);
115
+ }
116
+ convertToRelativePath(filePath, relativePathFromRoot) {
117
+ let fromPath = context_1.Context.outputPath + filePath.substring(0, filePath.lastIndexOf('/'));
118
+ let toPath = context_1.Context.config.projectRoot + relativePathFromRoot.substring(1);
119
+ return path_1.default.relative(fromPath, toPath).replace(/\\/g, '/');
120
+ }
121
+ replaceOutput(output, replaceMap) {
122
+ replaceMap.forEach(item => {
123
+ output = output.replace(new RegExp(item.target, 'g'), item.replace);
124
+ });
125
+ return output;
126
+ }
127
+ async format(str) {
128
+ return prettier.format(str, {
129
+ parser: 'typescript',
130
+ trailingComma: 'none',
131
+ tabWidth: 2,
132
+ printWidth: 130,
133
+ singleQuote: true,
134
+ arrowParens: 'avoid'
135
+ });
136
+ }
137
+ stringify(obj) {
138
+ // eslint-disable-next-line no-null/no-null
139
+ return JSON.stringify(obj, (k, v) => (v === undefined ? null : v)).replace(/null/gm, 'undefined');
140
+ }
121
141
  }
122
142
  exports.OutputHelper = new OutputHelperClass();
123
- //# sourceMappingURL=output-helper.js.map
143
+ //# sourceMappingURL=output-helper.js.map
@@ -1,24 +1,24 @@
1
1
  export declare const Const: {
2
- type: string;
3
- material: string;
4
- maxQuantity: number;
5
- mainHand: undefined;
6
- offHand: undefined;
7
- bothHands: {
8
- imageOnCharacter: string;
9
- parryDice: undefined;
10
- attacks: {
11
- actionIcon: string;
12
- attackDices: string[];
13
- range: string;
14
- requiresSetup: boolean;
15
- unparryable: boolean;
16
- lowersQuantity: boolean;
17
- projectileType: string;
18
- sounds: {
19
- hit: string;
20
- pre: string;
21
- };
22
- }[];
23
- };
2
+ type: string;
3
+ material: string;
4
+ maxQuantity: number;
5
+ mainHand: undefined;
6
+ offHand: undefined;
7
+ bothHands: {
8
+ imageOnCharacter: string;
9
+ parryDice: undefined;
10
+ attacks: {
11
+ actionIcon: string;
12
+ attackDices: string[];
13
+ range: string;
14
+ requiresSetup: boolean;
15
+ unparryable: boolean;
16
+ lowersQuantity: boolean;
17
+ projectileType: string;
18
+ sounds: {
19
+ hit: string;
20
+ pre: string;
21
+ };
22
+ }[];
23
+ };
24
24
  };