@reliverse/dler 1.5.1 → 1.5.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.
@@ -65,5 +65,15 @@ declare const _default: import("@reliverse/rempts").Command<{
65
65
  type: "string";
66
66
  default: string;
67
67
  };
68
+ separateTypesFile: {
69
+ description: string;
70
+ type: "boolean";
71
+ default: false;
72
+ };
73
+ typesOut: {
74
+ description: string;
75
+ type: "string";
76
+ required: false;
77
+ };
68
78
  }>;
69
79
  export default _default;
@@ -68,6 +68,16 @@ export default defineCommand({
68
68
  description: "Comma-separated list of file extensions to process (default: .ts,.js,.mts,.cts,.mjs,.cjs)",
69
69
  type: "string",
70
70
  default: ".ts,.js,.mts,.cts,.mjs,.cjs"
71
+ },
72
+ separateTypesFile: {
73
+ description: "Create a separate file for type exports",
74
+ type: "boolean",
75
+ default: false
76
+ },
77
+ typesOut: {
78
+ description: "Output file path for types (used when separateTypesFile is true)",
79
+ type: "string",
80
+ required: false
71
81
  }
72
82
  }),
73
83
  async run({ args }) {
@@ -84,7 +94,9 @@ export default defineCommand({
84
94
  includeInternal: !!args.includeInternal,
85
95
  internalMarker: args.internalMarker,
86
96
  overrideFile: !!args.override,
87
- fileExtensions: args.extensions.split(",").map((ext) => ext.trim())
97
+ fileExtensions: args.extensions.split(",").map((ext) => ext.trim()),
98
+ separateTypesFile: !!args.separateTypesFile,
99
+ typesOutFile: args.typesOut ? path.resolve(args.typesOut) : void 0
88
100
  });
89
101
  }
90
102
  });
@@ -15,7 +15,7 @@
15
15
  * - By default, updates only the auto-generated block in the aggregator file,
16
16
  * leaving any other content intact. Pass `overrideFile: true` to rewrite the entire file.
17
17
  */
18
- export declare function useAggregator({ inputDir, isRecursive, outFile, stripPrefix, useImport, useNamed, ignoreDirs, sortLines, headerComment, verbose, includeInternal, internalMarker, overrideFile, fileExtensions, }: {
18
+ export declare function useAggregator({ inputDir, isRecursive, outFile, stripPrefix, useImport, useNamed, ignoreDirs, sortLines, headerComment, verbose, includeInternal, internalMarker, overrideFile, fileExtensions, separateTypesFile, typesOutFile, }: {
19
19
  inputDir: string;
20
20
  isRecursive: boolean;
21
21
  outFile: string;
@@ -30,6 +30,8 @@ export declare function useAggregator({ inputDir, isRecursive, outFile, stripPre
30
30
  internalMarker?: string;
31
31
  overrideFile?: boolean;
32
32
  fileExtensions?: string[];
33
+ separateTypesFile?: boolean;
34
+ typesOutFile?: string;
33
35
  }): Promise<void>;
34
36
  /**
35
37
  * Prints usage examples based on whether dev mode or not.
@@ -1,7 +1,6 @@
1
1
  import path from "@reliverse/pathkit";
2
2
  import fs from "@reliverse/relifso";
3
3
  import { relinka } from "@reliverse/relinka";
4
- import MagicString from "magic-string";
5
4
  const AGGREGATOR_START = "// AUTO-GENERATED AGGREGATOR START";
6
5
  const AGGREGATOR_END = "// AUTO-GENERATED AGGREGATOR END";
7
6
  export async function useAggregator({
@@ -18,7 +17,9 @@ export async function useAggregator({
18
17
  includeInternal = false,
19
18
  internalMarker = "#",
20
19
  overrideFile = false,
21
- fileExtensions = [".ts", ".js", ".mts", ".cts", ".mjs", ".cjs"]
20
+ fileExtensions = [".ts", ".js", ".mts", ".cts", ".mjs", ".cjs"],
21
+ separateTypesFile = false,
22
+ typesOutFile
22
23
  }) {
23
24
  try {
24
25
  const st = await fs.stat(inputDir).catch(() => null);
@@ -37,6 +38,19 @@ ${error}`
37
38
  );
38
39
  process.exit(1);
39
40
  }
41
+ if (separateTypesFile && typesOutFile) {
42
+ const typesOutDir = path.dirname(typesOutFile);
43
+ try {
44
+ await fs.ensureDir(typesOutDir);
45
+ } catch (error) {
46
+ relinka(
47
+ "error",
48
+ `Error: Cannot create types output directory: ${typesOutDir}
49
+ ${error}`
50
+ );
51
+ process.exit(1);
52
+ }
53
+ }
40
54
  const outExt = path.extname(outFile).toLowerCase();
41
55
  if (!fileExtensions.includes(outExt)) {
42
56
  relinka(
@@ -98,62 +112,48 @@ ${error}`
98
112
  )
99
113
  );
100
114
  const allLines = aggregatorLinesArrays.flat();
115
+ const typeLines = [];
116
+ const valueLines = [];
117
+ for (const line of allLines) {
118
+ if (line.includes("type {")) {
119
+ typeLines.push(line);
120
+ } else {
121
+ valueLines.push(line);
122
+ }
123
+ }
101
124
  if (sortLines) {
102
- allLines.sort();
125
+ typeLines.sort();
126
+ valueLines.sort();
103
127
  if (verbose) relinka("log", "Sorted aggregator lines alphabetically.");
104
128
  }
105
- const aggregatorContent = allLines.join("\n");
106
- const aggregatorBlock = `${headerComment ? `${headerComment}
129
+ const buildAggregatorBlock = (lines) => `${headerComment ? `${headerComment}
107
130
  ` : ""}${AGGREGATOR_START}
108
- ${aggregatorContent}
131
+ ${lines.join("\n")}
109
132
  ${AGGREGATOR_END}
110
133
  `;
111
- let finalText;
112
- if (overrideFile) {
113
- finalText = aggregatorBlock;
114
- if (verbose) {
115
- relinka("log", "Override mode: rewriting entire file.");
116
- }
134
+ if (separateTypesFile && typesOutFile) {
135
+ const typeBlock = buildAggregatorBlock(typeLines);
136
+ await fs.ensureFile(typesOutFile);
137
+ await fs.writeFile(typesOutFile, typeBlock, "utf8");
138
+ const valueBlock = buildAggregatorBlock([
139
+ ...valueLines,
140
+ `export * from "${path.relative(path.dirname(outFile), typesOutFile).replace(/\\/g, "/")}";`
141
+ ]);
142
+ await fs.ensureFile(outFile);
143
+ await fs.writeFile(outFile, valueBlock, "utf8");
144
+ relinka(
145
+ "success",
146
+ `Aggregator done: processed ${typeLines.length} type lines in: ${typesOutFile} and ${valueLines.length} value lines in: ${outFile}`
147
+ );
117
148
  } else {
118
- let existingContent = "";
119
- try {
120
- existingContent = await fs.readFile(outFile, "utf8");
121
- } catch {
122
- if (verbose)
123
- relinka("log", "Aggregator file does not exist. Creating new one.");
124
- }
125
- if (existingContent?.includes(AGGREGATOR_START) && existingContent.includes(AGGREGATOR_END)) {
126
- if (verbose) {
127
- relinka(
128
- "log",
129
- "Existing aggregator block found. Updating auto-generated section."
130
- );
131
- }
132
- const s = new MagicString(existingContent);
133
- const startIdx = existingContent.indexOf(AGGREGATOR_START);
134
- const endIdx = existingContent.indexOf(AGGREGATOR_END) + AGGREGATOR_END.length;
135
- s.update(startIdx, endIdx, aggregatorBlock.trim());
136
- finalText = s.toString();
137
- } else {
138
- if (existingContent) {
139
- if (verbose)
140
- relinka(
141
- "log",
142
- "No aggregator block found. Appending auto-generated section."
143
- );
144
- finalText = `${existingContent.trim()}
145
- ${aggregatorBlock}`;
146
- } else {
147
- finalText = aggregatorBlock;
148
- }
149
- }
149
+ const aggregatorBlock = buildAggregatorBlock(allLines);
150
+ await fs.ensureFile(outFile);
151
+ await fs.writeFile(outFile, aggregatorBlock, "utf8");
152
+ relinka(
153
+ "success",
154
+ `Aggregator done: processed ${allLines.length} lines in: ${outFile}`
155
+ );
150
156
  }
151
- await fs.ensureFile(outFile);
152
- await fs.writeFile(outFile, finalText, "utf8");
153
- relinka(
154
- "success",
155
- `Aggregator done: processed ${allLines.length} lines in: ${outFile}`
156
- );
157
157
  } catch (error) {
158
158
  relinka("error", `Aggregator failed: ${error}`);
159
159
  process.exit(1);
@@ -33,6 +33,8 @@ export async function promptAggCommand() {
33
33
  let out = "";
34
34
  let recursive = true;
35
35
  let strip = "";
36
+ let separateTypesFile = false;
37
+ let typesOut = "";
36
38
  if (selectedLibName && selectedLibName !== "") {
37
39
  const libConfig = config?.libsList?.[selectedLibName];
38
40
  if (config && libConfig) {
@@ -72,12 +74,24 @@ export async function promptAggCommand() {
72
74
  defaultValue: strip
73
75
  });
74
76
  }
77
+ separateTypesFile = await confirmPrompt({
78
+ title: "Do you want to create a separate file for type exports?",
79
+ defaultValue: separateTypesFile
80
+ });
81
+ if (separateTypesFile) {
82
+ typesOut = await inputPrompt({
83
+ title: "Enter the output file for types",
84
+ defaultValue: out.replace(/\.(ts|js)$/, ".types.$1")
85
+ });
86
+ }
75
87
  await runCmd(await cmdAgg(), [
76
88
  `--imports=${imports}`,
77
89
  `--input=${input}`,
78
90
  `--named=${named}`,
79
91
  `--out=${out}`,
80
92
  `--recursive=${recursive}`,
81
- `--strip=${strip}`
93
+ `--strip=${strip}`,
94
+ `--separateTypesFile=${separateTypesFile}`,
95
+ ...separateTypesFile ? [`--typesOut=${typesOut}`] : []
82
96
  ]);
83
97
  }
package/bin/app/cmds.d.ts CHANGED
@@ -134,6 +134,16 @@ export declare function cmdAgg(): Promise<import("@reliverse/rempts").Command<{
134
134
  type: "string";
135
135
  default: string;
136
136
  };
137
+ separateTypesFile: {
138
+ description: string;
139
+ type: "boolean";
140
+ default: false;
141
+ };
142
+ typesOut: {
143
+ description: string;
144
+ type: "string";
145
+ required: false;
146
+ };
137
147
  }>>;
138
148
  export declare function cmdBuild(): Promise<import("@reliverse/rempts").Command<{
139
149
  dev: {
package/bin/init/info.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { endPrompt, startPrompt } from "@reliverse/rempts";
2
+ const version = "1.5.2";
2
3
  export async function showStartPrompt(isDev) {
3
4
  await startPrompt({
4
5
  titleColor: "inverse",
@@ -6,7 +7,7 @@ export async function showStartPrompt(isDev) {
6
7
  // packageName: getPkgName(),
7
8
  // packageVersion: getPkgVersion(),
8
9
  packageName: "dler",
9
- packageVersion: "1.3.5",
10
+ packageVersion: version,
10
11
  isDev
11
12
  });
12
13
  }
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.1",
44
+ "version": "1.5.2",
45
45
  "keywords": [
46
46
  "reliverse",
47
47
  "cli",