@reliverse/dler 1.5.2 → 1.5.3

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,26 @@ 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) {
25
44
  const configPath = ".config/dler.ts";
26
45
  let srcDir = "src";
27
46
  if (existsSync(configPath)) {
@@ -34,17 +53,17 @@ async function prepareCLIFiles(revert = false) {
34
53
  if (!existsSync(srcDir)) {
35
54
  throw new Error(`Source directory not found: ${srcDir}`);
36
55
  }
37
- const files = readdirSync(srcDir, { recursive: true, encoding: "utf-8" });
56
+ const files = await getAllFilesAsync(srcDir, srcDir, recursive);
38
57
  for (const file of files) {
39
58
  const fullPath = join(srcDir, file);
40
- if (!existsSync(fullPath)) continue;
59
+ if (!await fileExists(fullPath)) continue;
41
60
  const ext = extname(file);
42
61
  const baseName = basename(file, ext);
43
62
  const dir = dirname(fullPath);
44
63
  if (revert) {
45
64
  if (file.endsWith(".json.json")) {
46
65
  await safeRename(fullPath, join(dir, baseName));
47
- } else if (file.endsWith(".d.ts.txt")) {
66
+ } else if (file.endsWith(".d.ts.txt") && useDtsTxtForPrepareMyCLI) {
48
67
  await safeRename(fullPath, join(dir, `${baseName}.d.ts`));
49
68
  } else if (file.endsWith(".cjs")) {
50
69
  await safeRename(fullPath, join(dir, `${baseName}.js`));
@@ -54,8 +73,9 @@ async function prepareCLIFiles(revert = false) {
54
73
  await safeRename(fullPath, join(dir, "tsconfig.json.json"));
55
74
  } else if (file === "package.json" && !file.endsWith(".json.json")) {
56
75
  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`));
76
+ } else if (file.endsWith(".d.ts") && !file.endsWith(".d.ts.txt") && useDtsTxtForPrepareMyCLI) {
77
+ const baseWithoutD = baseName.slice(0, -2);
78
+ await safeRename(fullPath, join(dir, `${baseWithoutD}.d.ts.txt`));
59
79
  } else if (file.endsWith(".js") && !file.endsWith(".cjs")) {
60
80
  const content = readFileSync(fullPath, "utf-8");
61
81
  if (isCommonJSFile(content)) {
@@ -95,13 +115,36 @@ export default defineCommand({
95
115
  type: "string",
96
116
  description: "Destination name for the rename operation",
97
117
  required: false
118
+ },
119
+ recursive: {
120
+ type: "boolean",
121
+ description: "Recursively process all files in subdirectories (default: true)",
122
+ required: false,
123
+ default: true
124
+ },
125
+ useDtsTxtForPrepareMyCLI: {
126
+ type: "boolean",
127
+ description: "Use .d.ts.txt extension for .d.ts files in prepareMyCLI mode (default: false)",
128
+ required: false,
129
+ default: false
98
130
  }
99
131
  },
100
132
  async run({ args }) {
101
- const { prepareMyCLI, revert, source, destination } = args;
133
+ const {
134
+ prepareMyCLI,
135
+ revert,
136
+ source,
137
+ destination,
138
+ recursive = true,
139
+ useDtsTxtForPrepareMyCLI = false
140
+ } = args;
102
141
  if (prepareMyCLI === true) {
103
142
  try {
104
- await prepareCLIFiles(revert === true);
143
+ await prepareCLIFiles(
144
+ revert === true,
145
+ recursive,
146
+ useDtsTxtForPrepareMyCLI
147
+ );
105
148
  relinka("log", "Successfully prepared CLI files");
106
149
  } catch (error) {
107
150
  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.3";
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.3",
45
45
  "keywords": [
46
46
  "reliverse",
47
47
  "cli",