@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 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
  }>>;
@@ -29,11 +29,11 @@ export default defineCommand({
29
29
  },
30
30
  {
31
31
  value: "rename-prepare",
32
- label: "Rename files (prepare CLI)"
32
+ label: "My project is a bootstrapper CLI (apply rename optimizations)"
33
33
  },
34
34
  {
35
35
  value: "rename-prepare-revert",
36
- label: "Rename files (prepare CLI)"
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, readdirSync } from "node:fs";
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 prepareCLIFiles(revert = false) {
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 = readdirSync(srcDir, { recursive: true, encoding: "utf-8" });
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 (!existsSync(fullPath)) continue;
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
- await safeRename(fullPath, join(dir, `${baseName}.d.ts.txt`));
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 { prepareMyCLI, revert, source, destination } = args;
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(revert === true);
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
@@ -1,5 +1,5 @@
1
1
  import { endPrompt, startPrompt } from "@reliverse/rempts";
2
- const version = "1.5.2";
2
+ const version = "1.5.4";
3
3
  export async function showStartPrompt(isDev) {
4
4
  await startPrompt({
5
5
  titleColor: "inverse",
package/package.json CHANGED
@@ -41,7 +41,7 @@
41
41
  "license": "MIT",
42
42
  "name": "@reliverse/dler",
43
43
  "type": "module",
44
- "version": "1.5.2",
44
+ "version": "1.5.4",
45
45
  "keywords": [
46
46
  "reliverse",
47
47
  "cli",