@reliverse/dler 1.5.2 → 1.5.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/bin/app/cmds.d.ts +12 -0
- package/bin/app/relifso/cmd.js +2 -2
- package/bin/app/relifso/rename/cmd.d.ts +12 -0
- package/bin/app/relifso/rename/cmd.js +82 -10
- package/bin/init/info.js +1 -1
- package/package.json +1 -1
package/bin/app/cmds.d.ts
CHANGED
|
@@ -182,4 +182,16 @@ export declare function cmdRelifsoRename(): Promise<import("@reliverse/rempts").
|
|
|
182
182
|
description: string;
|
|
183
183
|
required: false;
|
|
184
184
|
};
|
|
185
|
+
recursive: {
|
|
186
|
+
type: "boolean";
|
|
187
|
+
description: string;
|
|
188
|
+
required: false;
|
|
189
|
+
default: true;
|
|
190
|
+
};
|
|
191
|
+
useDtsTxtForPrepareMyCLI: {
|
|
192
|
+
type: "boolean";
|
|
193
|
+
description: string;
|
|
194
|
+
required: false;
|
|
195
|
+
default: false;
|
|
196
|
+
};
|
|
185
197
|
}>>;
|
package/bin/app/relifso/cmd.js
CHANGED
|
@@ -29,11 +29,11 @@ export default defineCommand({
|
|
|
29
29
|
},
|
|
30
30
|
{
|
|
31
31
|
value: "rename-prepare",
|
|
32
|
-
label: "
|
|
32
|
+
label: "My project is a bootstrapper CLI (apply rename optimizations)"
|
|
33
33
|
},
|
|
34
34
|
{
|
|
35
35
|
value: "rename-prepare-revert",
|
|
36
|
-
label: "
|
|
36
|
+
label: "Revert rename CLI files optimizations"
|
|
37
37
|
}
|
|
38
38
|
]
|
|
39
39
|
});
|
|
@@ -23,5 +23,17 @@ declare const _default: import("@reliverse/rempts").Command<{
|
|
|
23
23
|
description: string;
|
|
24
24
|
required: false;
|
|
25
25
|
};
|
|
26
|
+
recursive: {
|
|
27
|
+
type: "boolean";
|
|
28
|
+
description: string;
|
|
29
|
+
required: false;
|
|
30
|
+
default: true;
|
|
31
|
+
};
|
|
32
|
+
useDtsTxtForPrepareMyCLI: {
|
|
33
|
+
type: "boolean";
|
|
34
|
+
description: string;
|
|
35
|
+
required: false;
|
|
36
|
+
default: false;
|
|
37
|
+
};
|
|
26
38
|
}>;
|
|
27
39
|
export default _default;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { relinka } from "@reliverse/relinka";
|
|
2
2
|
import { defineCommand } from "@reliverse/rempts";
|
|
3
|
-
import { existsSync
|
|
3
|
+
import { existsSync } from "node:fs";
|
|
4
4
|
import { readFileSync } from "node:fs";
|
|
5
|
-
import { rename, access } from "node:fs/promises";
|
|
5
|
+
import { rename, access, readdir } from "node:fs/promises";
|
|
6
6
|
import { join, dirname, basename, extname } from "node:path";
|
|
7
7
|
async function fileExists(path) {
|
|
8
8
|
try {
|
|
@@ -21,7 +21,27 @@ async function safeRename(source, destination) {
|
|
|
21
21
|
function isCommonJSFile(content) {
|
|
22
22
|
return content.includes("module.exports") || content.includes("require(");
|
|
23
23
|
}
|
|
24
|
-
async function
|
|
24
|
+
async function getAllFilesAsync(dir, baseDir = dir, recursive = true) {
|
|
25
|
+
let fileList = [];
|
|
26
|
+
const entries = await readdir(dir, {
|
|
27
|
+
encoding: "utf-8",
|
|
28
|
+
withFileTypes: true
|
|
29
|
+
});
|
|
30
|
+
for (const entry of entries) {
|
|
31
|
+
const fullPath = join(dir, entry.name);
|
|
32
|
+
if (entry.isDirectory()) {
|
|
33
|
+
if (recursive) {
|
|
34
|
+
const subFiles = await getAllFilesAsync(fullPath, baseDir, recursive);
|
|
35
|
+
fileList = fileList.concat(subFiles);
|
|
36
|
+
}
|
|
37
|
+
} else if (entry.isFile()) {
|
|
38
|
+
fileList.push(fullPath.slice(baseDir.length + 1));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return fileList;
|
|
42
|
+
}
|
|
43
|
+
async function prepareCLIFiles(revert = false, recursive = true, useDtsTxtForPrepareMyCLI = false) {
|
|
44
|
+
relinka("log", "Starting CLI file preparation...");
|
|
25
45
|
const configPath = ".config/dler.ts";
|
|
26
46
|
let srcDir = "src";
|
|
27
47
|
if (existsSync(configPath)) {
|
|
@@ -34,36 +54,65 @@ async function prepareCLIFiles(revert = false) {
|
|
|
34
54
|
if (!existsSync(srcDir)) {
|
|
35
55
|
throw new Error(`Source directory not found: ${srcDir}`);
|
|
36
56
|
}
|
|
37
|
-
const files =
|
|
57
|
+
const files = await getAllFilesAsync(srcDir, srcDir, recursive);
|
|
58
|
+
relinka("log", `Found ${files.length} files to process.`);
|
|
38
59
|
for (const file of files) {
|
|
39
60
|
const fullPath = join(srcDir, file);
|
|
40
|
-
if (!
|
|
61
|
+
if (!await fileExists(fullPath)) continue;
|
|
41
62
|
const ext = extname(file);
|
|
42
63
|
const baseName = basename(file, ext);
|
|
43
64
|
const dir = dirname(fullPath);
|
|
65
|
+
relinka("log", `Processing file: ${fullPath}`);
|
|
44
66
|
if (revert) {
|
|
45
67
|
if (file.endsWith(".json.json")) {
|
|
68
|
+
relinka("log", `Reverting ${fullPath} to ${join(dir, baseName)}`);
|
|
46
69
|
await safeRename(fullPath, join(dir, baseName));
|
|
47
|
-
} else if (file.endsWith(".d.ts.txt")) {
|
|
70
|
+
} else if (file.endsWith(".d.ts.txt") && useDtsTxtForPrepareMyCLI) {
|
|
71
|
+
relinka(
|
|
72
|
+
"log",
|
|
73
|
+
`Reverting ${fullPath} to ${join(dir, `${baseName}.d.ts`)}`
|
|
74
|
+
);
|
|
48
75
|
await safeRename(fullPath, join(dir, `${baseName}.d.ts`));
|
|
49
76
|
} else if (file.endsWith(".cjs")) {
|
|
77
|
+
relinka(
|
|
78
|
+
"log",
|
|
79
|
+
`Reverting ${fullPath} to ${join(dir, `${baseName}.js`)}`
|
|
80
|
+
);
|
|
50
81
|
await safeRename(fullPath, join(dir, `${baseName}.js`));
|
|
51
82
|
}
|
|
52
83
|
} else {
|
|
53
84
|
if (file === "tsconfig.json" && !file.endsWith(".json.json")) {
|
|
85
|
+
relinka(
|
|
86
|
+
"log",
|
|
87
|
+
`Renaming ${fullPath} to ${join(dir, "tsconfig.json.json")}`
|
|
88
|
+
);
|
|
54
89
|
await safeRename(fullPath, join(dir, "tsconfig.json.json"));
|
|
55
90
|
} else if (file === "package.json" && !file.endsWith(".json.json")) {
|
|
91
|
+
relinka(
|
|
92
|
+
"log",
|
|
93
|
+
`Renaming ${fullPath} to ${join(dir, "package.json.json")}`
|
|
94
|
+
);
|
|
56
95
|
await safeRename(fullPath, join(dir, "package.json.json"));
|
|
57
|
-
} else if (file.endsWith(".d.ts") && !file.endsWith(".d.ts.txt")) {
|
|
58
|
-
|
|
96
|
+
} else if (file.endsWith(".d.ts") && !file.endsWith(".d.ts.txt") && useDtsTxtForPrepareMyCLI) {
|
|
97
|
+
const baseWithoutD = baseName.slice(0, -2);
|
|
98
|
+
relinka(
|
|
99
|
+
"log",
|
|
100
|
+
`Renaming ${fullPath} to ${join(dir, `${baseWithoutD}.d.ts.txt`)}`
|
|
101
|
+
);
|
|
102
|
+
await safeRename(fullPath, join(dir, `${baseWithoutD}.d.ts.txt`));
|
|
59
103
|
} else if (file.endsWith(".js") && !file.endsWith(".cjs")) {
|
|
60
104
|
const content = readFileSync(fullPath, "utf-8");
|
|
61
105
|
if (isCommonJSFile(content)) {
|
|
106
|
+
relinka(
|
|
107
|
+
"log",
|
|
108
|
+
`Renaming ${fullPath} to ${join(dir, `${baseName}.cjs`)}`
|
|
109
|
+
);
|
|
62
110
|
await safeRename(fullPath, join(dir, `${baseName}.cjs`));
|
|
63
111
|
}
|
|
64
112
|
}
|
|
65
113
|
}
|
|
66
114
|
}
|
|
115
|
+
relinka("log", "CLI file preparation completed.");
|
|
67
116
|
}
|
|
68
117
|
export default defineCommand({
|
|
69
118
|
meta: {
|
|
@@ -95,13 +144,36 @@ export default defineCommand({
|
|
|
95
144
|
type: "string",
|
|
96
145
|
description: "Destination name for the rename operation",
|
|
97
146
|
required: false
|
|
147
|
+
},
|
|
148
|
+
recursive: {
|
|
149
|
+
type: "boolean",
|
|
150
|
+
description: "Recursively process all files in subdirectories (default: true)",
|
|
151
|
+
required: false,
|
|
152
|
+
default: true
|
|
153
|
+
},
|
|
154
|
+
useDtsTxtForPrepareMyCLI: {
|
|
155
|
+
type: "boolean",
|
|
156
|
+
description: "Use .d.ts.txt extension for .d.ts files in prepareMyCLI mode (default: false)",
|
|
157
|
+
required: false,
|
|
158
|
+
default: false
|
|
98
159
|
}
|
|
99
160
|
},
|
|
100
161
|
async run({ args }) {
|
|
101
|
-
const {
|
|
162
|
+
const {
|
|
163
|
+
prepareMyCLI,
|
|
164
|
+
revert,
|
|
165
|
+
source,
|
|
166
|
+
destination,
|
|
167
|
+
recursive = true,
|
|
168
|
+
useDtsTxtForPrepareMyCLI = false
|
|
169
|
+
} = args;
|
|
102
170
|
if (prepareMyCLI === true) {
|
|
103
171
|
try {
|
|
104
|
-
await prepareCLIFiles(
|
|
172
|
+
await prepareCLIFiles(
|
|
173
|
+
revert === true,
|
|
174
|
+
recursive,
|
|
175
|
+
useDtsTxtForPrepareMyCLI
|
|
176
|
+
);
|
|
105
177
|
relinka("log", "Successfully prepared CLI files");
|
|
106
178
|
} catch (error) {
|
|
107
179
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
package/bin/init/info.js
CHANGED