@ryziz/cli 0.0.54 → 0.0.60
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/create.js +57 -24
- package/package.json +12 -12
package/create.js
CHANGED
|
@@ -5,49 +5,82 @@ import { fileURLToPath } from 'node:url';
|
|
|
5
5
|
import { execSync } from 'node:child_process';
|
|
6
6
|
import { f } from '@ryziz/task';
|
|
7
7
|
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
f('
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
8
|
+
const ctx = {
|
|
9
|
+
root: null,
|
|
10
|
+
name: null,
|
|
11
|
+
dest: null,
|
|
12
|
+
src: null,
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
await f('Preparing',
|
|
16
|
+
f('Parsing',
|
|
17
|
+
f('Args', () => ({ name: ctx.name, dest: ctx.dest } = parseArgs())),
|
|
18
|
+
f('Root', () => ctx.root = resolveRoot()),
|
|
19
|
+
),
|
|
20
|
+
f('Locating', () => ctx.src = findTemplate(ctx.root, ctx.name)),
|
|
21
|
+
)();
|
|
22
|
+
|
|
23
|
+
await f('Initializing',
|
|
24
|
+
f('Cloning', () => clone(ctx.src, ctx.dest)),
|
|
25
|
+
f('Configuring', () => configure(ctx.dest)),
|
|
26
|
+
f('Installing', () => install(ctx.dest)),
|
|
27
|
+
f('Completing', () => complete(ctx.dest)),
|
|
28
|
+
{ skip: getSkipReason(ctx) },
|
|
20
29
|
)();
|
|
21
30
|
|
|
22
|
-
function
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
31
|
+
function parseArgs() {
|
|
32
|
+
const name = basename(process.argv[1]);
|
|
33
|
+
const dest = process.argv[2] ? resolve(process.argv[2]) : null;
|
|
34
|
+
return { name, dest };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function resolveRoot() {
|
|
38
|
+
return resolve(dirname(fileURLToPath(import.meta.url)), '../');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function findTemplate(root, name) {
|
|
42
|
+
return [resolve(root, name), resolve(root, '../templates', name)]
|
|
43
|
+
.find((p) => exists(join(p, 'package.json')));
|
|
26
44
|
}
|
|
27
45
|
|
|
28
|
-
function
|
|
46
|
+
function getSkipReason(ctx) {
|
|
47
|
+
if (!ctx.src) return `Template ${ctx.name} not found`;
|
|
48
|
+
if (!ctx.dest) return 'Project name/directory is missing';
|
|
49
|
+
if (exists(ctx.dest)) return 'Directory exists';
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function clone(src, dest) {
|
|
29
54
|
cpSync(src, dest, { recursive: true });
|
|
30
|
-
if (exists(join(dest, 'gitignore')))
|
|
55
|
+
if (exists(join(dest, 'gitignore')))
|
|
31
56
|
renameSync(join(dest, 'gitignore'), join(dest, '.gitignore'));
|
|
32
|
-
|
|
57
|
+
|
|
33
58
|
}
|
|
34
59
|
|
|
35
|
-
function
|
|
60
|
+
function configure(dest) {
|
|
36
61
|
const pkgPath = join(dest, 'package.json');
|
|
37
|
-
const pkg =
|
|
62
|
+
const pkg = readJson(pkgPath);
|
|
38
63
|
delete pkg.bin;
|
|
39
64
|
pkg.name = basename(dest);
|
|
40
65
|
if (pkg.dependencies?.['@ryziz/cli']) {
|
|
41
66
|
(pkg.devDependencies ||= {})['@ryziz/cli'] = pkg.dependencies['@ryziz/cli'];
|
|
42
67
|
delete pkg.dependencies['@ryziz/cli'];
|
|
43
68
|
}
|
|
44
|
-
|
|
69
|
+
writeJson(pkgPath, pkg);
|
|
45
70
|
}
|
|
46
71
|
|
|
47
|
-
function
|
|
72
|
+
function install(dest) {
|
|
48
73
|
execSync('npm install', { cwd: dest });
|
|
49
74
|
}
|
|
50
75
|
|
|
51
|
-
function
|
|
76
|
+
function complete(dest) {
|
|
52
77
|
console.log(dest);
|
|
53
78
|
}
|
|
79
|
+
|
|
80
|
+
function readJson(path) {
|
|
81
|
+
return JSON.parse(readFileSync(path, 'utf8'));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function writeJson(path, data) {
|
|
85
|
+
writeFileSync(path, JSON.stringify(data, null, 2) + '\n');
|
|
86
|
+
}
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
2
|
+
"name": "@ryziz/cli",
|
|
3
|
+
"version": "0.0.60",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"bin": {
|
|
6
|
+
"ryziz": "./index.js",
|
|
7
|
+
"create-react": "./create.js"
|
|
8
|
+
},
|
|
9
|
+
"dependencies": {
|
|
10
|
+
"@ryziz/task": "^0.0.4",
|
|
11
|
+
"commander": "^14.0.2",
|
|
12
|
+
"esbuild": "^0.27.2"
|
|
13
|
+
}
|
|
14
14
|
}
|