creatium 0.0.6 → 0.1.0

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/dist/main.mjs CHANGED
@@ -713,7 +713,7 @@ let Core$1 = class Core {
713
713
  __publicField$3(this, "_text", {
714
714
  initialValueSuccess: (t, v) => `${t}
715
715
  ${this._utils.style.color.dim.gray(v)}`,
716
- initialValueError: (v) => `Initial value ${this._utils.style.color.yellow(" " + v + " ")} is not valid`
716
+ initialValueError: (v) => `Initial value ${this._utils.style.color.yellow(v)} is not valid`
717
717
  });
718
718
  }
719
719
  async getPromptHooked() {
@@ -746,13 +746,15 @@ class Select extends Core$1 {
746
746
  choices: Object.keys(this.config.options)
747
747
  };
748
748
  }
749
- async validateInitialValue() {
749
+ async validateInitialValue(data) {
750
750
  const message = this.config.promptMsg || this.config.desc;
751
751
  if (typeof this.initialValue === "number" || typeof this.initialValue === "string") {
752
- this._utils.prompt.log.success(this._text.initialValueSuccess(message, this.initialValue.toString()));
752
+ if (data?.showSuccess !== false)
753
+ this._utils.prompt.log.success(this._text.initialValueSuccess(message, this.initialValue.toString()));
753
754
  return this.initialValue;
754
755
  }
755
- this._utils.prompt.log.warn(this._text.initialValueError(this.initialValue));
756
+ if (data?.showError !== false)
757
+ this._utils.prompt.log.warn(this._text.initialValueError(this.initialValue));
756
758
  return void 0;
757
759
  }
758
760
  async prompt() {
@@ -773,7 +775,7 @@ class Select extends Core$1 {
773
775
  }
774
776
  }
775
777
 
776
- const IDE = {
778
+ const TEXT_EDITOR = {
777
779
  ...SELECT_BASE_OPTS,
778
780
  VSCODE: "code",
779
781
  SUBLIME: "subl",
@@ -782,34 +784,36 @@ const IDE = {
782
784
  class Editor extends Select {
783
785
  constructor(config) {
784
786
  const defaultOptions = {
785
- [IDE.SUBLIME]: { name: "Sublime Text" },
786
- [IDE.VSCODE]: { name: "Visual Studio Code" },
787
- [IDE.WEBSTORM]: { name: "WebStorm" },
788
- [IDE.NONE]: {
787
+ [TEXT_EDITOR.SUBLIME]: { name: "Sublime Text" },
788
+ [TEXT_EDITOR.VSCODE]: { name: "Visual Studio Code" },
789
+ [TEXT_EDITOR.WEBSTORM]: { name: "WebStorm" },
790
+ [TEXT_EDITOR.NONE]: {
789
791
  name: "None",
790
792
  desc: "Do not open the project with any text editor"
791
793
  }
792
794
  };
793
795
  if (!config.desc)
794
- config.desc = "Select the code editor to open the project.";
796
+ config.desc = "Select the code editor to open the project";
795
797
  const finalConfig = mergeSelectBaseOptions(config, defaultOptions);
796
798
  super(finalConfig);
797
799
  this.config = finalConfig;
798
800
  }
799
- async validateInitialValue() {
800
- const validateValue = await super.validateInitialValue();
801
+ async validateInitialValue(data) {
802
+ const validateValue = await super.validateInitialValue({ showSuccess: false });
801
803
  if (!validateValue)
802
804
  return void 0;
803
805
  if (validateValue && await existsLocalBin(validateValue)) {
804
- this._utils.prompt.log.success(this._text.initialValueSuccess(this.config.promptMsg || this.config.desc, validateValue));
806
+ if (data?.showSuccess !== false)
807
+ this._utils.prompt.log.success(this._text.initialValueSuccess(this.config.promptMsg || this.config.desc, validateValue));
805
808
  return validateValue;
806
809
  }
807
- this._utils.prompt.log.warn(this._text.initialValueError(this.initialValue));
810
+ if (data?.showError !== false)
811
+ this._utils.prompt.log.warn(this._text.initialValueError(this.initialValue));
808
812
  return void 0;
809
813
  }
810
814
  async prompt() {
811
815
  let value = await super.prompt();
812
- if (value === IDE.NONE)
816
+ if (value === TEXT_EDITOR.NONE)
813
817
  return value;
814
818
  const exists = await existsLocalBin(value);
815
819
  if (!exists) {
@@ -849,15 +853,17 @@ class Install extends Select {
849
853
  super(finalConfig);
850
854
  this.config = finalConfig;
851
855
  }
852
- async validateInitialValue() {
853
- const validateValue = await super.validateInitialValue();
856
+ async validateInitialValue(data) {
857
+ const validateValue = await super.validateInitialValue({ showSuccess: false });
854
858
  if (!validateValue)
855
859
  return void 0;
856
860
  if (validateValue && await existsLocalBin(validateValue)) {
857
- this._utils.prompt.log.success(this._text.initialValueSuccess(this.config.promptMsg || this.config.desc, validateValue));
861
+ if (data?.showSuccess !== false)
862
+ this._utils.prompt.log.success(this._text.initialValueSuccess(this.config.promptMsg || this.config.desc, validateValue));
858
863
  return validateValue;
859
864
  }
860
- this._utils.prompt.log.warn(this._text.initialValueError(this.initialValue));
865
+ if (data?.showError !== false)
866
+ this._utils.prompt.log.warn(this._text.initialValueError(this.initialValue));
861
867
  return void 0;
862
868
  }
863
869
  async prompt() {
@@ -919,18 +925,21 @@ let Array$1 = class Array extends Core$1 {
919
925
  alias: this.config.alias
920
926
  };
921
927
  }
922
- async validateInitialValue() {
928
+ async validateInitialValue(data) {
923
929
  const separator = this.config.separator || __privateGet$3(this, _defaultSeparator);
924
930
  const message = this.config.promptMsg || this.config.desc;
925
931
  const value = this.initialValue;
926
932
  if (value && globalThis.Array.isArray(value)) {
927
- this._utils.prompt.log.success(this._text.initialValueSuccess(message, value.join(separator)));
933
+ if (data?.showSuccess !== false)
934
+ this._utils.prompt.log.success(this._text.initialValueSuccess(message, value.join(separator)));
928
935
  return value;
929
936
  } else if (value && typeof value === "string") {
930
- this._utils.prompt.log.success(this._text.initialValueSuccess(message, value));
937
+ if (data?.showSuccess !== false)
938
+ this._utils.prompt.log.success(this._text.initialValueSuccess(message, value));
931
939
  return value.split(separator).map((v) => v.trim());
932
940
  }
933
- this._utils.prompt.log.warn(this._text.initialValueError(value));
941
+ if (data?.showError !== false)
942
+ this._utils.prompt.log.warn(this._text.initialValueError(value));
934
943
  return void 0;
935
944
  }
936
945
  async prompt() {
@@ -964,13 +973,15 @@ let Boolean$1 = class Boolean extends Core$1 {
964
973
  alias: this.config.alias
965
974
  };
966
975
  }
967
- async validateInitialValue() {
976
+ async validateInitialValue(data) {
968
977
  const message = this.config.promptMsg || this.config.desc;
969
978
  if (typeof this.initialValue === "boolean") {
970
- this._utils.prompt.log.success(this._text.initialValueSuccess(message, this.initialValue.toString()));
979
+ if (data?.showSuccess !== false)
980
+ this._utils.prompt.log.success(this._text.initialValueSuccess(message, this.initialValue.toString()));
971
981
  return this.initialValue;
972
982
  }
973
- this._utils.prompt.log.warn(this._text.initialValueError(this.initialValue));
983
+ if (data?.showError !== false)
984
+ this._utils.prompt.log.warn(this._text.initialValueError(this.initialValue));
974
985
  return void 0;
975
986
  }
976
987
  async prompt() {
@@ -996,13 +1007,15 @@ class Multiselect extends Core$1 {
996
1007
  choices: Object.keys(this.config.options)
997
1008
  };
998
1009
  }
999
- async validateInitialValue() {
1010
+ async validateInitialValue(data) {
1000
1011
  const message = this.config.promptMsg || this.config.desc;
1001
1012
  if (this.initialValue && Array.isArray(this.initialValue) && Object.keys(this.config.options).every((v) => this.initialValue?.includes(v))) {
1002
- this._utils.prompt.log.success(this._text.initialValueSuccess(message, this.initialValue.join(", ")));
1013
+ if (data?.showSuccess !== false)
1014
+ this._utils.prompt.log.success(this._text.initialValueSuccess(message, this.initialValue.join(", ")));
1003
1015
  return this.initialValue;
1004
1016
  }
1005
- this._utils.prompt.log.warn(this._text.initialValueError(this.initialValue?.join(", ")));
1017
+ if (data?.showError !== false)
1018
+ this._utils.prompt.log.warn(this._text.initialValueError(this.initialValue?.join(", ")));
1006
1019
  return void 0;
1007
1020
  }
1008
1021
  // @ts-ignore
@@ -1033,17 +1046,20 @@ let Number$1 = class Number extends Core$1 {
1033
1046
  alias: this.config.alias
1034
1047
  };
1035
1048
  }
1036
- async validateInitialValue() {
1049
+ async validateInitialValue(data) {
1037
1050
  const message = this.config.promptMsg || this.config.desc;
1038
1051
  const value = this.initialValue;
1039
1052
  if (typeof value === "number") {
1040
- this._utils.prompt.log.success(this._text.initialValueSuccess(message, value.toString()));
1053
+ if (data?.showSuccess !== false)
1054
+ this._utils.prompt.log.success(this._text.initialValueSuccess(message, value.toString()));
1041
1055
  return value;
1042
1056
  } else if (typeof value === "string") {
1043
- this._utils.prompt.log.success(this._text.initialValueSuccess(message, value));
1057
+ if (data?.showSuccess !== false)
1058
+ this._utils.prompt.log.success(this._text.initialValueSuccess(message, value));
1044
1059
  return globalThis.Number(value);
1045
1060
  }
1046
- this._utils.prompt.log.warn(this._text.initialValueError(value));
1061
+ if (data?.showError !== false)
1062
+ this._utils.prompt.log.warn(this._text.initialValueError(value));
1047
1063
  return void 0;
1048
1064
  }
1049
1065
  async prompt() {
@@ -1073,13 +1089,15 @@ class Text extends Core$1 {
1073
1089
  alias: this.config.alias
1074
1090
  };
1075
1091
  }
1076
- async validateInitialValue() {
1092
+ async validateInitialValue(data) {
1077
1093
  const message = this.config.promptMsg || this.config.desc;
1078
1094
  if (typeof this.initialValue === "string") {
1079
- this._utils.prompt.log.success(this._text.initialValueSuccess(message, this.initialValue));
1095
+ if (data?.showSuccess !== false)
1096
+ this._utils.prompt.log.success(this._text.initialValueSuccess(message, this.initialValue));
1080
1097
  return this.initialValue;
1081
1098
  }
1082
- this._utils.prompt.log.warn(this._text.initialValueError(this.initialValue));
1099
+ if (data?.showError !== false)
1100
+ this._utils.prompt.log.warn(this._text.initialValueError(this.initialValue));
1083
1101
  return void 0;
1084
1102
  }
1085
1103
  async prompt() {
@@ -1118,21 +1136,24 @@ class Void extends Core$1 {
1118
1136
  class Name extends Text {
1119
1137
  constructor(config) {
1120
1138
  const finalConfig = {
1121
- desc: config.desc ?? "Set the name of the project.",
1139
+ desc: config.desc ?? "Set the name of the project",
1122
1140
  ...config
1123
1141
  };
1124
1142
  super(finalConfig);
1125
1143
  this.config = finalConfig;
1126
1144
  }
1127
- async validateInitialValue() {
1128
- const validateValue = await super.validateInitialValue();
1145
+ async validateInitialValue(data) {
1146
+ const validateValue = await super.validateInitialValue({ showSuccess: false });
1129
1147
  if (!validateValue)
1130
1148
  return void 0;
1131
- if (validateValue && /\s/.test(validateValue)) {
1132
- this._utils.prompt.log.success(this._text.initialValueSuccess(this.config.promptMsg || this.config.desc, validateValue));
1149
+ const hasSpaces = /\s/.test(validateValue);
1150
+ if (validateValue && !hasSpaces) {
1151
+ if (data?.showSuccess !== false)
1152
+ this._utils.prompt.log.success(this._text.initialValueSuccess(this.config.promptMsg || this.config.desc, validateValue));
1133
1153
  return validateValue;
1134
1154
  }
1135
- this._utils.prompt.log.warn(this._text.initialValueError(this.initialValue));
1155
+ if (data?.showError !== false)
1156
+ this._utils.prompt.log.warn(this._text.initialValueError(this.initialValue));
1136
1157
  return void 0;
1137
1158
  }
1138
1159
  async prompt() {
@@ -1202,15 +1223,17 @@ class Path extends Text {
1202
1223
  __privateSet$2(this, _existsPath, config.exists);
1203
1224
  __privateSet$2(this, _pathType, config.pathType);
1204
1225
  }
1205
- async validateInitialValue() {
1206
- const validateValue = await super.validateInitialValue();
1226
+ async validateInitialValue(data) {
1227
+ const validateValue = await super.validateInitialValue({ showSuccess: false });
1207
1228
  if (!validateValue)
1208
1229
  return void 0;
1209
1230
  if (validateValue && await __privateMethod$2(this, _validatePath, validatePath_fn).call(this, validateValue)) {
1210
- this._utils.prompt.log.success(this._text.initialValueSuccess(this.config.promptMsg || this.config.desc, validateValue));
1231
+ if (data?.showSuccess !== false)
1232
+ this._utils.prompt.log.success(this._text.initialValueSuccess(this.config.promptMsg || this.config.desc, validateValue));
1211
1233
  return validateValue;
1212
1234
  }
1213
- this._utils.prompt.log.warn(this._text.initialValueError(this.initialValue));
1235
+ if (data?.showError !== false)
1236
+ this._utils.prompt.log.warn(this._text.initialValueError(this.initialValue));
1214
1237
  return void 0;
1215
1238
  }
1216
1239
  async prompt() {
@@ -1243,13 +1266,13 @@ validatePath_fn = async function(path) {
1243
1266
  const type = __privateGet$2(this, _pathType);
1244
1267
  const existsPath = type === PATH_TYPE.file ? await existsFile(path) : await existsDir(path);
1245
1268
  const validation = mustExists === existsPath;
1246
- console.debug({
1269
+ console.debug({ pathValueData: {
1247
1270
  validatePath: path,
1248
1271
  existsPath,
1249
1272
  mustExists,
1250
1273
  type,
1251
1274
  validation
1252
- });
1275
+ } });
1253
1276
  if (validation)
1254
1277
  return path;
1255
1278
  this._utils.prompt.log.error(`${type === PATH_TYPE.file ? "File" : "Folder"} [${path}] ${mustExists ? "not exists. Set path that exists" : "already exists. Set path that not exists"}`);
@@ -1378,12 +1401,12 @@ class Core {
1378
1401
  }
1379
1402
  return res;
1380
1403
  }
1381
- async getPrompts() {
1404
+ async getPrompts(initialValues) {
1382
1405
  const res = {};
1383
1406
  const Klass = __privateMethod$1(this, _getClass, getClass_fn).call(this);
1384
1407
  const cached = await __privateMethod$1(this, _getCache, getCache_fn).call(this);
1385
1408
  const cachedValues = cached?.get();
1386
- console.debug({ cache: {
1409
+ console.debug({ cacheData: {
1387
1410
  active: this.cache,
1388
1411
  ...cached,
1389
1412
  values: cachedValues
@@ -1398,6 +1421,9 @@ class Core {
1398
1421
  const instance = new Klass[type](props);
1399
1422
  instance._onCancel = this.onCancel;
1400
1423
  instance.debugMode = this.debugMode;
1424
+ const initialValue = initialValues?.[key];
1425
+ if (initialValue)
1426
+ instance.initialValue = initialValue;
1401
1427
  const cachedValue = cachedValues?.[key];
1402
1428
  if (cachedValue)
1403
1429
  instance.config.placeholderValue = cachedValue;
@@ -1471,18 +1497,18 @@ var __privateMethod = (obj, member, method) => {
1471
1497
  __accessCheck$1(obj, member, "access private method");
1472
1498
  return method;
1473
1499
  };
1474
- var _core$1, _data, _style, _exec, exec_fn, _getCliArgs, getCliArgs_fn, _initCli, initCli_fn, _createTemplate, createTemplate_fn;
1500
+ var _core$1, _data, _style, _cwd, _exec, exec_fn, _getCliArgs, getCliArgs_fn, _initCli, initCli_fn;
1475
1501
  class CreatiumCore {
1476
1502
  constructor(config) {
1477
1503
  __privateAdd$1(this, _exec);
1478
1504
  __privateAdd$1(this, _getCliArgs);
1479
1505
  __privateAdd$1(this, _initCli);
1480
- __privateAdd$1(this, _createTemplate);
1481
1506
  __privateAdd$1(this, _core$1, void 0);
1482
1507
  __privateAdd$1(this, _data, void 0);
1483
1508
  __publicField$1(this, "utils");
1484
1509
  __publicField$1(this, "config");
1485
1510
  __privateAdd$1(this, _style, void 0);
1511
+ __privateAdd$1(this, _cwd, process$1.cwd());
1486
1512
  __privateSet$1(this, _core$1, new Core(config.prompt));
1487
1513
  this.config = config;
1488
1514
  this.utils = __privateGet$1(this, _core$1).utils;
@@ -1495,16 +1521,54 @@ class CreatiumCore {
1495
1521
  set debugMode(value) {
1496
1522
  __privateGet$1(this, _core$1).debugMode = value;
1497
1523
  }
1498
- async updateNotify() {
1524
+ /**
1525
+ * Shows a notification if the current package is outdated.
1526
+ *
1527
+ * **information**: If this 'custom' function is provided, the default
1528
+ * notification will not be shown.
1529
+ *
1530
+ * ---
1531
+ * @param {object} [opts] - Options for the update notification.
1532
+ * @param {object} [opts.opts] - Options for the `update-notifier` package.
1533
+ * @param {Function} [opts.custom] - A custom function to run with the update
1534
+ * @example
1535
+ * // With default options. Recommended for most use cases.
1536
+ * await core.updateNotify()
1537
+ * @example
1538
+ * // With custom options
1539
+ * await core.updateNotify({ opts: { ... } })
1540
+ * @example
1541
+ * // With custom function
1542
+ * await core.updateNotify({ custom: () => {} })
1543
+ */
1544
+ async updateNotify({
1545
+ custom,
1546
+ opts
1547
+ } = {}) {
1499
1548
  const { default: up } = await import('update-notifier');
1500
1549
  const updater = up({ pkg: {
1501
1550
  name: this.config.name,
1502
1551
  version: this.config.version
1503
1552
  } });
1504
- updater.notify();
1553
+ if (custom)
1554
+ await custom(updater.update);
1555
+ else
1556
+ updater.notify(opts);
1505
1557
  }
1506
- async cancel() {
1507
- if (this.config.onCancel && __privateGet$1(this, _data))
1558
+ /**
1559
+ * Cancels the current process and exits with code 0.
1560
+ *
1561
+ * If a `message` is provided, it will be displayed in the console.
1562
+ * If `onCancel` is set in the config, it will be called with the current data.
1563
+ * If `onCancel` is not set, a default message will be displayed.
1564
+ * @param {string} [message] - The message to display before exiting.
1565
+ */
1566
+ async cancel(message) {
1567
+ if (message) {
1568
+ this.utils.prompt.log.step("");
1569
+ this.utils.prompt.cancel(message);
1570
+ process$1.exit(0);
1571
+ } else if (this.config.onCancel && __privateGet$1(this, _data))
1508
1572
  await this.config.onCancel(__privateGet$1(this, _data));
1509
1573
  else if (this.config.onCancel === void 0) {
1510
1574
  this.utils.prompt.log.step("");
@@ -1512,8 +1576,18 @@ class CreatiumCore {
1512
1576
  process$1.exit(0);
1513
1577
  }
1514
1578
  }
1515
- async intro() {
1516
- if (typeof this.config.intro === "function")
1579
+ /**
1580
+ * Intro prompt line.
1581
+ *
1582
+ * If the parameter `message` is provided, it will be used as the intro message.
1583
+ * If the `intro` option is a function, it will be called with the `this.#data` as the argument.
1584
+ * If the `intro` option is undefined, the default intro message will be used.
1585
+ * @param {string} [message] The intro message.
1586
+ */
1587
+ async intro(message) {
1588
+ if (message)
1589
+ this.utils.prompt.outro(message);
1590
+ else if (typeof this.config.intro === "function")
1517
1591
  await this.config.intro(__privateGet$1(this, _data) || {});
1518
1592
  else if (this.config.intro === void 0) {
1519
1593
  console.log();
@@ -1521,28 +1595,68 @@ class CreatiumCore {
1521
1595
  this.utils.prompt.log.step("");
1522
1596
  }
1523
1597
  }
1524
- async outro() {
1525
- if (typeof this.config.outro === "function" && __privateGet$1(this, _data))
1598
+ /**
1599
+ * Outro prompt line.
1600
+ *
1601
+ * If the parameter `message` is provided, it will be used as the outro message.
1602
+ * If the `outro` option is a function, it will be called with the `this.#data` as the argument.
1603
+ * If the `outro` option is undefined, the default outro message will be used.
1604
+ * @param {string} [message] The outro message.
1605
+ */
1606
+ async outro(message) {
1607
+ if (message)
1608
+ this.utils.prompt.outro(message);
1609
+ else if (typeof this.config.outro === "function" && __privateGet$1(this, _data))
1526
1610
  await this.config.outro(__privateGet$1(this, _data));
1527
1611
  else if (this.config.outro === void 0)
1528
1612
  this.utils.prompt.outro("Succesfully finished \u{1F308}");
1529
1613
  }
1530
- async copyDir(input, output) {
1531
- return await copyDir({
1532
- input,
1533
- output
1534
- });
1614
+ /**
1615
+ * Copy a directory from input path to output path.
1616
+ * @param {object} data - Options object with input and output paths.
1617
+ * @param {string} data.input - The path to the directory to copy.
1618
+ * @param {string} data.output - The path to the destination directory.
1619
+ * @returns {Promise<void>} - Resolves when the directory has been copied.
1620
+ * @example
1621
+ *
1622
+ * const copyResult = await core.copyDir({
1623
+ * input : '/path/to/sourceDir',
1624
+ * output: '/path/to/destinationDir',
1625
+ * })
1626
+ */
1627
+ async copyDir(data) {
1628
+ console.debug({ copyDirData: data });
1629
+ return await copyDir(data);
1535
1630
  }
1536
- async install(installer, output) {
1631
+ /**
1632
+ * Installs the project with the given package manager.
1633
+ * @param {object} [options] - The options to install.
1634
+ * @param {Installer} [options.installer] - The package manager to use for the installation.
1635
+ * @param {string} [options.input] - The path to the folder. If not provided, the current directory is used.
1636
+ * @returns {Promise<void>}
1637
+ * @example
1638
+ * await core.install( {
1639
+ * installer : 'pnpm',
1640
+ * input : 'my/project/path',
1641
+ * } )
1642
+ */
1643
+ async install({
1644
+ installer,
1645
+ input
1646
+ } = {}) {
1647
+ console.debug({ installData: {
1648
+ installer,
1649
+ input: input || __privateGet$1(this, _cwd)
1650
+ } });
1537
1651
  if (!installer || installer === "none")
1538
1652
  return;
1539
1653
  const s = this.utils.prompt.spinner();
1540
1654
  const command = {
1541
- [INSTALLER.PNPM]: !output ? "pnpm i" : `pnpm i --dir ${output}`,
1542
- [INSTALLER.NPM]: !output ? "npm install" : `npm install --prefix ${output}`,
1543
- [INSTALLER.YARN]: !output ? "yarn install" : `yarn install --cwd ${output}`,
1544
- [INSTALLER.DENO]: !output ? "deno install" : `deno install --root ${output}`,
1545
- [INSTALLER.BUN]: !output ? "bun install" : `bun install --cwd ${output}`
1655
+ [INSTALLER.PNPM]: `pnpm install${input ? ` --dir ${input}` : ""}`,
1656
+ [INSTALLER.NPM]: `npm install${input ? ` --prefix ${input}` : ""}`,
1657
+ [INSTALLER.YARN]: `yarn install${input ? ` --cwd ${input}` : ""}`,
1658
+ [INSTALLER.DENO]: `deno install${input ? ` --root ${input}` : ""}`,
1659
+ [INSTALLER.BUN]: `bun install${input ? ` --cwd ${input}` : ""}`
1546
1660
  };
1547
1661
  try {
1548
1662
  s.start(`Installing with ${installer}`);
@@ -1555,24 +1669,70 @@ class CreatiumCore {
1555
1669
  s.stop(`Error in installation with [${installer}]`);
1556
1670
  }
1557
1671
  }
1558
- async openEditor(editor, output) {
1672
+ /**
1673
+ * Open the project in the given editor.
1674
+ * @param {object} params - The parameters for opening the editor.
1675
+ * @param {TextEditor} params.editor - The editor to open the project in.
1676
+ * @param {string} params.input - The input path. If not provided, the current directory is used.
1677
+ * @returns {Promise<void>}
1678
+ * @example
1679
+ * await core.openEditor( {
1680
+ * editor : 'vscode',
1681
+ * input : 'my/project/path',
1682
+ * })
1683
+ */
1684
+ async openEditor({
1685
+ editor,
1686
+ input
1687
+ } = {}) {
1688
+ if (!input)
1689
+ input = __privateGet$1(this, _cwd);
1690
+ console.debug({ openEditorData: {
1691
+ editor,
1692
+ input
1693
+ } });
1559
1694
  if (!editor || editor === "none")
1560
1695
  return;
1561
1696
  const s = this.utils.prompt.spinner();
1562
1697
  try {
1563
1698
  s.start(`Opening in ${editor}`);
1564
- await execChild(`${editor} ${output}`);
1565
- s.stop(__privateGet$1(this, _style).tick + " IDE opened successfully");
1699
+ await execChild(`${editor} ${input}`);
1700
+ s.stop(__privateGet$1(this, _style).tick + " TEXT_EDITOR opened successfully");
1566
1701
  } catch (_e) {
1567
1702
  if (this.debugMode)
1568
1703
  s.stop(`Error opening in [${editor}]: ${_e?.toString()}`);
1569
1704
  else
1570
- s.stop("Error opening IDE");
1705
+ s.stop("Error opening TEXT_EDITOR");
1571
1706
  }
1572
1707
  }
1573
- async replacePlaceholders(input, params) {
1574
- if (!input || !params)
1575
- throw new Error('Missing parameters "output" and "params" for replace placeholders');
1708
+ /**
1709
+ * Replaces placeholders in files within the specified directory.
1710
+ *
1711
+ * This function searches for files in the provided input directory and replaces
1712
+ * placeholders within those files using the specified parameters. The placeholders
1713
+ * in the content are replaced with values from the `params` object.
1714
+ * @param {object} args - The arguments object.
1715
+ * @param {string} [args.input] - The directory path containing files with placeholders.
1716
+ * @param {object} [args.params] - An object containing key-value pairs for replacing placeholders.
1717
+ * @returns {Promise<void>} A Promise that resolves once all placeholders have been replaced.
1718
+ * @example
1719
+ * await core.replacePlaceholders( {
1720
+ * input : 'my/project/path',
1721
+ * params : { placeholder1: 'value1', placeholder2: 'value2' },
1722
+ * })
1723
+ */
1724
+ async replacePlaceholders({
1725
+ input,
1726
+ params
1727
+ } = {}) {
1728
+ if (!input)
1729
+ input = __privateGet$1(this, _cwd);
1730
+ console.debug({ replacePlaceholdersData: {
1731
+ params,
1732
+ input
1733
+ } });
1734
+ if (!params)
1735
+ return;
1576
1736
  const getContent = async (filePath) => {
1577
1737
  try {
1578
1738
  const content = await readFile(filePath, "utf-8");
@@ -1594,13 +1754,28 @@ class CreatiumCore {
1594
1754
  await writeFile(path, res, "utf-8");
1595
1755
  }
1596
1756
  }
1597
- async getTemplateInput(input) {
1757
+ /**
1758
+ * Return the input path of a template by name or path.
1759
+ * @param {string} [input] The name of the template or the path to the template.
1760
+ * @returns {Promise<string | undefined>} The input path of the template or undefined if not found.
1761
+ * @example
1762
+ * // with template path
1763
+ * const input = await core.getTemplateInput( { input : 'my/template/path' } )
1764
+ * @example
1765
+ * // With template key
1766
+ * // template key must be specified in the config prompt secction.
1767
+ * const input = await core.getTemplateInput( { input : 'templateKey' )
1768
+ */
1769
+ async getTemplateInput({ input } = {}) {
1598
1770
  const templates = Object.entries(this.config.prompt).reduce((acc, [_key, value]) => {
1599
1771
  if (value.type === OPTION.template && value.options)
1600
1772
  Object.assign(acc, value.options);
1601
1773
  return acc;
1602
1774
  }, {});
1603
- console.debug({ templates });
1775
+ console.debug({ getTemplateInputData: {
1776
+ input,
1777
+ templates
1778
+ } });
1604
1779
  if (input && templates[input].input)
1605
1780
  return templates[input].input;
1606
1781
  if (input && await existsDir(input))
@@ -1630,7 +1805,48 @@ class CreatiumCore {
1630
1805
  */
1631
1806
  async createTemplate(values) {
1632
1807
  try {
1633
- await __privateMethod(this, _createTemplate, createTemplate_fn).call(this, values);
1808
+ const {
1809
+ openEditor,
1810
+ input,
1811
+ output,
1812
+ install,
1813
+ consts,
1814
+ ...prompt
1815
+ } = values;
1816
+ const data = {
1817
+ input: await this.getTemplateInput({ input }),
1818
+ output: output ? resolvePath(output) : void 0
1819
+ };
1820
+ console.debug({ createTemplate: {
1821
+ values,
1822
+ data
1823
+ } });
1824
+ this.utils.prompt.log.step("");
1825
+ if (!(data.input && data.output))
1826
+ throw new Error("Invalid input or output template");
1827
+ await this.copyDir({
1828
+ input: data.input,
1829
+ output: data.output
1830
+ });
1831
+ await this.replacePlaceholders({
1832
+ input: data.output,
1833
+ params: {
1834
+ name: this.config.name,
1835
+ version: this.config.version,
1836
+ consts,
1837
+ prompt
1838
+ }
1839
+ });
1840
+ await this.install({
1841
+ input: data.output,
1842
+ installer: install
1843
+ });
1844
+ await this.openEditor({
1845
+ input: data.output,
1846
+ editor: openEditor
1847
+ });
1848
+ this.utils.prompt.log.step("");
1849
+ await this.outro();
1634
1850
  } catch (e) {
1635
1851
  const error = e instanceof Error ? e.message : e?.toString();
1636
1852
  this.utils.prompt.log.error(`Unexpected error creating template:
@@ -1670,22 +1886,23 @@ ${error}
1670
1886
  _core$1 = new WeakMap();
1671
1887
  _data = new WeakMap();
1672
1888
  _style = new WeakMap();
1889
+ _cwd = new WeakMap();
1673
1890
  _exec = new WeakSet();
1674
1891
  exec_fn = async function(values) {
1675
1892
  __privateSet$1(this, _data, { values });
1676
- console.debug({ data: __privateGet$1(this, _data) });
1893
+ console.debug({ initData: __privateGet$1(this, _data) });
1677
1894
  __privateGet$1(this, _core$1).onCancel = async () => await this.cancel();
1678
1895
  if (this.config.hooks?.beforePrompt)
1679
1896
  await this.config.hooks.beforePrompt(__privateGet$1(this, _data));
1680
- console.debug({ beforePrompt: __privateGet$1(this, _data) });
1897
+ console.debug({ beforePromptData: __privateGet$1(this, _data) });
1681
1898
  await this.intro();
1682
- const prompts = await __privateGet$1(this, _core$1).getPrompts();
1899
+ const prompts = await __privateGet$1(this, _core$1).getPrompts(__privateGet$1(this, _data).values);
1683
1900
  const answers = await this.utils.prompt.group(prompts, { onCancel: __privateGet$1(this, _core$1).onCancel });
1684
1901
  __privateGet$1(this, _data).values = answers;
1685
- console.debug({ answers });
1902
+ console.debug({ promptData: __privateGet$1(this, _data) });
1686
1903
  if (this.config.hooks?.afterPrompt)
1687
1904
  await this.config.hooks.afterPrompt(__privateGet$1(this, _data));
1688
- console.debug({ afterPrompt: __privateGet$1(this, _data) });
1905
+ console.debug({ afterPromptData: __privateGet$1(this, _data) });
1689
1906
  return answers;
1690
1907
  };
1691
1908
  _getCliArgs = new WeakSet();
@@ -1724,36 +1941,6 @@ initCli_fn = async function(props) {
1724
1941
  } = argv;
1725
1942
  return values;
1726
1943
  };
1727
- _createTemplate = new WeakSet();
1728
- createTemplate_fn = async function(values) {
1729
- const {
1730
- openEditor,
1731
- input,
1732
- output,
1733
- install,
1734
- consts,
1735
- ...prompt
1736
- } = values;
1737
- const data = {
1738
- input: await this.getTemplateInput(input),
1739
- output: output ? resolvePath(output) : void 0
1740
- };
1741
- console.debug({ templateData: data });
1742
- this.utils.prompt.log.step("");
1743
- if (!(data.input && data.output))
1744
- throw new Error("Invalid input or output template");
1745
- await this.copyDir(data.input, data.output);
1746
- await this.replacePlaceholders(data.output, {
1747
- name: this.config.name,
1748
- version: this.config.version,
1749
- consts,
1750
- prompt
1751
- });
1752
- await this.install(install, data.output);
1753
- await this.openEditor(openEditor, data.output);
1754
- this.utils.prompt.log.step("");
1755
- await this.outro();
1756
- };
1757
1944
 
1758
1945
  var __defProp = Object.defineProperty;
1759
1946
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
@@ -1856,4 +2043,4 @@ class Creatium {
1856
2043
  }
1857
2044
  _core = new WeakMap();
1858
2045
 
1859
- export { Creatium, CreatiumCore, IDE, INSTALLER, OPTION, env, prompt, style, sys };
2046
+ export { Creatium, CreatiumCore, INSTALLER, OPTION, TEXT_EDITOR, env, prompt, style, sys };