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 +85 -84
- package/package.json +1 -1
- package/readme.md +2 -2
- package/source/main.ts +9 -1
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
|
-
|
|
6
|
-
|
|
7
|
-
.
|
|
8
|
-
.
|
|
9
|
-
.option('--
|
|
10
|
-
.option('--
|
|
11
|
-
.option('--
|
|
12
|
-
.option('--
|
|
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
|
-
var
|
|
59
|
-
var
|
|
60
|
-
var
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
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/
|
|
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/
|
|
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(
|
|
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')
|