creatium 0.1.17 → 0.2.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.
@@ -1,830 +1,13 @@
1
- import { deepmergeCustom, deepmerge } from 'deepmerge-ts';
2
- import process$1 from 'node:process';
3
- import { spawn } from 'node:child_process';
4
- import yargs from 'yargs';
5
- import { hideBin as hideBin$1 } from 'yargs/helpers';
6
- import * as p from '@clack/prompts';
7
- import { TextPrompt } from '@clack/core';
8
- import gradientString from 'gradient-string';
9
- import { styleText } from 'node:util';
10
- import stringWidth from 'string-width';
11
- import { boxen } from '@visulima/boxen';
12
- import Table from 'cli-table3';
13
- import columnify from 'columnify';
14
- import { writeFile as writeFile$1, readFile as readFile$1, readdir, rm, unlink, stat, mkdir, access, constants, copyFile as copyFile$1, lstat, symlink } from 'node:fs/promises';
15
- import { resolve, relative, extname, dirname, basename, isAbsolute, normalize, join } from 'node:path';
16
- import { fileURLToPath } from 'node:url';
17
- import glob from 'tiny-glob';
18
- import { homedir as homedir$1, tmpdir as tmpdir$1, platform, arch } from 'node:os';
1
+ import { formatter } from '@clippium/preset-colored';
2
+ import { hiddenBin, Clippium } from 'clippium';
3
+ import { W as Wn, q as qn, U as Un, z as zn, S as Sn, P as Pn, a2 as Si, x as xi, T as Tn, ae as Hi, O as On, V as Vn, a as ai, ab as Wi, ag as Vi, ac as Li, L as Ln, a4 as Ti } from './shared/creatium.v0AbQ44Q.mjs';
4
+ import 'module';
19
5
 
20
- const isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined";
21
- const isNode = typeof process !== "undefined" && process.versions != null && process.versions.node != null;
22
- const isWebWorker = typeof self === "object" && self.constructor && self.constructor.name === "DedicatedWorkerGlobalScope";
23
- const isJsDom = typeof window !== "undefined" && window.name === "nodejs" || typeof navigator !== "undefined" && "userAgent" in navigator && typeof navigator.userAgent === "string" && (navigator.userAgent.includes("Node.js") || navigator.userAgent.includes("jsdom"));
24
- const isDeno = typeof Deno !== "undefined" && typeof Deno.version !== "undefined" && typeof Deno.version.deno !== "undefined";
25
- const isBun = typeof process !== "undefined" && process.versions != null && process.versions.bun != null;
26
- const env$2 = {
27
- isBrowser,
28
- isWebWorker,
29
- isNode,
30
- isJsDom,
31
- isDeno,
32
- isBun
33
- };
34
-
35
- const execChild = async (cmd) => {
36
- return new Promise((resolve, reject) => {
37
- const options = {
38
- shell: true,
39
- stdio: "pipe"
40
- };
41
- const childProcess = spawn(cmd, options);
42
- let stdout = "", stderr = "";
43
- childProcess.stdout?.on("data", (data) => {
44
- stdout += data.toString();
45
- });
46
- childProcess.stderr?.on("data", (data) => {
47
- stderr += data.toString();
48
- });
49
- childProcess.on("close", (code) => {
50
- if (code === 0) {
51
- resolve({
52
- stdout,
53
- stderr
54
- });
55
- } else {
56
- const data = {
57
- code,
58
- stdout,
59
- stderr
60
- };
61
- reject(data);
62
- }
63
- });
64
- childProcess.on("error", (err) => {
65
- reject(err);
66
- });
67
- });
68
- };
69
- const existsLocalBin = async (binName) => {
70
- const command = process$1.platform === "win32" ? `where ${binName}` : `which ${binName}`;
71
- try {
72
- await execChild(command);
73
- return true;
74
- } catch (_e) {
75
- return false;
76
- }
77
- };
78
-
79
- const hideBin = hideBin$1;
80
- const createCli = async (options) => {
81
- const {
82
- args = process.argv,
83
- fn
84
- } = options;
85
- const bin = yargs(args);
86
- await fn(bin);
87
- bin.help();
88
- bin.parse();
89
- return bin;
90
- };
91
-
92
- const cTypes = [
93
- // ForegroundColors
94
- "black",
95
- "blackBright",
96
- "blue",
97
- "blueBright",
98
- "cyan",
99
- "cyanBright",
100
- "gray",
101
- "green",
102
- "greenBright",
103
- "grey",
104
- "magenta",
105
- "magentaBright",
106
- "red",
107
- "redBright",
108
- "white",
109
- "whiteBright",
110
- "yellow",
111
- "yellowBright",
112
- // BackgroundColors
113
- "bgBlack",
114
- "bgBlackBright",
115
- "bgBlue",
116
- "bgBlueBright",
117
- "bgCyan",
118
- "bgCyanBright",
119
- "bgGray",
120
- "bgGreen",
121
- "bgGreenBright",
122
- "bgGrey",
123
- "bgMagenta",
124
- "bgMagentaBright",
125
- "bgRed",
126
- "bgRedBright",
127
- "bgWhite",
128
- "bgWhiteBright",
129
- "bgYellow",
130
- "bgYellowBright",
131
- // Modifiers
132
- "blink",
133
- "bold",
134
- "dim",
135
- "doubleunderline",
136
- "framed",
137
- "hidden",
138
- "inverse",
139
- "italic",
140
- "overlined",
141
- "reset",
142
- "strikethrough",
143
- "underline"
144
- ];
145
- const _color = (t, v) => styleText(t, v);
146
- const _colorObj = cTypes.reduce((acc, t) => {
147
- acc[t] = (v) => _color(t, v);
148
- return acc;
149
- }, {});
150
- const color = _colorObj;
151
- const gradient = (txt, colors, opts) => {
152
- return gradientString(colors, opts).multiline(txt);
153
- };
154
-
155
- const line = ({
156
- title,
157
- lineChar = "\u23AF",
158
- align = "center"
159
- }) => {
160
- const lineCharLength = stringWidth(lineChar);
161
- const totalWidth = process.stdout.columns;
162
- const textLength = title ? stringWidth(title) : 0;
163
- const width = Math.floor((totalWidth - textLength) / (2 * lineCharLength));
164
- const line2 = lineChar.repeat(width);
165
- if (align === "left") return title + line2 + line2;
166
- else if (align === "right") return line2 + line2 + title;
167
- return line2 + title + line2;
168
- };
169
-
170
- const table = (data, options) => {
171
- const _table = new Table(options);
172
- _table.push(...data);
173
- return _table.toString();
174
- };
175
- const box = (text, options) => boxen(text, options);
176
- const columns = (data, options) => columnify(data, options);
177
-
178
- const style$1 = {
179
- color,
180
- gradient,
181
- box,
182
- columns,
183
- table,
184
- line
185
- };
186
-
187
- const isUnicodeSupported = () => {
188
- if (process$1.platform !== "win32") return process$1.env.TERM !== "linux";
189
- return Boolean(process$1.env.WT_SESSION) || Boolean(process$1.env.TERMINUS_SUBLIME) || process$1.env.ConEmuTask === "{cmd::Cmder}" || process$1.env.TERM_PROGRAM === "Terminus-Sublime" || process$1.env.TERM_PROGRAM === "vscode" || process$1.env.TERM === "xterm-256color" || process$1.env.TERM === "alacritty" || process$1.env.TERMINAL_EMULATOR === "JetBrains-JediTerm";
190
- };
191
- const unicode = isUnicodeSupported();
192
- const s = (c, fallback) => unicode ? c : fallback;
193
- const symbols = {
194
- STEP_ACTIVE: s("\u25C6", "*"),
195
- STEP_CANCEL: s("\u25A0", "x"),
196
- STEP_ERROR: s("\u25B2", "x"),
197
- STEP_SUBMIT: s("\u25C7", "o"),
198
- BAR: s("\u2502", "|"),
199
- BAR_END: s("\u2514", "\u2014")
200
- };
201
- const symbol = (state) => {
202
- if (state === "initial" || state === "active")
203
- return color.cyan(symbols.STEP_ACTIVE);
204
- else if (state === "cancel")
205
- return color.red(symbols.STEP_CANCEL);
206
- else if (state === "error")
207
- return color.yellow(symbols.STEP_ERROR);
208
- else if (state === "submit")
209
- return color.green(symbols.STEP_SUBMIT);
210
- };
211
-
212
- async function number(opts) {
213
- return new TextPrompt({
214
- validate: (value) => {
215
- const errorDefault = "Value must be a number without";
216
- const spaces = /\s/.test(value);
217
- const isNum = typeof Number(value) === "number" && !isNaN(Number(value));
218
- if (!value || !isNum) return opts.errorText ? opts.errorText : errorDefault;
219
- if (spaces) return opts.errorText ? opts.errorText : errorDefault;
220
- if (opts.validate) return opts.validate(value);
221
- },
222
- placeholder: opts.placeholder,
223
- defaultValue: opts.defaultValue,
224
- initialValue: opts.initialValue,
225
- render() {
226
- const title = `${color.gray(symbols.BAR)}
227
- ${symbol(this.state)} ${opts.message}
228
- `;
229
- const placeholder = opts.placeholder ? color.inverse(opts.placeholder[0]) + color.dim(opts.placeholder.slice(1)) : color.inverse(color.hidden("_"));
230
- const value = !this.value ? placeholder : this.valueWithCursor;
231
- switch (this.state) {
232
- case "error":
233
- return `${title.trim()}
234
- ${color.yellow(symbols.BAR)} ${value}
235
- ${color.yellow(
236
- symbols.BAR_END
237
- )} ${color.yellow(this.error)}
238
- `;
239
- case "submit":
240
- return `${title}${color.gray(symbols.BAR)} ${color.dim(this.value || opts.placeholder)}`;
241
- case "cancel":
242
- return `${title}${color.gray(symbols.BAR)} ${color.strikethrough(
243
- color.dim(this.value ?? "")
244
- )}${this.value?.trim() ? "\n" + color.gray(symbols.BAR) : ""}`;
245
- default:
246
- return `${title}${color.cyan(symbols.BAR)} ${value}
247
- ${color.cyan(symbols.BAR_END)}
248
- `;
249
- }
250
- }
251
- }).prompt();
252
- }
253
-
254
- const promptLineMethods = {
255
- message: "message"};
256
-
257
- const clackPrompts = p;
258
- const printOptions = {
259
- /**
260
- * Logs a table in the prompt line.
261
- */
262
- table: ({
263
- value,
264
- opts,
265
- type = promptLineMethods.message
266
- }) => p.log[type](table(value, opts)),
267
- /**
268
- * Logs data formatted into aligned columns in the prompt line.
269
- */
270
- columns: ({
271
- value,
272
- opts,
273
- type = promptLineMethods.message
274
- }) => p.log[type](columns(value, opts)),
275
- /**
276
- * Logs a styled box in the prompt line.
277
- */
278
- box: ({
279
- value,
280
- opts,
281
- type = promptLineMethods.message
282
- }) => p.log[type](box(value, opts))
283
- };
284
- const corePromptLine = {
285
- ...clackPrompts,
286
- number,
287
- ...printOptions
288
- };
289
-
290
- const replacePlaceholders = async (props) => {
291
- const { content, params, transform, opts } = props;
292
- const { prefix, suffix } = opts?.mark || {
293
- prefix: "{{",
294
- suffix: "}}"
295
- };
296
- const escapeRegExp = (v) => v.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
297
- const regex = new RegExp(
298
- `${escapeRegExp(prefix)}\\s*([^}]+?)\\s*${escapeRegExp(suffix)}`,
299
- "g"
300
- );
301
- const getValue = (obj, path) => {
302
- const parts = path.split(".");
303
- let result2 = obj;
304
- for (const part of parts) {
305
- if (result2 === void 0) return void 0;
306
- if (part.includes("[") && part.includes("]")) {
307
- const [arrayName, indexStr] = part.split("[");
308
- const index = parseInt(indexStr.replace("]", ""), 10);
309
- result2 = result2[arrayName]?.[index];
310
- } else {
311
- result2 = result2[part];
312
- }
313
- }
314
- return result2;
315
- };
316
- const replaceAsync = async (match, key) => {
317
- if (transform) {
318
- const transformed = await transform(key);
319
- if (transformed !== key) return transformed;
320
- }
321
- const value = getValue(params, key);
322
- if (value === void 0) {
323
- if (opts?.throw) throw new Error(`Placeholder ${key} not found`);
324
- return match;
325
- }
326
- return String(value);
327
- };
328
- let result = content;
329
- const matches = [...content.matchAll(regex)];
330
- for (const match of matches) {
331
- const [fullMatch, key] = match;
332
- const replacement = await replaceAsync(fullMatch, key);
333
- result = result.replace(fullMatch, replacement);
334
- }
335
- return result;
336
- };
337
-
338
- const getHomeDir = homedir$1;
339
- const getTempDir = () => tmpdir$1();
340
- const getPlatform = async () => {
341
- const p = platform();
342
- switch (p) {
343
- case "win32":
344
- return "windows";
345
- case "darwin":
346
- return "macos";
347
- case "linux":
348
- return "linux";
349
- default:
350
- return "unknown";
351
- }
352
- };
353
- function getArch() {
354
- const architecture = arch();
355
- switch (architecture) {
356
- case "arm64":
357
- return "arm64";
358
- case "arm":
359
- return "arm64";
360
- // As 'arm' is also treated as 'arm64'.
361
- case "x64":
362
- return "x64";
363
- default:
364
- return "unknown";
365
- }
366
- }
367
-
368
- const resolvePath = resolve;
369
- const relativePath = relative;
370
- const getExtName = extname;
371
- const getDirName = dirname;
372
- const getBaseName = basename;
373
- const isAbsolutePath = isAbsolute;
374
- const normalizePath = normalize;
375
- const writeFile = writeFile$1;
376
- const getPaths = glob;
377
- const arePathsEqual = (path1, path2) => {
378
- const normalizedPath1 = resolvePath(path1);
379
- const normalizedPath2 = resolvePath(path2);
380
- return normalizedPath1 === normalizedPath2;
381
- };
382
- const isPath = (str) => {
383
- if (isAbsolute(str) || /^(\.\/|\.\.\/|[A-Za-z]:\\|\/)/.test(str)) {
384
- if (isAbsolute(str) || /^(\.\/|\.\.\/|[A-Za-z]:\\|\/)/.test(str)) {
385
- if (/\s(?!\\)/.test(str) && !/\\\s/.test(str))
386
- return false;
387
- try {
388
- const normalizedPath = join(str);
389
- return normalizedPath !== "";
390
- } catch {
391
- return false;
392
- }
393
- }
394
- }
395
- return false;
396
- };
397
- const ensureDir = async (path) => {
398
- const exist = await existsDir(path);
399
- if (!exist) await createDir(path);
400
- };
401
- const readDir = async (path) => {
402
- path = validateHomeDir(path);
403
- return await readdir(path, { withFileTypes: true });
404
- };
405
- async function getFilteredFileNames({
406
- path,
407
- extensions = []
408
- }) {
409
- const files = await readDir(path);
410
- const filteredFileNames = files.filter((file) => {
411
- const ext = getExtName(file.name);
412
- return extensions.includes(ext);
413
- }).map((file) => getBaseName(file.name, getExtName(file.name)));
414
- return filteredFileNames;
415
- }
416
- const getCurrentDir = (path = import.meta.url) => getDirName(fileURLToPath(path));
417
- function joinPath(...paths) {
418
- return join(...paths);
419
- }
420
- const getAbsolutePath = resolve;
421
- function validateHomeDir(path) {
422
- let resolvedPath = path;
423
- if (path.startsWith("~/")) {
424
- resolvedPath = path.replace(/^~(?=$|\/|\\)/, getHomeDir());
425
- }
426
- return getAbsolutePath(resolvedPath);
427
- }
428
- const readFile = readFile$1;
429
- async function removeDir(path) {
430
- try {
431
- path = validateHomeDir(path);
432
- await rm(path, {
433
- recursive: true,
434
- force: true
435
- });
436
- } catch (error) {
437
- throw new Error(`Error removing ${path}: ${error.message}`);
438
- }
439
- }
440
- async function removeDirIfExist(path) {
441
- path = validateHomeDir(path);
442
- const exists = await existsDir(path);
443
- if (exists) await removeDir(path);
444
- }
445
- async function removePathIfExist(path) {
446
- path = validateHomeDir(path);
447
- const isDir = await isDirectory(path);
448
- if (isDir) await removeDirIfExist(path);
449
- else await removeFileIfExist(path);
450
- }
451
- async function removeFileIfExist(path) {
452
- path = validateHomeDir(path);
453
- const exists = await existsFile(path);
454
- if (exists) await unlink(path);
455
- }
456
- async function removeFile(path) {
457
- await unlink(path);
458
- }
459
- async function isDirectory(path) {
460
- path = validateHomeDir(path);
461
- const stats = await stat(path);
462
- return stats.isDirectory();
463
- }
464
- async function createDir(path) {
465
- try {
466
- path = validateHomeDir(path);
467
- await mkdir(path, { recursive: true });
468
- } catch (error) {
469
- throw Error(`Error creating the directory: ${error}`);
470
- }
471
- }
472
- async function existsDir(path) {
473
- try {
474
- path = validateHomeDir(path);
475
- await access(path, constants.F_OK);
476
- const stats = await stat(path);
477
- return stats.isDirectory();
478
- } catch (error) {
479
- if (error.code === "ENOENT") {
480
- return false;
481
- } else {
482
- throw error;
483
- }
484
- }
485
- }
486
- async function existsFile(path) {
487
- try {
488
- path = validateHomeDir(path);
489
- await access(path);
490
- const stats = await stat(path);
491
- return stats.isFile();
492
- } catch (error) {
493
- if (error.code === "ENOENT") {
494
- return false;
495
- } else {
496
- throw error;
497
- }
498
- }
499
- }
500
- async function writeFileContent(path, content) {
501
- path = validateHomeDir(path);
502
- await writeFile$1(path, content);
503
- }
504
- async function existsPath(path) {
505
- const isFile = await existsFile(path);
506
- if (isFile) return true;
507
- const isDir = await existsDir(path);
508
- return isDir;
509
- }
510
- const copyFile = async ({
511
- input,
512
- output
513
- }) => {
514
- try {
515
- await copyFile$1(input, output);
516
- } catch (error) {
517
- console.error(error);
518
- }
519
- };
520
- const copyDir = async ({
521
- input,
522
- output
523
- }) => {
524
- const _copyDir = async ({
525
- input: input2,
526
- output: output2
527
- }) => {
528
- if (!await existsDir(input2)) throw new Error(`Input directory does not exist`);
529
- const entries = await readDir(input2);
530
- const exist = await existsDir(output2);
531
- if (!exist) await createDir(output2);
532
- for (const entry of entries) {
533
- const srcPath = join(input2, entry.name);
534
- const destPath = join(output2, entry.name);
535
- if (entry.isDirectory()) {
536
- await _copyDir({
537
- input: srcPath,
538
- output: destPath
539
- });
540
- } else {
541
- await copyFile({
542
- input: srcPath,
543
- output: destPath
544
- });
545
- }
546
- }
547
- };
548
- try {
549
- await _copyDir({
550
- input,
551
- output
552
- });
553
- } catch (error) {
554
- if (error instanceof Error)
555
- throw new Error(`Error copying directory "${input}" to "${output}": ${error.message}`);
556
- throw new Error(`Error copying directory: ${error}`);
557
- }
558
- };
559
- const createSymlink = async ({
560
- input,
561
- output
562
- }) => {
563
- try {
564
- await access(output);
565
- } catch (error) {
566
- if (error.code === "ENOENT") {
567
- await mkdir(output, { recursive: true });
568
- } else {
569
- throw `\u274C\u{1F517} ${error}`;
570
- }
571
- }
572
- const sourceStat = await lstat(input);
573
- const isWin = process$1.platform === "win32";
574
- if (sourceStat.isDirectory()) {
575
- if (isWin) {
576
- await symlink(input, join(output, basename(input)), "junction");
577
- } else {
578
- await symlink(input, join(output, basename(input)), "dir");
579
- }
580
- } else if (sourceStat.isFile()) {
581
- await symlink(input, join(output, basename(input)));
582
- }
583
- console.log(`\u{1F517} symlink: "${input}" to "${output}".`);
584
- };
585
-
586
- const homedir = getHomeDir();
587
- const tmpdir = getTempDir();
588
- const { env: env$1 } = process$1;
589
- const macos = (name) => {
590
- const library = joinPath(homedir, "Library");
591
- return {
592
- data: joinPath(library, "Application Support", name),
593
- config: joinPath(library, "Preferences", name),
594
- cache: joinPath(library, "Caches", name),
595
- log: joinPath(library, "Logs", name),
596
- temp: joinPath(tmpdir, name)
597
- };
598
- };
599
- const windows = (name) => {
600
- const appData = env$1.APPDATA || joinPath(homedir, "AppData", "Roaming");
601
- const localAppData = env$1.LOCALAPPDATA || joinPath(homedir, "AppData", "Local");
602
- return {
603
- // Data/config/cache/log are invented by me as Windows isn't opinionated about this
604
- data: joinPath(localAppData, name, "Data"),
605
- config: joinPath(appData, name, "Config"),
606
- cache: joinPath(localAppData, name, "Cache"),
607
- log: joinPath(localAppData, name, "Log"),
608
- temp: joinPath(tmpdir, name)
609
- };
610
- };
611
- const linux = (name) => {
612
- const username = getBaseName(homedir);
613
- return {
614
- data: joinPath(env$1.XDG_DATA_HOME || joinPath(homedir, ".local", "share"), name),
615
- config: joinPath(env$1.XDG_CONFIG_HOME || joinPath(homedir, ".config"), name),
616
- cache: joinPath(env$1.XDG_CACHE_HOME || joinPath(homedir, ".cache"), name),
617
- // https://wiki.debian.org/XDGBaseDirectorySpecification#state
618
- log: joinPath(env$1.XDG_STATE_HOME || joinPath(homedir, ".local", "state"), name),
619
- temp: joinPath(tmpdir, username, name)
620
- };
621
- };
622
- const getSystemEnvPaths = ({
623
- name,
624
- suffix = "nodejs"
625
- }) => {
626
- if (typeof name !== "string")
627
- throw new TypeError(`Expected a string, got ${typeof name}`);
628
- if (suffix) name += `-${suffix}`;
629
- if (process$1.platform === "darwin") return macos(name);
630
- if (process$1.platform === "win32") return windows(name);
631
- return linux(name);
632
- };
633
-
634
- const getFileContent = async (path) => {
635
- path = validateHomeDir(path);
636
- const fileContentBuffer = await readFile(path);
637
- const fileContent = fileContentBuffer.toString("utf8");
638
- return fileContent;
639
- };
640
- const getObjectFromJSONContent = async (content) => {
641
- const r = JSON.parse(content);
642
- return r;
643
- };
644
- const getObjectFromJSONFile = async (path) => {
645
- try {
646
- const fileContent = await getFileContent(path);
647
- return await getObjectFromJSONContent(fileContent);
648
- } catch (error) {
649
- throw new Error(`Error reading JSON file ${path}: ${error.message}`);
650
- }
651
- };
652
-
653
- const cache = async (opts) => {
654
- const {
655
- id,
656
- values,
657
- projectName,
658
- cwd,
659
- suffix
660
- } = opts;
661
- const dir = cwd || getSystemEnvPaths({
662
- name: projectName,
663
- suffix
664
- }).config;
665
- const path = joinPath(dir, `config.json`);
666
- const exists = await existsFile(path);
667
- const defaultValues = { [id]: values };
668
- const merge = deepmergeCustom({ mergeArrays: false });
669
- const getCachedDataFromFile = async () => {
670
- try {
671
- const data = await getObjectFromJSONFile(path);
672
- return data;
673
- } catch {
674
- return defaultValues;
675
- }
676
- };
677
- let cachedData = exists ? await getCachedDataFromFile() : defaultValues;
678
- const set = async (obj) => {
679
- const exists2 = await existsFile(path);
680
- if (!exists2) await ensureDir(dir);
681
- const updatedData = merge(cachedData, { [id]: obj });
682
- await writeFile(path, JSON.stringify(updatedData, null, 2));
683
- cachedData = updatedData;
684
- };
685
- const get = async (v) => {
686
- if (typeof v === "string") {
687
- if (!cachedData[id] || typeof cachedData[id][v] === "undefined") return void 0;
688
- return cachedData[id][v];
689
- }
690
- return cachedData[id];
691
- };
692
- const reset = async () => await set(values);
693
- if (!exists) await set(values);
694
- else {
695
- const updatedData = merge({ [id]: values }, cachedData);
696
- await set(updatedData[id]);
697
- }
698
- return {
699
- /**
700
- * The default values for the cache.
701
- */
702
- defaultValues: values,
703
- /**
704
- * Retrieve a value from the cache.
705
- *
706
- * @example
707
- * const theme = get('theme');
708
- * console.log(theme); // Output: 'light'
709
- */
710
- get,
711
- /**
712
- * Updates the cache with the provided values.
713
- *
714
- * Merges the existing cached values with the new partial values and updates the cache.
715
- */
716
- set,
717
- /**
718
- * Resets the cache to its default values.
719
- *
720
- * @example
721
- * reset();
722
- */
723
- reset,
724
- /**
725
- * The path to the cache file.
726
- */
727
- path
728
- };
729
- };
730
-
731
- const getClosestPackageJson = async (startDir = process$1.cwd()) => {
732
- let currentDir = resolvePath(startDir);
733
- while (true) {
734
- const pkgPath = joinPath(currentDir, "package.json");
735
- if (await existsFile(pkgPath)) return pkgPath;
736
- const parentDir = getDirName(currentDir);
737
- if (parentDir === currentDir)
738
- throw new Error("No package.json found in any parent directory.");
739
- currentDir = parentDir;
740
- }
741
- };
742
- const getClosestPackageDir = async (startDir = process$1.cwd()) => {
743
- const pkgPath = await getClosestPackageJson(startDir);
744
- return getDirName(pkgPath);
745
- };
746
-
747
- const _sys = {
748
- __proto__: null,
749
- arePathsEqual: arePathsEqual,
750
- cache: cache,
751
- copyDir: copyDir,
752
- copyFile: copyFile,
753
- createDir: createDir,
754
- createSymlink: createSymlink,
755
- ensureDir: ensureDir,
756
- existsDir: existsDir,
757
- existsFile: existsFile,
758
- existsPath: existsPath,
759
- fileURLToPath: fileURLToPath,
760
- getAbsolutePath: getAbsolutePath,
761
- getArch: getArch,
762
- getBaseName: getBaseName,
763
- getClosestPackageDir: getClosestPackageDir,
764
- getClosestPackageJson: getClosestPackageJson,
765
- getCurrentDir: getCurrentDir,
766
- getDirName: getDirName,
767
- getExtName: getExtName,
768
- getFilteredFileNames: getFilteredFileNames,
769
- getHomeDir: getHomeDir,
770
- getObjectFromJSONFile: getObjectFromJSONFile,
771
- getPaths: getPaths,
772
- getPlatform: getPlatform,
773
- getSystemEnvPaths: getSystemEnvPaths,
774
- getTempDir: getTempDir,
775
- isAbsolutePath: isAbsolutePath,
776
- isDirectory: isDirectory,
777
- isPath: isPath,
778
- joinPath: joinPath,
779
- normalizePath: normalizePath,
780
- readDir: readDir,
781
- readFile: readFile,
782
- relativePath: relativePath,
783
- removeDir: removeDir,
784
- removeDirIfExist: removeDirIfExist,
785
- removeFile: removeFile,
786
- removeFileIfExist: removeFileIfExist,
787
- removePathIfExist: removePathIfExist,
788
- resolvePath: resolvePath,
789
- validateHomeDir: validateHomeDir,
790
- writeFile: writeFile,
791
- writeFileContent: writeFileContent
792
- };
793
-
794
- const SELECT_BASE_OPTS = { NONE: "none" };
795
- const mergeSelectBaseOptions = (config, defaultOptions) => {
796
- const options = deepmerge(defaultOptions || {}, config.options || {});
797
- const filteredOptions = config.onlyOptions && config.onlyOptions.length > 1 ? Object.entries(options).reduce((acc, [key, value]) => {
798
- if (key === SELECT_BASE_OPTS.NONE || config.onlyOptions.includes(key))
799
- acc[key] = value;
800
- return acc;
801
- }, {}) : options;
802
- return {
803
- ...config,
804
- options: Object.keys(filteredOptions).length > 1 ? filteredOptions : options
805
- };
806
- };
807
-
808
- const sys = _sys;
809
- const prompt = corePromptLine;
810
- const env = env$2;
811
- const style = style$1;
812
-
813
- const utils = {
814
- __proto__: null,
815
- env: env,
816
- prompt: prompt,
817
- style: style,
818
- sys: sys
819
- };
820
-
821
- const coreUtils = utils;
822
- let Core$1 = class Core {
823
- constructor(config) {
6
+ class Core {
7
+ constructor(config, _utils) {
824
8
  this.config = config;
9
+ this._utils = _utils;
825
10
  }
826
- // for use outside
827
- _utils = utils;
828
11
  /** On cancel callback */
829
12
  _onCancel = async () => {
830
13
  };
@@ -843,12 +26,13 @@ let Core$1 = class Core {
843
26
  string: "string",
844
27
  number: "number",
845
28
  boolean: "boolean",
846
- array: "array"
29
+ array: "array",
30
+ choices: "choices"
847
31
  };
848
32
  _text = {
849
33
  initialValueSuccess: (t, v) => `${t}
850
- ${this._utils.style.color.dim(this._utils.style.color.gray(v))}`,
851
- initialValueError: (v) => `Initial value ${this._utils.style.color.yellow(v || "")} is not valid`
34
+ ${this._utils.color.dim(this._utils.color.gray(v))}`,
35
+ initialValueError: (v) => `Initial value ${this._utils.color.yellow(v || "")} is not valid`
852
36
  };
853
37
  async getPromptHooked() {
854
38
  if (!("prompt" in this && typeof this.prompt === "function")) return;
@@ -862,171 +46,13 @@ ${this._utils.style.color.dim(this._utils.style.color.gray(v))}`,
862
46
  return res;
863
47
  } catch (error) {
864
48
  if (error instanceof Error)
865
- this._utils.prompt.log.error("Unexpected error:" + error?.message);
49
+ this._utils.prompt.log.error("Unexpected error: " + error?.message);
866
50
  return await this.prompt();
867
51
  }
868
52
  }
869
- };
870
-
871
- class Select extends Core$1 {
872
- async cmd() {
873
- return {
874
- desc: this.config.desc,
875
- type: this._type.string,
876
- alias: this.config.alias,
877
- choices: Object.keys(this.config.options)
878
- };
879
- }
880
- async validateInitialValue(data) {
881
- const message = this.config.promptMsg || this.config.desc;
882
- if (typeof this.initialValue === "number" || typeof this.initialValue === "string") {
883
- if (data?.showSuccess !== false)
884
- this._utils.prompt.log.success(this._text.initialValueSuccess(message, this.initialValue.toString()));
885
- return this.initialValue;
886
- }
887
- if (data?.showError !== false)
888
- this._utils.prompt.log.warn(this._text.initialValueError(this.initialValue));
889
- return void 0;
890
- }
891
- async prompt() {
892
- const value = await this._utils.prompt.select({
893
- message: this.config.promptMsg || this.config.desc,
894
- options: Object.entries(this.config.options).map(([key, value2]) => ({
895
- value: key,
896
- label: value2?.name || key,
897
- hint: value2?.desc
898
- })),
899
- initialValue: this.config.placeholderValue?.toString()
900
- });
901
- if (this._utils.prompt.isCancel(value)) {
902
- await this._onCancel();
903
- throw "";
904
- }
905
- return value;
906
- }
907
- }
908
-
909
- const TEXT_EDITOR = {
910
- ...SELECT_BASE_OPTS,
911
- VSCODE: "code",
912
- SUBLIME: "subl",
913
- WEBSTORM: "webstorm"
914
- };
915
- class Editor extends Select {
916
- constructor(config) {
917
- const defaultOptions = {
918
- [TEXT_EDITOR.SUBLIME]: { name: "Sublime Text" },
919
- [TEXT_EDITOR.VSCODE]: { name: "Visual Studio Code" },
920
- [TEXT_EDITOR.WEBSTORM]: { name: "WebStorm" },
921
- [TEXT_EDITOR.NONE]: {
922
- name: "None",
923
- desc: "Do not open the project with any text editor"
924
- }
925
- };
926
- if (!config.desc) config.desc = "Select the text editor to open the project";
927
- const finalConfig = mergeSelectBaseOptions(config, defaultOptions);
928
- super(finalConfig);
929
- this.config = finalConfig;
930
- }
931
- async validateInitialValue(data) {
932
- const validateValue = await super.validateInitialValue({ showSuccess: false });
933
- if (!validateValue) return void 0;
934
- if (validateValue && await existsLocalBin(validateValue)) {
935
- if (data?.showSuccess !== false)
936
- this._utils.prompt.log.success(this._text.initialValueSuccess(this.config.promptMsg || this.config.desc, validateValue));
937
- return validateValue;
938
- }
939
- if (data?.showError !== false)
940
- this._utils.prompt.log.warn(this._text.initialValueError(this.initialValue));
941
- return void 0;
942
- }
943
- async prompt() {
944
- let value = await super.prompt();
945
- if (value === TEXT_EDITOR.NONE) return value;
946
- const exists = await existsLocalBin(value);
947
- if (!exists) {
948
- this.config.options = Object.fromEntries(
949
- Object.entries(this.config.options).filter(([key]) => key !== value)
950
- );
951
- const badge = (txt) => this._utils.style.color.red(this._utils.style.color.inverse(" " + txt + " "));
952
- this._utils.prompt.log.error(`Binary ${badge(value)} not found in system`);
953
- value = await this.prompt();
954
- }
955
- return value;
956
- }
957
- }
958
-
959
- const INSTALLER = {
960
- DENO: "deno",
961
- BUN: "bun",
962
- NPM: "npm",
963
- PNPM: "pnpm",
964
- YARN: "yarn",
965
- ...SELECT_BASE_OPTS
966
- };
967
- class Install extends Select {
968
- constructor(config) {
969
- const defaultOptions = {
970
- [INSTALLER.NPM]: { name: "npm" },
971
- [INSTALLER.PNPM]: { name: "pnpm" },
972
- [INSTALLER.YARN]: { name: "yarn" },
973
- [INSTALLER.DENO]: { name: "deno" },
974
- [INSTALLER.NONE]: {
975
- name: "None",
976
- desc: "Do not install project dependencies"
977
- }
978
- };
979
- if (!config.desc) config.desc = "Select the package manager to install the dependencies.";
980
- const finalConfig = mergeSelectBaseOptions(config, defaultOptions);
981
- super(finalConfig);
982
- this.config = finalConfig;
983
- }
984
- async validateInitialValue(data) {
985
- const validateValue = await super.validateInitialValue({ showSuccess: false });
986
- if (!validateValue) return void 0;
987
- if (validateValue && await existsLocalBin(validateValue)) {
988
- if (data?.showSuccess !== false)
989
- this._utils.prompt.log.success(this._text.initialValueSuccess(this.config.promptMsg || this.config.desc, validateValue));
990
- return validateValue;
991
- }
992
- if (data?.showError !== false)
993
- this._utils.prompt.log.warn(this._text.initialValueError(this.initialValue));
994
- return void 0;
995
- }
996
- async prompt() {
997
- let value = await super.prompt();
998
- if (value === INSTALLER.NONE) return value;
999
- const exists = await existsLocalBin(value);
1000
- if (!exists) {
1001
- this.config.options = Object.fromEntries(
1002
- Object.entries(this.config.options).filter(([key]) => key !== value)
1003
- );
1004
- const badge = (txt) => this._utils.style.color.red(this._utils.style.color.inverse(" " + txt + " "));
1005
- this._utils.prompt.log.error(`Binary ${badge(value)} not found in system`);
1006
- value = await this.prompt();
1007
- }
1008
- return value;
1009
- }
1010
53
  }
1011
54
 
1012
- const OPTION = {
1013
- array: "array",
1014
- select: "select",
1015
- multiselect: "multiselect",
1016
- boolean: "boolean",
1017
- number: "number",
1018
- text: "text",
1019
- void: "void",
1020
- // customs
1021
- output: "output",
1022
- name: "name",
1023
- template: "template",
1024
- install: "install",
1025
- openEditor: "openEditor",
1026
- path: "path"
1027
- };
1028
-
1029
- let Array$1 = class Array extends Core$1 {
55
+ let Array$1 = class Array extends Core {
1030
56
  #defaultSeparator = ",";
1031
57
  async cmd() {
1032
58
  return {
@@ -1072,7 +98,7 @@ let Array$1 = class Array extends Core$1 {
1072
98
  }
1073
99
  };
1074
100
 
1075
- let Boolean$1 = class Boolean extends Core$1 {
101
+ class Boolean extends Core {
1076
102
  async cmd() {
1077
103
  return {
1078
104
  desc: this.config.desc,
@@ -1103,13 +129,13 @@ let Boolean$1 = class Boolean extends Core$1 {
1103
129
  }
1104
130
  return value;
1105
131
  }
1106
- };
132
+ }
1107
133
 
1108
- class Multiselect extends Core$1 {
134
+ class Multiselect extends Core {
1109
135
  async cmd() {
1110
136
  return {
1111
137
  desc: this.config.desc,
1112
- type: this._type.array,
138
+ type: this._type.choices,
1113
139
  alias: this.config.alias,
1114
140
  choices: Object.keys(this.config.options)
1115
141
  };
@@ -1145,7 +171,7 @@ class Multiselect extends Core$1 {
1145
171
  }
1146
172
  }
1147
173
 
1148
- let Number$1 = class Number extends Core$1 {
174
+ class Number extends Core {
1149
175
  async cmd() {
1150
176
  return {
1151
177
  desc: this.config.desc,
@@ -1186,9 +212,50 @@ let Number$1 = class Number extends Core$1 {
1186
212
  }
1187
213
  return value;
1188
214
  }
1189
- };
215
+ }
1190
216
 
1191
- class Text extends Core$1 {
217
+ class Select extends Core {
218
+ async cmd() {
219
+ return {
220
+ desc: this.config.desc,
221
+ type: this._type.choices,
222
+ alias: this.config.alias,
223
+ choices: Object.keys(this.config.options)
224
+ };
225
+ }
226
+ async validateInitialValue(data) {
227
+ const message = this.config.promptMsg || this.config.desc;
228
+ if (typeof this.initialValue === "number" || typeof this.initialValue === "string") {
229
+ if (data?.showSuccess !== false)
230
+ this._utils.prompt.log.success(this._text.initialValueSuccess(message, this.initialValue.toString()));
231
+ return this.initialValue;
232
+ }
233
+ if (data?.showError !== false)
234
+ this._utils.prompt.log.warn(this._text.initialValueError(this.initialValue));
235
+ return void 0;
236
+ }
237
+ async prompt() {
238
+ const value = await this._utils.prompt.select({
239
+ message: this.config.promptMsg || this.config.desc,
240
+ options: Object.entries(this.config.options).map(([key, v]) => ({
241
+ value: key,
242
+ label: v?.name || key,
243
+ hint: v?.desc
244
+ })),
245
+ initialValue: this.config.placeholderValue?.toString()
246
+ });
247
+ console.debug({ selectData: {
248
+ value
249
+ } });
250
+ if (this._utils.prompt.isCancel(value)) {
251
+ await this._onCancel();
252
+ throw "";
253
+ }
254
+ return value;
255
+ }
256
+ }
257
+
258
+ class Text extends Core {
1192
259
  async cmd() {
1193
260
  return {
1194
261
  desc: this.config.desc,
@@ -1225,7 +292,7 @@ class Text extends Core$1 {
1225
292
  }
1226
293
  }
1227
294
 
1228
- class Void extends Core$1 {
295
+ class Void extends Core {
1229
296
  async cmd() {
1230
297
  return void 0;
1231
298
  }
@@ -1238,13 +305,136 @@ class Void extends Core$1 {
1238
305
  }
1239
306
  }
1240
307
 
308
+ const name = "creatium";
309
+
310
+ const SELECT_BASE_OPTS = { NONE: "none" };
311
+ const mergeSelectBaseOptions = (config, defaultOptions) => {
312
+ const options = Wn(defaultOptions || {}, config.options || {});
313
+ const filteredOptions = config.onlyOptions && config.onlyOptions.length > 1 ? Object.entries(options).reduce((acc, [key, value]) => {
314
+ if (key === SELECT_BASE_OPTS.NONE || config.onlyOptions.includes(key))
315
+ acc[key] = value;
316
+ return acc;
317
+ }, {}) : options;
318
+ return {
319
+ ...config,
320
+ options: Object.keys(filteredOptions).length > 1 ? filteredOptions : options
321
+ };
322
+ };
323
+
324
+ const TEXT_EDITOR = {
325
+ ...SELECT_BASE_OPTS,
326
+ VSCODE: "code",
327
+ SUBLIME: "subl",
328
+ WEBSTORM: "webstorm"
329
+ };
330
+ class Editor extends Select {
331
+ constructor(config, _utils) {
332
+ const defaultOptions = {
333
+ [TEXT_EDITOR.SUBLIME]: { name: "Sublime Text" },
334
+ [TEXT_EDITOR.VSCODE]: { name: "Visual Studio Code" },
335
+ [TEXT_EDITOR.WEBSTORM]: { name: "WebStorm" },
336
+ [TEXT_EDITOR.NONE]: {
337
+ name: "None",
338
+ desc: "Do not open the project with any text editor"
339
+ }
340
+ };
341
+ if (!config.desc) config.desc = "Select the text editor to open the project";
342
+ const finalConfig = mergeSelectBaseOptions(config, defaultOptions);
343
+ super(finalConfig, _utils);
344
+ this._utils = _utils;
345
+ this.config = finalConfig;
346
+ }
347
+ async validateInitialValue(data) {
348
+ const validateValue = await super.validateInitialValue({ showSuccess: false });
349
+ if (!validateValue) return void 0;
350
+ if (validateValue && await qn(validateValue)) {
351
+ if (data?.showSuccess !== false)
352
+ this._utils.prompt.log.success(this._text.initialValueSuccess(this.config.promptMsg || this.config.desc, validateValue));
353
+ return validateValue;
354
+ }
355
+ if (data?.showError !== false)
356
+ this._utils.prompt.log.warn(this._text.initialValueError(this.initialValue));
357
+ return void 0;
358
+ }
359
+ async prompt() {
360
+ let value = await super.prompt();
361
+ if (value === TEXT_EDITOR.NONE) return value;
362
+ const exists = await qn(value);
363
+ if (!exists) {
364
+ this.config.options = Object.fromEntries(
365
+ Object.entries(this.config.options).filter(([key]) => key !== value)
366
+ );
367
+ const badge = (txt) => this._utils.color.red(this._utils.color.inverse(" " + txt + " "));
368
+ this._utils.prompt.log.error(`Binary ${badge(value)} not found in system`);
369
+ value = await this.prompt();
370
+ }
371
+ return value;
372
+ }
373
+ }
374
+
375
+ const INSTALLER = {
376
+ DENO: "deno",
377
+ BUN: "bun",
378
+ NPM: "npm",
379
+ PNPM: "pnpm",
380
+ YARN: "yarn",
381
+ ...SELECT_BASE_OPTS
382
+ };
383
+ class Install extends Select {
384
+ constructor(config, _utils) {
385
+ const defaultOptions = {
386
+ [INSTALLER.NPM]: { name: "npm" },
387
+ [INSTALLER.PNPM]: { name: "pnpm" },
388
+ [INSTALLER.YARN]: { name: "yarn" },
389
+ [INSTALLER.DENO]: { name: "deno" },
390
+ [INSTALLER.NONE]: {
391
+ name: "None",
392
+ desc: "Do not install project dependencies"
393
+ }
394
+ };
395
+ if (!config.desc) config.desc = "Select the package manager to install the dependencies.";
396
+ const finalConfig = mergeSelectBaseOptions(config, defaultOptions);
397
+ super(finalConfig, _utils);
398
+ this._utils = _utils;
399
+ this.config = finalConfig;
400
+ }
401
+ async validateInitialValue(data) {
402
+ const validateValue = await super.validateInitialValue({ showSuccess: false });
403
+ if (!validateValue) return void 0;
404
+ const exists = await qn(validateValue);
405
+ if (validateValue && exists) {
406
+ if (data?.showSuccess !== false)
407
+ this._utils.prompt.log.success(this._text.initialValueSuccess(this.config.promptMsg || this.config.desc, validateValue));
408
+ return validateValue;
409
+ }
410
+ if (data?.showError !== false)
411
+ this._utils.prompt.log.warn(this._text.initialValueError(this.initialValue));
412
+ return void 0;
413
+ }
414
+ async prompt() {
415
+ let value = await super.prompt();
416
+ if (value === INSTALLER.NONE) return value;
417
+ const exists = await qn(value);
418
+ if (!exists) {
419
+ this.config.options = Object.fromEntries(
420
+ Object.entries(this.config.options).filter(([key]) => key !== value)
421
+ );
422
+ const badge = (txt) => this._utils.color.red(this._utils.color.inverse(" " + txt + " "));
423
+ this._utils.prompt.log.error(`Binary ${badge(value)} not found in system`);
424
+ value = await this.prompt();
425
+ }
426
+ return value;
427
+ }
428
+ }
429
+
1241
430
  class Name extends Text {
1242
- constructor(config) {
431
+ constructor(config, _utils) {
1243
432
  const finalConfig = {
1244
433
  desc: config.desc ?? "Set the name of the project",
1245
434
  ...config
1246
435
  };
1247
- super(finalConfig);
436
+ super(finalConfig, _utils);
437
+ this._utils = _utils;
1248
438
  this.config = finalConfig;
1249
439
  }
1250
440
  async validateInitialValue(data) {
@@ -1284,24 +474,25 @@ const PATH_TYPE = {
1284
474
  file: "file"
1285
475
  };
1286
476
  class Path extends Text {
1287
- #existsPath;
1288
- #pathType;
1289
- constructor(config) {
477
+ constructor(config, _utils) {
1290
478
  if (!config.pathType) config.pathType = PATH_TYPE.file;
1291
479
  if (!config.exists) config.exists = false;
1292
480
  const finalConfig = {
1293
481
  desc: config.desc ?? `Set input ${config.exists ? "existing" : "new"} ${config.pathType}`,
1294
482
  ...config
1295
483
  };
1296
- super(finalConfig);
484
+ super(finalConfig, _utils);
485
+ this._utils = _utils;
1297
486
  this.config = finalConfig;
1298
487
  this.#existsPath = config.exists;
1299
488
  this.#pathType = config.pathType;
1300
489
  }
490
+ #existsPath;
491
+ #pathType;
1301
492
  async #validatePath(path) {
1302
493
  const mustExists = this.#existsPath;
1303
494
  const type = this.#pathType;
1304
- const existsPath = type === PATH_TYPE.file ? await existsFile(path) : await existsDir(path);
495
+ const existsPath = type === PATH_TYPE.file ? await Un(path) : await zn(path);
1305
496
  const validation = mustExists === existsPath;
1306
497
  console.debug({ pathValueData: {
1307
498
  validatePath: path,
@@ -1347,7 +538,7 @@ class Path extends Text {
1347
538
  }
1348
539
 
1349
540
  class Output extends Path {
1350
- constructor(config) {
541
+ constructor(config, _utils) {
1351
542
  const finalConfig = {
1352
543
  desc: config.desc ?? "Set the path where you want to create your project",
1353
544
  promptMsg: config.promptMsg ?? "Where do you want to create your project?",
@@ -1357,13 +548,14 @@ class Output extends Path {
1357
548
  ...finalConfig,
1358
549
  pathType: PATH_TYPE.folder,
1359
550
  exists: false
1360
- });
551
+ }, _utils);
552
+ this._utils = _utils;
1361
553
  this.config = finalConfig;
1362
554
  }
1363
555
  }
1364
556
 
1365
557
  class Template extends Select {
1366
- constructor(config) {
558
+ constructor(config, _utils) {
1367
559
  const {
1368
560
  options: _options,
1369
561
  ...rest
@@ -1383,21 +575,19 @@ class Template extends Select {
1383
575
  ...rest
1384
576
  // Propiedades opcionales adicionales
1385
577
  };
1386
- super(finalConfig);
578
+ super(finalConfig, _utils);
579
+ this._utils = _utils;
1387
580
  this.config = finalConfig;
1388
581
  }
1389
582
  }
1390
583
 
1391
- const name = "creatium";
1392
-
1393
- class Core {
1394
- constructor(config) {
584
+ class Options {
585
+ constructor(config, utils) {
1395
586
  this.config = config;
1396
- this.utils = coreUtils;
587
+ this.utils = utils;
1397
588
  this.onCancel = async () => {
1398
589
  };
1399
590
  }
1400
- utils;
1401
591
  onCancel;
1402
592
  /** Enable cache */
1403
593
  cache = false;
@@ -1409,15 +599,15 @@ class Core {
1409
599
  /** Debug mode */
1410
600
  set debugMode(value) {
1411
601
  if (value === true) {
1412
- const dim = (txt) => this.utils.style.color.gray(this.utils.style.color.dim(txt));
602
+ const dim = (txt) => this.utils.color.gray(this.utils.color.dim(txt));
1413
603
  console.debug = (...args) => {
1414
604
  console.log();
1415
- const TITLE = dim(this.utils.style.line({
605
+ const TITLE = dim(this.utils.line({
1416
606
  title: "DEBUG",
1417
607
  lineChar: " ",
1418
608
  align: "left"
1419
609
  }));
1420
- const LINE = dim(this.utils.style.line({ title: "" }));
610
+ const LINE = dim(this.utils.line({ title: "" }));
1421
611
  console.log(TITLE);
1422
612
  console.log(LINE);
1423
613
  console.log(...args);
@@ -1435,7 +625,7 @@ class Core {
1435
625
  }, {});
1436
626
  };
1437
627
  if (!this.cache) return;
1438
- return await cache({
628
+ return await Sn({
1439
629
  projectName: this.projectName,
1440
630
  id: "create-prompts",
1441
631
  values: resetObjectValues(this.config)
@@ -1444,8 +634,8 @@ class Core {
1444
634
  #getClass() {
1445
635
  return {
1446
636
  array: Array$1,
1447
- number: Number$1,
1448
- boolean: Boolean$1,
637
+ number: Number,
638
+ boolean: Boolean,
1449
639
  multiselect: Multiselect,
1450
640
  select: Select,
1451
641
  text: Text,
@@ -1506,21 +696,42 @@ class Core {
1506
696
  }
1507
697
  }
1508
698
 
699
+ const OPTION = {
700
+ array: "array",
701
+ select: "select",
702
+ multiselect: "multiselect",
703
+ boolean: "boolean",
704
+ number: "number",
705
+ text: "text",
706
+ void: "void",
707
+ // customs
708
+ output: "output",
709
+ name: "name",
710
+ template: "template",
711
+ install: "install",
712
+ openEditor: "openEditor",
713
+ path: "path"
714
+ };
715
+
1509
716
  class CreatiumCore {
1510
717
  #core;
1511
718
  #data;
1512
719
  utils;
1513
720
  config;
1514
721
  #style;
1515
- #cwd = process$1.cwd();
722
+ #cwd = Pn.cwd();
1516
723
  constructor(config) {
1517
- this.#core = new Core(config.prompt);
724
+ this.#core = new Options(config.prompt, {
725
+ color: Tn,
726
+ line: xi,
727
+ prompt: Si
728
+ });
1518
729
  this.config = config;
1519
730
  this.utils = this.#core.utils;
1520
731
  this.#core.cache = this.config.cache === void 0 ? true : this.config.cache;
1521
732
  this.#core.projectName = this.config.name;
1522
733
  this.debugMode = false;
1523
- this.#style = { tick: this.utils.style.color.green(this.utils.style.color.dim("\u2713")) };
734
+ this.#style = { tick: this.utils.color.green(this.utils.color.dim("\u2713")) };
1524
735
  }
1525
736
  #_spinnerFN;
1526
737
  /** Force debug mode */
@@ -1540,52 +751,80 @@ class CreatiumCore {
1540
751
  }
1541
752
  }
1542
753
  async #exec(values) {
1543
- this.#data = { values };
1544
- console.debug({ initData: this.#data });
1545
- this.#core.onCancel = async () => await this.cancel();
1546
- if (this.config.hooks?.beforePrompt)
1547
- await this.config.hooks.beforePrompt(this.#data);
1548
- console.debug({ beforePromptData: this.#data });
1549
- await this.intro();
1550
- const prompts = await this.#core.getPrompts(this.#data.values);
1551
- const answers = await this.utils.prompt.group(prompts, { onCancel: this.#core.onCancel });
1552
- this.#data.values = answers;
1553
- console.debug({ promptData: this.#data });
1554
- if (this.config.hooks?.afterPrompt)
1555
- await this.config.hooks.afterPrompt(this.#data);
1556
- console.debug({ afterPromptData: this.#data });
1557
- return answers;
754
+ try {
755
+ this.#data = { values };
756
+ console.debug({ initData: this.#data });
757
+ this.#core.onCancel = async () => await this.cancel();
758
+ await this.config.hooks?.beforePrompt?.(this.#data);
759
+ console.debug({ beforePromptData: this.#data });
760
+ await this.intro();
761
+ const prompts = await this.#core.getPrompts(this.#data.values);
762
+ const answers = await this.utils.prompt.group(prompts, { onCancel: this.#core.onCancel });
763
+ this.#data.values = answers;
764
+ console.debug({ promptData: this.#data });
765
+ await this.config.hooks?.afterPrompt?.(this.#data);
766
+ console.debug({ afterPromptData: this.#data });
767
+ return answers;
768
+ } catch (err) {
769
+ if (err instanceof Error) throw new Error(Hi(err.message, 200, "..."));
770
+ throw new Error("Unexpected error in execution");
771
+ }
1558
772
  }
1559
773
  #getCliArgs(props) {
1560
- return props?.args && props.hideBin ? hideBin(props.args) ? props.args : props?.args : hideBin(process$1.argv);
774
+ return props?.args && props.hideBin ? hiddenBin(props.args) ? props.args : props?.args : hiddenBin(Pn.argv);
1561
775
  }
1562
776
  async #initCli(props) {
1563
777
  if (this.config.updater) await this.updateNotify();
1564
778
  const args = this.#getCliArgs(props);
1565
- const instance = await createCli({
1566
- args,
1567
- fn: async (cli) => {
1568
- cli.scriptName(this.config.name).version(this.config.version).usage("Usage: $0 [options]").locale("en").help(false).showHelpOnFail(false).alias("h", "help").alias("v", "version");
1569
- if (this.config.prompt) {
1570
- const props2 = await this.#core.getCmds();
1571
- cli.options(props2);
779
+ const cli = new Clippium({
780
+ name: this.config.name.replaceAll(" ", "-").toLowerCase(),
781
+ version: this.config.version,
782
+ flags: {
783
+ ...this.config.prompt ? await this.#core.getCmds() : {},
784
+ help: {
785
+ type: "boolean",
786
+ alias: ["h"],
787
+ group: "Global flags:",
788
+ desc: "Show help"
789
+ },
790
+ version: {
791
+ type: "boolean",
792
+ alias: ["v"],
793
+ group: "Global flags:",
794
+ desc: "Show version"
795
+ },
796
+ debug: {
797
+ type: "boolean",
798
+ group: "Global flags:",
799
+ desc: "Debug mode"
1572
800
  }
1573
- cli.option("debug", {
1574
- desc: "Set Debug mode",
1575
- type: "boolean"
1576
- });
1577
- return cli;
1578
801
  }
1579
- });
1580
- const argv = await instance.argv;
1581
- if (!argv.debug) this.debugMode = false;
802
+ }, { help: { formatter: formatter({
803
+ title: (v) => Tn.cyan(Tn.inverse(Tn.bold(v))),
804
+ bin: Tn.cyan,
805
+ version: (v) => Tn.cyan(Tn.dim(Tn.italic(v))),
806
+ name: Tn.bold,
807
+ positionals: (v) => Tn.green(Tn.dim(v)),
808
+ commands: Tn.green,
809
+ flags: Tn.yellow,
810
+ desc: (v) => Tn.white(Tn.dim(v)),
811
+ examples: Tn.cyan,
812
+ sectionTitle: (v) => Tn.white(Tn.bold(Tn.underline(v))),
813
+ //color.white.bold.underline,
814
+ sectionDesc: (v) => Tn.white(Tn.dim(v)),
815
+ sectionsProps: (v) => Tn.white(Tn.dim(Tn.italic(v)))
816
+ }) } });
817
+ const { flags } = await cli.parse(args);
818
+ if (flags.help) {
819
+ console.log(cli.getHelp(args));
820
+ Pn.exit(0);
821
+ } else if (flags.version) {
822
+ console.log(cli.getVersion());
823
+ Pn.exit(0);
824
+ }
825
+ if (!flags.debug) this.debugMode = false;
1582
826
  else this.debugMode = true;
1583
- const {
1584
- _,
1585
- $0,
1586
- ...values
1587
- } = argv;
1588
- return values;
827
+ return flags;
1589
828
  }
1590
829
  /**
1591
830
  * Shows a notification if the current package is outdated.
@@ -1616,13 +855,13 @@ class CreatiumCore {
1616
855
  if (message) {
1617
856
  this.utils.prompt.log.step("");
1618
857
  this.utils.prompt.cancel(message);
1619
- process$1.exit(0);
858
+ Pn.exit(0);
1620
859
  } else if (this.config.onCancel && this.#data)
1621
860
  await this.config.onCancel(this.#data);
1622
861
  else if (this.config.onCancel === void 0) {
1623
862
  this.utils.prompt.log.step("");
1624
863
  this.utils.prompt.cancel("Canceled \u{1F494}");
1625
- process$1.exit(0);
864
+ Pn.exit(0);
1626
865
  }
1627
866
  }
1628
867
  /**
@@ -1641,7 +880,7 @@ class CreatiumCore {
1641
880
  await this.config.intro(this.#data || {});
1642
881
  else if (this.config.intro === void 0) {
1643
882
  console.log();
1644
- const badge = (txt) => this.utils.style.color.blue(this.utils.style.color.inverse(" " + this.utils.style.color.bold(txt) + " "));
883
+ const badge = (txt) => this.utils.color.blue(this.utils.color.inverse(" " + this.utils.color.bold(txt) + " "));
1645
884
  this.utils.prompt.intro(badge(this.config.name));
1646
885
  this.utils.prompt.log.step("");
1647
886
  }
@@ -1662,26 +901,37 @@ class CreatiumCore {
1662
901
  else if (typeof this.config.outro === "function" && this.#data)
1663
902
  await this.config.outro(this.#data);
1664
903
  else if (this.config.outro === void 0) {
1665
- this.utils.prompt.outro(this.utils.style.color.greenBright("Successfully completed \u{1F308}"));
904
+ this.utils.prompt.outro(this.utils.color.greenBright("Successfully completed \u{1F308}"));
1666
905
  }
1667
906
  }
1668
907
  /**
1669
908
  * Copy a directory from input path to output path.
1670
909
  *
1671
- * @param {object} data - Options object with input and output paths.
1672
- * @param {string} data.input - The path to the directory to copy.
1673
- * @param {string} data.output - The path to the destination directory.
1674
- * @returns {Promise<void>} - Resolves when the directory has been copied.
910
+ * @param {object} data - Options object with input and output paths.
911
+ * @returns {Promise<void>} - Resolves when the directory has been copied.
1675
912
  * @example
1676
913
  *
1677
914
  * const copyResult = await core.copyDir({
1678
915
  * input : '/path/to/sourceDir',
1679
916
  * output: '/path/to/destinationDir',
1680
917
  * })
918
+ * const copyResult = await copyDir({
919
+ * input : [
920
+ * {
921
+ * name: 'file1.txt',
922
+ * content: 'Hello, world!',
923
+ * },
924
+ * {
925
+ * name: 'file2.txt',
926
+ * content: 'Goodbye, world!',
927
+ * },
928
+ * ],
929
+ * output: '/path/to/destinationDir',
930
+ * })
1681
931
  */
1682
932
  async copyDir(data) {
1683
933
  console.debug({ copyDirData: data });
1684
- return await copyDir(data);
934
+ return await On(data);
1685
935
  }
1686
936
  /**
1687
937
  * Installs the project with the given package manager.
@@ -1715,7 +965,7 @@ class CreatiumCore {
1715
965
  };
1716
966
  try {
1717
967
  s.start(`Installing with ${installer}`);
1718
- await execChild(command[installer]);
968
+ await Vn(command[installer]);
1719
969
  s.stop(`${this.#style.tick} Package installed with [${installer}] successfully`);
1720
970
  } catch (_e) {
1721
971
  if (this.debugMode)
@@ -1750,7 +1000,7 @@ class CreatiumCore {
1750
1000
  const s = this.utils.prompt.spinner();
1751
1001
  try {
1752
1002
  s.start(`Opening in ${editor}`);
1753
- await execChild(`${editor} ${input}`);
1003
+ await Vn(`${editor} ${input}`);
1754
1004
  s.stop(`${this.#style.tick} Text editor [${editor}] opened successfully`);
1755
1005
  } catch (_e) {
1756
1006
  if (this.debugMode)
@@ -1789,13 +1039,13 @@ class CreatiumCore {
1789
1039
  if (!params) return;
1790
1040
  const getContent = async (filePath) => {
1791
1041
  try {
1792
- const content = await readFile(filePath, "utf-8");
1042
+ const content = await Ti(filePath, "utf-8");
1793
1043
  return typeof content === "string" && content.trim().length > 0 ? content : void 0;
1794
1044
  } catch (_e) {
1795
1045
  return void 0;
1796
1046
  }
1797
1047
  };
1798
- const paths = await getPaths("**", {
1048
+ const paths = await ai("**", {
1799
1049
  filesOnly: true,
1800
1050
  cwd: input,
1801
1051
  absolute: true,
@@ -1809,11 +1059,11 @@ class CreatiumCore {
1809
1059
  await Promise.all(paths.map(async (path) => {
1810
1060
  const content = await getContent(path);
1811
1061
  if (!content) return;
1812
- const res = await replacePlaceholders({
1062
+ const res = await Wi({
1813
1063
  content,
1814
1064
  params
1815
1065
  });
1816
- await writeFile(path, res, "utf-8");
1066
+ await Vi(path, res, "utf-8");
1817
1067
  }));
1818
1068
  }
1819
1069
  /**
@@ -1840,7 +1090,7 @@ class CreatiumCore {
1840
1090
  templates
1841
1091
  } });
1842
1092
  if (input && templates[input].input) return templates[input].input;
1843
- if (input && await existsDir(input)) return input;
1093
+ if (input && await zn(input)) return input;
1844
1094
  this.utils.prompt.log.error(`Error creating Template: template input "${input}" not found`);
1845
1095
  return;
1846
1096
  }
@@ -1873,11 +1123,11 @@ class CreatiumCore {
1873
1123
  output,
1874
1124
  install,
1875
1125
  consts,
1876
- ...prompt
1126
+ ...prompt2
1877
1127
  } = values;
1878
1128
  const data = {
1879
1129
  input: await this.getTemplateInput({ input }),
1880
- output: output ? resolvePath(output) : void 0
1130
+ output: output ? Li(output) : void 0
1881
1131
  };
1882
1132
  console.debug({ createTemplate: {
1883
1133
  values,
@@ -1896,7 +1146,7 @@ class CreatiumCore {
1896
1146
  name: this.config.name,
1897
1147
  version: this.config.version,
1898
1148
  consts,
1899
- prompt
1149
+ prompt: prompt2
1900
1150
  }
1901
1151
  });
1902
1152
  await this.install({
@@ -1911,7 +1161,7 @@ class CreatiumCore {
1911
1161
  } catch (e) {
1912
1162
  const error = e instanceof Error ? e.message : e?.toString();
1913
1163
  this.utils.prompt.log.error(`Unexpected error creating template:
1914
- ${error}
1164
+ ${Hi(error || "", 100, "...")}
1915
1165
 
1916
1166
  `);
1917
1167
  await this.#core.onCancel();
@@ -1926,7 +1176,7 @@ ${error}
1926
1176
  */
1927
1177
  async build(values, opts) {
1928
1178
  const cliValues = opts?.activeCli !== false ? await this.#initCli(opts) : {};
1929
- const config = values ? deepmergeCustom({})(values, cliValues) : cliValues;
1179
+ const config = values ? Ln({})(values, cliValues) : cliValues;
1930
1180
  return await this.#exec(config);
1931
1181
  }
1932
1182
  /**
@@ -2024,4 +1274,4 @@ class Creatium {
2024
1274
  }
2025
1275
  }
2026
1276
 
2027
- export { Creatium, CreatiumCore, INSTALLER, OPTION, TEXT_EDITOR, env, prompt, style, sys };
1277
+ export { Creatium, CreatiumCore, INSTALLER, OPTION, TEXT_EDITOR };