definition-generator-framework 1.6.3 → 1.6.4

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 (40) hide show
  1. package/package.json +58 -56
  2. package/package.json.bak +58 -0
  3. package/scripts/prepare-package-json.ts +23 -0
  4. package/src/_mocks/mocks.ts +0 -43
  5. package/src/decorators/definition-component.ts +0 -39
  6. package/src/decorators/definition-generator.ts +0 -23
  7. package/src/framework/context.ts +0 -13
  8. package/src/framework/definition-store.ts +0 -68
  9. package/src/framework/interfaces.ts +0 -42
  10. package/src/framework/kernel.ts +0 -167
  11. package/src/helpers/common-functions/common-functions.test.ts +0 -54
  12. package/src/helpers/common-functions/common-functions.ts +0 -31
  13. package/src/helpers/duplicate-helper/duplicate-helper.test.ts +0 -62
  14. package/src/helpers/duplicate-helper/duplicate-helper.ts +0 -38
  15. package/src/helpers/output-helper/output-helper.test.ts +0 -269
  16. package/src/helpers/output-helper/output-helper.ts +0 -125
  17. package/src/helpers/raw-definition-helper/raw-definition.helper.test.ts +0 -145
  18. package/src/helpers/raw-definition-helper/raw-definition.helper.ts +0 -60
  19. package/src/helpers/validator/custom-validator-helper/custom-validator.helper.test.ts +0 -206
  20. package/src/helpers/validator/custom-validator-helper/custom-validator.helper.ts +0 -55
  21. package/src/helpers/validator/custom-validators/path.custom-validator.ts +0 -34
  22. package/src/helpers/validator/custom-validators/reference.custom-validator.ts +0 -69
  23. package/src/helpers/validator/custom-validators/sprite.custom-validator.ts +0 -49
  24. package/src/helpers/validator/joi-custom-validators.ts +0 -58
  25. package/src/helpers/validator/validator.test.ts +0 -381
  26. package/src/helpers/validator/validator.ts +0 -74
  27. package/src/index.ts +0 -8
  28. package/src/pipeline/1-select-definitions.helper.test.ts +0 -163
  29. package/src/pipeline/1-select-definitions.helper.ts +0 -91
  30. package/src/pipeline/2-structure-parser.helper.test.ts +0 -318
  31. package/src/pipeline/2-structure-parser.helper.ts +0 -72
  32. package/src/pipeline/3-config.ts +0 -28
  33. package/src/pipeline/_mocks/index.ts +0 -50
  34. package/src/pipeline/parsers/array-parser.test.ts +0 -136
  35. package/src/pipeline/parsers/array-parser.ts +0 -65
  36. package/src/pipeline/parsers/object-parser.test.ts +0 -195
  37. package/src/pipeline/parsers/object-parser.ts +0 -124
  38. package/src/pipeline/parsers/primitive-parser.test.ts +0 -92
  39. package/src/pipeline/parsers/primitive-parser.ts +0 -95
  40. package/src/pipeline/raw-data-parser.ts +0 -27
package/package.json CHANGED
@@ -1,56 +1,58 @@
1
- {
2
- "name": "definition-generator-framework",
3
- "version": "1.6.3",
4
- "description": "Definition Generator Framework",
5
- "main": "src/index.ts",
6
- "publishConfig": {
7
- "main": "dist/index.js"
8
- },
9
- "repository": {
10
- "type": "git",
11
- "url": "git+https://github.com/sefabaser/definition-generator-framework.git"
12
- },
13
- "author": "sefabaser",
14
- "license": "MIT",
15
- "bugs": {
16
- "url": "https://github.com/sefabaser/definition-generator-framework/issues"
17
- },
18
- "prettier": {
19
- "trailingComma": "none",
20
- "tabWidth": 2,
21
- "printWidth": 130,
22
- "singleQuote": true,
23
- "arrowParens": "avoid"
24
- },
25
- "homepage": "https://github.com/sefabaser/definition-generator-framework#readme",
26
- "scripts": {
27
- "clean-install": "cls && rm -rf node_modules && rm -rf package-lock.json && npm install",
28
- "pretest": "cls",
29
- "test": "vitest",
30
- "start": "npm run build && node dist",
31
- "build": "tsc",
32
- "lint": "eslint \"src/**/*.ts\" --fix",
33
- "deploy": "vitest run && npm run build && npm publish"
34
- },
35
- "dependencies": {
36
- "helpers-lib": "1.5.32",
37
- "image-size": "1.1.1",
38
- "joi": "17.11.0",
39
- "prettier": "3.1.1"
40
- },
41
- "devDependencies": {
42
- "@types/glob": "8.1.0",
43
- "@types/node": "20.10.5",
44
- "@types/rimraf": "4.0.5",
45
- "@typescript-eslint/eslint-plugin": "6.16.0",
46
- "@typescript-eslint/parser": "6.16.0",
47
- "eslint": "8.56.0",
48
- "eslint-config-prettier": "9.1.0",
49
- "eslint-plugin-import": "2.29.1",
50
- "eslint-plugin-no-null": "1.0.2",
51
- "eslint-plugin-sort-class-members": "1.19.0",
52
- "ts-node": "10.9.2",
53
- "typescript": "5.3.3",
54
- "vitest": "1.6.0"
55
- }
56
- }
1
+ {
2
+ "name": "definition-generator-framework",
3
+ "version": "1.6.4",
4
+ "description": "Definition Generator Framework",
5
+ "main": "dist/index.js",
6
+ "publishConfig": {
7
+ "main": "dist/index.js"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/sefabaser/definition-generator-framework.git"
12
+ },
13
+ "author": "sefabaser",
14
+ "license": "MIT",
15
+ "bugs": {
16
+ "url": "https://github.com/sefabaser/definition-generator-framework/issues"
17
+ },
18
+ "prettier": {
19
+ "trailingComma": "none",
20
+ "tabWidth": 2,
21
+ "printWidth": 130,
22
+ "singleQuote": true,
23
+ "arrowParens": "avoid"
24
+ },
25
+ "homepage": "https://github.com/sefabaser/definition-generator-framework#readme",
26
+ "scripts": {
27
+ "clean-install": "cls && rm -rf node_modules && rm -rf package-lock.json && npm install",
28
+ "pretest": "cls",
29
+ "test": "vitest",
30
+ "start": "npm run build && node dist",
31
+ "build": "tsc",
32
+ "lint": "eslint \"src/**/*.ts\" --fix",
33
+ "deploy": "vitest run && npm run build && npm publish",
34
+ "prepack": "cp package.json package.json.bak && ts-node scripts/prepare-package-json.ts",
35
+ "postpack": "mv package.json.bak package.json"
36
+ },
37
+ "dependencies": {
38
+ "helpers-lib": "1.5.32",
39
+ "image-size": "1.1.1",
40
+ "joi": "17.11.0",
41
+ "prettier": "3.1.1"
42
+ },
43
+ "devDependencies": {
44
+ "@types/glob": "8.1.0",
45
+ "@types/node": "20.10.5",
46
+ "@types/rimraf": "4.0.5",
47
+ "@typescript-eslint/eslint-plugin": "6.16.0",
48
+ "@typescript-eslint/parser": "6.16.0",
49
+ "eslint": "8.56.0",
50
+ "eslint-config-prettier": "9.1.0",
51
+ "eslint-plugin-import": "2.29.1",
52
+ "eslint-plugin-no-null": "1.0.2",
53
+ "eslint-plugin-sort-class-members": "1.19.0",
54
+ "ts-node": "10.9.2",
55
+ "typescript": "5.3.3",
56
+ "vitest": "1.6.0"
57
+ }
58
+ }
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "definition-generator-framework",
3
+ "version": "1.6.4",
4
+ "description": "Definition Generator Framework",
5
+ "main": "src/index.ts",
6
+ "publishConfig": {
7
+ "main": "dist/index.js"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/sefabaser/definition-generator-framework.git"
12
+ },
13
+ "author": "sefabaser",
14
+ "license": "MIT",
15
+ "bugs": {
16
+ "url": "https://github.com/sefabaser/definition-generator-framework/issues"
17
+ },
18
+ "prettier": {
19
+ "trailingComma": "none",
20
+ "tabWidth": 2,
21
+ "printWidth": 130,
22
+ "singleQuote": true,
23
+ "arrowParens": "avoid"
24
+ },
25
+ "homepage": "https://github.com/sefabaser/definition-generator-framework#readme",
26
+ "scripts": {
27
+ "clean-install": "cls && rm -rf node_modules && rm -rf package-lock.json && npm install",
28
+ "pretest": "cls",
29
+ "test": "vitest",
30
+ "start": "npm run build && node dist",
31
+ "build": "tsc",
32
+ "lint": "eslint \"src/**/*.ts\" --fix",
33
+ "deploy": "vitest run && npm run build && npm publish",
34
+ "prepack": "cp package.json package.json.bak && ts-node scripts/prepare-package-json.ts",
35
+ "postpack": "mv package.json.bak package.json"
36
+ },
37
+ "dependencies": {
38
+ "helpers-lib": "1.5.32",
39
+ "image-size": "1.1.1",
40
+ "joi": "17.11.0",
41
+ "prettier": "3.1.1"
42
+ },
43
+ "devDependencies": {
44
+ "@types/glob": "8.1.0",
45
+ "@types/node": "20.10.5",
46
+ "@types/rimraf": "4.0.5",
47
+ "@typescript-eslint/eslint-plugin": "6.16.0",
48
+ "@typescript-eslint/parser": "6.16.0",
49
+ "eslint": "8.56.0",
50
+ "eslint-config-prettier": "9.1.0",
51
+ "eslint-plugin-import": "2.29.1",
52
+ "eslint-plugin-no-null": "1.0.2",
53
+ "eslint-plugin-sort-class-members": "1.19.0",
54
+ "ts-node": "10.9.2",
55
+ "typescript": "5.3.3",
56
+ "vitest": "1.6.0"
57
+ }
58
+ }
@@ -0,0 +1,23 @@
1
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
2
+ let fs = require('fs');
3
+
4
+ let cwd = process.cwd();
5
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
6
+ let packageJson = require(`${cwd}/package.json`);
7
+
8
+ let newPackageJson = {
9
+ ...packageJson,
10
+ main: packageJson.publishConfig?.main ?? packageJson.main
11
+ };
12
+
13
+ if (packageJson.publishConfig?.types) {
14
+ newPackageJson.types = packageJson.publishConfig.types;
15
+ }
16
+
17
+ if (packageJson.publishConfig?.module) {
18
+ newPackageJson.module = packageJson.publishConfig.module;
19
+ }
20
+
21
+ try {
22
+ fs.writeFileSync(`${cwd}/package.json`, JSON.stringify(newPackageJson, undefined, 2));
23
+ } catch (e) {}
@@ -1,43 +0,0 @@
1
- import { Context } from '../framework/context';
2
- import { FileInfo, LocationInFile } from '../framework/interfaces';
3
-
4
- export function resetContext(): void {
5
- Context.compilerExecutionPath = 'D:/test';
6
- Context.outputPath = 'D:/test/.asset-build';
7
- Context.config.projectRoot = 'D:/';
8
- Context.files = [];
9
- Context.rawDefinitions = [];
10
- Context.errorLogs = [];
11
- Context.output = [];
12
- }
13
-
14
- export function setMockContextFromContents(contents: string[]): void {
15
- resetContext();
16
- let fileIndex = 0;
17
- contents.forEach(content => {
18
- fileIndex++;
19
- Context.files.push({ path: `D:/test/file-${fileIndex}.md`, content });
20
- });
21
- }
22
-
23
- export function getMockFileInfo(content: string): FileInfo {
24
- return {
25
- content,
26
- path: 'D:/test/sample.md'
27
- };
28
- }
29
-
30
- export const SampleLocation1: LocationInFile = {
31
- line: 2,
32
- path: 'D:/test/file-1.md'
33
- };
34
-
35
- export const SampleLocation2: LocationInFile = {
36
- line: 2,
37
- path: 'D:/test/file-2.md'
38
- };
39
-
40
- export const SampleLocation3: LocationInFile = {
41
- line: 2,
42
- path: 'D:/test/file-3.md'
43
- };
@@ -1,39 +0,0 @@
1
- import Joi from 'joi';
2
-
3
- import { Output } from '../framework/interfaces';
4
-
5
- export type DefinitionComponentClassType<T> = new (...args: any[]) => DefinitionComponent<T> | SingleDefinitionComponent<T>;
6
-
7
- export interface DefinitionComponentMeta {
8
- componentName: string;
9
- keyName?: string;
10
- singleton?: boolean;
11
- validationSchema: Joi.Schema;
12
- }
13
-
14
- export function DefinitionComponentDecorator(meta: DefinitionComponentMeta) {
15
- return function (ComponentClass: DefinitionComponentClassType<any>): any {
16
- (<any>ComponentClass).$meta = {
17
- componentName: meta.componentName,
18
- keyName: meta.keyName,
19
- singleton: meta.singleton,
20
- validationSchema: meta.validationSchema
21
- };
22
- };
23
- }
24
-
25
- export abstract class DefinitionComponent<T> {
26
- static getSchema(): Joi.Schema {
27
- return (<any>this).$meta.validationSchema;
28
- }
29
-
30
- abstract process(definitions: T[], context: Output): Promise<void>;
31
- }
32
-
33
- export abstract class SingleDefinitionComponent<T> {
34
- static getSchema(): Joi.Schema {
35
- return (<any>this).$meta.validationSchema;
36
- }
37
-
38
- abstract process(definitions: T, context: Output): Promise<void>;
39
- }
@@ -1,23 +0,0 @@
1
- import { DefinitionComponentClassType } from './definition-component';
2
- import { Kernel } from '../framework/kernel';
3
-
4
- interface DefinitionGeneratorMeta {
5
- modules: DefinitionComponentClassType<any>[];
6
- interfaces: string;
7
- }
8
-
9
- let ModuleIsRegistered = false;
10
- export function DefinitionGeneratorDecorator(meta: DefinitionGeneratorMeta) {
11
- return function (ModuleClass: DefinitionGeneratorClassType): any {
12
- if (ModuleIsRegistered) {
13
- console.error('There can be only one definition module!');
14
- } else {
15
- ModuleIsRegistered = true;
16
- Kernel.process(meta.modules, meta.interfaces);
17
- }
18
- };
19
- }
20
-
21
- export type DefinitionGeneratorClassType = new (...args: any[]) => DefinitionGenerator;
22
-
23
- export abstract class DefinitionGenerator {}
@@ -1,13 +0,0 @@
1
- import { Config, ErrorLog, FileInfo, RawDefinition } from './interfaces';
2
-
3
- export class Context {
4
- static compilerExecutionPath: string = '';
5
- static outputPath: string = '';
6
- static config: Config = {
7
- projectRoot: ''
8
- };
9
- static rawDefinitions: RawDefinition[] = [];
10
- static files: FileInfo[] = [];
11
- static output: FileInfo[] = [];
12
- static errorLogs: ErrorLog[] = [];
13
- }
@@ -1,68 +0,0 @@
1
- import { JsonHelper } from 'helpers-lib';
2
-
3
- import { DefinitionComponentClassType } from '../decorators/definition-component';
4
- import { RawDefinition } from './interfaces';
5
-
6
- export class DefinitionStore {
7
- private static rawDefinitionsMap: Map<string, Map<string, RawDefinition>> = new Map<string, Map<string, RawDefinition>>();
8
- private static definitionsMap: Map<string, Map<string, any>> = new Map<string, any>();
9
-
10
- static getDefinition<T>(definitionClass: DefinitionComponentClassType<T>, key: string): T | undefined {
11
- if (!(<any>definitionClass).$meta.keyName) {
12
- throw new Error(`"${definitionClass.name}" doesn't have a keyName, getDefinition cannot be called on it.`);
13
- }
14
- return this.definitionsMap.get(this.getComponentName(definitionClass))?.get(key);
15
- }
16
-
17
- static getDefinitionOrFail<T>(definitionClass: DefinitionComponentClassType<T>, key: string): T {
18
- let definition = this.getDefinition(definitionClass, key);
19
- if (!definition) {
20
- throw new Error(`No result found for "${key}" in "${definitionClass.name}".`);
21
- }
22
- return definition;
23
- }
24
-
25
- private static isValidComponentName(componentName: string): boolean {
26
- return this.definitionsMap.has(componentName);
27
- }
28
-
29
- private static setComponentNames(componentNames: string[]): void {
30
- componentNames.forEach(componentName => {
31
- this.definitionsMap.set(componentName, new Map<string, any>());
32
- });
33
- }
34
-
35
- private static setDefinition<T>(definitionClass: DefinitionComponentClassType<T>, key: string, definition: T): void {
36
- let classMap = this.definitionsMap.get(this.getComponentName(definitionClass));
37
- if (classMap) {
38
- classMap.set(key, JsonHelper.deepCopy(definition));
39
- }
40
- }
41
-
42
- private static isRawDefinitionExists<T>(definitionClass: DefinitionComponentClassType<T>, key: string): boolean {
43
- return this.rawDefinitionsMap.get(definitionClass.name)?.has(key) ? true : false;
44
- }
45
-
46
- private static getRawDefinition<T>(definitionClass: DefinitionComponentClassType<T>, key: string): RawDefinition | undefined {
47
- return this.rawDefinitionsMap.get(definitionClass.name)?.get(key);
48
- }
49
-
50
- private static setRawDefinition<T>(
51
- definitionClass: DefinitionComponentClassType<T>,
52
- key: string,
53
- definition: RawDefinition
54
- ): void {
55
- if (!this.rawDefinitionsMap.has(definitionClass.name)) {
56
- this.rawDefinitionsMap.set(definitionClass.name, new Map<string, RawDefinition>());
57
- }
58
-
59
- let classMap = this.rawDefinitionsMap.get(definitionClass.name);
60
- if (classMap) {
61
- classMap.set(key, JsonHelper.deepCopy(definition));
62
- }
63
- }
64
-
65
- private static getComponentName<T>(definitionClass: DefinitionComponentClassType<T>): string {
66
- return (<any>definitionClass).$meta.componentName;
67
- }
68
- }
@@ -1,42 +0,0 @@
1
- export interface FileSystem {
2
- existsSync: (path: string) => boolean;
3
- }
4
-
5
- export interface FileInfo {
6
- path: string;
7
- content: string;
8
- }
9
-
10
- // UTIL
11
- export interface LocationInFile {
12
- readonly path: string;
13
- readonly line: number;
14
- }
15
-
16
- export interface ErrorLog {
17
- readonly description: string;
18
- readonly location: LocationInFile;
19
- }
20
-
21
- export interface Config {
22
- projectRoot: string;
23
- }
24
-
25
- // RAW-DEFINITIONS
26
- export type RawData = undefined | string | ParsedStructure[] | Record<string, ParsedStructure>;
27
-
28
- export interface ParsedStructure {
29
- readonly rawData: RawData;
30
- readonly line: number;
31
- }
32
-
33
- export interface RawDefinition {
34
- readonly componentName: string;
35
- readonly parsedStructure: ParsedStructure;
36
- readonly location: LocationInFile;
37
- }
38
-
39
- export interface Output {
40
- addFile: (fileInfo: FileInfo) => void;
41
- addError: (errorLog: ErrorLog) => void;
42
- }
@@ -1,167 +0,0 @@
1
- import * as fs from 'fs';
2
- import * as glob from 'glob';
3
- import * as path from 'path';
4
- import * as rimraf from 'rimraf';
5
- import { Comparator } from 'helpers-lib';
6
-
7
- import { ErrorLog, FileInfo, Output } from './interfaces';
8
- import { RawDataParser } from '../pipeline/raw-data-parser';
9
- import { Validator } from '../helpers/validator/validator';
10
- import { CustomValidatorHelper } from '../helpers/validator/custom-validator-helper/custom-validator.helper';
11
- import { DefinitionStore } from './definition-store';
12
- import { DefinitionComponentClassType, DefinitionComponentMeta } from '../decorators/definition-component';
13
- import { Context } from './context';
14
-
15
- export const ConfigDefinitionComponentName = 'CONFIG';
16
- const KeyValueRegex = /^[a-z]+([a-zA-Z0-9]+)*$/;
17
-
18
- export class Kernel {
19
- static async process(modules: DefinitionComponentClassType<any>[], interfaces: string): Promise<void> {
20
- DefinitionStore['setComponentNames']([
21
- ConfigDefinitionComponentName,
22
- ...modules.map(module => (<any>module).$meta.componentName)
23
- ]);
24
-
25
- Context.compilerExecutionPath = path.resolve('./').replace(/\\/g, '/');
26
- Context.outputPath = `${Context.compilerExecutionPath}/.asset-build`;
27
- Context.files = glob.sync(`${Context.compilerExecutionPath}/**/*.md`).map(filePath => {
28
- let content = fs.readFileSync(filePath).toString();
29
- let fileInfo: FileInfo = { path: filePath, content };
30
- return fileInfo;
31
- });
32
-
33
- let outputFiles = await this.generateOutputFiles(modules, interfaces);
34
- rimraf.sync(Context.outputPath); // Remove the output folder if it exists
35
- outputFiles.forEach(outputFile => {
36
- let fullPath = Context.outputPath + outputFile.path;
37
- let folderPath = fullPath.substring(0, fullPath.lastIndexOf('/'));
38
- fs.mkdirSync(folderPath, { recursive: true });
39
- fs.writeFileSync(fullPath, outputFile.content);
40
- });
41
- }
42
-
43
- private static async generateOutputFiles(
44
- modules: DefinitionComponentClassType<any>[],
45
- interfaces: string
46
- ): Promise<FileInfo[]> {
47
- Context.output.push({
48
- path: '/index.ts',
49
- content: interfaces
50
- });
51
-
52
- RawDataParser.process();
53
- let preparedItems = modules.map(ModuleClass => {
54
- let meta: DefinitionComponentMeta = (<any>ModuleClass).$meta;
55
-
56
- let output: Output = {
57
- addFile: (fileInfo: FileInfo) => {
58
- Context.output.push(fileInfo);
59
- },
60
- addError: (errorLog: ErrorLog) => {
61
- Context.errorLogs.push(errorLog);
62
- }
63
- };
64
-
65
- this.iterateOnKeyNames(meta.keyName, meta.componentName, ModuleClass);
66
-
67
- let definitions: any[];
68
- if (meta.singleton) {
69
- definitions = Validator.validateAndConvertSingular<any>(meta.componentName, meta.validationSchema) || [];
70
- } else {
71
- definitions = Validator.validateAndConvert<any>(meta.componentName, meta.validationSchema);
72
- }
73
-
74
- this.registerDefinitions(definitions, meta.keyName, ModuleClass);
75
-
76
- return {
77
- definitions,
78
- output,
79
- ModuleClass
80
- };
81
- });
82
-
83
- for (let preparedItem of preparedItems) {
84
- if (preparedItem.definitions) {
85
- let module = new preparedItem.ModuleClass();
86
- await module.process(preparedItem.definitions, preparedItem.output);
87
- }
88
- }
89
-
90
- CustomValidatorHelper.logDuplicates();
91
- return this.getOutputFiles();
92
- }
93
-
94
- private static iterateOnKeyNames(
95
- keyName: string | undefined,
96
- componentName: string,
97
- ModuleClass: DefinitionComponentClassType<any>
98
- ): void {
99
- let rawDefinitions = Validator.getRawDefinitions(componentName);
100
- if (keyName) {
101
- rawDefinitions.forEach(rawDefinition => {
102
- let rootRawData = rawDefinition.parsedStructure.rawData;
103
- if (!Comparator.isObject(rootRawData) || Comparator.isArray(rootRawData)) {
104
- Context.errorLogs.push({
105
- description: `KeyName shold not be used with a content which is not an object, keyName: "${keyName}" in "${componentName}"`,
106
- location: { line: rawDefinition.parsedStructure.line, path: rawDefinition.location.path }
107
- });
108
- } else {
109
- let keyValue = rootRawData[keyName]?.rawData;
110
- if (!Comparator.isString(keyValue)) {
111
- // Do nothing, joi validation will log the errors
112
- } else if (KeyValueRegex.test(keyValue) === false) {
113
- Context.errorLogs.push({
114
- description: `KeyName should be a valid key, keyName: "${keyName}" in "${componentName}"`,
115
- location: { line: rootRawData[keyName].line, path: rawDefinition.location.path }
116
- });
117
- } else if (DefinitionStore['isRawDefinitionExists'](ModuleClass, keyValue)) {
118
- Context.errorLogs.push({
119
- description: `Definition with key "${keyValue}" already exists in "${componentName}"`,
120
- location: { line: rootRawData[keyName].line, path: rawDefinition.location.path }
121
- });
122
- } else {
123
- DefinitionStore['setRawDefinition'](ModuleClass, keyValue, rawDefinition);
124
- }
125
- }
126
- });
127
- }
128
- }
129
-
130
- private static registerDefinitions(
131
- definitions: any[],
132
- keyName: string | undefined,
133
- ModuleClass: DefinitionComponentClassType<any>
134
- ): void {
135
- if (keyName) {
136
- definitions.forEach((definition: any) => {
137
- let definitionName: string = definition[keyName];
138
- DefinitionStore['setDefinition'](ModuleClass, definitionName, definition);
139
- });
140
- }
141
- }
142
-
143
- private static getOutputFiles(): FileInfo[] {
144
- if (Context.errorLogs.length === 0) {
145
- console.dir('Definition generation completed without errors.');
146
- return Context.output;
147
- } else {
148
- console.dir(
149
- Context.errorLogs.map(log => ({
150
- description: log.description,
151
- location: `${log.location.path}:${log.location.line}`
152
- })),
153
- { depth: undefined }
154
- );
155
- return [
156
- {
157
- path: '/error-logs.md',
158
- content: Context.errorLogs
159
- .map(
160
- errorLog => `${errorLog.description}\r\nPath: '${errorLog.location.path}', Line: '${errorLog.location.line}'\r\n`
161
- )
162
- .join('\r\n')
163
- }
164
- ];
165
- }
166
- }
167
- }
@@ -1,54 +0,0 @@
1
- import { describe, expect, test } from 'vitest';
2
-
3
- import { CommonFunctions } from './common-functions';
4
-
5
- describe('COMMON FUNCTIONS', () => {
6
- test('kabab case to camel case', () => {
7
- expect(CommonFunctions.kebabCaseToCamelCase('')).toEqual('');
8
- expect(CommonFunctions.kebabCaseToCamelCase('text')).toEqual('text');
9
- expect(CommonFunctions.kebabCaseToCamelCase('TEXT')).toEqual('text');
10
- expect(CommonFunctions.kebabCaseToCamelCase('text-asdf')).toEqual('textAsdf');
11
- expect(CommonFunctions.kebabCaseToCamelCase('TEXT-ASDF')).toEqual('textAsdf');
12
- });
13
-
14
- test('lower case first letter', () => {
15
- expect(CommonFunctions.lowerCaseFirstLetter('')).toEqual('');
16
- expect(CommonFunctions.lowerCaseFirstLetter('text')).toEqual('text');
17
- expect(CommonFunctions.lowerCaseFirstLetter(' ')).toEqual(' ');
18
- expect(CommonFunctions.lowerCaseFirstLetter('Text')).toEqual('text');
19
- expect(CommonFunctions.lowerCaseFirstLetter(' Text')).toEqual(' Text');
20
- });
21
-
22
- test('upper case first letter', () => {
23
- expect(CommonFunctions.upperCaseFirstLetter('')).toEqual('');
24
- expect(CommonFunctions.upperCaseFirstLetter('Text')).toEqual('Text');
25
- expect(CommonFunctions.upperCaseFirstLetter(' ')).toEqual(' ');
26
- expect(CommonFunctions.upperCaseFirstLetter('text')).toEqual('Text');
27
- expect(CommonFunctions.upperCaseFirstLetter(' text')).toEqual(' text');
28
- });
29
-
30
- test('remove whitespace', () => {
31
- expect(CommonFunctions.removeWhiteSpace('')).toEqual('');
32
- expect(CommonFunctions.removeWhiteSpace('text')).toEqual('text');
33
- expect(CommonFunctions.removeWhiteSpace(' text')).toEqual('text');
34
- expect(CommonFunctions.removeWhiteSpace('text ')).toEqual('text');
35
- expect(CommonFunctions.removeWhiteSpace('text\n')).toEqual('text');
36
- expect(CommonFunctions.removeWhiteSpace('text\r')).toEqual('text');
37
- expect(CommonFunctions.removeWhiteSpace('text\r\n')).toEqual('text');
38
- expect(CommonFunctions.removeWhiteSpace('text//')).toEqual('text');
39
- expect(CommonFunctions.removeWhiteSpace('text //')).toEqual('text');
40
- expect(CommonFunctions.removeWhiteSpace('text // asdf')).toEqual('text');
41
- expect(CommonFunctions.removeWhiteSpace('text text')).toEqual('text text');
42
- expect(CommonFunctions.removeWhiteSpace('text text')).toEqual('text text');
43
- });
44
-
45
- test('remove comments', () => {
46
- expect(CommonFunctions.removeComments('')).toEqual('');
47
- expect(CommonFunctions.removeComments('text')).toEqual('text');
48
- expect(CommonFunctions.removeComments(' text ')).toEqual(' text');
49
- expect(CommonFunctions.removeComments(' text//')).toEqual(' text');
50
- expect(CommonFunctions.removeComments(' text //')).toEqual(' text');
51
- expect(CommonFunctions.removeComments(' text // asdf')).toEqual(' text');
52
- expect(CommonFunctions.removeComments('- Symbol: □ // Dirt\n')).toEqual('- Symbol: □');
53
- });
54
- });