tshex-cli 1.0.11 → 1.0.13

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/build/main.js CHANGED
@@ -1,84 +1,85 @@
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
- })();
1
+ #!/usr/bin/env node
2
+ import { program } from 'commander';
3
+ import fs from 'fs';
4
+ import path from 'path';
5
+ var packageJson = JSON.parse(fs.readFileSync(path.join(import.meta.dirname, '..', 'package.json'), 'utf-8'));
6
+ program
7
+ .name('tshex')
8
+ .version(packageJson.version)
9
+ .option('--lib <name>', 'creates a new library with it\'s shared directory')
10
+ .option('--ctx <name>', 'creates a new context')
11
+ .option('--cls <name>', 'creates a new class')
12
+ .option('--rfc <name>', 'creates a new react functional component')
13
+ .option('--dir <path>', 'sets the directory to create the new item')
14
+ .parse(process.argv);
15
+ function executeCreateLib(templatesDir, libraryDir) {
16
+ try {
17
+ fs.cpSync(path.join(templatesDir, 'lib'), libraryDir, {
18
+ recursive: true,
19
+ filter: function (src) { return (!src.endsWith('.gitkeep')); }
20
+ });
21
+ console.log('Library created successfully');
22
+ }
23
+ catch (err) {
24
+ console.error(err);
25
+ }
26
+ }
27
+ function executeCreateContext(templatesDir, contextDir) {
28
+ try {
29
+ fs.cpSync(path.join(templatesDir, 'ctx'), contextDir, {
30
+ recursive: true,
31
+ filter: function (src) { return (!src.endsWith('.gitkeep')); }
32
+ });
33
+ console.log('Context created successfully');
34
+ }
35
+ catch (err) {
36
+ console.error(err);
37
+ }
38
+ }
39
+ function executeCreateClass(templatesDir, classDir) {
40
+ try {
41
+ fs.cpSync(path.join(templatesDir, 'cls.example'), classDir, {});
42
+ console.log('Class created successfully');
43
+ }
44
+ catch (err) {
45
+ console.error(err);
46
+ }
47
+ }
48
+ function executeCreateReactFunctionalComponent(templatesDir, classDir) {
49
+ try {
50
+ fs.cpSync(path.join(templatesDir, 'rfc.example'), classDir, {});
51
+ console.log('React component created successfully');
52
+ }
53
+ catch (err) {
54
+ console.error(err);
55
+ }
56
+ }
57
+ (function () {
58
+ var _a;
59
+ var templatesDir = path.join(import.meta.dirname, '..', 'templates');
60
+ var options = program.opts();
61
+ var targetDir = path.resolve((_a = options.dir) !== null && _a !== void 0 ? _a : process.cwd());
62
+ if (Object.keys(options).length === 0) {
63
+ program.help();
64
+ return;
65
+ }
66
+ if (!fs.existsSync(targetDir)) {
67
+ fs.mkdirSync(targetDir, { recursive: true });
68
+ }
69
+ if (options.lib !== undefined) {
70
+ targetDir = path.join(targetDir, options.lib);
71
+ executeCreateLib(templatesDir, targetDir);
72
+ }
73
+ if (options.ctx !== undefined) {
74
+ targetDir = path.join(targetDir, options.ctx);
75
+ executeCreateContext(templatesDir, targetDir);
76
+ }
77
+ if (options.cls !== undefined) {
78
+ var target = path.join(targetDir, options.cls + '.ts');
79
+ executeCreateClass(templatesDir, target);
80
+ }
81
+ if (options.rfc !== undefined) {
82
+ var target = path.join(targetDir, options.rfc + '.tsx');
83
+ executeCreateReactFunctionalComponent(templatesDir, target);
84
+ }
85
+ })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tshex-cli",
3
- "version": "1.0.11",
3
+ "version": "1.0.13",
4
4
  "author": "https://github.com/virtualitems/",
5
5
  "description": "Typescript Hexagonal Architecture CLI",
6
6
  "type": "module",
package/readme.md CHANGED
@@ -10,7 +10,7 @@ Because what we are trying to achieve is a separation between the domain code an
10
10
 
11
11
  # Usage example
12
12
 
13
- https://github.com/virtualitems/typescript-codebase/tree/hexagonal-example
13
+ https://github.com/virtualitems/tshex-cli
14
14
 
15
15
  # Note!!!
16
16
 
@@ -18,7 +18,7 @@ This tool and its templates are in constant development, so be aware that some c
18
18
 
19
19
  If you have any suggestions or improvements, please let me know.
20
20
 
21
- https://github.com/virtualitems/typescript-codebase/issues
21
+ https://github.com/virtualitems/tshex-cli/issues
22
22
 
23
23
  # Installation
24
24
 
package/source/main.ts CHANGED
@@ -10,12 +10,20 @@ import { program } from 'commander';
10
10
  import fs from 'fs';
11
11
  import path from 'path';
12
12
 
13
+ // Read package.json
14
+ const packageJson = JSON.parse(
15
+ fs.readFileSync(
16
+ path.join(import.meta.dirname, '..', 'package.json'),
17
+ 'utf-8'
18
+ )
19
+ );
20
+
13
21
 
14
22
  // COMMANDER SETUP
15
23
 
16
24
  program
17
25
  .name('tshex')
18
- .version('1.0.0')
26
+ .version(packageJson.version)
19
27
  .option('--lib <name>', 'creates a new library with it\'s shared directory')
20
28
  .option('--ctx <name>', 'creates a new context')
21
29
  .option('--cls <name>', 'creates a new class')