tshex-cli 1.0.12 → 1.0.14
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.
- package/LICENSE +21 -21
- package/build/main.js +60 -84
- package/package.json +50 -52
- package/readme.md +75 -75
- package/source/main.ts +84 -137
- package/templates/ctx/index.ts +9 -9
- package/templates/lib/index.d.ts +1 -1
- package/templates/lib/main.ts +5 -5
- package/templates/lib/shared/application/databases.ts +81 -0
- package/templates/lib/shared/application/events.ts +121 -0
- package/templates/lib/shared/application/{Response.ts → http.ts} +48 -52
- package/templates/{cls.example → lib/shared/application/loggers.ts} +50 -50
- package/templates/lib/shared/application/{Service.ts → services.ts} +43 -47
- package/templates/lib/shared/domain/{Aggregate.ts → aggregates.ts} +44 -48
- package/templates/lib/shared/domain/{Entity.ts → entities.ts} +46 -50
- package/templates/lib/shared/{application/DataTransferObject.ts → domain/errors.ts} +46 -46
- package/templates/lib/shared/domain/value-objects.ts +194 -0
- package/templates/ctx/ports/.gitkeep +0 -0
- package/templates/lib/shared/adapters/.gitkeep +0 -0
- package/templates/lib/shared/application/Logger.ts +0 -54
- package/templates/lib/shared/application/data/DataManager.ts +0 -50
- package/templates/lib/shared/application/data/Repository.ts +0 -55
- package/templates/lib/shared/application/errors/.gitkeep +0 -0
- package/templates/lib/shared/application/events/Event.ts +0 -56
- package/templates/lib/shared/application/events/EventDispatcher.ts +0 -55
- package/templates/lib/shared/application/events/EventHandler.ts +0 -50
- package/templates/lib/shared/constants/.gitkeep +0 -0
- package/templates/lib/shared/domain/errors/ValueError.ts +0 -69
- package/templates/lib/shared/domain/utils/.gitkeep +0 -0
- package/templates/lib/shared/domain/value-objects/BooleanValueObject.ts +0 -87
- package/templates/lib/shared/domain/value-objects/DateValueObject.ts +0 -100
- package/templates/lib/shared/domain/value-objects/EmailValueObject.ts +0 -89
- package/templates/lib/shared/domain/value-objects/NullableBooleanValueObject.ts +0 -87
- package/templates/lib/shared/domain/value-objects/NumericValueObject.ts +0 -136
- package/templates/lib/shared/domain/value-objects/StringValueObject.ts +0 -87
- package/templates/lib/shared/domain/value-objects/SymbolValueObject.ts +0 -82
- package/templates/lib/shared/domain/value-objects/ValueObject.ts +0 -57
- package/templates/rfc.example +0 -42
package/LICENSE
CHANGED
|
@@ -1,21 +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.
|
|
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
CHANGED
|
@@ -1,84 +1,60 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { program } from 'commander';
|
|
3
|
-
import fs from 'fs';
|
|
4
|
-
import path from 'path';
|
|
5
|
-
|
|
6
|
-
.
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
(
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
|
-
})();
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { program } from 'commander';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
function readPackageJson() {
|
|
6
|
+
return JSON.parse(fs.readFileSync(path.join(import.meta.dirname, '..', 'package.json'), 'utf-8'));
|
|
7
|
+
}
|
|
8
|
+
function executeCreateLib(templatesDir, libraryDir) {
|
|
9
|
+
try {
|
|
10
|
+
fs.cpSync(path.join(templatesDir, 'lib'), libraryDir, {
|
|
11
|
+
recursive: true,
|
|
12
|
+
filter: (src) => !src.endsWith('.gitkeep')
|
|
13
|
+
});
|
|
14
|
+
console.log('Library created successfully');
|
|
15
|
+
}
|
|
16
|
+
catch (err) {
|
|
17
|
+
console.error(err);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function executeCreateContext(templatesDir, contextDir) {
|
|
21
|
+
try {
|
|
22
|
+
fs.cpSync(path.join(templatesDir, 'ctx'), contextDir, {
|
|
23
|
+
recursive: true,
|
|
24
|
+
filter: (src) => !src.endsWith('.gitkeep')
|
|
25
|
+
});
|
|
26
|
+
console.log('Context created successfully');
|
|
27
|
+
}
|
|
28
|
+
catch (err) {
|
|
29
|
+
console.error(err);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function main(program) {
|
|
33
|
+
const templatesDir = path.join(import.meta.dirname, '..', 'templates');
|
|
34
|
+
const options = program.opts();
|
|
35
|
+
let targetDir = path.resolve(options.dir ?? process.cwd());
|
|
36
|
+
if (Object.keys(options).length === 0) {
|
|
37
|
+
program.help();
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
if (!fs.existsSync(targetDir)) {
|
|
41
|
+
fs.mkdirSync(targetDir, { recursive: true });
|
|
42
|
+
}
|
|
43
|
+
if (options.lib !== undefined) {
|
|
44
|
+
targetDir = path.join(targetDir, options.lib);
|
|
45
|
+
executeCreateLib(templatesDir, targetDir);
|
|
46
|
+
}
|
|
47
|
+
if (options.ctx !== undefined) {
|
|
48
|
+
targetDir = path.join(targetDir, options.ctx);
|
|
49
|
+
executeCreateContext(templatesDir, targetDir);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const packageJson = readPackageJson();
|
|
53
|
+
program
|
|
54
|
+
.name('tshex')
|
|
55
|
+
.version(packageJson.version)
|
|
56
|
+
.option('--lib <name>', "creates a new library with it's shared directory")
|
|
57
|
+
.option('--ctx <name>', 'creates a new context')
|
|
58
|
+
.option('--dir <path>', 'sets the directory to create the new item')
|
|
59
|
+
.parse(process.argv);
|
|
60
|
+
main(program);
|
package/package.json
CHANGED
|
@@ -1,52 +1,50 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "tshex-cli",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"author": "https://github.com/virtualitems/",
|
|
5
|
-
"description": "Typescript Hexagonal Architecture CLI",
|
|
6
|
-
"type": "module",
|
|
7
|
-
"main": "./build/main.js",
|
|
8
|
-
"keywords": [
|
|
9
|
-
"architecture",
|
|
10
|
-
"clean-architecture",
|
|
11
|
-
"clean",
|
|
12
|
-
"cli",
|
|
13
|
-
"ddd",
|
|
14
|
-
"design-patterns",
|
|
15
|
-
"design",
|
|
16
|
-
"domain-driven-design",
|
|
17
|
-
"hexagonal",
|
|
18
|
-
"pattern",
|
|
19
|
-
"software-architecture",
|
|
20
|
-
"tshex",
|
|
21
|
-
"tshex-cli",
|
|
22
|
-
"typescript",
|
|
23
|
-
"virtualitems"
|
|
24
|
-
],
|
|
25
|
-
"homepage": "https://github.com/virtualitems/tshex-cli",
|
|
26
|
-
"bugs": {
|
|
27
|
-
"url": "https://github.com/virtualitems/tshex-cli/issues"
|
|
28
|
-
},
|
|
29
|
-
"files": [
|
|
30
|
-
"./build",
|
|
31
|
-
"./source",
|
|
32
|
-
"./templates"
|
|
33
|
-
],
|
|
34
|
-
"types": "./source/index.d.ts",
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
"
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
"
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "tshex-cli",
|
|
3
|
+
"version": "1.0.14",
|
|
4
|
+
"author": "https://github.com/virtualitems/",
|
|
5
|
+
"description": "Typescript Hexagonal Architecture CLI",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./build/main.js",
|
|
8
|
+
"keywords": [
|
|
9
|
+
"architecture",
|
|
10
|
+
"clean-architecture",
|
|
11
|
+
"clean",
|
|
12
|
+
"cli",
|
|
13
|
+
"ddd",
|
|
14
|
+
"design-patterns",
|
|
15
|
+
"design",
|
|
16
|
+
"domain-driven-design",
|
|
17
|
+
"hexagonal",
|
|
18
|
+
"pattern",
|
|
19
|
+
"software-architecture",
|
|
20
|
+
"tshex",
|
|
21
|
+
"tshex-cli",
|
|
22
|
+
"typescript",
|
|
23
|
+
"virtualitems"
|
|
24
|
+
],
|
|
25
|
+
"homepage": "https://github.com/virtualitems/tshex-cli",
|
|
26
|
+
"bugs": {
|
|
27
|
+
"url": "https://github.com/virtualitems/tshex-cli/issues"
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"./build",
|
|
31
|
+
"./source",
|
|
32
|
+
"./templates"
|
|
33
|
+
],
|
|
34
|
+
"types": "./source/index.d.ts",
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@types/node": "^22.5.4",
|
|
37
|
+
"typescript": "^5.4.5"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"commander": "^12.1.0"
|
|
41
|
+
},
|
|
42
|
+
"bin": {
|
|
43
|
+
"tshex": "./build/main.js"
|
|
44
|
+
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"examples": "tsc -p examples",
|
|
47
|
+
"build": "tsc",
|
|
48
|
+
"dev": "tsc -w"
|
|
49
|
+
}
|
|
50
|
+
}
|
package/readme.md
CHANGED
|
@@ -1,76 +1,76 @@
|
|
|
1
|
-
# Hexagonal Architecture CLI
|
|
2
|
-
|
|
3
|
-
This CLI will help you to generate a hexagonal architecture structure.
|
|
4
|
-
|
|
5
|
-
# Why?
|
|
6
|
-
|
|
7
|
-
Hexagonal architecture is a software design pattern that separates the internal domain of the application from the external dependencies.. This separation is achieved by dividing the application into layers. Each layer has a specific responsibility and interacts with the other layers in a specific way.
|
|
8
|
-
|
|
9
|
-
Because what we are trying to achieve is a separation between the domain code and the installed dependencies, a Hexagonal Architecture Framework is a step in the opposite direction, as it couples the domain code with the framework. This is why we need a tool to help us to create the structure with our own codebase.
|
|
10
|
-
|
|
11
|
-
# Usage example
|
|
12
|
-
|
|
13
|
-
https://github.com/virtualitems/tshex-cli
|
|
14
|
-
|
|
15
|
-
# Note!!!
|
|
16
|
-
|
|
17
|
-
This tool and its templates are in constant development, so be aware that some changes may occur and be careful when updating the tool.
|
|
18
|
-
|
|
19
|
-
If you have any suggestions or improvements, please let me know.
|
|
20
|
-
|
|
21
|
-
https://github.com/virtualitems/tshex-cli/issues
|
|
22
|
-
|
|
23
|
-
# Installation
|
|
24
|
-
|
|
25
|
-
```bash
|
|
26
|
-
npm install -g tshex-cli
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
# Usage
|
|
30
|
-
|
|
31
|
-
> Remember to replace placeholders `<...>` with the actual data.
|
|
32
|
-
>
|
|
33
|
-
|
|
34
|
-
## Getting started
|
|
35
|
-
|
|
36
|
-
```bash
|
|
37
|
-
tshex --lib <library-name> --ctx <context-name>
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
## Help
|
|
41
|
-
|
|
42
|
-
```bash
|
|
43
|
-
tshex -h
|
|
44
|
-
|
|
45
|
-
tshex --help
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
## Create a new library
|
|
49
|
-
|
|
50
|
-
```bash
|
|
51
|
-
tshex --lib <name>
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
## Create a new context
|
|
55
|
-
|
|
56
|
-
```bash
|
|
57
|
-
tshex --ctx <name>
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
## Create a new class
|
|
61
|
-
|
|
62
|
-
```bash
|
|
63
|
-
tshex --cls <name>
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
## Create a new react functional component
|
|
67
|
-
|
|
68
|
-
```bash
|
|
69
|
-
tshex --rfc <name>
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
## Set the directory to create the new items
|
|
73
|
-
|
|
74
|
-
```bash
|
|
75
|
-
tshex --lib <lib-name> --ctx <ctx-name> --dir <path>
|
|
1
|
+
# Hexagonal Architecture CLI
|
|
2
|
+
|
|
3
|
+
This CLI will help you to generate a hexagonal architecture structure.
|
|
4
|
+
|
|
5
|
+
# Why?
|
|
6
|
+
|
|
7
|
+
Hexagonal architecture is a software design pattern that separates the internal domain of the application from the external dependencies.. This separation is achieved by dividing the application into layers. Each layer has a specific responsibility and interacts with the other layers in a specific way.
|
|
8
|
+
|
|
9
|
+
Because what we are trying to achieve is a separation between the domain code and the installed dependencies, a Hexagonal Architecture Framework is a step in the opposite direction, as it couples the domain code with the framework. This is why we need a tool to help us to create the structure with our own codebase.
|
|
10
|
+
|
|
11
|
+
# Usage example
|
|
12
|
+
|
|
13
|
+
https://github.com/virtualitems/tshex-cli
|
|
14
|
+
|
|
15
|
+
# Note!!!
|
|
16
|
+
|
|
17
|
+
This tool and its templates are in constant development, so be aware that some changes may occur and be careful when updating the tool.
|
|
18
|
+
|
|
19
|
+
If you have any suggestions or improvements, please let me know.
|
|
20
|
+
|
|
21
|
+
https://github.com/virtualitems/tshex-cli/issues
|
|
22
|
+
|
|
23
|
+
# Installation
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm install -g tshex-cli
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
# Usage
|
|
30
|
+
|
|
31
|
+
> Remember to replace placeholders `<...>` with the actual data.
|
|
32
|
+
>
|
|
33
|
+
|
|
34
|
+
## Getting started
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
tshex --lib <library-name> --ctx <context-name>
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Help
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
tshex -h
|
|
44
|
+
|
|
45
|
+
tshex --help
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Create a new library
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
tshex --lib <name>
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Create a new context
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
tshex --ctx <name>
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Create a new class
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
tshex --cls <name>
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Create a new react functional component
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
tshex --rfc <name>
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Set the directory to create the new items
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
tshex --lib <lib-name> --ctx <ctx-name> --dir <path>
|
|
76
76
|
```
|
package/source/main.ts
CHANGED
|
@@ -1,137 +1,84 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
// NPM LIBRARIES
|
|
4
|
-
|
|
5
|
-
import { program } from 'commander'
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
import
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
{
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
catch (err) {
|
|
43
|
-
console.error(err)
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
{
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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
|
-
})();
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// NPM LIBRARIES
|
|
4
|
+
|
|
5
|
+
import { program } from 'commander'
|
|
6
|
+
|
|
7
|
+
// NODE LIBRARIES
|
|
8
|
+
|
|
9
|
+
import fs from 'node:fs'
|
|
10
|
+
import path from 'node:path'
|
|
11
|
+
|
|
12
|
+
// FUNCTIONS
|
|
13
|
+
|
|
14
|
+
function readPackageJson() {
|
|
15
|
+
return JSON.parse(
|
|
16
|
+
fs.readFileSync(
|
|
17
|
+
path.join(import.meta.dirname, '..', 'package.json'),
|
|
18
|
+
'utf-8'
|
|
19
|
+
)
|
|
20
|
+
)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function executeCreateLib(templatesDir: string, libraryDir: string) {
|
|
24
|
+
try {
|
|
25
|
+
fs.cpSync(path.join(templatesDir, 'lib'), libraryDir, {
|
|
26
|
+
recursive: true,
|
|
27
|
+
filter: (src) => !src.endsWith('.gitkeep')
|
|
28
|
+
})
|
|
29
|
+
console.log('Library created successfully')
|
|
30
|
+
} catch (err) {
|
|
31
|
+
console.error(err)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function executeCreateContext(templatesDir: string, contextDir: string) {
|
|
36
|
+
try {
|
|
37
|
+
fs.cpSync(path.join(templatesDir, 'ctx'), contextDir, {
|
|
38
|
+
recursive: true,
|
|
39
|
+
filter: (src) => !src.endsWith('.gitkeep')
|
|
40
|
+
})
|
|
41
|
+
console.log('Context created successfully')
|
|
42
|
+
} catch (err) {
|
|
43
|
+
console.error(err)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function main(program: typeof import('commander').program) {
|
|
48
|
+
const templatesDir = path.join(import.meta.dirname, '..', 'templates')
|
|
49
|
+
|
|
50
|
+
const options = program.opts()
|
|
51
|
+
|
|
52
|
+
let targetDir = path.resolve(options.dir ?? process.cwd())
|
|
53
|
+
|
|
54
|
+
if (Object.keys(options).length === 0) {
|
|
55
|
+
program.help()
|
|
56
|
+
return
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (!fs.existsSync(targetDir)) {
|
|
60
|
+
fs.mkdirSync(targetDir, { recursive: true })
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (options.lib !== undefined) {
|
|
64
|
+
targetDir = path.join(targetDir, options.lib)
|
|
65
|
+
executeCreateLib(templatesDir, targetDir)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (options.ctx !== undefined) {
|
|
69
|
+
targetDir = path.join(targetDir, options.ctx)
|
|
70
|
+
executeCreateContext(templatesDir, targetDir)
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const packageJson = readPackageJson()
|
|
75
|
+
|
|
76
|
+
program
|
|
77
|
+
.name('tshex')
|
|
78
|
+
.version(packageJson.version)
|
|
79
|
+
.option('--lib <name>', "creates a new library with it's shared directory")
|
|
80
|
+
.option('--ctx <name>', 'creates a new context')
|
|
81
|
+
.option('--dir <path>', 'sets the directory to create the new item')
|
|
82
|
+
.parse(process.argv)
|
|
83
|
+
|
|
84
|
+
main(program)
|