tshex-cli 1.0.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 (39) hide show
  1. package/LICENSE +21 -0
  2. package/build/main.js +84 -0
  3. package/package.json +30 -0
  4. package/readme.md +53 -0
  5. package/source/index.d.ts +0 -0
  6. package/source/main.ts +137 -0
  7. package/templates/cls.example +50 -0
  8. package/templates/ctx/adapters/.gitkeep +0 -0
  9. package/templates/ctx/application/.gitkeep +0 -0
  10. package/templates/ctx/domain/.gitkeep +0 -0
  11. package/templates/ctx/index.ts +9 -0
  12. package/templates/ctx/ports/.gitkeep +0 -0
  13. package/templates/lib/index.d.ts +1 -0
  14. package/templates/lib/main.ts +5 -0
  15. package/templates/lib/shared/adapters/.gitkeep +0 -0
  16. package/templates/lib/shared/application/DataTransferObject.ts +46 -0
  17. package/templates/lib/shared/application/Facade.ts +47 -0
  18. package/templates/lib/shared/application/Logger.ts +54 -0
  19. package/templates/lib/shared/application/Response.ts +52 -0
  20. package/templates/lib/shared/application/data/DataManager.ts +50 -0
  21. package/templates/lib/shared/application/data/Repository.ts +55 -0
  22. package/templates/lib/shared/application/errors/.gitkeep +0 -0
  23. package/templates/lib/shared/application/events/Event.ts +56 -0
  24. package/templates/lib/shared/application/events/EventDispatcher.ts +55 -0
  25. package/templates/lib/shared/application/events/EventHandler.ts +50 -0
  26. package/templates/lib/shared/constants/.gitkeep +0 -0
  27. package/templates/lib/shared/domain/Entity.ts +50 -0
  28. package/templates/lib/shared/domain/Service.ts +48 -0
  29. package/templates/lib/shared/domain/errors/ValueError.ts +69 -0
  30. package/templates/lib/shared/domain/utils/.gitkeep +0 -0
  31. package/templates/lib/shared/domain/value-objects/BooleanValueObject.ts +87 -0
  32. package/templates/lib/shared/domain/value-objects/DateValueObject.ts +100 -0
  33. package/templates/lib/shared/domain/value-objects/EmailValueObject.ts +89 -0
  34. package/templates/lib/shared/domain/value-objects/NullableBooleanValueObject.ts +87 -0
  35. package/templates/lib/shared/domain/value-objects/NumericValueObject.ts +136 -0
  36. package/templates/lib/shared/domain/value-objects/StringValueObject.ts +87 -0
  37. package/templates/lib/shared/domain/value-objects/SymbolValueObject.ts +82 -0
  38. package/templates/lib/shared/domain/value-objects/ValueObject.ts +57 -0
  39. package/templates/rfc.example +42 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 virtualitems
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/build/main.js ADDED
@@ -0,0 +1,84 @@
1
+ #!/usr/bin/env node
2
+ import { program } from 'commander';
3
+ import fs from 'fs';
4
+ import path from 'path';
5
+ program
6
+ .name('tshex')
7
+ .version('1.0.0')
8
+ .option('--lib <name>', 'creates a new library with it\'s shared directory')
9
+ .option('--ctx <name>', 'creates a new context')
10
+ .option('--cls <name>', 'creates a new class')
11
+ .option('--rfc <name>', 'creates a new react functional component')
12
+ .option('--dir <path>', 'sets the directory to create the new item')
13
+ .parse(process.argv);
14
+ function executeCreateLib(templatesDir, libraryDir) {
15
+ try {
16
+ fs.cpSync(path.join(templatesDir, 'lib'), libraryDir, {
17
+ recursive: true,
18
+ filter: function (src) { return (!src.endsWith('.gitkeep')); }
19
+ });
20
+ console.log('Library created successfully');
21
+ }
22
+ catch (err) {
23
+ console.error(err);
24
+ }
25
+ }
26
+ function executeCreateContext(templatesDir, contextDir) {
27
+ try {
28
+ fs.cpSync(path.join(templatesDir, 'ctx'), contextDir, {
29
+ recursive: true,
30
+ filter: function (src) { return (!src.endsWith('.gitkeep')); }
31
+ });
32
+ console.log('Context created successfully');
33
+ }
34
+ catch (err) {
35
+ console.error(err);
36
+ }
37
+ }
38
+ function executeCreateClass(templatesDir, classDir) {
39
+ try {
40
+ fs.cpSync(path.join(templatesDir, 'cls.example'), classDir, {});
41
+ console.log('Class created successfully');
42
+ }
43
+ catch (err) {
44
+ console.error(err);
45
+ }
46
+ }
47
+ function executeCreateReactFunctionalComponent(templatesDir, classDir) {
48
+ try {
49
+ fs.cpSync(path.join(templatesDir, 'rfc.example'), classDir, {});
50
+ console.log('React component created successfully');
51
+ }
52
+ catch (err) {
53
+ console.error(err);
54
+ }
55
+ }
56
+ (function () {
57
+ var _a;
58
+ var templatesDir = path.join(import.meta.dirname, '..', 'templates');
59
+ var options = program.opts();
60
+ var targetDir = path.resolve((_a = options.dir) !== null && _a !== void 0 ? _a : process.cwd());
61
+ if (Object.keys(options).length === 0) {
62
+ program.help();
63
+ return;
64
+ }
65
+ if (!fs.existsSync(targetDir)) {
66
+ fs.mkdirSync(targetDir, { recursive: true });
67
+ }
68
+ if (options.lib !== undefined) {
69
+ targetDir = path.join(targetDir, options.lib);
70
+ executeCreateLib(templatesDir, targetDir);
71
+ }
72
+ if (options.ctx !== undefined) {
73
+ targetDir = path.join(targetDir, options.ctx);
74
+ executeCreateContext(templatesDir, targetDir);
75
+ }
76
+ if (options.cls !== undefined) {
77
+ var target = path.join(targetDir, options.cls + '.ts');
78
+ executeCreateClass(templatesDir, target);
79
+ }
80
+ if (options.rfc !== undefined) {
81
+ var target = path.join(targetDir, options.rfc + '.tsx');
82
+ executeCreateReactFunctionalComponent(templatesDir, target);
83
+ }
84
+ })();
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "tshex-cli",
3
+ "version": "1.0.2",
4
+ "author": "https://github.com/virtualitems/",
5
+ "description": "Typescript Hexagonal Architecture CLI",
6
+ "type": "module",
7
+ "main": "./build/main.js",
8
+ "files": [
9
+ "./build",
10
+ "./source",
11
+ "./templates"
12
+ ],
13
+ "types": "./source/index.d.ts",
14
+ "scripts": {
15
+ "build": "tsc && tsc-alias",
16
+ "dev": "tsc -w"
17
+ },
18
+ "devDependencies": {
19
+ "@types/commander": "^2.12.0",
20
+ "@types/node": "^22.5.4",
21
+ "tsc-alias": "^1.8.10",
22
+ "typescript": "^5.4.5"
23
+ },
24
+ "dependencies": {
25
+ "commander": "^12.1.0"
26
+ },
27
+ "bin": {
28
+ "tshex": "./build/main.js"
29
+ }
30
+ }
package/readme.md ADDED
@@ -0,0 +1,53 @@
1
+ # Hexagonal Architecture CLI
2
+
3
+ This CLI will help you to generate a hexagonal architecture structure.
4
+
5
+ # Installation
6
+
7
+ ```bash
8
+ npm install -g tshex-cli
9
+ ```
10
+
11
+ # Usage
12
+
13
+ ## Help
14
+
15
+ ```bash
16
+ tshex -h
17
+
18
+ tshex --help
19
+ ```
20
+
21
+ ## Create a new library
22
+
23
+ ```bash
24
+ tshex --lib <name>
25
+ ```
26
+
27
+ ## Create a new context
28
+
29
+ ```bash
30
+ tshex --ctx <name>
31
+ ```
32
+
33
+ ## Create a new class
34
+
35
+ ```bash
36
+ tshex --cls <name>
37
+ ```
38
+
39
+ ## Create a new react functional component
40
+
41
+ ```bash
42
+ tshex --rfc <name>
43
+ ```
44
+
45
+ ## Set the directory to create the new items
46
+
47
+ ```bash
48
+ tshex --lib <name> --ctx <name> --dir <path>
49
+ ```
50
+
51
+ # example
52
+
53
+ https://github.com/virtualitems/typescript-codebase/tree/hexagonal-example
File without changes
package/source/main.ts ADDED
@@ -0,0 +1,137 @@
1
+ #!/usr/bin/env node
2
+
3
+ // NPM LIBRARIES
4
+
5
+ import { program } from 'commander';
6
+
7
+
8
+ // NODE LIBRARIES
9
+
10
+ import fs from 'fs';
11
+ import path from 'path';
12
+
13
+
14
+ // COMMANDER SETUP
15
+
16
+ program
17
+ .name('tshex')
18
+ .version('1.0.0')
19
+ .option('--lib <name>', 'creates a new library with it\'s shared directory')
20
+ .option('--ctx <name>', 'creates a new context')
21
+ .option('--cls <name>', 'creates a new class')
22
+ .option('--rfc <name>', 'creates a new react functional component')
23
+ .option('--dir <path>', 'sets the directory to create the new item')
24
+ .parse(process.argv);
25
+
26
+
27
+ // FUNCTIONS
28
+
29
+ function executeCreateLib(templatesDir: string, libraryDir: string)
30
+ {
31
+ try {
32
+ fs.cpSync(
33
+ path.join(templatesDir, 'lib'),
34
+ libraryDir,
35
+ {
36
+ recursive: true,
37
+ filter: (src) => (!src.endsWith('.gitkeep'))
38
+ },
39
+ );
40
+ console.log('Library created successfully');
41
+ }
42
+ catch (err) {
43
+ console.error(err);
44
+ }
45
+ }
46
+
47
+
48
+ function executeCreateContext(templatesDir: string, contextDir: string)
49
+ {
50
+ try {
51
+ fs.cpSync(
52
+ path.join(templatesDir, 'ctx'),
53
+ contextDir,
54
+ {
55
+ recursive: true,
56
+ filter: (src) => (!src.endsWith('.gitkeep'))
57
+ },
58
+ );
59
+ console.log('Context created successfully');
60
+ }
61
+ catch (err) {
62
+ console.error(err);
63
+ }
64
+ }
65
+
66
+
67
+ function executeCreateClass(templatesDir: string, classDir: string)
68
+ {
69
+ try {
70
+ fs.cpSync(
71
+ path.join(templatesDir, 'cls.example'),
72
+ classDir,
73
+ {},
74
+ );
75
+ console.log('Class created successfully');
76
+ } catch (err) {
77
+ console.error(err);
78
+ }
79
+ }
80
+
81
+
82
+ function executeCreateReactFunctionalComponent(templatesDir: string, classDir: string)
83
+ {
84
+ try {
85
+ fs.cpSync(
86
+ path.join(templatesDir, 'rfc.example'),
87
+ classDir,
88
+ {},
89
+ );
90
+ console.log('React component created successfully');
91
+ } catch (err) {
92
+ console.error(err);
93
+ }
94
+ }
95
+
96
+
97
+ // CLIENT CODE
98
+
99
+ (function ()
100
+ {
101
+
102
+ const templatesDir = path.join(import.meta.dirname, '..', 'templates');
103
+
104
+ const options = program.opts();
105
+
106
+ let targetDir = path.resolve(options.dir ?? process.cwd());
107
+
108
+ if (Object.keys(options).length === 0) {
109
+ program.help();
110
+ return;
111
+ }
112
+
113
+ if (!fs.existsSync(targetDir)) {
114
+ fs.mkdirSync(targetDir, { recursive: true });
115
+ }
116
+
117
+ if (options.lib !== undefined) {
118
+ targetDir = path.join(targetDir, options.lib);
119
+ executeCreateLib(templatesDir, targetDir);
120
+ }
121
+
122
+ if (options.ctx !== undefined) {
123
+ targetDir = path.join(targetDir, options.ctx);
124
+ executeCreateContext(templatesDir, targetDir);
125
+ }
126
+
127
+ if (options.cls !== undefined) {
128
+ const target = path.join(targetDir, options.cls + '.ts');
129
+ executeCreateClass(templatesDir, target);
130
+ }
131
+
132
+ if (options.rfc !== undefined) {
133
+ const target = path.join(targetDir, options.rfc + '.tsx');
134
+ executeCreateReactFunctionalComponent(templatesDir, target);
135
+ }
136
+
137
+ })();
@@ -0,0 +1,50 @@
1
+ // Libraries
2
+
3
+ // Shared Module
4
+
5
+ // Other Modules
6
+
7
+ // Same Layer
8
+
9
+ // Lower Layers
10
+
11
+ // Types
12
+
13
+ // Constants
14
+
15
+
16
+ /**
17
+ * @description
18
+ */
19
+ export default class __CLASS__ extends __DECLARE_FIRST__OVERRIDE_SECOND__ABSTRACT_LAST__
20
+ {
21
+
22
+ [property: string]: unknown;
23
+
24
+ // public ATTRIBUTES
25
+
26
+ // protected ATTRIBUTES
27
+
28
+ // private ATTRIBUTES
29
+
30
+ // public static ATTRIBUTES
31
+
32
+ // protected static ATTRIBUTES
33
+
34
+ // private static ATTRIBUTES
35
+
36
+ // Constructor, Getters, Setters
37
+
38
+ // public METHODS
39
+
40
+ // protected METHODS
41
+
42
+ // private METHODS
43
+
44
+ // public static METHODS
45
+
46
+ // protected static METHODS
47
+
48
+ // private static METHODS
49
+
50
+ } //:: class
File without changes
File without changes
File without changes
@@ -0,0 +1,9 @@
1
+ // Ports layer
2
+
3
+ // Adapters layer
4
+
5
+ // Application layer
6
+
7
+ // Domain layer
8
+
9
+ // Constants
File without changes
@@ -0,0 +1 @@
1
+ type Generic<T=unknown> = Record<string, T>;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @fileoverview This file is used only for exporting the main components of the library.
3
+ */
4
+
5
+ throw new Error('Not implemented yet');
File without changes
@@ -0,0 +1,46 @@
1
+ // Libraries
2
+
3
+ // Same Layer
4
+
5
+ // Lower Layers
6
+
7
+ // Types
8
+
9
+ // Constants
10
+
11
+
12
+ /**
13
+ * @description
14
+ */
15
+ export default abstract class DataTransferObject
16
+ {
17
+
18
+ [property: string]: unknown;
19
+
20
+ // public ATTRIBUTES
21
+
22
+ // protected ATTRIBUTES
23
+
24
+ // private ATTRIBUTES
25
+
26
+ // public static ATTRIBUTES
27
+
28
+ // protected static ATTRIBUTES
29
+
30
+ // private static ATTRIBUTES
31
+
32
+ // Constructor, Getters, Setters
33
+
34
+ // public METHODS
35
+
36
+ // protected METHODS
37
+
38
+ // private METHODS
39
+
40
+ // public static METHODS
41
+
42
+ // protected static METHODS
43
+
44
+ // private static METHODS
45
+
46
+ } //:: class
@@ -0,0 +1,47 @@
1
+ // Libraries
2
+
3
+ // Same Layer
4
+
5
+ // Lower Layers
6
+
7
+ // Types
8
+
9
+ // Constants
10
+
11
+
12
+ /**
13
+ * @description
14
+ * function arguments are Entity
15
+ */
16
+ export default abstract class Facade
17
+ {
18
+
19
+ [property: string]: unknown;
20
+
21
+ // public ATTRIBUTES
22
+
23
+ // protected ATTRIBUTES
24
+
25
+ // private ATTRIBUTES
26
+
27
+ // public static ATTRIBUTES
28
+
29
+ // protected static ATTRIBUTES
30
+
31
+ // private static ATTRIBUTES
32
+
33
+ // Constructor, Getters, Setters
34
+
35
+ // public METHODS
36
+
37
+ // protected METHODS
38
+
39
+ // private METHODS
40
+
41
+ // public static METHODS
42
+
43
+ // protected static METHODS
44
+
45
+ // private static METHODS
46
+
47
+ } //:: class
@@ -0,0 +1,54 @@
1
+ // Libraries
2
+
3
+ // Same Layer
4
+
5
+ // Lower Layers
6
+
7
+ // Types
8
+
9
+ // Constants
10
+
11
+
12
+ /**
13
+ * @description
14
+ */
15
+ export default abstract class Logger
16
+ {
17
+
18
+ [property: string]: unknown;
19
+
20
+ // public ATTRIBUTES
21
+
22
+ // protected ATTRIBUTES
23
+
24
+ // private ATTRIBUTES
25
+
26
+ // public static ATTRIBUTES
27
+
28
+ // protected static ATTRIBUTES
29
+
30
+ // private static ATTRIBUTES
31
+
32
+ // Constructor, Getters, Setters
33
+
34
+ // public METHODS
35
+
36
+ public abstract debug(message: string): void;
37
+
38
+ public abstract info(message: string): void;
39
+
40
+ public abstract warning(message: string): void;
41
+
42
+ public abstract error(message: string): void;
43
+
44
+ // protected METHODS
45
+
46
+ // private METHODS
47
+
48
+ // public static METHODS
49
+
50
+ // protected static METHODS
51
+
52
+ // private static METHODS
53
+
54
+ } //:: class
@@ -0,0 +1,52 @@
1
+ // Libraries
2
+
3
+ // Same Layer
4
+
5
+ // Lower Layers
6
+
7
+ // Types
8
+
9
+ // Constants
10
+
11
+
12
+ /**
13
+ * @description
14
+ */
15
+ export default class Response
16
+ {
17
+
18
+ [property: string]: unknown;
19
+
20
+ // public ATTRIBUTES
21
+
22
+ // protected ATTRIBUTES
23
+
24
+ // private ATTRIBUTES
25
+
26
+ // public static ATTRIBUTES
27
+
28
+ // protected static ATTRIBUTES
29
+
30
+ // private static ATTRIBUTES
31
+
32
+ // Constructor, Getters, Setters
33
+
34
+ public constructor(
35
+ public readonly data: unknown,
36
+ public readonly error: unknown,
37
+ public readonly message: unknown,
38
+ ) { }
39
+
40
+ // public METHODS
41
+
42
+ // protected METHODS
43
+
44
+ // private METHODS
45
+
46
+ // public static METHODS
47
+
48
+ // protected static METHODS
49
+
50
+ // private static METHODS
51
+
52
+ } //:: class
@@ -0,0 +1,50 @@
1
+ // Libraries
2
+
3
+ // Same Layer
4
+
5
+ // Lower Layers
6
+
7
+ // Types
8
+
9
+ // Constants
10
+
11
+
12
+ /**
13
+ * @description
14
+ */
15
+ export default abstract class DataManager
16
+ {
17
+
18
+ [property: string]: unknown;
19
+
20
+ // Public Attributes
21
+
22
+ // Protected Attributes
23
+
24
+ // Private Attributes
25
+
26
+ // Public Static Attributes
27
+
28
+ // Protected Static Attributes
29
+
30
+ // Private Static Attributes
31
+
32
+ // Constructor, Getters, Setters
33
+
34
+ // Public Methods
35
+
36
+ public abstract connect(...args: unknown[]): Promise<unknown>;
37
+
38
+ public abstract disconnect(): Promise<unknown>;
39
+
40
+ // Protected Methods
41
+
42
+ // Private Methods
43
+
44
+ // Public Static Methods
45
+
46
+ // Protected Static Methods
47
+
48
+ // Private Static Methods
49
+
50
+ } //:: class