@reliverse/dler 1.2.3 → 1.2.4
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/README.md +0 -8
- package/bin/app/cmds.js +6 -0
- package/bin/app/inject/README.md +20 -20
- package/bin/app/inject/cmd.js +7 -3
- package/bin/app/inject/expect/cmd.js +43 -0
- package/bin/app/inject/expect/impl.js +162 -0
- package/bin/app/relifso/cmd.js +36 -5
- package/bin/app/{rempts/cmd.txt → relifso/init/cmd.js} +93 -121
- package/bin/app/relifso/init/impl/mod.js +248 -0
- package/bin/app/rempts/{impl/index.js → init/cmd/cmd.js} +1 -1
- package/bin/app/rempts/init/cmds/cmd.js +80 -0
- package/bin/init.js +4 -0
- package/bin/libs/cfg/cfg-default.js +3 -1
- package/package.json +2 -2
- package/bin/app/inject/impl/arg-ts-expect-error.txt +0 -49
- package/bin/app/inject/impl/inject-mod.txt +0 -28
- package/bin/app/inject/impl/reinject.config.js +0 -4
- package/bin/app/inject/impl/ts-expect-error.txt +0 -277
- package/bin/app/relifso/impl/reinit-mod.txt +0 -395
- /package/bin/app/relifso/{impl → init/impl}/const.js +0 -0
- /package/bin/app/relifso/{impl → init/impl}/templates/t-gitignore.js +0 -0
- /package/bin/app/relifso/{impl → init/impl}/templates/t-license.js +0 -0
- /package/bin/app/relifso/{impl → init/impl}/templates/t-readme.js +0 -0
- /package/bin/app/relifso/{impl → init/impl}/types.js +0 -0
- /package/bin/app/relifso/{impl → init/impl}/utils.js +0 -0
package/README.md
CHANGED
|
@@ -66,14 +66,6 @@ bun dev # bun src/mod.ts --dev
|
|
|
66
66
|
bun update --latest
|
|
67
67
|
```
|
|
68
68
|
|
|
69
|
-
**or install globally**:
|
|
70
|
-
|
|
71
|
-
```sh
|
|
72
|
-
bun i -g @reliverse/dler
|
|
73
|
-
# or update as needed:
|
|
74
|
-
bun -g update --latest
|
|
75
|
-
```
|
|
76
|
-
|
|
77
69
|
2. **prepare your project**:
|
|
78
70
|
|
|
79
71
|
a. **configure `.gitignore`**:
|
package/bin/app/cmds.js
CHANGED
package/bin/app/inject/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
#
|
|
1
|
+
# dler inject
|
|
2
2
|
|
|
3
|
-
[💖 GitHub Sponsors](https://github.com/sponsors/blefnk) • [💬 Discord](https://discord.gg/Pb8uKbwpsJ) • [📦 NPM](https://npmjs.com/@reliverse/
|
|
3
|
+
[💖 GitHub Sponsors](https://github.com/sponsors/blefnk) • [💬 Discord](https://discord.gg/Pb8uKbwpsJ) • [📦 NPM](https://npmjs.com/@reliverse/inject) • [📚 Docs](https://blefnk.reliverse.org/blog/my-products/inject)
|
|
4
4
|
|
|
5
|
-
**@reliverse/
|
|
5
|
+
**@reliverse/inject** handles the boring parts for you. For example:
|
|
6
6
|
|
|
7
|
-
- ✅ Need to insert `// @ts-expect-error` above a TypeScript error?
|
|
7
|
+
- ✅ Need to insert `// @ts-expect-error` above a TypeScript error? Inject’s got you.
|
|
8
8
|
- 🔜 Fixing repetitive warns, lint suppressions, or compiler nags? One-liner.
|
|
9
9
|
- 🔜 Even more features to come!
|
|
10
10
|
|
|
@@ -23,18 +23,18 @@ Make sure you have Git, Node.js, and bun•pnpm•yarn•npm installed.
|
|
|
23
23
|
### Installation
|
|
24
24
|
|
|
25
25
|
```bash
|
|
26
|
-
bun i -g @reliverse/
|
|
26
|
+
bun i -g @reliverse/inject
|
|
27
27
|
```
|
|
28
28
|
|
|
29
29
|
Or use with `bun x` (or `npx`):
|
|
30
30
|
|
|
31
31
|
```bash
|
|
32
|
-
bun x @reliverse/
|
|
32
|
+
bun x @reliverse/inject
|
|
33
33
|
```
|
|
34
34
|
|
|
35
35
|
### Basic Usage
|
|
36
36
|
|
|
37
|
-
**User config** in `
|
|
37
|
+
**User config** in `inject.config.ts`:
|
|
38
38
|
|
|
39
39
|
```ts
|
|
40
40
|
export default {
|
|
@@ -47,15 +47,15 @@ export default {
|
|
|
47
47
|
|
|
48
48
|
```bash
|
|
49
49
|
# 1) Automatic mode:
|
|
50
|
-
|
|
50
|
+
inject ts-expect-error auto
|
|
51
51
|
# => runs `tsc`, finds errors, injects comment above them.
|
|
52
52
|
|
|
53
53
|
# 2) Lines-file mode:
|
|
54
|
-
|
|
54
|
+
inject ts-expect-error linesA.txt linesB.txt
|
|
55
55
|
# => no TSC, just parses references from lines files
|
|
56
56
|
|
|
57
57
|
# 3) Mixed:
|
|
58
|
-
|
|
58
|
+
inject ts-expect-error auto lines.txt
|
|
59
59
|
# => merges TSC errors with references in lines.txt
|
|
60
60
|
```
|
|
61
61
|
|
|
@@ -63,41 +63,41 @@ reinject ts-expect-error auto lines.txt
|
|
|
63
63
|
|
|
64
64
|
```bash
|
|
65
65
|
# When you need a custom comment:
|
|
66
|
-
|
|
66
|
+
inject ts-expect-error auto --comment="// @ts-expect-error FIXME"
|
|
67
67
|
```
|
|
68
68
|
|
|
69
69
|
Run on a TypeScript file with tsc output:
|
|
70
70
|
|
|
71
71
|
```bash
|
|
72
|
-
|
|
72
|
+
inject ts-expect-error src
|
|
73
73
|
```
|
|
74
74
|
|
|
75
75
|
You can also run on a specific TypeScript file with manually generated tsc output:
|
|
76
76
|
|
|
77
77
|
```bash
|
|
78
78
|
tsc --noEmit > tsc.log
|
|
79
|
-
|
|
79
|
+
inject tsc.log
|
|
80
80
|
rm tsc.log
|
|
81
81
|
```
|
|
82
82
|
|
|
83
83
|
You can also run it directly on output from stdin:
|
|
84
84
|
|
|
85
85
|
```bash
|
|
86
|
-
tsc --noEmit |
|
|
86
|
+
tsc --noEmit | inject
|
|
87
87
|
```
|
|
88
88
|
|
|
89
89
|
Or use with other tools:
|
|
90
90
|
|
|
91
91
|
```bash
|
|
92
|
-
eslint . |
|
|
93
|
-
biome check . |
|
|
92
|
+
eslint . | inject
|
|
93
|
+
biome check . | inject
|
|
94
94
|
```
|
|
95
95
|
|
|
96
96
|
### Filter by error code or rule ID
|
|
97
97
|
|
|
98
98
|
```bash
|
|
99
|
-
|
|
100
|
-
|
|
99
|
+
inject tsc.log --code TS2322
|
|
100
|
+
inject eslint.log --rule no-unused-vars
|
|
101
101
|
```
|
|
102
102
|
|
|
103
103
|
## ✨ Examples
|
|
@@ -137,9 +137,9 @@ const x: string = 123;
|
|
|
137
137
|
|
|
138
138
|
## 🫶 Show some love
|
|
139
139
|
|
|
140
|
-
If `@reliverse/
|
|
140
|
+
If `@reliverse/inject` saved you time or sanity:
|
|
141
141
|
|
|
142
|
-
- ⭐ [Star the repo](https://github.com/reliverse/
|
|
142
|
+
- ⭐ [Star the repo](https://github.com/reliverse/inject)
|
|
143
143
|
- 💖 [Sponsor on GitHub](https://github.com/sponsors/blefnk)
|
|
144
144
|
- 🫶 Share it with a dev friend!
|
|
145
145
|
|
package/bin/app/inject/cmd.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { relinka } from "@reliverse/relinka";
|
|
2
|
-
import { defineCommand, selectPrompt } from "@reliverse/rempts";
|
|
2
|
+
import { defineCommand, runCmd, selectPrompt } from "@reliverse/rempts";
|
|
3
|
+
import { getCmdInjectTsExpectError } from "../cmds.js";
|
|
3
4
|
export default defineCommand({
|
|
4
5
|
meta: {
|
|
5
6
|
name: "cli",
|
|
6
|
-
description: "Runs the
|
|
7
|
+
description: "Runs the Inject command interactive menu (displays list of available commands)"
|
|
7
8
|
},
|
|
8
9
|
args: {
|
|
9
10
|
dev: {
|
|
@@ -19,7 +20,7 @@ export default defineCommand({
|
|
|
19
20
|
run: async ({ args }) => {
|
|
20
21
|
const isDev = args.dev;
|
|
21
22
|
relinka("verbose", `Running in ${isDev ? "dev" : "prod"} mode`);
|
|
22
|
-
await selectPrompt({
|
|
23
|
+
const cmd = await selectPrompt({
|
|
23
24
|
title: "Select a command",
|
|
24
25
|
options: [
|
|
25
26
|
{
|
|
@@ -28,5 +29,8 @@ export default defineCommand({
|
|
|
28
29
|
}
|
|
29
30
|
]
|
|
30
31
|
});
|
|
32
|
+
if (cmd === "ts-expect-error") {
|
|
33
|
+
await runCmd(await getCmdInjectTsExpectError(), []);
|
|
34
|
+
}
|
|
31
35
|
}
|
|
32
36
|
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { relinka } from "@reliverse/relinka";
|
|
2
|
+
import { defineArgs, defineCommand } from "@reliverse/rempts";
|
|
3
|
+
import { useTsExpectError } from "./impl.js";
|
|
4
|
+
export default defineCommand({
|
|
5
|
+
meta: {
|
|
6
|
+
name: "expect",
|
|
7
|
+
version: "1.0.0",
|
|
8
|
+
description: "Inject `@ts-expect-error` above lines where TS errors occur"
|
|
9
|
+
},
|
|
10
|
+
args: defineArgs({
|
|
11
|
+
dev: {
|
|
12
|
+
type: "boolean",
|
|
13
|
+
description: "Run the CLI in dev mode"
|
|
14
|
+
},
|
|
15
|
+
files: {
|
|
16
|
+
type: "positional",
|
|
17
|
+
description: `'auto' or path(s) to line references file(s)`,
|
|
18
|
+
default: "auto"
|
|
19
|
+
},
|
|
20
|
+
comment: {
|
|
21
|
+
type: "string",
|
|
22
|
+
description: "Override the comment line to insert. Default is `// @ts-expect-error TODO: fix ts`"
|
|
23
|
+
},
|
|
24
|
+
tscPaths: {
|
|
25
|
+
type: "string",
|
|
26
|
+
description: "Optional: specify path(s) to restrict TSC processing (only effective when using 'auto')"
|
|
27
|
+
}
|
|
28
|
+
}),
|
|
29
|
+
async run({ args }) {
|
|
30
|
+
if (args.dev) {
|
|
31
|
+
relinka("verbose", "Using dev mode");
|
|
32
|
+
}
|
|
33
|
+
let pathsTsc = args.tscPaths;
|
|
34
|
+
if (pathsTsc === void 0 && args.files === "auto") {
|
|
35
|
+
pathsTsc = "./tsconfig.json";
|
|
36
|
+
}
|
|
37
|
+
await useTsExpectError({
|
|
38
|
+
files: [args.files],
|
|
39
|
+
comment: args.comment,
|
|
40
|
+
tscPaths: [pathsTsc]
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
});
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { relinka } from "@reliverse/relinka";
|
|
2
|
+
import { execa } from "execa";
|
|
3
|
+
import fs from "fs-extra";
|
|
4
|
+
import path from "pathe";
|
|
5
|
+
function parseCommand(command) {
|
|
6
|
+
const regex = /"([^"]+)"|'([^']+)'|(\S+)/g;
|
|
7
|
+
const args = [];
|
|
8
|
+
let match;
|
|
9
|
+
while (regex.exec(command) !== null) {
|
|
10
|
+
match = regex.exec(command);
|
|
11
|
+
if (match) {
|
|
12
|
+
const value = match[1] ?? match[2] ?? match[3];
|
|
13
|
+
if (value) {
|
|
14
|
+
args.push(value);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
const cmd = args.shift() ?? "";
|
|
19
|
+
return { cmd, args };
|
|
20
|
+
}
|
|
21
|
+
async function parseLinesFile(linesFile) {
|
|
22
|
+
const fileContents = await fs.readFile(linesFile, "utf-8");
|
|
23
|
+
const splitted = fileContents.split(/\r?\n/);
|
|
24
|
+
const results = [];
|
|
25
|
+
for (const rawLine of splitted) {
|
|
26
|
+
const trimmed = rawLine.trim();
|
|
27
|
+
if (!trimmed) continue;
|
|
28
|
+
const firstMatch = trimmed.match(/^(\d+)\s+(.+?):(\d+)$/);
|
|
29
|
+
if (firstMatch?.[2] && firstMatch?.[3]) {
|
|
30
|
+
results.push({
|
|
31
|
+
filePath: firstMatch[2],
|
|
32
|
+
lineNumber: Number.parseInt(firstMatch[3], 10)
|
|
33
|
+
});
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
const secondMatch = trimmed.match(/^(.+?):(\d+)$/);
|
|
37
|
+
if (secondMatch?.[1] && secondMatch?.[2]) {
|
|
38
|
+
results.push({
|
|
39
|
+
filePath: secondMatch[1],
|
|
40
|
+
lineNumber: Number.parseInt(secondMatch[2], 10)
|
|
41
|
+
});
|
|
42
|
+
} else {
|
|
43
|
+
relinka("warn", `Line doesn't match expected format: ${trimmed}`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return results;
|
|
47
|
+
}
|
|
48
|
+
async function runTscAndParseErrors(tscCommand, tscPaths) {
|
|
49
|
+
try {
|
|
50
|
+
const { cmd, args: cmdArgs } = parseCommand(tscCommand);
|
|
51
|
+
if (tscPaths?.length) {
|
|
52
|
+
cmdArgs.push(...tscPaths);
|
|
53
|
+
}
|
|
54
|
+
const subprocess = await execa(cmd, cmdArgs, { all: true, reject: false });
|
|
55
|
+
const combinedOutput = subprocess.all ?? "";
|
|
56
|
+
return parseErrorOutput(combinedOutput);
|
|
57
|
+
} catch (error) {
|
|
58
|
+
if (error && typeof error === "object" && "all" in error) {
|
|
59
|
+
const combined = error.all ?? "";
|
|
60
|
+
if (!combined) {
|
|
61
|
+
relinka("log", "TSC returned no error lines. Possibly no TS errors?");
|
|
62
|
+
return [];
|
|
63
|
+
}
|
|
64
|
+
return parseErrorOutput(combined);
|
|
65
|
+
}
|
|
66
|
+
return [];
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function parseErrorOutput(output) {
|
|
70
|
+
const results = [];
|
|
71
|
+
const splitted = output.split(/\r?\n/);
|
|
72
|
+
const regex = /^(.+?)\((\d+),(\d+)\): error TS\d+: /;
|
|
73
|
+
for (const line of splitted) {
|
|
74
|
+
const match = line.trim().match(regex);
|
|
75
|
+
if (match?.[1] && match?.[2]) {
|
|
76
|
+
const file = match[1].replace(/\\/g, "/");
|
|
77
|
+
const row = Number.parseInt(match[2], 10);
|
|
78
|
+
if (row > 0) {
|
|
79
|
+
results.push({ filePath: file, lineNumber: row });
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return results;
|
|
84
|
+
}
|
|
85
|
+
function isWithin(filePath, dirs) {
|
|
86
|
+
const absFile = path.resolve(filePath);
|
|
87
|
+
return dirs.some((dir) => {
|
|
88
|
+
const absDir = path.resolve(dir);
|
|
89
|
+
const normalizedDir = absDir.endsWith(path.sep) ? absDir : absDir + path.sep;
|
|
90
|
+
return absFile.startsWith(normalizedDir);
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
async function injectCommentIntoFiles(linesRecords, commentText) {
|
|
94
|
+
const byFile = /* @__PURE__ */ new Map();
|
|
95
|
+
for (const rec of linesRecords) {
|
|
96
|
+
const lines = byFile.get(rec.filePath) ?? [];
|
|
97
|
+
lines.push(rec.lineNumber);
|
|
98
|
+
byFile.set(rec.filePath, lines);
|
|
99
|
+
}
|
|
100
|
+
for (const [filePath, lineNums] of byFile.entries()) {
|
|
101
|
+
lineNums.sort((a, b) => b - a);
|
|
102
|
+
const absPath = path.resolve(filePath);
|
|
103
|
+
relinka(
|
|
104
|
+
"log",
|
|
105
|
+
`Injecting into ${absPath} at lines: ${lineNums.join(", ")}`
|
|
106
|
+
);
|
|
107
|
+
try {
|
|
108
|
+
const original = await fs.readFile(absPath, "utf-8");
|
|
109
|
+
const splitted = original.split(/\r?\n/);
|
|
110
|
+
for (const ln of lineNums) {
|
|
111
|
+
if (ln <= splitted.length) {
|
|
112
|
+
splitted.splice(ln - 1, 0, commentText);
|
|
113
|
+
} else {
|
|
114
|
+
relinka("warn", `Line ${ln} exceeds file length for ${absPath}`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
const newContent = splitted.join("\n");
|
|
118
|
+
await fs.writeFile(absPath, newContent, "utf-8");
|
|
119
|
+
} catch (error) {
|
|
120
|
+
relinka("error", `Failed editing ${filePath}: ${error}`);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
export async function useTsExpectError(args) {
|
|
125
|
+
const finalComment = args.comment ?? "// @ts-expect-error TODO: fix ts";
|
|
126
|
+
const tscCommand = "tsc --project ./tsconfig.json --noEmit";
|
|
127
|
+
const lines = [];
|
|
128
|
+
const usedAuto = args.files.some((item) => item.toLowerCase() === "auto");
|
|
129
|
+
if (usedAuto) {
|
|
130
|
+
relinka("log", "Running TSC to discover error lines...");
|
|
131
|
+
try {
|
|
132
|
+
const discovered = await runTscAndParseErrors(tscCommand, args.tscPaths);
|
|
133
|
+
if (args.tscPaths?.length) {
|
|
134
|
+
const filtered = discovered.filter(
|
|
135
|
+
(rec) => args.tscPaths ? isWithin(rec.filePath, args.tscPaths) : true
|
|
136
|
+
);
|
|
137
|
+
lines.push(...filtered);
|
|
138
|
+
} else {
|
|
139
|
+
lines.push(...discovered);
|
|
140
|
+
}
|
|
141
|
+
} catch (error) {
|
|
142
|
+
relinka("error", `Failed running tsc: ${error}`);
|
|
143
|
+
process.exit(1);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
for (const item of args.files) {
|
|
147
|
+
if (item.toLowerCase() === "auto") continue;
|
|
148
|
+
try {
|
|
149
|
+
const recs = await parseLinesFile(item);
|
|
150
|
+
lines.push(...recs);
|
|
151
|
+
} catch (error) {
|
|
152
|
+
relinka("error", `Failed reading lines file ${item}: ${error}`);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
if (lines.length === 0) {
|
|
156
|
+
relinka("error", "No references found. Nothing to do.");
|
|
157
|
+
relinka("error", "Lines: ", JSON.stringify(lines));
|
|
158
|
+
process.exit(1);
|
|
159
|
+
}
|
|
160
|
+
await injectCommentIntoFiles(lines, finalComment);
|
|
161
|
+
relinka("success", "All lines processed successfully.");
|
|
162
|
+
}
|
package/bin/app/relifso/cmd.js
CHANGED
|
@@ -1,5 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export {
|
|
5
|
-
|
|
1
|
+
import { relinka } from "@reliverse/relinka";
|
|
2
|
+
import { defineCommand, runCmd, selectPrompt } from "@reliverse/rempts";
|
|
3
|
+
import { getCmdRelifsoInit } from "../cmds.js";
|
|
4
|
+
export default defineCommand({
|
|
5
|
+
meta: {
|
|
6
|
+
name: "cli",
|
|
7
|
+
description: "Runs the Relifso helper interactive menu (displays list of available commands)"
|
|
8
|
+
},
|
|
9
|
+
args: {
|
|
10
|
+
dev: {
|
|
11
|
+
type: "boolean",
|
|
12
|
+
description: "Runs the CLI in dev mode"
|
|
13
|
+
},
|
|
14
|
+
cwd: {
|
|
15
|
+
type: "string",
|
|
16
|
+
description: "The working directory to run the CLI in",
|
|
17
|
+
required: false
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
run: async ({ args }) => {
|
|
21
|
+
const isDev = args.dev;
|
|
22
|
+
relinka("verbose", `Running in ${isDev ? "dev" : "prod"} mode`);
|
|
23
|
+
const cmd = await selectPrompt({
|
|
24
|
+
title: "Select a command",
|
|
25
|
+
options: [
|
|
26
|
+
{
|
|
27
|
+
value: "init",
|
|
28
|
+
label: "Initialize files"
|
|
29
|
+
}
|
|
30
|
+
]
|
|
31
|
+
});
|
|
32
|
+
if (cmd === "init") {
|
|
33
|
+
await runCmd(await getCmdRelifsoInit(), []);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
});
|
|
@@ -1,121 +1,93 @@
|
|
|
1
|
-
import { relinka } from "@reliverse/relinka";
|
|
2
|
-
import {
|
|
3
|
-
defineCommand,
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
} from "
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
type: "
|
|
27
|
-
description: "
|
|
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
|
-
concurrency
|
|
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
|
-
if (
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
} else {
|
|
95
|
-
// Single file approach
|
|
96
|
-
let finalFileType = effectiveFileType;
|
|
97
|
-
if (!finalFileType) {
|
|
98
|
-
// If user didn't specify, prompt for a single file type
|
|
99
|
-
const possibleTypes = FILE_TYPES.map((ft) => ft.type);
|
|
100
|
-
const picked = await selectPrompt({
|
|
101
|
-
title: "Pick a file type to initialize",
|
|
102
|
-
options: possibleTypes.map((pt) => ({ label: pt, value: pt })),
|
|
103
|
-
});
|
|
104
|
-
finalFileType = picked;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
const result = await initFile({
|
|
108
|
-
fileType: finalFileType,
|
|
109
|
-
destDir,
|
|
110
|
-
});
|
|
111
|
-
relinka("verbose", `Single file result: ${JSON.stringify(result)}`);
|
|
112
|
-
}
|
|
113
|
-
},
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
await runMain(main).catch((error: unknown) => {
|
|
117
|
-
errorHandler(
|
|
118
|
-
error instanceof Error ? error : new Error(String(error)),
|
|
119
|
-
"An unhandled error occurred, please report it at https://github.com/reliverse/reinit",
|
|
120
|
-
);
|
|
121
|
-
});
|
|
1
|
+
import { relinka } from "@reliverse/relinka";
|
|
2
|
+
import {
|
|
3
|
+
defineCommand,
|
|
4
|
+
multiselectPrompt,
|
|
5
|
+
selectPrompt
|
|
6
|
+
} from "@reliverse/rempts";
|
|
7
|
+
import { FILE_TYPES } from "./impl/const.js";
|
|
8
|
+
import { initFile, initFiles } from "./impl/mod.js";
|
|
9
|
+
export default defineCommand({
|
|
10
|
+
meta: {
|
|
11
|
+
name: "relifso",
|
|
12
|
+
version: "1.0.0",
|
|
13
|
+
description: "relifso helper utils"
|
|
14
|
+
},
|
|
15
|
+
args: {
|
|
16
|
+
dev: {
|
|
17
|
+
type: "boolean",
|
|
18
|
+
description: "Runs the CLI in dev mode"
|
|
19
|
+
},
|
|
20
|
+
fileType: {
|
|
21
|
+
type: "string",
|
|
22
|
+
description: "File type to initialize (e.g. 'md:README')",
|
|
23
|
+
required: false
|
|
24
|
+
},
|
|
25
|
+
destDir: {
|
|
26
|
+
type: "string",
|
|
27
|
+
description: "Destination directory",
|
|
28
|
+
default: ".",
|
|
29
|
+
required: false
|
|
30
|
+
},
|
|
31
|
+
multiple: {
|
|
32
|
+
type: "boolean",
|
|
33
|
+
description: "Whether to select multiple file types from the library",
|
|
34
|
+
required: false,
|
|
35
|
+
default: false
|
|
36
|
+
},
|
|
37
|
+
parallel: {
|
|
38
|
+
type: "boolean",
|
|
39
|
+
description: "Run tasks in parallel",
|
|
40
|
+
required: false,
|
|
41
|
+
default: false
|
|
42
|
+
},
|
|
43
|
+
concurrency: {
|
|
44
|
+
type: "string",
|
|
45
|
+
description: "Concurrency limit if parallel is true",
|
|
46
|
+
required: false,
|
|
47
|
+
default: "4"
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
async run({ args }) {
|
|
51
|
+
const { fileType, destDir, multiple, parallel, concurrency } = args;
|
|
52
|
+
const concurrencyNum = Number(concurrency);
|
|
53
|
+
if (fileType && !FILE_TYPES.find((ft) => ft.type === fileType)) {
|
|
54
|
+
throw new Error(`Invalid file type: ${fileType}`);
|
|
55
|
+
}
|
|
56
|
+
const effectiveFileType = fileType;
|
|
57
|
+
if (multiple) {
|
|
58
|
+
const possibleTypes = FILE_TYPES.map((ft) => ft.type);
|
|
59
|
+
const chosen = await multiselectPrompt({
|
|
60
|
+
title: "Select file types to initialize",
|
|
61
|
+
options: possibleTypes.map((pt) => ({ label: pt, value: pt }))
|
|
62
|
+
});
|
|
63
|
+
if (chosen.length === 0) {
|
|
64
|
+
relinka("log", "No file types selected. Exiting...");
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const requests = chosen.map((ct) => ({
|
|
68
|
+
fileType: ct,
|
|
69
|
+
destDir
|
|
70
|
+
}));
|
|
71
|
+
const results = await initFiles(requests, {
|
|
72
|
+
parallel,
|
|
73
|
+
concurrency: concurrencyNum
|
|
74
|
+
});
|
|
75
|
+
relinka("verbose", `Multiple files result: ${JSON.stringify(results)}`);
|
|
76
|
+
} else {
|
|
77
|
+
let finalFileType = effectiveFileType;
|
|
78
|
+
if (!finalFileType) {
|
|
79
|
+
const possibleTypes = FILE_TYPES.map((ft) => ft.type);
|
|
80
|
+
const picked = await selectPrompt({
|
|
81
|
+
title: "Pick a file type to initialize",
|
|
82
|
+
options: possibleTypes.map((pt) => ({ label: pt, value: pt }))
|
|
83
|
+
});
|
|
84
|
+
finalFileType = picked;
|
|
85
|
+
}
|
|
86
|
+
const result = await initFile({
|
|
87
|
+
fileType: finalFileType,
|
|
88
|
+
destDir
|
|
89
|
+
});
|
|
90
|
+
relinka("verbose", `Single file result: ${JSON.stringify(result)}`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
});
|