@reliverse/dler 2.1.4 → 2.1.6

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.
@@ -1,8 +1,4 @@
1
- import {
2
- defineCmd,
3
- defineCmdArgs,
4
- defineCmdCfg
5
- } from "@reliverse/dler-launcher";
1
+ import { defineArgs, defineCommand } from "@reliverse/dler-launcher";
6
2
  import { logger } from "@reliverse/dler-logger";
7
3
  import fs from "fs/promises";
8
4
  const isWindows = () => globalThis.Bun?.platform?.() === "win32" || process.platform === "win32";
@@ -156,229 +152,234 @@ export ${name}="${newVal}"
156
152
  await fs.writeFile(profile, next);
157
153
  logger.info(`Persisted ${name} in ${profile}`);
158
154
  };
159
- const senvCmdArgs = defineCmdArgs({
160
- action: {
161
- type: "string",
162
- required: true,
163
- description: "Operation to perform: list|get|set|append|remove|contains"
155
+ export default defineCommand({
156
+ meta: {
157
+ name: "senv",
158
+ description: "Inspect and modify environment variables (process and user-level)",
159
+ examples: [
160
+ "dler senv --action list",
161
+ "dler senv --action list --name Path",
162
+ "dler senv --action get --name Path",
163
+ "dler senv --action set --name Path --value C\\\\bin",
164
+ "dler senv --action append --name Path --value C\\\\msys64\\\\ucrt64\\\\bin --yes",
165
+ "dler senv --action contains --name Path --value C\\\\bin"
166
+ ]
164
167
  },
165
- name: {
166
- type: "string",
167
- description: "Environment variable name (optional for list)"
168
- },
169
- value: {
170
- type: "string",
171
- description: "Value for set/append/remove/contains"
172
- },
173
- persist: {
174
- type: "boolean",
175
- description: "Persist change to user environment (default: true)"
176
- },
177
- yes: {
178
- type: "boolean",
179
- description: "Skip interactive confirmation message"
180
- }
181
- });
182
- const senvCmdCfg = defineCmdCfg({
183
- name: "senv",
184
- description: "Inspect and modify environment variables (process and user-level)",
185
- examples: [
186
- "dler senv --action list",
187
- "dler senv --action list --name Path",
188
- "dler senv --action get --name Path",
189
- "dler senv --action set --name Path --value C\\\\bin",
190
- "dler senv --action append --name Path --value C\\\\msys64\\\\ucrt64\\\\bin --yes",
191
- "dler senv --action contains --name Path --value C\\\\bin"
192
- ]
193
- });
194
- const senvCmd = async (args) => {
195
- try {
196
- if (typeof process.versions.bun === "undefined") {
197
- logger.error("\u274C This command requires Bun runtime. Sorry.");
198
- process.exit(1);
199
- }
200
- const { action, name, value } = args;
201
- const persist = args.persist ?? true;
202
- const yes = args.yes ?? false;
203
- const allowed = /* @__PURE__ */ new Set([
204
- "list",
205
- "get",
206
- "set",
207
- "append",
208
- "remove",
209
- "contains"
210
- ]);
211
- if (!allowed.has(action)) {
212
- logger.error(
213
- "Unknown action. Allowed: list, get, set, append, remove, contains"
214
- );
215
- process.exit(2);
216
- }
217
- if (action === "list") {
218
- if (name) {
219
- logger.log(`${name}=${process.env[name] ?? ""}`);
220
- } else {
221
- for (const k of Object.keys(process.env).sort()) {
222
- logger.log(`${k}=${process.env[k]}`);
223
- }
224
- }
225
- return;
226
- }
227
- if (!name) {
228
- logger.error("Name is required for this action");
229
- process.exit(2);
230
- }
231
- if (action === "get") {
232
- logger.log(process.env[name] ?? "");
233
- return;
168
+ args: defineArgs({
169
+ action: {
170
+ type: "string",
171
+ required: true,
172
+ description: "Operation to perform: list|get|set|append|remove|contains"
173
+ },
174
+ name: {
175
+ type: "string",
176
+ description: "Environment variable name (optional for list)"
177
+ },
178
+ value: {
179
+ type: "string",
180
+ description: "Value for set/append/remove/contains"
181
+ },
182
+ persist: {
183
+ type: "boolean",
184
+ description: "Persist change to user environment (default: true)"
185
+ },
186
+ yes: {
187
+ type: "boolean",
188
+ description: "Skip interactive confirmation message"
234
189
  }
235
- if (action === "contains") {
236
- if (!value) {
237
- logger.error("Value required for contains");
238
- process.exit(2);
190
+ }),
191
+ run: async ({ args }) => {
192
+ try {
193
+ if (typeof process.versions.bun === "undefined") {
194
+ logger.error("\u274C This command requires Bun runtime. Sorry.");
195
+ process.exit(1);
239
196
  }
240
- const cur2 = process.env[name] ?? "";
241
- const entries2 = normalizePathEntries(cur2).map(normalizeEntry);
242
- const keys = new Set(entries2.map(toComparable));
243
- process.exit(keys.has(toComparable(value)) ? 0 : 1);
244
- }
245
- if (action === "set") {
246
- if (typeof value === "undefined") {
247
- logger.error("Value required for set");
197
+ const { action, name, value } = args;
198
+ const persist = args.persist ?? true;
199
+ const yes = args.yes ?? false;
200
+ const allowed = /* @__PURE__ */ new Set([
201
+ "list",
202
+ "get",
203
+ "set",
204
+ "append",
205
+ "remove",
206
+ "contains"
207
+ ]);
208
+ if (!allowed.has(action)) {
209
+ logger.error(
210
+ "Unknown action. Allowed: list, get, set, append, remove, contains"
211
+ );
248
212
  process.exit(2);
249
213
  }
250
- process.env[name] = value;
251
- logger.info(`Set ${name} for current process.`);
252
- if (persist) {
253
- if (!yes) {
254
- logger.info(
255
- "Persisting to user environment (will create backup). Use --yes to skip this message."
256
- );
257
- }
258
- if (isWindows()) {
259
- try {
260
- await runPowerShellSetUser(name, value);
261
- logger.success(`Persisted ${name} to User environment (Windows).`);
262
- } catch (e) {
263
- logger.error("Failed to persist via PowerShell:");
264
- logger.error(String(e));
265
- }
214
+ if (action === "list") {
215
+ if (name) {
216
+ logger.log(`${name}=${process.env[name] ?? ""}`);
266
217
  } else {
267
- try {
268
- await persistPosix(name, value);
269
- } catch (e) {
270
- logger.error("Failed to persist on POSIX:");
271
- logger.error(String(e));
218
+ for (const k of Object.keys(process.env).sort()) {
219
+ logger.log(`${k}=${process.env[k]}`);
272
220
  }
273
221
  }
222
+ return;
274
223
  }
275
- return;
276
- }
277
- if (!value) {
278
- logger.error("Value required for append/remove");
279
- process.exit(2);
280
- }
281
- const cur = process.env[name] ?? "";
282
- const normalizedValue = normalizeEntry(value);
283
- let entries = normalizePathEntries(cur).map(normalizeEntry);
284
- if (action === "append") {
285
- const keySet = new Set(entries.map(toComparable));
286
- const targetKey = toComparable(normalizedValue);
287
- if (keySet.has(targetKey)) {
288
- logger.info("Entry already present \u2014 nothing to do.");
289
- } else {
290
- entries.push(normalizedValue);
291
- entries = uniqueByComparable(entries);
292
- const newVal = joinPathEntries(entries);
293
- process.env[name] = newVal;
294
- logger.info(`Appended to ${name} for current process.`);
224
+ if (!name) {
225
+ logger.error("Name is required for this action");
226
+ process.exit(2);
227
+ }
228
+ if (action === "get") {
229
+ logger.log(process.env[name] ?? "");
230
+ return;
231
+ }
232
+ if (action === "contains") {
233
+ if (!value) {
234
+ logger.error("Value required for contains");
235
+ process.exit(2);
236
+ }
237
+ const cur2 = process.env[name] ?? "";
238
+ const entries2 = normalizePathEntries(cur2).map(normalizeEntry);
239
+ const keys = new Set(entries2.map(toComparable));
240
+ process.exit(keys.has(toComparable(value)) ? 0 : 1);
241
+ }
242
+ if (action === "set") {
243
+ if (typeof value === "undefined") {
244
+ logger.error("Value required for set");
245
+ process.exit(2);
246
+ }
247
+ process.env[name] = value;
248
+ logger.info(`Set ${name} for current process.`);
295
249
  if (persist) {
250
+ if (!yes) {
251
+ logger.info(
252
+ "Persisting to user environment (will create backup). Use --yes to skip this message."
253
+ );
254
+ }
296
255
  if (isWindows()) {
297
256
  try {
298
- const userVal = (await runPowerShellGetUser(name)).trim();
299
- const userEntries = normalizePathEntries(userVal || "").map(
300
- normalizeEntry
257
+ await runPowerShellSetUser(name, value);
258
+ logger.success(
259
+ `Persisted ${name} to User environment (Windows).`
301
260
  );
302
- const uSet = new Set(userEntries.map(toComparable));
303
- if (!uSet.has(targetKey)) {
304
- userEntries.push(normalizedValue);
305
- const uniqueEntries = uniqueByComparable(userEntries);
306
- const joined = joinPathEntries(uniqueEntries);
307
- await runPowerShellSetUser(name, joined);
308
- logger.success(`Persisted append to User ${name} (Windows).`);
309
- } else {
310
- logger.info(
311
- "User-level already contains the entry \u2014 no change."
312
- );
313
- }
314
261
  } catch (e) {
315
- logger.error("Failed to persist append on Windows:");
262
+ logger.error("Failed to persist via PowerShell:");
316
263
  logger.error(String(e));
317
264
  }
318
265
  } else {
319
266
  try {
320
- await persistPosixEditPath(name, value, "append");
267
+ await persistPosix(name, value);
321
268
  } catch (e) {
322
- logger.error("Failed to persist append on POSIX:");
269
+ logger.error("Failed to persist on POSIX:");
323
270
  logger.error(String(e));
324
271
  }
325
272
  }
326
273
  }
274
+ return;
327
275
  }
328
- return;
329
- }
330
- if (action === "remove") {
331
- const targetKey = toComparable(normalizedValue);
332
- const idx = entries.findIndex((e) => toComparable(e) === targetKey);
333
- if (idx === -1) {
334
- logger.info("Entry not present \u2014 nothing to remove.");
335
- } else {
336
- entries.splice(idx, 1);
337
- entries = uniqueByComparable(entries);
338
- const newVal = joinPathEntries(entries);
339
- process.env[name] = newVal;
340
- logger.info(`Removed entry from ${name} for current process.`);
341
- if (persist) {
342
- if (isWindows()) {
343
- try {
344
- const userVal = (await runPowerShellGetUser(name)).trim();
345
- const userEntries = normalizePathEntries(userVal || "").map(
346
- normalizeEntry
347
- );
348
- const i2 = userEntries.findIndex(
349
- (e) => toComparable(e) === targetKey
350
- );
351
- if (i2 >= 0) {
352
- userEntries.splice(i2, 1);
353
- const uniqueEntries = uniqueByComparable(userEntries);
354
- await runPowerShellSetUser(
355
- name,
356
- joinPathEntries(uniqueEntries)
276
+ if (!value) {
277
+ logger.error("Value required for append/remove");
278
+ process.exit(2);
279
+ }
280
+ const cur = process.env[name] ?? "";
281
+ const normalizedValue = normalizeEntry(value);
282
+ let entries = normalizePathEntries(cur).map(normalizeEntry);
283
+ if (action === "append") {
284
+ const keySet = new Set(entries.map(toComparable));
285
+ const targetKey = toComparable(normalizedValue);
286
+ if (keySet.has(targetKey)) {
287
+ logger.info("Entry already present \u2014 nothing to do.");
288
+ } else {
289
+ entries.push(normalizedValue);
290
+ entries = uniqueByComparable(entries);
291
+ const newVal = joinPathEntries(entries);
292
+ process.env[name] = newVal;
293
+ logger.info(`Appended to ${name} for current process.`);
294
+ if (persist) {
295
+ if (isWindows()) {
296
+ try {
297
+ const userVal = (await runPowerShellGetUser(name)).trim();
298
+ const userEntries = normalizePathEntries(userVal || "").map(
299
+ normalizeEntry
357
300
  );
358
- logger.success(`Persisted removal to User ${name} (Windows).`);
359
- } else {
360
- logger.info("User-level did not contain entry \u2014 no change.");
301
+ const uSet = new Set(userEntries.map(toComparable));
302
+ if (!uSet.has(targetKey)) {
303
+ userEntries.push(normalizedValue);
304
+ const uniqueEntries = uniqueByComparable(userEntries);
305
+ const joined = joinPathEntries(uniqueEntries);
306
+ await runPowerShellSetUser(name, joined);
307
+ logger.success(`Persisted append to User ${name} (Windows).`);
308
+ } else {
309
+ logger.info(
310
+ "User-level already contains the entry \u2014 no change."
311
+ );
312
+ }
313
+ } catch (e) {
314
+ logger.error("Failed to persist append on Windows:");
315
+ logger.error(String(e));
316
+ }
317
+ } else {
318
+ try {
319
+ await persistPosixEditPath(name, value, "append");
320
+ } catch (e) {
321
+ logger.error("Failed to persist append on POSIX:");
322
+ logger.error(String(e));
361
323
  }
362
- } catch (e) {
363
- logger.error("Failed to persist removal on Windows:");
364
- logger.error(String(e));
365
324
  }
366
- } else {
367
- try {
368
- await persistPosixEditPath(name, value, "remove");
369
- } catch (e) {
370
- logger.error("Failed to persist removal on POSIX:");
371
- logger.error(String(e));
325
+ }
326
+ }
327
+ return;
328
+ }
329
+ if (action === "remove") {
330
+ const targetKey = toComparable(normalizedValue);
331
+ const idx = entries.findIndex((e) => toComparable(e) === targetKey);
332
+ if (idx === -1) {
333
+ logger.info("Entry not present \u2014 nothing to remove.");
334
+ } else {
335
+ entries.splice(idx, 1);
336
+ entries = uniqueByComparable(entries);
337
+ const newVal = joinPathEntries(entries);
338
+ process.env[name] = newVal;
339
+ logger.info(`Removed entry from ${name} for current process.`);
340
+ if (persist) {
341
+ if (isWindows()) {
342
+ try {
343
+ const userVal = (await runPowerShellGetUser(name)).trim();
344
+ const userEntries = normalizePathEntries(userVal || "").map(
345
+ normalizeEntry
346
+ );
347
+ const i2 = userEntries.findIndex(
348
+ (e) => toComparable(e) === targetKey
349
+ );
350
+ if (i2 >= 0) {
351
+ userEntries.splice(i2, 1);
352
+ const uniqueEntries = uniqueByComparable(userEntries);
353
+ await runPowerShellSetUser(
354
+ name,
355
+ joinPathEntries(uniqueEntries)
356
+ );
357
+ logger.success(
358
+ `Persisted removal to User ${name} (Windows).`
359
+ );
360
+ } else {
361
+ logger.info("User-level did not contain entry \u2014 no change.");
362
+ }
363
+ } catch (e) {
364
+ logger.error("Failed to persist removal on Windows:");
365
+ logger.error(String(e));
366
+ }
367
+ } else {
368
+ try {
369
+ await persistPosixEditPath(name, value, "remove");
370
+ } catch (e) {
371
+ logger.error("Failed to persist removal on POSIX:");
372
+ logger.error(String(e));
373
+ }
372
374
  }
373
375
  }
374
376
  }
377
+ return;
375
378
  }
376
- return;
379
+ } catch (e) {
380
+ logger.error("Fatal:");
381
+ logger.error(String(e));
382
+ process.exit(3);
377
383
  }
378
- } catch (e) {
379
- logger.error("Fatal:");
380
- logger.error(String(e));
381
- process.exit(3);
382
384
  }
383
- };
384
- export default defineCmd(senvCmd, senvCmdArgs, senvCmdCfg);
385
+ });
@@ -1,3 +1,2 @@
1
- #!/usr/bin/env bun
2
1
  declare const _default: any;
3
2
  export default _default;
@@ -1,50 +1,46 @@
1
- #!/usr/bin/env bun
2
- import {
3
- defineCmd,
4
- defineCmdArgs,
5
- defineCmdCfg
6
- } from "@reliverse/dler-launcher";
1
+ import { defineArgs, defineCommand } from "@reliverse/dler-launcher";
7
2
  import { logger } from "@reliverse/dler-logger";
8
3
  import { $ } from "bun";
9
- const shellCmd = async (args) => {
10
- try {
11
- const commandParts = args.x.split(/\s+/);
12
- const [command, ...commandArgs] = commandParts;
13
- await $`${command} ${commandArgs.join(" ")}`;
14
- } catch (error) {
15
- logger.error("\n\u274C Command failed:");
16
- if (error instanceof Error) {
17
- if ("exitCode" in error) {
18
- logger.error(`Exit code: ${error.exitCode}`);
19
- if (error.stdout) {
20
- logger.error(`STDOUT: ${error.stdout.toString()}`);
21
- }
22
- if (error.stderr) {
23
- logger.error(`STDERR: ${error.stderr.toString()}`);
4
+ export default defineCommand({
5
+ meta: {
6
+ name: "shell",
7
+ description: "Execute shell commands using Bun Shell API",
8
+ examples: [
9
+ 'dler shell --x "echo Hello World"',
10
+ 'dler shell --x "ls -la"',
11
+ 'dler shell --x "cat package.json | grep name"'
12
+ ]
13
+ },
14
+ args: defineArgs({
15
+ x: {
16
+ type: "string",
17
+ required: true,
18
+ description: "Shell command to execute"
19
+ }
20
+ }),
21
+ run: async ({ args }) => {
22
+ try {
23
+ const commandParts = args.x.split(/\s+/);
24
+ const [command, ...commandArgs] = commandParts;
25
+ await $`${command} ${commandArgs.join(" ")}`;
26
+ } catch (error) {
27
+ logger.error("\n\u274C Command failed:");
28
+ if (error instanceof Error) {
29
+ if ("exitCode" in error) {
30
+ logger.error(`Exit code: ${error.exitCode}`);
31
+ if (error.stdout) {
32
+ logger.error(`STDOUT: ${error.stdout.toString()}`);
33
+ }
34
+ if (error.stderr) {
35
+ logger.error(`STDERR: ${error.stderr.toString()}`);
36
+ }
37
+ } else {
38
+ logger.error(error.message);
24
39
  }
25
40
  } else {
26
- logger.error(error.message);
41
+ logger.error(String(error));
27
42
  }
28
- } else {
29
- logger.error(String(error));
43
+ process.exit(1);
30
44
  }
31
- process.exit(1);
32
45
  }
33
- };
34
- const shellCmdArgs = defineCmdArgs({
35
- x: {
36
- type: "string",
37
- required: true,
38
- description: "Shell command to execute"
39
- }
40
- });
41
- const shellCmdCfg = defineCmdCfg({
42
- name: "shell",
43
- description: "Execute shell commands using Bun Shell API",
44
- examples: [
45
- 'dler shell --x "echo Hello World"',
46
- 'dler shell --x "ls -la"',
47
- 'dler shell --x "cat package.json | grep name"'
48
- ]
49
46
  });
50
- export default defineCmd(shellCmd, shellCmdArgs, shellCmdCfg);