@reliverse/dler 1.5.0 → 1.5.1
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/bin/app/cmds.d.ts +41 -0
- package/bin/app/cmds.js +3 -0
- package/bin/app/relifso/cmd.js +13 -1
- package/bin/app/relifso/rename/cmd.d.ts +27 -0
- package/bin/app/relifso/rename/cmd.js +126 -0
- package/package.json +1 -1
package/bin/app/cmds.d.ts
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 👉 `dler rempts init --cmds`
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* import { cmdAgg } from "./cmds.js";
|
|
7
|
+
* await runCmd(await cmdAgg(), [
|
|
8
|
+
* `--imports=${imports}`,
|
|
9
|
+
* `--input=${input}`,
|
|
10
|
+
* `--named=${named}`,
|
|
11
|
+
* `--out=${out}`,
|
|
12
|
+
* `--recursive=${recursive}`,
|
|
13
|
+
* `--strip=${strip}`,
|
|
14
|
+
* ]);
|
|
15
|
+
*/
|
|
1
16
|
export declare function cmdRelifsoInit(): Promise<import("@reliverse/rempts").Command<{
|
|
2
17
|
dev: {
|
|
3
18
|
type: "boolean";
|
|
@@ -132,3 +147,29 @@ export declare function cmdPub(): Promise<import("@reliverse/rempts").Command<{
|
|
|
132
147
|
description: string;
|
|
133
148
|
};
|
|
134
149
|
}>>;
|
|
150
|
+
export declare function cmdRelifsoRename(): Promise<import("@reliverse/rempts").Command<{
|
|
151
|
+
dev: {
|
|
152
|
+
type: "boolean";
|
|
153
|
+
description: string;
|
|
154
|
+
};
|
|
155
|
+
prepareMyCLI: {
|
|
156
|
+
type: "boolean";
|
|
157
|
+
description: string;
|
|
158
|
+
required: false;
|
|
159
|
+
};
|
|
160
|
+
revert: {
|
|
161
|
+
type: "boolean";
|
|
162
|
+
description: string;
|
|
163
|
+
required: false;
|
|
164
|
+
};
|
|
165
|
+
source: {
|
|
166
|
+
type: "string";
|
|
167
|
+
description: string;
|
|
168
|
+
required: false;
|
|
169
|
+
};
|
|
170
|
+
destination: {
|
|
171
|
+
type: "string";
|
|
172
|
+
description: string;
|
|
173
|
+
required: false;
|
|
174
|
+
};
|
|
175
|
+
}>>;
|
package/bin/app/cmds.js
CHANGED
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 { cmdRelifsoInit } from "../cmds.js";
|
|
3
|
+
import { cmdRelifsoInit, cmdRelifsoRename } from "../cmds.js";
|
|
4
4
|
export default defineCommand({
|
|
5
5
|
meta: {
|
|
6
6
|
name: "relifso",
|
|
@@ -26,11 +26,23 @@ export default defineCommand({
|
|
|
26
26
|
{
|
|
27
27
|
value: "init",
|
|
28
28
|
label: "Initialize files"
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
value: "rename-prepare",
|
|
32
|
+
label: "Rename files (prepare CLI)"
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
value: "rename-prepare-revert",
|
|
36
|
+
label: "Rename files (prepare CLI)"
|
|
29
37
|
}
|
|
30
38
|
]
|
|
31
39
|
});
|
|
32
40
|
if (cmd === "init") {
|
|
33
41
|
await runCmd(await cmdRelifsoInit(), []);
|
|
42
|
+
} else if (cmd === "rename-prepare") {
|
|
43
|
+
await runCmd(await cmdRelifsoRename(), ["--prepareMyCLI"]);
|
|
44
|
+
} else if (cmd === "rename-prepare-revert") {
|
|
45
|
+
await runCmd(await cmdRelifsoRename(), ["--prepareMyCLI", "--revert"]);
|
|
34
46
|
}
|
|
35
47
|
}
|
|
36
48
|
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
declare const _default: import("@reliverse/rempts").Command<{
|
|
2
|
+
dev: {
|
|
3
|
+
type: "boolean";
|
|
4
|
+
description: string;
|
|
5
|
+
};
|
|
6
|
+
prepareMyCLI: {
|
|
7
|
+
type: "boolean";
|
|
8
|
+
description: string;
|
|
9
|
+
required: false;
|
|
10
|
+
};
|
|
11
|
+
revert: {
|
|
12
|
+
type: "boolean";
|
|
13
|
+
description: string;
|
|
14
|
+
required: false;
|
|
15
|
+
};
|
|
16
|
+
source: {
|
|
17
|
+
type: "string";
|
|
18
|
+
description: string;
|
|
19
|
+
required: false;
|
|
20
|
+
};
|
|
21
|
+
destination: {
|
|
22
|
+
type: "string";
|
|
23
|
+
description: string;
|
|
24
|
+
required: false;
|
|
25
|
+
};
|
|
26
|
+
}>;
|
|
27
|
+
export default _default;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { relinka } from "@reliverse/relinka";
|
|
2
|
+
import { defineCommand } from "@reliverse/rempts";
|
|
3
|
+
import { existsSync, readdirSync } from "node:fs";
|
|
4
|
+
import { readFileSync } from "node:fs";
|
|
5
|
+
import { rename, access } from "node:fs/promises";
|
|
6
|
+
import { join, dirname, basename, extname } from "node:path";
|
|
7
|
+
async function fileExists(path) {
|
|
8
|
+
try {
|
|
9
|
+
await access(path);
|
|
10
|
+
return true;
|
|
11
|
+
} catch {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
async function safeRename(source, destination) {
|
|
16
|
+
if (await fileExists(destination)) {
|
|
17
|
+
throw new Error(`Destination file already exists: ${destination}`);
|
|
18
|
+
}
|
|
19
|
+
await rename(source, destination);
|
|
20
|
+
}
|
|
21
|
+
function isCommonJSFile(content) {
|
|
22
|
+
return content.includes("module.exports") || content.includes("require(");
|
|
23
|
+
}
|
|
24
|
+
async function prepareCLIFiles(revert = false) {
|
|
25
|
+
const configPath = ".config/dler.ts";
|
|
26
|
+
let srcDir = "src";
|
|
27
|
+
if (existsSync(configPath)) {
|
|
28
|
+
const configContent = readFileSync(configPath, "utf-8");
|
|
29
|
+
const configMatch = configContent.match(
|
|
30
|
+
/coreEntrySrcDir:\s*["']([^"']+)["']/
|
|
31
|
+
);
|
|
32
|
+
srcDir = configMatch?.[1] ?? srcDir;
|
|
33
|
+
}
|
|
34
|
+
if (!existsSync(srcDir)) {
|
|
35
|
+
throw new Error(`Source directory not found: ${srcDir}`);
|
|
36
|
+
}
|
|
37
|
+
const files = readdirSync(srcDir, { recursive: true, encoding: "utf-8" });
|
|
38
|
+
for (const file of files) {
|
|
39
|
+
const fullPath = join(srcDir, file);
|
|
40
|
+
if (!existsSync(fullPath)) continue;
|
|
41
|
+
const ext = extname(file);
|
|
42
|
+
const baseName = basename(file, ext);
|
|
43
|
+
const dir = dirname(fullPath);
|
|
44
|
+
if (revert) {
|
|
45
|
+
if (file.endsWith(".json.json")) {
|
|
46
|
+
await safeRename(fullPath, join(dir, baseName));
|
|
47
|
+
} else if (file.endsWith(".d.ts.txt")) {
|
|
48
|
+
await safeRename(fullPath, join(dir, `${baseName}.d.ts`));
|
|
49
|
+
} else if (file.endsWith(".cjs")) {
|
|
50
|
+
await safeRename(fullPath, join(dir, `${baseName}.js`));
|
|
51
|
+
}
|
|
52
|
+
} else {
|
|
53
|
+
if (file === "tsconfig.json" && !file.endsWith(".json.json")) {
|
|
54
|
+
await safeRename(fullPath, join(dir, "tsconfig.json.json"));
|
|
55
|
+
} else if (file === "package.json" && !file.endsWith(".json.json")) {
|
|
56
|
+
await safeRename(fullPath, join(dir, "package.json.json"));
|
|
57
|
+
} else if (file.endsWith(".d.ts") && !file.endsWith(".d.ts.txt")) {
|
|
58
|
+
await safeRename(fullPath, join(dir, `${baseName}.d.ts.txt`));
|
|
59
|
+
} else if (file.endsWith(".js") && !file.endsWith(".cjs")) {
|
|
60
|
+
const content = readFileSync(fullPath, "utf-8");
|
|
61
|
+
if (isCommonJSFile(content)) {
|
|
62
|
+
await safeRename(fullPath, join(dir, `${baseName}.cjs`));
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
export default defineCommand({
|
|
69
|
+
meta: {
|
|
70
|
+
name: "rename",
|
|
71
|
+
version: "1.0.0",
|
|
72
|
+
description: "Rename files for CLI preparation"
|
|
73
|
+
},
|
|
74
|
+
args: {
|
|
75
|
+
dev: {
|
|
76
|
+
type: "boolean",
|
|
77
|
+
description: "Runs the CLI in dev mode"
|
|
78
|
+
},
|
|
79
|
+
prepareMyCLI: {
|
|
80
|
+
type: "boolean",
|
|
81
|
+
description: "Prepare CLI by renaming files",
|
|
82
|
+
required: false
|
|
83
|
+
},
|
|
84
|
+
revert: {
|
|
85
|
+
type: "boolean",
|
|
86
|
+
description: "Revert renamed files back to original names",
|
|
87
|
+
required: false
|
|
88
|
+
},
|
|
89
|
+
source: {
|
|
90
|
+
type: "string",
|
|
91
|
+
description: "Source file or directory to rename",
|
|
92
|
+
required: false
|
|
93
|
+
},
|
|
94
|
+
destination: {
|
|
95
|
+
type: "string",
|
|
96
|
+
description: "Destination name for the rename operation",
|
|
97
|
+
required: false
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
async run({ args }) {
|
|
101
|
+
const { prepareMyCLI, revert, source, destination } = args;
|
|
102
|
+
if (prepareMyCLI === true) {
|
|
103
|
+
try {
|
|
104
|
+
await prepareCLIFiles(revert === true);
|
|
105
|
+
relinka("log", "Successfully prepared CLI files");
|
|
106
|
+
} catch (error) {
|
|
107
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
108
|
+
relinka("error", `Error preparing CLI: ${errorMessage}`);
|
|
109
|
+
process.exit(1);
|
|
110
|
+
}
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
if (!source || !destination) {
|
|
114
|
+
relinka("error", "Usage: dler relifso rename <source> <destination>");
|
|
115
|
+
process.exit(1);
|
|
116
|
+
}
|
|
117
|
+
try {
|
|
118
|
+
await safeRename(source, destination);
|
|
119
|
+
relinka("log", `Successfully renamed '${source}' to '${destination}'`);
|
|
120
|
+
} catch (error) {
|
|
121
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
122
|
+
relinka("error", `Error renaming: ${errorMessage}`);
|
|
123
|
+
process.exit(1);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
});
|