definition-generator-framework 1.12.4 → 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 (185) 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.d.ts +1 -0
  15. package/dist/helpers/common-functions/common-functions.spec.js +50 -0
  16. package/dist/helpers/duplicate-helper/duplicate-helper.spec.d.ts +1 -0
  17. package/dist/helpers/duplicate-helper/duplicate-helper.spec.js +54 -0
  18. package/dist/helpers/output-helper/output-helper.d.ts +26 -26
  19. package/dist/helpers/output-helper/output-helper.js +127 -107
  20. package/dist/helpers/output-helper/output-helper.spec.d.ts +24 -0
  21. package/dist/helpers/output-helper/output-helper.spec.js +261 -0
  22. package/dist/helpers/output-helper/output-helper.test.d.ts +22 -22
  23. package/dist/helpers/output-helper/output-helper.test.js +224 -212
  24. package/dist/helpers/raw-definition-helper/raw-definition.helper.spec.d.ts +1 -0
  25. package/dist/helpers/raw-definition-helper/raw-definition.helper.spec.js +143 -0
  26. package/dist/helpers/validator/custom-validator-helper/custom-validator.helper.spec.d.ts +1 -0
  27. package/dist/helpers/validator/custom-validator-helper/custom-validator.helper.spec.js +191 -0
  28. package/dist/helpers/validator/custom-validators/image.custom-validator.d.ts +6 -6
  29. package/dist/helpers/validator/custom-validators/image.custom-validator.js +40 -39
  30. package/dist/helpers/validator/custom-validators/unique-name-group.custom-validator.d.ts +4 -4
  31. package/dist/helpers/validator/custom-validators/unique-name-group.custom-validator.js +29 -29
  32. package/dist/helpers/validator/joi-custom-validators.spec.d.ts +1 -0
  33. package/dist/helpers/validator/joi-custom-validators.spec.js +304 -0
  34. package/dist/helpers/validator/validator.spec.d.ts +1 -0
  35. package/dist/helpers/validator/validator.spec.js +332 -0
  36. package/dist/pipeline/1-select-definitions-helper.d.ts +13 -13
  37. package/dist/pipeline/1-select-definitions-helper.js +68 -72
  38. package/dist/pipeline/1-select-definitions.helper.test.js +40 -40
  39. package/dist/pipeline/1-select-definitions.spec.d.ts +1 -0
  40. package/dist/pipeline/1-select-definitions.spec.js +140 -0
  41. package/dist/pipeline/2-structure-parser.helper.spec.d.ts +1 -0
  42. package/dist/pipeline/2-structure-parser.helper.spec.js +280 -0
  43. package/dist/pipeline/parsers/array-parser.spec.d.ts +1 -0
  44. package/dist/pipeline/parsers/array-parser.spec.js +128 -0
  45. package/dist/pipeline/parsers/object-parser.spec.d.ts +1 -0
  46. package/dist/pipeline/parsers/object-parser.spec.js +179 -0
  47. package/dist/pipeline/parsers/primitive-parser.spec.d.ts +1 -0
  48. package/dist/pipeline/parsers/primitive-parser.spec.js +79 -0
  49. package/dist/pre-made-components/assets/3-font.js +4 -4
  50. package/dist/pre-made-components/events/1-event.d.ts +1 -1
  51. package/dist/pre-made-components/events/1-event.js +157 -125
  52. package/dist/pre-made-components/events/2-event-test.d.ts +8 -8
  53. package/dist/pre-made-components/events/2-event-test.js +156 -119
  54. package/dist/pre-made-components/events/2-script-test.js +0 -1
  55. package/dist/pre-made-components/events/event-setup.d.ts +10 -5
  56. package/dist/pre-made-components/events/event-setup.js +15 -15
  57. package/dist/pre-made-components/events/script-setup.d.ts +5 -3
  58. package/dist/pre-made-components/events/script-setup.js +11 -11
  59. package/package.json +11 -11
  60. package/.eslintrc.js +0 -212
  61. package/.vscode/launch.json +0 -15
  62. package/.vscode/settings.json +0 -25
  63. package/coverage/clover.xml +0 -503
  64. package/coverage/coverage-final.json +0 -16
  65. package/coverage/lcov-report/_mocks/index.html +0 -116
  66. package/coverage/lcov-report/_mocks/mocks.ts.html +0 -223
  67. package/coverage/lcov-report/base.css +0 -224
  68. package/coverage/lcov-report/block-navigation.js +0 -87
  69. package/coverage/lcov-report/favicon.png +0 -0
  70. package/coverage/lcov-report/framework/framework.data.ts.html +0 -109
  71. package/coverage/lcov-report/framework/index.html +0 -116
  72. package/coverage/lcov-report/helpers/common-functions/common-functions.ts.html +0 -178
  73. package/coverage/lcov-report/helpers/common-functions/index.html +0 -116
  74. package/coverage/lcov-report/helpers/duplicate-helper/duplicate-helper.ts.html +0 -196
  75. package/coverage/lcov-report/helpers/duplicate-helper/index.html +0 -116
  76. package/coverage/lcov-report/helpers/output-helper/index.html +0 -116
  77. package/coverage/lcov-report/helpers/output-helper/output-helper.ts.html +0 -277
  78. package/coverage/lcov-report/helpers/raw-definition-helper/index.html +0 -116
  79. package/coverage/lcov-report/helpers/raw-definition-helper/raw-definition.helper.ts.html +0 -256
  80. package/coverage/lcov-report/helpers/validator/index.html +0 -131
  81. package/coverage/lcov-report/helpers/validator/joi-custom-validators.ts.html +0 -643
  82. package/coverage/lcov-report/helpers/validator/validator.ts.html +0 -310
  83. package/coverage/lcov-report/index.html +0 -251
  84. package/coverage/lcov-report/pipeline/1-select-definitions-helper.ts.html +0 -358
  85. package/coverage/lcov-report/pipeline/2-structure-parser.helper.ts.html +0 -301
  86. package/coverage/lcov-report/pipeline/3-config.ts.html +0 -178
  87. package/coverage/lcov-report/pipeline/_mocks/index.html +0 -116
  88. package/coverage/lcov-report/pipeline/_mocks/index.ts.html +0 -229
  89. package/coverage/lcov-report/pipeline/index.html +0 -146
  90. package/coverage/lcov-report/pipeline/parsers/array-parser.ts.html +0 -271
  91. package/coverage/lcov-report/pipeline/parsers/index.html +0 -146
  92. package/coverage/lcov-report/pipeline/parsers/object-parser.ts.html +0 -439
  93. package/coverage/lcov-report/pipeline/parsers/primitive-parser.ts.html +0 -370
  94. package/coverage/lcov-report/prettify.css +0 -1
  95. package/coverage/lcov-report/prettify.js +0 -2
  96. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  97. package/coverage/lcov-report/sorter.js +0 -196
  98. package/coverage/lcov.info +0 -911
  99. package/dist/_mocks/mocks.js.map +0 -1
  100. package/dist/decorators/definition-component.js.map +0 -1
  101. package/dist/decorators/definition-generator.js.map +0 -1
  102. package/dist/framework/context.js.map +0 -1
  103. package/dist/framework/definition-component.js.map +0 -1
  104. package/dist/framework/definition-generator.js.map +0 -1
  105. package/dist/framework/definition-store.js.map +0 -1
  106. package/dist/framework/file-content-generator/file-content-generator.js.map +0 -1
  107. package/dist/framework/file-content-generator/file-content-generator.test.js.map +0 -1
  108. package/dist/framework/framework.data.js.map +0 -1
  109. package/dist/framework/framework.js.map +0 -1
  110. package/dist/framework/framework.model.js.map +0 -1
  111. package/dist/framework/index-file-generator/index-file-generator.js.map +0 -1
  112. package/dist/framework/interfaces.js.map +0 -1
  113. package/dist/framework/kernel.js.map +0 -1
  114. package/dist/helpers/common-functions/common-functions.js.map +0 -1
  115. package/dist/helpers/common-functions/common-functions.spec.js.map +0 -1
  116. package/dist/helpers/common-functions/common-functions.test.js.map +0 -1
  117. package/dist/helpers/duplicate-helper/duplicate-helper.js.map +0 -1
  118. package/dist/helpers/duplicate-helper/duplicate-helper.spec.js.map +0 -1
  119. package/dist/helpers/duplicate-helper/duplicate-helper.test.js.map +0 -1
  120. package/dist/helpers/output-helper/output-helper.js.map +0 -1
  121. package/dist/helpers/output-helper/output-helper.spec.js.map +0 -1
  122. package/dist/helpers/output-helper/output-helper.test.js.map +0 -1
  123. package/dist/helpers/raw-definition-helper/raw-definition.helper.js.map +0 -1
  124. package/dist/helpers/raw-definition-helper/raw-definition.helper.spec.js.map +0 -1
  125. package/dist/helpers/raw-definition-helper/raw-definition.helper.test.js.map +0 -1
  126. package/dist/helpers/validator/custom-validator-helper/custom-validator.helper.js.map +0 -1
  127. package/dist/helpers/validator/custom-validator-helper/custom-validator.helper.spec.js.map +0 -1
  128. package/dist/helpers/validator/custom-validator-helper/custom-validator.helper.test.js.map +0 -1
  129. package/dist/helpers/validator/custom-validators/helpers/sprite-validation.helper.js.map +0 -1
  130. package/dist/helpers/validator/custom-validators/helpers/sprite-validation.helper.test.js.map +0 -1
  131. package/dist/helpers/validator/custom-validators/image.custom-validator.js.map +0 -1
  132. package/dist/helpers/validator/custom-validators/path.custom-validator.js.map +0 -1
  133. package/dist/helpers/validator/custom-validators/position-on-sprite.js.map +0 -1
  134. package/dist/helpers/validator/custom-validators/reference.custom-validator.js.map +0 -1
  135. package/dist/helpers/validator/custom-validators/sprite.custom-validator.js.map +0 -1
  136. package/dist/helpers/validator/custom-validators/unique-name-group.custom-validator.js.map +0 -1
  137. package/dist/helpers/validator/custom-validators/unique.custom-validator.js.map +0 -1
  138. package/dist/helpers/validator/joi-custom-validators.js.map +0 -1
  139. package/dist/helpers/validator/joi-custom-validators.spec.js.map +0 -1
  140. package/dist/helpers/validator/validator.js.map +0 -1
  141. package/dist/helpers/validator/validator.spec.js.map +0 -1
  142. package/dist/helpers/validator/validator.test.js.map +0 -1
  143. package/dist/index.js.map +0 -1
  144. package/dist/pipeline/1-select-definitions-helper.js.map +0 -1
  145. package/dist/pipeline/1-select-definitions.helper.js.map +0 -1
  146. package/dist/pipeline/1-select-definitions.helper.test.js.map +0 -1
  147. package/dist/pipeline/1-select-definitions.spec.js.map +0 -1
  148. package/dist/pipeline/2-structure-parser.helper.js.map +0 -1
  149. package/dist/pipeline/2-structure-parser.helper.spec.js.map +0 -1
  150. package/dist/pipeline/2-structure-parser.helper.test.js.map +0 -1
  151. package/dist/pipeline/3-config.js.map +0 -1
  152. package/dist/pipeline/_mocks/index.js.map +0 -1
  153. package/dist/pipeline/parsers/array-parser.js.map +0 -1
  154. package/dist/pipeline/parsers/array-parser.spec.js.map +0 -1
  155. package/dist/pipeline/parsers/array-parser.test.js.map +0 -1
  156. package/dist/pipeline/parsers/object-parser.js.map +0 -1
  157. package/dist/pipeline/parsers/object-parser.spec.js.map +0 -1
  158. package/dist/pipeline/parsers/object-parser.test.js.map +0 -1
  159. package/dist/pipeline/parsers/primitive-parser.js.map +0 -1
  160. package/dist/pipeline/parsers/primitive-parser.spec.js.map +0 -1
  161. package/dist/pipeline/parsers/primitive-parser.test.js.map +0 -1
  162. package/dist/pipeline/raw-data-parser.js.map +0 -1
  163. package/dist/pre-made-components/_validators/shape-validators.js.map +0 -1
  164. package/dist/pre-made-components/_validators/sprite-validators.js.map +0 -1
  165. package/dist/pre-made-components/assets/1-sprite.js.map +0 -1
  166. package/dist/pre-made-components/assets/2-sprite-group.js.map +0 -1
  167. package/dist/pre-made-components/assets/3-font.js.map +0 -1
  168. package/dist/pre-made-components/events/1-event.js.map +0 -1
  169. package/dist/pre-made-components/events/1-script.js.map +0 -1
  170. package/dist/pre-made-components/events/2-event-test.js.map +0 -1
  171. package/dist/pre-made-components/events/2-script-test.js.map +0 -1
  172. package/dist/pre-made-components/events/3-event.js.map +0 -1
  173. package/dist/pre-made-components/events/4-event-test.js.map +0 -1
  174. package/dist/pre-made-components/events/event-setup.js.map +0 -1
  175. package/dist/pre-made-components/events/helpers/quotes-to-tags.helper.js.map +0 -1
  176. package/dist/pre-made-components/events/helpers/quotes-to-tags.helper.test.js.map +0 -1
  177. package/dist/pre-made-components/events/helpers/script-testing.helper.js.map +0 -1
  178. package/dist/pre-made-components/events/script-setup.js.map +0 -1
  179. package/dist/pre-made-components/events/scripting-setup.js.map +0 -1
  180. package/dist/pre-made-components/events/validators.js.map +0 -1
  181. package/dist/setup.js.map +0 -1
  182. package/package.json.bak +0 -60
  183. package/scripts/prepare-package-json.ts +0 -23
  184. package/tsconfig.json +0 -24
  185. package/vitest.config.ts +0 -1
@@ -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
@@ -0,0 +1,24 @@
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
+ };
24
+ };
@@ -0,0 +1,261 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, '__esModule', { value: true });
3
+ exports.Const = void 0;
4
+ const mocks_1 = require('../../_mocks/mocks');
5
+ const context_1 = require('../../framework/context');
6
+ const output_helper_1 = require('./output-helper');
7
+ let complexObject = {
8
+ type: 'bow',
9
+ material: 'WoodenItemMaterial',
10
+ maxQuantity: 10,
11
+ mainHand: undefined,
12
+ offHand: undefined,
13
+ bothHands: {
14
+ imageOnCharacter: 'BodyPartImageNames',
15
+ parryDice: undefined,
16
+ attacks: [
17
+ {
18
+ actionIcon: 'AssetNames.characterActionBowAttack',
19
+ attackDices: ['DiceType.d6', 'DiceType.d6'],
20
+ range: 'WeaponRange.ranged',
21
+ requiresSetup: false,
22
+ unparryable: true,
23
+ lowersQuantity: true,
24
+ projectileType: 'ProjectileType.arrow',
25
+ sounds: {
26
+ hit: 'AssetGroups.battleSoundArrowHit',
27
+ pre: 'AssetGroups.battleSoundArrowShot'
28
+ }
29
+ }
30
+ ]
31
+ }
32
+ };
33
+ let emptyArrayExpected = `export const Groups: any[] = [];
34
+ `;
35
+ let basicArrayExpected = `export const Groups: any[] = [
36
+ { name: 'test1', source: './src/definitions-sample/images/test1.png' },
37
+ { name: 'test2', source: './src/definitions-sample/images/test2.png', pixelPerfectInteraction: true }
38
+ ];
39
+ `;
40
+ let complexArrayExpected = `export const Groups: any[] = [
41
+ {
42
+ type: 'bow',
43
+ material: 'WoodenItemMaterial',
44
+ maxQuantity: 10,
45
+ mainHand: undefined,
46
+ offHand: undefined,
47
+ bothHands: {
48
+ imageOnCharacter: 'BodyPartImageNames',
49
+ parryDice: undefined,
50
+ attacks: [
51
+ {
52
+ actionIcon: 'AssetNames.characterActionBowAttack',
53
+ attackDices: ['DiceType.d6', 'DiceType.d6'],
54
+ range: 'WeaponRange.ranged',
55
+ requiresSetup: false,
56
+ unparryable: true,
57
+ lowersQuantity: true,
58
+ projectileType: 'ProjectileType.arrow',
59
+ sounds: { hit: 'AssetGroups.battleSoundArrowHit', pre: 'AssetGroups.battleSoundArrowShot' }
60
+ }
61
+ ]
62
+ }
63
+ }
64
+ ];
65
+ `;
66
+ let complexArrayReplaceExpected = `export const Groups: any[] = [
67
+ {
68
+ type: 'bow',
69
+ material: 'WoodenItemMaterial',
70
+ maxQuantity: 10,
71
+ mainHand: undefined,
72
+ offHand: undefined,
73
+ bothHands: {
74
+ imageOnCharacter: 'BodyPartImageNames',
75
+ parryDice: undefined,
76
+ attacks: [
77
+ {
78
+ actionIcon: 'AssetNames.characterActionBowAttack',
79
+ attackDices: [DiceType.d6, DiceType.d6],
80
+ range: 'WeaponRange.ranged',
81
+ requiresSetup: false,
82
+ unparryable: true,
83
+ lowersQuantity: true,
84
+ projectileType: 'ProjectileType.arrow',
85
+ sounds: { hit: 'AssetGroups.battleSoundArrowHit', pre: 'AssetGroups.battleSoundArrowShot' }
86
+ }
87
+ ]
88
+ }
89
+ }
90
+ ];
91
+ `;
92
+ exports.Const = {
93
+ type: 'bow',
94
+ material: 'WoodenItemMaterial',
95
+ maxQuantity: 10,
96
+ mainHand: undefined,
97
+ offHand: undefined,
98
+ bothHands: {
99
+ imageOnCharacter: 'BodyPartImageNames',
100
+ parryDice: undefined,
101
+ attacks: [
102
+ {
103
+ actionIcon: 'AssetNames.characterActionBowAttack',
104
+ attackDices: ['DiceType.d6', 'DiceType.d6'],
105
+ range: 'WeaponRange.ranged',
106
+ requiresSetup: false,
107
+ unparryable: true,
108
+ lowersQuantity: true,
109
+ projectileType: 'ProjectileType.arrow',
110
+ sounds: {
111
+ hit: 'AssetGroups.battleSoundArrowHit',
112
+ pre: 'AssetGroups.battleSoundArrowShot'
113
+ }
114
+ }
115
+ ]
116
+ }
117
+ };
118
+ let noTypeExpected = `export const ConstSample = { type: 'item' };
119
+ `;
120
+ let basicConstExpected = `export const ConstSample: string = 'basic';
121
+ `;
122
+ let complexConstExpected = `export const ConstSample: any = {
123
+ type: 'bow',
124
+ material: 'WoodenItemMaterial',
125
+ maxQuantity: 10,
126
+ mainHand: undefined,
127
+ offHand: undefined,
128
+ bothHands: {
129
+ imageOnCharacter: 'BodyPartImageNames',
130
+ parryDice: undefined,
131
+ attacks: [
132
+ {
133
+ actionIcon: 'AssetNames.characterActionBowAttack',
134
+ attackDices: ['DiceType.d6', 'DiceType.d6'],
135
+ range: 'WeaponRange.ranged',
136
+ requiresSetup: false,
137
+ unparryable: true,
138
+ lowersQuantity: true,
139
+ projectileType: 'ProjectileType.arrow',
140
+ sounds: { hit: 'AssetGroups.battleSoundArrowHit', pre: 'AssetGroups.battleSoundArrowShot' }
141
+ }
142
+ ]
143
+ }
144
+ };
145
+ `;
146
+ let complexConstReplaceExpected = `export const ConstSample: any = {
147
+ type: 'bow',
148
+ material: 'WoodenItemMaterial',
149
+ maxQuantity: 10,
150
+ mainHand: undefined,
151
+ offHand: undefined,
152
+ bothHands: {
153
+ imageOnCharacter: 'BodyPartImageNames',
154
+ parryDice: undefined,
155
+ attacks: [
156
+ {
157
+ actionIcon: 'AssetNames.characterActionBowAttack',
158
+ attackDices: ['DiceType.d6', 'DiceType.d6'],
159
+ range: WeaponRange,
160
+ requiresSetup: false,
161
+ unparryable: true,
162
+ lowersQuantity: true,
163
+ projectileType: 'ProjectileType.arrow',
164
+ sounds: { hit: 'AssetGroups.battleSoundArrowHit', pre: 'AssetGroups.battleSoundArrowShot' }
165
+ }
166
+ ]
167
+ }
168
+ };
169
+ `;
170
+ describe('Output Helper: Array Output', () => {
171
+ test('should handle empty array', async () => {
172
+ let output = await output_helper_1.OutputHelper.generateArrayOutput({
173
+ variableName: 'Groups',
174
+ variableType: 'any[]',
175
+ variable: []
176
+ });
177
+ expect(output).toStrictEqual(emptyArrayExpected);
178
+ });
179
+ test('should handle basic array', async () => {
180
+ let output = await output_helper_1.OutputHelper.generateArrayOutput({
181
+ variableName: 'Groups',
182
+ variableType: 'any[]',
183
+ variable: [
184
+ { name: 'test1', source: './src/definitions-sample/images/test1.png' },
185
+ { name: 'test2', source: './src/definitions-sample/images/test2.png', pixelPerfectInteraction: true }
186
+ ]
187
+ });
188
+ expect(output).toStrictEqual(basicArrayExpected);
189
+ });
190
+ test('should handle complex array', async () => {
191
+ let output = await output_helper_1.OutputHelper.generateArrayOutput({
192
+ variableName: 'Groups',
193
+ variableType: 'any[]',
194
+ variable: [complexObject]
195
+ });
196
+ expect(output).toStrictEqual(complexArrayExpected);
197
+ });
198
+ test('should handle replacing complex array', async () => {
199
+ let output = await output_helper_1.OutputHelper.generateArrayOutput({
200
+ variableName: 'Groups',
201
+ variableType: 'any[]',
202
+ variable: [complexObject],
203
+ replaceMap: [{ target: `"DiceType.d6"`, replace: 'DiceType.d6' }]
204
+ });
205
+ expect(output).toStrictEqual(complexArrayReplaceExpected);
206
+ });
207
+ });
208
+ describe('Output Helper: Const Output', () => {
209
+ test('should handle no type', async () => {
210
+ let output = await output_helper_1.OutputHelper.generateOutput({ variableName: 'ConstSample', variable: { type: 'item' } });
211
+ expect(output).toStrictEqual(noTypeExpected);
212
+ });
213
+ test('should handle basic value', async () => {
214
+ let output = await output_helper_1.OutputHelper.generateOutput({
215
+ variableName: 'ConstSample',
216
+ variableType: 'string',
217
+ variable: 'basic'
218
+ });
219
+ expect(output).toStrictEqual(basicConstExpected);
220
+ });
221
+ test('should handle complex object', async () => {
222
+ let output = await output_helper_1.OutputHelper.generateOutput({
223
+ variableName: 'ConstSample',
224
+ variableType: 'any',
225
+ variable: complexObject
226
+ });
227
+ expect(output).toStrictEqual(complexConstExpected);
228
+ });
229
+ test('should handle replacing complex object', async () => {
230
+ let output = await output_helper_1.OutputHelper.generateOutput({
231
+ variableName: 'ConstSample',
232
+ variableType: 'any',
233
+ variable: complexObject,
234
+ replaceMap: [{ target: `"WeaponRange.ranged"`, replace: 'WeaponRange' }]
235
+ });
236
+ expect(output).toStrictEqual(complexConstReplaceExpected);
237
+ });
238
+ });
239
+ describe('Output Helper: stringify', () => {
240
+ test('should not lose properties with undefined or null value', async () => {
241
+ let output = await output_helper_1.OutputHelper['stringify']({
242
+ a: undefined,
243
+ // eslint-disable-next-line no-null/no-null
244
+ b: null
245
+ });
246
+ expect(output).toStrictEqual('{"a":undefined,"b":undefined}');
247
+ });
248
+ });
249
+ describe('Output Helper: convertToRelativePath', () => {
250
+ test('should convert to relative path', async () => {
251
+ (0, mocks_1.resetContext)();
252
+ context_1.Context.outputPath = 'D:/Projects/Game-Dev/Starfighter/Starfighter-Definitions-Generator/src/.asset-build';
253
+ context_1.Context.config.projectRoot = 'D:/Projects/Game-Dev/Starfighter/Starfighter-Definitions-Generator/';
254
+ let original = '.src/definitions-sample/images/nested/test2.png';
255
+ let desired = '../../../definitions-sample/images/nested/test2.png';
256
+ let filePath = '/0-global-definitions/assets/images.ts';
257
+ let output = output_helper_1.OutputHelper['convertToRelativePath'](filePath, original);
258
+ expect(output).toStrictEqual(desired);
259
+ });
260
+ });
261
+ //# sourceMappingURL=output-helper.spec.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
  };