@reliverse/dler 1.6.1 → 1.6.2
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 +40 -13
- package/bin/app/agg/run.js +2 -2
- package/bin/app/check/cmd.d.ts +8 -0
- package/bin/app/check/cmd.js +19 -0
- package/bin/app/cmds.d.ts +297 -72
- package/bin/app/cmds.js +50 -11
- package/bin/app/conv/cmd.d.ts +33 -0
- package/bin/app/conv/cmd.js +189 -0
- package/bin/app/inject/cmd.js +2 -2
- package/bin/app/libs/cmd.d.ts +13 -0
- package/bin/app/libs/cmd.js +109 -0
- package/bin/app/relifso/cmd.js +4 -4
- package/bin/app/relinka/cmd.d.ts +18 -0
- package/bin/app/relinka/cmd.js +149 -0
- package/bin/app/rempts/{init/cmd → cmd}/cmd.d.ts +8 -4
- package/bin/app/rempts/cmd/cmd.js +152 -0
- package/bin/app/rempts/cmd/templates.d.ts +2 -0
- package/bin/app/rempts/cmd/templates.js +30 -0
- package/bin/app/rempts/{init/cmds → cmdsTs}/cmd.d.ts +1 -3
- package/bin/app/rempts/{init/cmds → cmdsTs}/cmd.js +30 -13
- package/bin/cli.js +3 -3
- package/bin/init/info.js +1 -1
- package/bin/init/load.d.ts +2 -2
- package/bin/libs/sdk/default.d.ts +2 -2
- package/bin/libs/sdk/sdk-impl/build/build-library.d.ts +2 -2
- package/bin/libs/sdk/sdk-impl/build/build-regular.d.ts +3 -3
- package/bin/libs/sdk/sdk-impl/library-flow.d.ts +3 -3
- package/bin/libs/sdk/sdk-impl/regular-flow.d.ts +2 -2
- package/bin/libs/sdk/sdk-impl/utils/utils-deps.d.ts +2 -2
- package/bin/libs/sdk/sdk-impl/utils/utils-pkg-json-libs.d.ts +2 -2
- package/bin/libs/sdk/sdk-impl/utils/utils-pkg-json-reg.d.ts +2 -2
- package/bin/libs/sdk/sdk-types.d.ts +1 -1
- package/bin/mod.d.ts +2 -2
- package/package.json +2 -2
- package/bin/app/mono/cmd.d.ts +0 -0
- package/bin/app/mono/cmd.js +0 -0
- package/bin/app/rempts/init/cmd/cmd.js +0 -67
package/bin/app/conv/cmd.d.ts
CHANGED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
declare const _default: import("@reliverse/rempts").Command<{
|
|
2
|
+
type: {
|
|
3
|
+
type: "string";
|
|
4
|
+
required: true;
|
|
5
|
+
description: string;
|
|
6
|
+
};
|
|
7
|
+
input: {
|
|
8
|
+
type: "string";
|
|
9
|
+
required: true;
|
|
10
|
+
description: string;
|
|
11
|
+
};
|
|
12
|
+
output: {
|
|
13
|
+
type: "string";
|
|
14
|
+
description: string;
|
|
15
|
+
};
|
|
16
|
+
pattern: {
|
|
17
|
+
type: "string";
|
|
18
|
+
description: string;
|
|
19
|
+
};
|
|
20
|
+
replacement: {
|
|
21
|
+
type: "string";
|
|
22
|
+
description: string;
|
|
23
|
+
};
|
|
24
|
+
line: {
|
|
25
|
+
type: "number";
|
|
26
|
+
description: string;
|
|
27
|
+
};
|
|
28
|
+
transform: {
|
|
29
|
+
type: "string";
|
|
30
|
+
description: string;
|
|
31
|
+
};
|
|
32
|
+
}>;
|
|
33
|
+
export default _default;
|
package/bin/app/conv/cmd.js
CHANGED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import fs from "@reliverse/relifso";
|
|
2
|
+
import { relinka } from "@reliverse/relinka";
|
|
3
|
+
import { defineArgs, defineCommand } from "@reliverse/rempts";
|
|
4
|
+
import { executeSpell } from "../../libs/sdk/sdk-mod.js";
|
|
5
|
+
export default defineCommand({
|
|
6
|
+
meta: {
|
|
7
|
+
name: "conv",
|
|
8
|
+
version: "1.0.0",
|
|
9
|
+
description: "Convert files using various SDK converters."
|
|
10
|
+
},
|
|
11
|
+
args: defineArgs({
|
|
12
|
+
type: {
|
|
13
|
+
type: "string",
|
|
14
|
+
required: true,
|
|
15
|
+
description: "Type of conversion to perform (replace, rename, remove-comment, remove-line, remove-file, copy, move, transform, insert)"
|
|
16
|
+
},
|
|
17
|
+
input: {
|
|
18
|
+
type: "string",
|
|
19
|
+
required: true,
|
|
20
|
+
description: "Input file or directory path"
|
|
21
|
+
},
|
|
22
|
+
output: {
|
|
23
|
+
type: "string",
|
|
24
|
+
description: "Output file or directory path (required for copy/move/rename operations)"
|
|
25
|
+
},
|
|
26
|
+
pattern: {
|
|
27
|
+
type: "string",
|
|
28
|
+
description: "Pattern to match (for replace/remove operations)"
|
|
29
|
+
},
|
|
30
|
+
replacement: {
|
|
31
|
+
type: "string",
|
|
32
|
+
description: "Replacement text (for replace/insert operations)"
|
|
33
|
+
},
|
|
34
|
+
line: {
|
|
35
|
+
type: "number",
|
|
36
|
+
description: "Line number (for insert/remove-line operations)"
|
|
37
|
+
},
|
|
38
|
+
transform: {
|
|
39
|
+
type: "string",
|
|
40
|
+
description: "Transform function name (for transform operation)"
|
|
41
|
+
}
|
|
42
|
+
}),
|
|
43
|
+
async run({ args }) {
|
|
44
|
+
const { type, input, output, pattern, replacement, line, transform } = args;
|
|
45
|
+
if (!await fs.pathExists(input)) {
|
|
46
|
+
relinka("error", `\u274C Input path does not exist: ${input}`);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
let spell;
|
|
50
|
+
switch (type) {
|
|
51
|
+
case "replace":
|
|
52
|
+
if (!pattern || !replacement) {
|
|
53
|
+
relinka(
|
|
54
|
+
"error",
|
|
55
|
+
"\u274C Pattern and replacement are required for replace operation"
|
|
56
|
+
);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
spell = {
|
|
60
|
+
type: "replace-line",
|
|
61
|
+
params: { hooked: false },
|
|
62
|
+
value: replacement,
|
|
63
|
+
fullMatch: pattern
|
|
64
|
+
};
|
|
65
|
+
break;
|
|
66
|
+
case "rename":
|
|
67
|
+
if (!output) {
|
|
68
|
+
relinka("error", "\u274C Output path is required for rename operation");
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
spell = {
|
|
72
|
+
type: "rename-file",
|
|
73
|
+
params: { hooked: false },
|
|
74
|
+
fileName: output
|
|
75
|
+
};
|
|
76
|
+
break;
|
|
77
|
+
case "remove-comment":
|
|
78
|
+
if (!pattern) {
|
|
79
|
+
relinka(
|
|
80
|
+
"error",
|
|
81
|
+
"\u274C Pattern is required for remove-comment operation"
|
|
82
|
+
);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
spell = {
|
|
86
|
+
type: "remove-comment",
|
|
87
|
+
params: { hooked: false },
|
|
88
|
+
fullMatch: pattern
|
|
89
|
+
};
|
|
90
|
+
break;
|
|
91
|
+
case "remove-line":
|
|
92
|
+
if (!pattern) {
|
|
93
|
+
relinka("error", "\u274C Pattern is required for remove-line operation");
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
spell = {
|
|
97
|
+
type: "remove-line",
|
|
98
|
+
params: { hooked: false },
|
|
99
|
+
fullMatch: pattern
|
|
100
|
+
};
|
|
101
|
+
break;
|
|
102
|
+
case "remove-file":
|
|
103
|
+
spell = {
|
|
104
|
+
type: "remove-file",
|
|
105
|
+
params: { hooked: false }
|
|
106
|
+
};
|
|
107
|
+
break;
|
|
108
|
+
case "copy":
|
|
109
|
+
if (!output) {
|
|
110
|
+
relinka("error", "\u274C Output path is required for copy operation");
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
spell = {
|
|
114
|
+
type: "copy-file",
|
|
115
|
+
params: { hooked: false },
|
|
116
|
+
fileName: output
|
|
117
|
+
};
|
|
118
|
+
break;
|
|
119
|
+
case "move":
|
|
120
|
+
if (!output) {
|
|
121
|
+
relinka("error", "\u274C Output path is required for move operation");
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
spell = {
|
|
125
|
+
type: "move-file",
|
|
126
|
+
params: { hooked: false },
|
|
127
|
+
fileName: output
|
|
128
|
+
};
|
|
129
|
+
break;
|
|
130
|
+
case "transform":
|
|
131
|
+
if (!transform) {
|
|
132
|
+
relinka(
|
|
133
|
+
"error",
|
|
134
|
+
"\u274C Transform function name is required for transform operation"
|
|
135
|
+
);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
spell = {
|
|
139
|
+
type: "transform-content",
|
|
140
|
+
params: { hooked: false },
|
|
141
|
+
value: transform
|
|
142
|
+
};
|
|
143
|
+
break;
|
|
144
|
+
case "insert":
|
|
145
|
+
if (!line || !replacement) {
|
|
146
|
+
relinka(
|
|
147
|
+
"error",
|
|
148
|
+
"\u274C Line number and replacement are required for insert operation"
|
|
149
|
+
);
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
spell = {
|
|
153
|
+
type: "insert-at",
|
|
154
|
+
params: { hooked: false },
|
|
155
|
+
value: replacement,
|
|
156
|
+
lineNumber: line
|
|
157
|
+
};
|
|
158
|
+
break;
|
|
159
|
+
default:
|
|
160
|
+
relinka("error", `\u274C Unknown conversion type: ${type}`);
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
try {
|
|
164
|
+
const content = await fs.readFile(input, "utf-8");
|
|
165
|
+
const result = await executeSpell(spell, input, content);
|
|
166
|
+
if (result.success) {
|
|
167
|
+
relinka(
|
|
168
|
+
"log",
|
|
169
|
+
`\u2705 Successfully performed ${type} operation on ${input}`
|
|
170
|
+
);
|
|
171
|
+
if (result.changes) {
|
|
172
|
+
relinka(
|
|
173
|
+
"log",
|
|
174
|
+
`\u{1F4DD} Changes:
|
|
175
|
+
Before: ${result.changes.before}
|
|
176
|
+
After: ${result.changes.after}`
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
} else {
|
|
180
|
+
relinka(
|
|
181
|
+
"error",
|
|
182
|
+
`\u274C Failed to perform ${type} operation: ${result.message}`
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
} catch (error) {
|
|
186
|
+
relinka("error", `\u274C Error during conversion: ${error}`);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
});
|
package/bin/app/inject/cmd.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { relinka } from "@reliverse/relinka";
|
|
2
2
|
import { defineCommand, runCmd, selectPrompt } from "@reliverse/rempts";
|
|
3
|
-
import {
|
|
3
|
+
import { getCmdInjectExpect } from "../cmds.js";
|
|
4
4
|
export default defineCommand({
|
|
5
5
|
meta: {
|
|
6
6
|
name: "cli",
|
|
@@ -30,7 +30,7 @@ export default defineCommand({
|
|
|
30
30
|
]
|
|
31
31
|
});
|
|
32
32
|
if (cmd === "ts-expect-error") {
|
|
33
|
-
await runCmd(await
|
|
33
|
+
await runCmd(await getCmdInjectExpect(), []);
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
});
|
package/bin/app/libs/cmd.d.ts
CHANGED
package/bin/app/libs/cmd.js
CHANGED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import path from "@reliverse/pathkit";
|
|
2
|
+
import fs from "@reliverse/relifso";
|
|
3
|
+
import { relinka } from "@reliverse/relinka";
|
|
4
|
+
import { defineArgs, defineCommand } from "@reliverse/rempts";
|
|
5
|
+
import { createJiti } from "jiti";
|
|
6
|
+
export default defineCommand({
|
|
7
|
+
meta: {
|
|
8
|
+
name: "libs",
|
|
9
|
+
version: "1.0.0",
|
|
10
|
+
description: "Initialize and manage library packages."
|
|
11
|
+
},
|
|
12
|
+
args: defineArgs({
|
|
13
|
+
init: {
|
|
14
|
+
type: "string",
|
|
15
|
+
required: true,
|
|
16
|
+
description: "Names of libraries to initialize (space-separated or quoted)"
|
|
17
|
+
},
|
|
18
|
+
overwrite: {
|
|
19
|
+
type: "boolean",
|
|
20
|
+
default: false,
|
|
21
|
+
description: "Overwrite existing libraries"
|
|
22
|
+
}
|
|
23
|
+
}),
|
|
24
|
+
async run({ args }) {
|
|
25
|
+
let libNames = [];
|
|
26
|
+
if (Array.isArray(args.init)) {
|
|
27
|
+
libNames = args.init;
|
|
28
|
+
} else if (typeof args.init === "string") {
|
|
29
|
+
libNames = args.init.split(/\s+/).filter(Boolean);
|
|
30
|
+
}
|
|
31
|
+
if (libNames.length === 1) {
|
|
32
|
+
const argv = process.argv;
|
|
33
|
+
const initIndex = argv.findIndex((arg) => arg === "--init");
|
|
34
|
+
if (initIndex !== -1 && initIndex + 1 < argv.length) {
|
|
35
|
+
const additionalArgs = [];
|
|
36
|
+
for (let i = initIndex + 2; i < argv.length; i++) {
|
|
37
|
+
const arg = argv[i];
|
|
38
|
+
if (arg?.startsWith("--")) break;
|
|
39
|
+
if (arg && !arg.startsWith("-")) {
|
|
40
|
+
additionalArgs.push(arg);
|
|
41
|
+
} else {
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (additionalArgs.length > 0 && libNames[0]) {
|
|
46
|
+
libNames = [libNames[0], ...additionalArgs];
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (libNames.length === 0) {
|
|
51
|
+
relinka("error", "\u274C No library names provided");
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const dlerConfigPath = path.resolve(".config/dler.ts");
|
|
55
|
+
let dlerConfig;
|
|
56
|
+
try {
|
|
57
|
+
const jiti = createJiti(import.meta.url);
|
|
58
|
+
dlerConfig = await jiti.import(dlerConfigPath, {
|
|
59
|
+
default: true
|
|
60
|
+
});
|
|
61
|
+
} catch {
|
|
62
|
+
relinka("error", "\u274C Failed to read .config/dler.ts");
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const { libsDirSrc, libsList } = dlerConfig;
|
|
66
|
+
if (!libsDirSrc || !libsList) {
|
|
67
|
+
relinka("error", "\u274C Missing libsDirSrc or libsList in dler config");
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
relinka(
|
|
71
|
+
"info",
|
|
72
|
+
`\u{1F680} Processing ${libNames.length} library(s): ${libNames.join(", ")}`
|
|
73
|
+
);
|
|
74
|
+
for (const libName of libNames) {
|
|
75
|
+
const libConfig = libsList[libName];
|
|
76
|
+
if (!libConfig) {
|
|
77
|
+
relinka("warn", `\u274C Library "${libName}" not found in libsList config`);
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
const { libDirName, libMainFile } = libConfig;
|
|
81
|
+
if (!libDirName || !libMainFile) {
|
|
82
|
+
relinka(
|
|
83
|
+
"warn",
|
|
84
|
+
`\u274C Missing libDirName or libMainFile for "${libName}"`
|
|
85
|
+
);
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
const libDirPath = path.join(libsDirSrc, libDirName);
|
|
89
|
+
const mainFilePath = path.join(libsDirSrc, libMainFile);
|
|
90
|
+
if (!await fs.pathExists(libDirPath)) {
|
|
91
|
+
await fs.ensureDir(libDirPath);
|
|
92
|
+
relinka("log", `\u2705 Created library directory: ${libDirPath}`);
|
|
93
|
+
}
|
|
94
|
+
if (!await fs.pathExists(mainFilePath) || args.overwrite) {
|
|
95
|
+
const mainFileContent = `// Main entry point for ${libName}
|
|
96
|
+
export * from "./${libDirName}";
|
|
97
|
+
`;
|
|
98
|
+
await fs.ensureDir(path.dirname(mainFilePath));
|
|
99
|
+
await fs.writeFile(mainFilePath, mainFileContent, "utf-8");
|
|
100
|
+
relinka("log", `\u2705 Created/Updated main file: ${mainFilePath}`);
|
|
101
|
+
} else {
|
|
102
|
+
relinka(
|
|
103
|
+
"warn",
|
|
104
|
+
`\u26A0\uFE0F Main file already exists: ${mainFilePath}. Use --overwrite to update.`
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
});
|
package/bin/app/relifso/cmd.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { relinka } from "@reliverse/relinka";
|
|
2
2
|
import { defineCommand, runCmd, selectPrompt } from "@reliverse/rempts";
|
|
3
|
-
import {
|
|
3
|
+
import { getCmdRelifsoInit, getCmdRelifsoRename } from "../cmds.js";
|
|
4
4
|
export default defineCommand({
|
|
5
5
|
meta: {
|
|
6
6
|
name: "relifso",
|
|
@@ -38,11 +38,11 @@ export default defineCommand({
|
|
|
38
38
|
]
|
|
39
39
|
});
|
|
40
40
|
if (cmd === "init") {
|
|
41
|
-
await runCmd(await
|
|
41
|
+
await runCmd(await getCmdRelifsoInit(), []);
|
|
42
42
|
} else if (cmd === "rename-prepare") {
|
|
43
|
-
await runCmd(await
|
|
43
|
+
await runCmd(await getCmdRelifsoRename(), ["--prepareMyCLI"]);
|
|
44
44
|
} else if (cmd === "rename-prepare-revert") {
|
|
45
|
-
await runCmd(await
|
|
45
|
+
await runCmd(await getCmdRelifsoRename(), ["--prepareMyCLI", "--revert"]);
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
});
|
package/bin/app/relinka/cmd.d.ts
CHANGED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
declare const _default: import("@reliverse/rempts").Command<{
|
|
2
|
+
input: {
|
|
3
|
+
type: "string";
|
|
4
|
+
required: true;
|
|
5
|
+
description: string;
|
|
6
|
+
};
|
|
7
|
+
from: {
|
|
8
|
+
type: "string";
|
|
9
|
+
required: true;
|
|
10
|
+
description: string;
|
|
11
|
+
};
|
|
12
|
+
to: {
|
|
13
|
+
type: "string";
|
|
14
|
+
required: true;
|
|
15
|
+
description: string;
|
|
16
|
+
};
|
|
17
|
+
}>;
|
|
18
|
+
export default _default;
|
package/bin/app/relinka/cmd.js
CHANGED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import fs from "@reliverse/relifso";
|
|
2
|
+
import { relinka } from "@reliverse/relinka";
|
|
3
|
+
import { defineArgs, defineCommand } from "@reliverse/rempts";
|
|
4
|
+
export default defineCommand({
|
|
5
|
+
meta: {
|
|
6
|
+
name: "relinka",
|
|
7
|
+
version: "1.0.0",
|
|
8
|
+
description: "Convert between different logging formats (console, consola method/object, relinka function/method/object)."
|
|
9
|
+
},
|
|
10
|
+
args: defineArgs({
|
|
11
|
+
input: {
|
|
12
|
+
type: "string",
|
|
13
|
+
required: true,
|
|
14
|
+
description: "Input file or directory path"
|
|
15
|
+
},
|
|
16
|
+
from: {
|
|
17
|
+
type: "string",
|
|
18
|
+
required: true,
|
|
19
|
+
description: "Source format (console, consolaMethod, consolaObject, relinkaFunction, relinkaMethod, relinkaObject)"
|
|
20
|
+
},
|
|
21
|
+
to: {
|
|
22
|
+
type: "string",
|
|
23
|
+
required: true,
|
|
24
|
+
description: "Target format (console, consolaMethod, consolaObject, relinkaFunction, relinkaMethod, relinkaObject)"
|
|
25
|
+
}
|
|
26
|
+
}),
|
|
27
|
+
async run({ args }) {
|
|
28
|
+
const { input, from, to } = args;
|
|
29
|
+
if (!await fs.pathExists(input)) {
|
|
30
|
+
relinka("error", `\u274C Input path does not exist: ${input}`);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
let content = await fs.readFile(input, "utf-8");
|
|
34
|
+
let changes = false;
|
|
35
|
+
const levels = [
|
|
36
|
+
"log",
|
|
37
|
+
"info",
|
|
38
|
+
"warn",
|
|
39
|
+
"error",
|
|
40
|
+
"debug",
|
|
41
|
+
"verbose",
|
|
42
|
+
"success",
|
|
43
|
+
"ready",
|
|
44
|
+
"start",
|
|
45
|
+
"box",
|
|
46
|
+
"trace"
|
|
47
|
+
];
|
|
48
|
+
const getSourcePattern = (level, format) => {
|
|
49
|
+
switch (format) {
|
|
50
|
+
case "console":
|
|
51
|
+
return new RegExp(`console\\.${level}\\((.*?)(?:,\\s*(.*))?\\)`, "g");
|
|
52
|
+
case "consolaMethod":
|
|
53
|
+
if (level === "box") {
|
|
54
|
+
return /consola\.box\(\s*{\s*title:\s*"([^"]*)",\s*message:\s*"([^"]*)"\s*\}\s*\)/g;
|
|
55
|
+
}
|
|
56
|
+
return new RegExp(`consola\\.${level}\\((.*?)(?:,\\s*(.*))?\\)`, "g");
|
|
57
|
+
case "consolaObject":
|
|
58
|
+
return new RegExp(
|
|
59
|
+
`consola\\({level:\\s*"${level}",\\s*message:\\s*(.*?)(?:,\\s*title:\\s*"([^"]*)")?\\s*\\}\\)`,
|
|
60
|
+
"g"
|
|
61
|
+
);
|
|
62
|
+
case "relinkaFunction":
|
|
63
|
+
return new RegExp(
|
|
64
|
+
`relinka\\("${level}",\\s*(.*?)(?:,\\s*(.*))?\\)`,
|
|
65
|
+
"g"
|
|
66
|
+
);
|
|
67
|
+
case "relinkaMethod":
|
|
68
|
+
return new RegExp(`relinka\\.${level}\\((.*?)(?:,\\s*(.*))?\\)`, "g");
|
|
69
|
+
case "relinkaObject":
|
|
70
|
+
return new RegExp(
|
|
71
|
+
`relinka\\({level:\\s*"${level}",\\s*message:\\s*(.*?)(?:,\\s*title:\\s*"([^"]*)")?\\s*\\}\\)`,
|
|
72
|
+
"g"
|
|
73
|
+
);
|
|
74
|
+
default:
|
|
75
|
+
throw new Error(`Invalid source format: ${format}`);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
const createReplacement = (level, message, title, args2) => {
|
|
79
|
+
switch (to) {
|
|
80
|
+
case "console":
|
|
81
|
+
return `console.${level}(${message}${args2 ? `, ${args2}` : ""})`;
|
|
82
|
+
case "consolaMethod":
|
|
83
|
+
if (level === "box" && title) {
|
|
84
|
+
return `consola.box({ title: "${title}", message: "${message}" })`;
|
|
85
|
+
}
|
|
86
|
+
return `consola.${level}(${message}${args2 ? `, ${args2}` : ""})`;
|
|
87
|
+
case "consolaObject": {
|
|
88
|
+
const obj = {
|
|
89
|
+
level: `"${level}"`,
|
|
90
|
+
message,
|
|
91
|
+
...title && { title: `"${title}"` },
|
|
92
|
+
...args2 && { args: `[${args2}]` }
|
|
93
|
+
};
|
|
94
|
+
return `consola(${JSON.stringify(obj).replace(/"([^"]+)":/g, "$1:")})`;
|
|
95
|
+
}
|
|
96
|
+
case "relinkaFunction":
|
|
97
|
+
if (level === "box" && title) {
|
|
98
|
+
return `relinka("${level}", "${title}\\n${message}"${args2 ? `, ${args2}` : ""})`;
|
|
99
|
+
}
|
|
100
|
+
return `relinka("${level}", ${message}${args2 ? `, ${args2}` : ""})`;
|
|
101
|
+
case "relinkaMethod":
|
|
102
|
+
if (level === "box" && title) {
|
|
103
|
+
return `relinka.${level}("${title}\\n${message}"${args2 ? `, ${args2}` : ""})`;
|
|
104
|
+
}
|
|
105
|
+
return `relinka.${level}(${message}${args2 ? `, ${args2}` : ""})`;
|
|
106
|
+
case "relinkaObject": {
|
|
107
|
+
const obj = {
|
|
108
|
+
level: `"${level}"`,
|
|
109
|
+
message,
|
|
110
|
+
...title && { title: `"${title}"` },
|
|
111
|
+
...args2 && { args: `[${args2}]` }
|
|
112
|
+
};
|
|
113
|
+
return `relinka(${JSON.stringify(obj).replace(/"([^"]+)":/g, "$1:")})`;
|
|
114
|
+
}
|
|
115
|
+
default:
|
|
116
|
+
throw new Error(`Invalid target format: ${to}`);
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
for (const level of levels) {
|
|
120
|
+
const pattern = getSourcePattern(level, from);
|
|
121
|
+
const newContent = content.replace(
|
|
122
|
+
pattern,
|
|
123
|
+
(_, message, titleOrArgs, args2) => {
|
|
124
|
+
changes = true;
|
|
125
|
+
if ((from === "consolaMethod" || from === "relinkaMethod") && level === "box") {
|
|
126
|
+
return createReplacement(level, message, titleOrArgs, args2);
|
|
127
|
+
}
|
|
128
|
+
return createReplacement(level, message, void 0, titleOrArgs);
|
|
129
|
+
}
|
|
130
|
+
);
|
|
131
|
+
if (newContent !== content) {
|
|
132
|
+
content = newContent;
|
|
133
|
+
relinka(
|
|
134
|
+
"log",
|
|
135
|
+
`\u2705 Converted ${level} calls from ${from} to ${to} format`
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
if (!changes) {
|
|
140
|
+
relinka("warn", "\u26A0\uFE0F No matching calls found to convert");
|
|
141
|
+
} else {
|
|
142
|
+
await fs.writeFile(input, content, "utf-8");
|
|
143
|
+
relinka(
|
|
144
|
+
"success",
|
|
145
|
+
"\u2728 Successfully converted all logging calls to the target format"
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
});
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
declare const _default: import("@reliverse/rempts").Command<{
|
|
2
|
-
|
|
3
|
-
type: "
|
|
2
|
+
init: {
|
|
3
|
+
type: "string";
|
|
4
4
|
required: true;
|
|
5
5
|
description: string;
|
|
6
|
-
options: string[];
|
|
7
6
|
};
|
|
8
|
-
|
|
7
|
+
overwrite: {
|
|
9
8
|
type: "boolean";
|
|
10
9
|
default: false;
|
|
11
10
|
description: string;
|
|
12
11
|
};
|
|
12
|
+
customCmdsRoot: {
|
|
13
|
+
type: "string";
|
|
14
|
+
default: string;
|
|
15
|
+
description: string;
|
|
16
|
+
};
|
|
13
17
|
}>;
|
|
14
18
|
export default _default;
|