@nanoforge-dev/cli 1.4.0 → 1.4.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.
@@ -11,10 +11,10 @@ var __decorateClass = (decorators, target, key, kind) => {
11
11
  };
12
12
 
13
13
  // src/command/command.loader.ts
14
- import { red as red6 } from "ansis";
14
+ import { red as red7 } from "ansis";
15
15
 
16
16
  // src/lib/ui/messages.ts
17
- import { green } from "ansis";
17
+ import { bold, green } from "ansis";
18
18
 
19
19
  // src/lib/ui/emojis.ts
20
20
  import { get } from "node-emoji";
@@ -49,8 +49,9 @@ var Messages = {
49
49
  BUILD_WATCH_START: "Watching for changes...",
50
50
  BUILD_PART_IN_PROGRESS: /* @__PURE__ */ __name((part) => `Building ${part}`, "BUILD_PART_IN_PROGRESS"),
51
51
  BUILD_PART_WATCH_IN_PROGRESS: /* @__PURE__ */ __name((part) => `${part} updated, rebuilding`, "BUILD_PART_WATCH_IN_PROGRESS"),
52
+ BUILD_PART_SUCCESS: /* @__PURE__ */ __name((name) => success(`Build of ${name} succeeded!`), "BUILD_PART_SUCCESS"),
52
53
  BUILD_PART_FAILED: /* @__PURE__ */ __name((part, command) => failure(`Build of ${part} failed!
53
- Try running manually: ${command}`), "BUILD_PART_FAILED"),
54
+ Try running manually: ${bold(command)}`), "BUILD_PART_FAILED"),
54
55
  // --- Install ---
55
56
  INSTALL_START: "NanoForge Installation",
56
57
  INSTALL_SUCCESS: success("Installation completed!"),
@@ -70,6 +71,7 @@ Try running manually: ${command}`), "BUILD_PART_FAILED"),
70
71
  NEW_START: "NanoForge Project Creation",
71
72
  NEW_SUCCESS: success("Project successfully created!"),
72
73
  NEW_FAILED: failure("Project creation failed!"),
74
+ NEW_GENERATION_START: "Creating project...",
73
75
  NEW_NAME_QUESTION: "What is the name of your project?",
74
76
  NEW_PACKAGE_MANAGER_QUESTION: "Which package manager do you want to use?",
75
77
  NEW_LANGUAGE_QUESTION: "Which language do you want to use?",
@@ -77,6 +79,8 @@ Try running manually: ${command}`), "BUILD_PART_FAILED"),
77
79
  NEW_SERVER_QUESTION: "Do you want to generate a server for multiplayer?",
78
80
  NEW_SKIP_INSTALL_QUESTION: "Do you want to skip dependency installation?",
79
81
  NEW_DOCKER_QUESTION: "Do you want to add a Dockerfile for containerization?",
82
+ NEW_GIT_QUESTION: "Do you want to create a git repository?",
83
+ NEW_GIT_REMOTE_QUESTION: "Do you want to setup a git remote? (leave empty if you don't want to)",
80
84
  // --- Create ---
81
85
  CREATE_START: "NanoForge Component/System Creation",
82
86
  CREATE_SUCCESS: success("Element successfully created!"),
@@ -98,6 +102,9 @@ Try running manually: ${command}`), "BUILD_PART_FAILED"),
98
102
  START_PART_IN_PROGRESS: /* @__PURE__ */ __name((part) => `Starting ${part}...`, "START_PART_IN_PROGRESS"),
99
103
  START_PART_SUCCESS: /* @__PURE__ */ __name((part) => success(`${part} terminated.`), "START_PART_SUCCESS"),
100
104
  START_PART_FAILED: /* @__PURE__ */ __name((part) => failure(`${part} failed!`), "START_PART_FAILED"),
105
+ EDITOR_START: "NanoForge Editor",
106
+ EDITOR_SUCCESS: "Editor ended",
107
+ EDITOR_FAILED: failure("Editor failed!"),
101
108
  // --- Publish ---
102
109
  PUBLISH_START: "NanoForge Publish",
103
110
  PUBLISH_SUCCESS: success("Publish completed!"),
@@ -109,7 +116,6 @@ Try running manually: ${command}`), "BUILD_PART_FAILED"),
109
116
  UNPUBLISH_FAILED: failure("Unpublish failed!"),
110
117
  UNPUBLISH_IN_PROGRESS: /* @__PURE__ */ __name((name) => `Unpublishing ${name}...`, "UNPUBLISH_IN_PROGRESS"),
111
118
  // --- Schematics ---
112
- SCHEMATICS_START: "Running schematics",
113
119
  SCHEMATIC_IN_PROGRESS: /* @__PURE__ */ __name((name) => `Generating ${name}...`, "SCHEMATIC_IN_PROGRESS"),
114
120
  SCHEMATIC_WATCH_IN_PROGRESS: /* @__PURE__ */ __name((name) => `Change detected, regenerating ${name}...`, "SCHEMATIC_WATCH_IN_PROGRESS"),
115
121
  SCHEMATIC_SUCCESS: /* @__PURE__ */ __name((name) => success(`${name} generated successfully!`), "SCHEMATIC_SUCCESS"),
@@ -119,10 +125,20 @@ Try running manually: ${command}`), "BUILD_PART_FAILED"),
119
125
  PACKAGE_MANAGER_INSTALLATION_NOTHING: "Nothing to install.",
120
126
  PACKAGE_MANAGER_INSTALLATION_SUCCEED: /* @__PURE__ */ __name((names) => names ? success(`Packages installed: ${names.map((n) => green(n)).join(", ")}`) : success("Packages installed!"), "PACKAGE_MANAGER_INSTALLATION_SUCCEED"),
121
127
  PACKAGE_MANAGER_INSTALLATION_FAILED: /* @__PURE__ */ __name((command) => failure(`Package installation failed!
122
- Try running manually: ${command}`), "PACKAGE_MANAGER_INSTALLATION_FAILED"),
128
+ Try running manually: ${bold(command)}`), "PACKAGE_MANAGER_INSTALLATION_FAILED"),
129
+ // --- Git init ---
130
+ GIT_INIT_IN_PROGRESS: `Initializing git repository... ${Emojis.COFFEE}`,
131
+ GIT_INIT_SUCCEED: success("Git repository initialized!"),
132
+ GIT_INIT_FAILED: /* @__PURE__ */ __name((command) => failure(`Git repository initialization failed!
133
+ Try running manually: ${bold(command)}`), "GIT_INIT_FAILED"),
134
+ // --- Git remote ---
135
+ GIT_REMOTE_IN_PROGRESS: `Adding git remote... ${Emojis.COFFEE}`,
136
+ GIT_REMOTE_SUCCEED: success("Git remote added!"),
137
+ GIT_REMOTE_FAILED: /* @__PURE__ */ __name((command) => failure(`Git remote addition failed!
138
+ Try running manually: ${bold(command)}`), "GIT_REMOTE_FAILED"),
123
139
  // --- Runner ---
124
140
  RUNNER_EXECUTION_ERROR: /* @__PURE__ */ __name((command) => `
125
- Failed to execute command: ${command}`, "RUNNER_EXECUTION_ERROR")
141
+ Failed to execute command: ${bold(command)}`, "RUNNER_EXECUTION_ERROR")
126
142
  };
127
143
 
128
144
  // src/lib/ui/prefixes.ts
@@ -334,6 +350,11 @@ var getDevGenerateInput = /* @__PURE__ */ __name((inputs) => {
334
350
  return getBooleanInputWithDefault(inputs, "generate", false);
335
351
  }, "getDevGenerateInput");
336
352
 
353
+ // src/lib/input/inputs/editor/open.input.ts
354
+ var getEditorOpenInput = /* @__PURE__ */ __name((inputs, defaultValue) => {
355
+ return getBooleanInputWithDefault(inputs, "open", defaultValue);
356
+ }, "getEditorOpenInput");
357
+
337
358
  // src/lib/input/inputs/install/lib.input.ts
338
359
  function getInstallLibInput(inputs) {
339
360
  return getBooleanInputWithDefault(inputs, "lib", false);
@@ -455,7 +476,7 @@ var getNewStrictOrAsk = /* @__PURE__ */ __name((inputs) => {
455
476
  }, "getNewStrictOrAsk");
456
477
 
457
478
  // src/lib/package-manager/package-manager.ts
458
- import { bold, red as red3 } from "ansis";
479
+ import { red as red4 } from "ansis";
459
480
 
460
481
  // src/lib/runner/process-logger.ts
461
482
  import { green as green2, red as red2, yellow } from "ansis";
@@ -502,15 +523,16 @@ var resolveCLINodeBinaryPath = /* @__PURE__ */ __name((name) => {
502
523
  }, "resolveCLINodeBinaryPath");
503
524
 
504
525
  // src/lib/utils/spinner.ts
505
- var withSpinner = /* @__PURE__ */ __name(async (message, task, onError) => {
506
- const spinner = getSpinner(message);
526
+ import { red as red3 } from "ansis";
527
+ var withSpinner = /* @__PURE__ */ __name(async (task, loadingMessage, successMessage, failureMessage, onError) => {
528
+ const spinner = getSpinner(loadingMessage);
507
529
  spinner.start();
508
530
  try {
509
531
  const value = await task(spinner);
510
- spinner.succeed();
532
+ spinner.succeed(successMessage);
511
533
  return { success: true, value };
512
534
  } catch (error) {
513
- spinner.fail();
535
+ spinner.fail(red3(failureMessage));
514
536
  if (onError) onError();
515
537
  return { success: false, error };
516
538
  }
@@ -532,12 +554,10 @@ var PackageManager = class {
532
554
  async install(directory) {
533
555
  const args = [this.commands.install, this.commands.silentFlag];
534
556
  const result = await withSpinner(
557
+ () => this.exec(args, directory),
535
558
  Messages.PACKAGE_MANAGER_INSTALLATION_IN_PROGRESS,
536
- async (spinner) => {
537
- await this.exec(args, directory, { onFail: /* @__PURE__ */ __name(() => spinner.fail(), "onFail") });
538
- this.logSuccess(Messages.PACKAGE_MANAGER_INSTALLATION_SUCCEED());
539
- },
540
- () => this.logFailure(this.formatFailCommand([this.commands.install]))
559
+ Messages.PACKAGE_MANAGER_INSTALLATION_SUCCEED(),
560
+ Messages.PACKAGE_MANAGER_INSTALLATION_FAILED(this.formatFailCommand([this.commands.install]))
541
561
  );
542
562
  return result.success;
543
563
  }
@@ -560,11 +580,10 @@ var PackageManager = class {
560
580
  ...flags
561
581
  ];
562
582
  const result = await withSpinner(
583
+ () => this.exec(args, directory),
563
584
  message,
564
- async (spinner) => {
565
- await this.exec(args, directory, { onFail: /* @__PURE__ */ __name(() => spinner.fail(), "onFail") });
566
- },
567
- () => this.logBuildFailure(name)
585
+ Messages.BUILD_PART_SUCCESS(name),
586
+ Messages.BUILD_PART_FAILED(name, this.formatFailCommand(args))
568
587
  );
569
588
  return result.success;
570
589
  }
@@ -582,7 +601,25 @@ var PackageManager = class {
582
601
  console.info(Messages.START_PART_SUCCESS(name));
583
602
  return true;
584
603
  } catch {
585
- console.error(red3(Messages.START_PART_FAILED(name)));
604
+ console.error(red4(Messages.START_PART_FAILED(name)));
605
+ return false;
606
+ }
607
+ }
608
+ async runFile(name, directory, script, params, env2 = {}, flags = [], silent = false) {
609
+ console.info(Messages.START_PART_IN_PROGRESS(name));
610
+ try {
611
+ const args = this.buildRunFileArgs(script, params, flags, silent);
612
+ await this.exec(args, directory, {
613
+ env: env2,
614
+ listeners: {
615
+ onStdout: createStdoutLogger(name),
616
+ onStderr: createStderrLogger(name)
617
+ }
618
+ });
619
+ console.info(Messages.START_PART_SUCCESS(name));
620
+ return true;
621
+ } catch {
622
+ console.error(red4(Messages.START_PART_FAILED(name)));
586
623
  return false;
587
624
  }
588
625
  }
@@ -603,12 +640,10 @@ var PackageManager = class {
603
640
  }
604
641
  const args = [this.commands.add, saveFlag, ...dependencies];
605
642
  const result = await withSpinner(
643
+ () => this.exec(args, directory),
606
644
  Messages.PACKAGE_MANAGER_INSTALLATION_IN_PROGRESS,
607
- async (spinner) => {
608
- await this.exec(args, directory, { onFail: /* @__PURE__ */ __name(() => spinner.fail(), "onFail") });
609
- this.logSuccess(Messages.PACKAGE_MANAGER_INSTALLATION_SUCCEED(dependencies));
610
- },
611
- () => this.logFailure(this.formatFailCommand(args))
645
+ Messages.PACKAGE_MANAGER_INSTALLATION_SUCCEED(),
646
+ Messages.PACKAGE_MANAGER_INSTALLATION_FAILED(this.formatFailCommand(args))
612
647
  );
613
648
  return result.success;
614
649
  }
@@ -625,6 +660,15 @@ var PackageManager = class {
625
660
  if (this.commands.runArgsFlag) args.push(this.commands.runArgsFlag);
626
661
  return args.concat(params);
627
662
  }
663
+ buildRunFileArgs(script, params, flags, silent) {
664
+ if (!this.commands.runFile) throw new Error("Package manager does not support runFile");
665
+ const args = [...flags, this.commands.runFile];
666
+ if (silent) args.push(this.commands.silentFlag);
667
+ args.push(script);
668
+ if (params.length === 0) return args;
669
+ if (this.commands.runArgsFlag) args.push(this.commands.runArgsFlag);
670
+ return args.concat(params);
671
+ }
628
672
  exec(args, directory, options = {}) {
629
673
  return this.runner.run(args, {
630
674
  collect: options.collect ?? true,
@@ -637,18 +681,6 @@ var PackageManager = class {
637
681
  formatFailCommand(args) {
638
682
  return this.runner.fullCommand(args);
639
683
  }
640
- logSuccess(message) {
641
- console.info();
642
- console.info(message);
643
- console.info();
644
- }
645
- logFailure(command) {
646
- console.error(red3(Messages.PACKAGE_MANAGER_INSTALLATION_FAILED(bold(command))));
647
- }
648
- logBuildFailure(name) {
649
- const command = this.formatFailCommand([this.commands.install]);
650
- console.error(red3(Messages.BUILD_PART_FAILED(name, bold(command))));
651
- }
652
684
  logEmpty(message) {
653
685
  console.info();
654
686
  console.info(message);
@@ -661,7 +693,7 @@ import fs2 from "fs";
661
693
  import { resolve as resolve2 } from "path";
662
694
 
663
695
  // src/lib/runner/runner.ts
664
- import { red as red4 } from "ansis";
696
+ import { red as red5 } from "ansis";
665
697
  import { spawn } from "child_process";
666
698
  import * as process2 from "process";
667
699
  var Runner = class {
@@ -718,7 +750,7 @@ var Runner = class {
718
750
  this.logCapturedOutput(output);
719
751
  }
720
752
  logFailedCommand(args) {
721
- console.error(red4(`
753
+ console.error(red5(`
722
754
  Failed to execute command: ${this.binary} ${args.join(" ")}`));
723
755
  }
724
756
  logCapturedOutput(output) {
@@ -887,17 +919,17 @@ var copyFiles = /* @__PURE__ */ __name((from, to) => {
887
919
  }, "copyFiles");
888
920
  var resetFolder = /* @__PURE__ */ __name((folder) => {
889
921
  if (fs3.existsSync(folder)) fs3.rmSync(folder, { recursive: true, force: true });
890
- fs3.mkdirSync(folder);
922
+ fs3.mkdirSync(folder, { recursive: true });
891
923
  }, "resetFolder");
892
924
 
893
925
  // src/lib/utils/run-safe.ts
894
- import { red as red5 } from "ansis";
926
+ import { red as red6 } from "ansis";
895
927
  var runSafe = /* @__PURE__ */ __name(async (fn, fallback) => {
896
928
  try {
897
929
  return await fn();
898
930
  } catch (error) {
899
931
  const msg = getErrorMessage(error);
900
- if (msg) console.error(red5(msg));
932
+ if (msg) console.error(red6(msg));
901
933
  return fallback;
902
934
  }
903
935
  }, "runSafe");
@@ -1073,7 +1105,7 @@ import { join as join3 } from "path";
1073
1105
  var CONFIG_FILE_NAME = "nanoforge.config.json";
1074
1106
  var MANIFEST_FILE_NAME = "nanoforge.manifest.json";
1075
1107
  var GLOBAL_CONFIG_FILE_NAME = ".nanoforgerc";
1076
- var REGISTRY_URL = "https://api.nanoforge.dev";
1108
+ var REGISTRY_URL = "https://api.nanoforge.eu";
1077
1109
 
1078
1110
  // src/lib/utils/object.ts
1079
1111
  var isObject = /* @__PURE__ */ __name((item) => {
@@ -1573,8 +1605,44 @@ var DevAction = class extends AbstractAction {
1573
1605
  }
1574
1606
  };
1575
1607
 
1576
- // src/action/actions/generate.action.ts
1608
+ // src/action/actions/editor.action.ts
1609
+ import open from "open";
1577
1610
  import { join as join5 } from "path";
1611
+ var EditorAction = class extends AbstractAction {
1612
+ static {
1613
+ __name(this, "EditorAction");
1614
+ }
1615
+ startMessage = Messages.EDITOR_START;
1616
+ successMessage = Messages.EDITOR_SUCCESS;
1617
+ failureMessage = Messages.EDITOR_FAILED;
1618
+ async handle(args, options) {
1619
+ const directory = getDirectoryInput(options);
1620
+ const path = getPathInput(args);
1621
+ const open2 = getEditorOpenInput(options, !!path);
1622
+ void this.startEditor(directory);
1623
+ if (open2) await this.openEditor(path);
1624
+ return { keepAlive: true };
1625
+ }
1626
+ async startEditor(directory) {
1627
+ const editorPath = join5(
1628
+ getModulePath("@nanoforge-dev/editor/package.json", true),
1629
+ "dist",
1630
+ "index.js"
1631
+ );
1632
+ await runSafe(async () => {
1633
+ const packageManager = PackageManagerFactory.create("local_bun" /* LOCAL_BUN */);
1634
+ await packageManager.run("Editor", directory, editorPath, [], {}, [], true);
1635
+ });
1636
+ }
1637
+ async openEditor(path) {
1638
+ const query = path ? `?projectPath=${encodeURIComponent(path)}` : "";
1639
+ const url = `http://localhost:3000/load-project${query}`;
1640
+ await open(url);
1641
+ }
1642
+ };
1643
+
1644
+ // src/action/actions/generate.action.ts
1645
+ import { join as join6 } from "path";
1578
1646
  var GenerateAction = class extends AbstractAction {
1579
1647
  static {
1580
1648
  __name(this, "GenerateAction");
@@ -1633,7 +1701,7 @@ var GenerateAction = class extends AbstractAction {
1633
1701
  );
1634
1702
  }
1635
1703
  watchPath(directory, subDir, saveFile) {
1636
- return join5(getCwd(directory), subDir, saveFile);
1704
+ return join6(getCwd(directory), subDir, saveFile);
1637
1705
  }
1638
1706
  enterWatchMode() {
1639
1707
  console.info();
@@ -1644,7 +1712,7 @@ var GenerateAction = class extends AbstractAction {
1644
1712
  };
1645
1713
 
1646
1714
  // src/action/actions/install.action.ts
1647
- import { join as join7 } from "path";
1715
+ import { join as join8 } from "path";
1648
1716
 
1649
1717
  // src/lib/global-config/global-config-handler.ts
1650
1718
  import { read, readUser, write, writeUser } from "rc9";
@@ -1888,7 +1956,7 @@ var concatDeps = /* @__PURE__ */ __name((deps) => {
1888
1956
 
1889
1957
  // src/lib/registry/registry.ts
1890
1958
  import fs4 from "fs";
1891
- import { join as join6 } from "path";
1959
+ import { join as join7 } from "path";
1892
1960
  var Registry = class {
1893
1961
  static {
1894
1962
  __name(this, "Registry");
@@ -1919,9 +1987,9 @@ var Registry = class {
1919
1987
  }
1920
1988
  static async installPackage(client2, manifest, dir) {
1921
1989
  const file = await client2.getFile(`/registry/${manifest.name}/-/${manifest._file}`);
1922
- const path = join6(dir, this.getTypeSubFolder(manifest.type));
1990
+ const path = join7(dir, this.getTypeSubFolder(manifest.type));
1923
1991
  fs4.mkdirSync(path, { recursive: true });
1924
- fs4.writeFileSync(join6(path, manifest._file), await file.bytes());
1992
+ fs4.writeFileSync(join7(path, manifest._file), await file.bytes());
1925
1993
  }
1926
1994
  static getTypeSubFolder(type) {
1927
1995
  if (type === "component") return "components";
@@ -1933,7 +2001,7 @@ var Registry = class {
1933
2001
  return withAuth(config2.apiKey, force, !headers ? {} : void 0);
1934
2002
  }
1935
2003
  static _getPackageFile(filename, dir) {
1936
- const path = join6(getCwd(dir ?? "."), filename);
2004
+ const path = join7(getCwd(dir ?? "."), filename);
1937
2005
  if (!fs4.existsSync(path))
1938
2006
  throw new Error(
1939
2007
  "Package not found, please specify path in the nanoforge.manifest.json : `publish.paths.package`!"
@@ -1968,17 +2036,16 @@ var InstallAction = class extends AbstractAction {
1968
2036
  }
1969
2037
  async _installNfPackages(directory, names, isServer) {
1970
2038
  const deps = await resolveManifestDependencies(names, directory);
2039
+ const part = isServer ? "server" : "client";
1971
2040
  const libSuccess = await this._installLibs(
1972
2041
  directory,
1973
2042
  deps.npm.map(([name, version]) => `${name}@${version}`)
1974
2043
  );
1975
2044
  if (!libSuccess) return { success: false };
1976
- return withSpinner(Messages.INSTALL_PACKAGES_IN_PROGRESS, async () => {
1977
- await Registry.install(
1978
- Object.values(deps.nf),
1979
- join7(directory, isServer ? "server" : "client")
1980
- );
1981
- });
2045
+ return withSpinner(
2046
+ () => Registry.install(Object.values(deps.nf), join8(directory, part)),
2047
+ Messages.INSTALL_PACKAGES_IN_PROGRESS
2048
+ );
1982
2049
  }
1983
2050
  };
1984
2051
 
@@ -2029,7 +2096,82 @@ var LogoutAction = class extends AbstractAction {
2029
2096
  };
2030
2097
 
2031
2098
  // src/action/actions/new.action.ts
2032
- import { join as join8 } from "path";
2099
+ import { join as join9 } from "path";
2100
+
2101
+ // src/lib/git/git-runner.ts
2102
+ var GIT = "git";
2103
+ var GIT_COMMANDS = {
2104
+ init: "init",
2105
+ remote: "remote"
2106
+ };
2107
+ var GitRunner = class {
2108
+ static {
2109
+ __name(this, "GitRunner");
2110
+ }
2111
+ runner;
2112
+ constructor() {
2113
+ this.runner = new Runner(GIT);
2114
+ }
2115
+ async init(directory) {
2116
+ const args = [GIT_COMMANDS.init];
2117
+ const result = await withSpinner(
2118
+ () => this.exec(args, directory),
2119
+ Messages.GIT_INIT_IN_PROGRESS,
2120
+ Messages.GIT_INIT_SUCCEED,
2121
+ Messages.GIT_INIT_FAILED(this.formatFailCommand(args))
2122
+ );
2123
+ return result.success;
2124
+ }
2125
+ async addRemote(directory, remote) {
2126
+ const args = [GIT_COMMANDS.remote, "add", "origin", remote];
2127
+ const result = await withSpinner(
2128
+ () => this.exec(args, directory),
2129
+ Messages.GIT_REMOTE_IN_PROGRESS,
2130
+ Messages.GIT_REMOTE_SUCCEED,
2131
+ Messages.GIT_REMOTE_FAILED(this.formatFailCommand(args))
2132
+ );
2133
+ return result.success;
2134
+ }
2135
+ exec(args, directory, options = {}) {
2136
+ return this.runner.run(args, {
2137
+ collect: options.collect ?? true,
2138
+ cwd: getCwd(directory),
2139
+ env: options.env,
2140
+ listeners: options.listeners,
2141
+ onFail: options.onFail
2142
+ });
2143
+ }
2144
+ formatFailCommand(args) {
2145
+ return this.runner.fullCommand(args);
2146
+ }
2147
+ };
2148
+
2149
+ // src/lib/input/inputs/new/git-remote.input.ts
2150
+ var getGitRemoteInput = /* @__PURE__ */ __name((inputs) => {
2151
+ return getStringInput(inputs, "gitRemote");
2152
+ }, "getGitRemoteInput");
2153
+ var getNewGitRemoteInputOrAsk = /* @__PURE__ */ __name((inputs) => {
2154
+ return getInputOrAsk(
2155
+ getGitRemoteInput(inputs),
2156
+ () => askInput(Messages.NEW_GIT_REMOTE_QUESTION, {
2157
+ required: false,
2158
+ default: ""
2159
+ })
2160
+ );
2161
+ }, "getNewGitRemoteInputOrAsk");
2162
+
2163
+ // src/lib/input/inputs/new/git.input.ts
2164
+ var getNewGitInput = /* @__PURE__ */ __name((inputs) => {
2165
+ return getBooleanInput(inputs, "git");
2166
+ }, "getNewGitInput");
2167
+ var getNewGitOrAsk = /* @__PURE__ */ __name((inputs) => {
2168
+ return getInputOrAsk(
2169
+ getNewGitInput(inputs),
2170
+ () => askConfirm(Messages.NEW_GIT_QUESTION, { default: true })
2171
+ );
2172
+ }, "getNewGitOrAsk");
2173
+
2174
+ // src/action/actions/new.action.ts
2033
2175
  var NewAction = class extends AbstractAction {
2034
2176
  static {
2035
2177
  __name(this, "NewAction");
@@ -2042,18 +2184,16 @@ var NewAction = class extends AbstractAction {
2042
2184
  const values = await this.collectValues(options);
2043
2185
  await this.scaffold(values, cwdDirectory);
2044
2186
  let res = true;
2187
+ const distDir = join9(cwdDirectory, values.directory);
2045
2188
  if (!values.skipInstall) {
2046
- res = await this.installDependencies(
2047
- values.packageManager,
2048
- join8(cwdDirectory, values.directory ?? values.name)
2049
- );
2189
+ res = await this.installDependencies(values.packageManager, distDir);
2050
2190
  }
2191
+ if (values.git) await this.setupGitRepository(values.gitRemote, distDir);
2051
2192
  return { success: res };
2052
2193
  }
2053
2194
  async collectValues(inputs) {
2054
- return {
2195
+ const values = {
2055
2196
  name: await getNewNameInputOrAsk(inputs),
2056
- directory: getPathInput(inputs),
2057
2197
  packageManager: await getNewPackageManagerInputOrAsk(inputs),
2058
2198
  language: await getNewLanguageInputOrAsk(inputs),
2059
2199
  strict: await getNewStrictOrAsk(inputs),
@@ -2062,12 +2202,19 @@ var NewAction = class extends AbstractAction {
2062
2202
  skipInstall: await getNewSkipInstallOrAsk(inputs),
2063
2203
  docker: await getNewDockerOrAsk(inputs),
2064
2204
  lint: getNewLintInput(inputs),
2065
- editor: getEditorInput(inputs)
2205
+ editor: getEditorInput(inputs),
2206
+ git: await getNewGitOrAsk(inputs)
2207
+ };
2208
+ return {
2209
+ ...values,
2210
+ directory: getPathInput(inputs) ?? values.name,
2211
+ gitRemote: values.git ? await getNewGitRemoteInputOrAsk(inputs) || null : null
2066
2212
  };
2067
2213
  }
2068
2214
  async scaffold(values, directory) {
2069
2215
  const collection = CollectionFactory.create("@nanoforge-dev/schematics" /* NANOFORGE */, directory);
2070
- console.info(Messages.SCHEMATICS_START);
2216
+ console.info();
2217
+ console.info(Messages.NEW_GENERATION_START);
2071
2218
  console.info();
2072
2219
  await this.generateApplication(collection, values);
2073
2220
  await this.generateConfiguration(collection, values);
@@ -2092,7 +2239,7 @@ var NewAction = class extends AbstractAction {
2092
2239
  generateConfiguration(collection, values) {
2093
2240
  return executeSchematic("Configuration", collection, "configuration", {
2094
2241
  name: values.name,
2095
- directory: values.directory ?? values.name,
2242
+ directory: values.directory,
2096
2243
  server: values.server,
2097
2244
  language: values.language,
2098
2245
  initFunctions: values.initFunctions
@@ -2120,14 +2267,14 @@ var NewAction = class extends AbstractAction {
2120
2267
  }
2121
2268
  async generateDocker(collection, values) {
2122
2269
  await executeSchematic("Docker", collection, "docker", {
2123
- directory: values.directory ?? values.name,
2270
+ directory: values.directory,
2124
2271
  packageManager: values.packageManager
2125
2272
  });
2126
2273
  }
2127
2274
  partOptions(values, part) {
2128
2275
  return {
2129
2276
  part,
2130
- directory: values.directory ?? values.name,
2277
+ directory: values.directory,
2131
2278
  language: values.language,
2132
2279
  initFunctions: values.initFunctions
2133
2280
  };
@@ -2136,6 +2283,13 @@ var NewAction = class extends AbstractAction {
2136
2283
  const packageManager = PackageManagerFactory.create(packageManagerName);
2137
2284
  return await packageManager.install(directory);
2138
2285
  }
2286
+ async setupGitRepository(gitRemote, dir) {
2287
+ const runner = new GitRunner();
2288
+ let res;
2289
+ res = await runner.init(dir);
2290
+ if (res && gitRemote) res = await runner.addRemote(dir, gitRemote);
2291
+ return res;
2292
+ }
2139
2293
  };
2140
2294
 
2141
2295
  // src/lib/manifest/manifest.type.ts
@@ -2234,10 +2388,10 @@ __decorateClass([
2234
2388
  import { plainToInstance as plainToInstance2 } from "class-transformer";
2235
2389
  import { validate as validate2 } from "class-validator";
2236
2390
  import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
2237
- import { join as join9 } from "path";
2391
+ import { join as join10 } from "path";
2238
2392
  var getManifestPath = /* @__PURE__ */ __name((directory) => {
2239
2393
  for (const n of [MANIFEST_FILE_NAME]) {
2240
- const path = join9(directory, n);
2394
+ const path = join10(directory, n);
2241
2395
  if (existsSync2(path)) return path;
2242
2396
  }
2243
2397
  throw new Error(`No manifest file found in directory: ${directory}`);
@@ -2272,15 +2426,16 @@ var PublishAction = class extends AbstractAction {
2272
2426
  async handle(_args, options) {
2273
2427
  const directory = getDirectoryInput(options);
2274
2428
  const manifest = await loadManifest(directory);
2275
- return withSpinner(Messages.PUBLISH_IN_PROGRESS(manifest.name), async () => {
2276
- await Registry.publish(manifest, directory);
2277
- });
2429
+ return withSpinner(
2430
+ () => Registry.publish(manifest, directory),
2431
+ Messages.PUBLISH_IN_PROGRESS(manifest.name)
2432
+ );
2278
2433
  }
2279
2434
  };
2280
2435
 
2281
2436
  // src/action/actions/start.action.ts
2282
2437
  import dotenv from "dotenv";
2283
- import { join as join10, resolve as resolve3 } from "path";
2438
+ import { join as join11, resolve as resolve3 } from "path";
2284
2439
  var StartAction = class extends AbstractAction {
2285
2440
  static {
2286
2441
  __name(this, "StartAction");
@@ -2341,14 +2496,14 @@ var StartAction = class extends AbstractAction {
2341
2496
  }
2342
2497
  buildClientParams(directory, config2, options) {
2343
2498
  const params = {
2344
- "-d": getCwd(join10(directory, options.clientDir)),
2499
+ "-d": getCwd(join11(directory, options.clientDir)),
2345
2500
  "-p": options.port
2346
2501
  };
2347
2502
  if (options.watch) params["--watch"] = true;
2348
2503
  if (options.watch) {
2349
2504
  params["--watch"] = true;
2350
2505
  if (config2.server.enable) {
2351
- params["--watch-server-dir"] = getCwd(join10(directory, options.serverDir));
2506
+ params["--watch-server-dir"] = getCwd(join11(directory, options.serverDir));
2352
2507
  }
2353
2508
  }
2354
2509
  if (options.ssl) {
@@ -2359,7 +2514,7 @@ var StartAction = class extends AbstractAction {
2359
2514
  }
2360
2515
  buildServerParams(directory, _config, options) {
2361
2516
  const params = {
2362
- "-d": getCwd(join10(directory, options.serverDir))
2517
+ "-d": getCwd(join11(directory, options.serverDir))
2363
2518
  };
2364
2519
  if (options.watch) params["--watch"] = true;
2365
2520
  return this.buildParams(params);
@@ -2375,7 +2530,7 @@ var StartAction = class extends AbstractAction {
2375
2530
  ...process.env
2376
2531
  };
2377
2532
  dotenv.config({
2378
- path: resolve3(getCwd(join10(dir, ".env"))),
2533
+ path: resolve3(getCwd(join11(dir, ".env"))),
2379
2534
  processEnv: rawEnv
2380
2535
  });
2381
2536
  const baseEnv = Object.entries(rawEnv).filter(
@@ -2409,9 +2564,10 @@ var UnpublishAction = class extends AbstractAction {
2409
2564
  async handle(_args, options) {
2410
2565
  const directory = getDirectoryInput(options);
2411
2566
  const manifest = await loadManifest(directory);
2412
- return withSpinner(Messages.UNPUBLISH_IN_PROGRESS(manifest.name), async () => {
2413
- await Registry.unpublish(manifest, directory);
2414
- });
2567
+ return withSpinner(
2568
+ () => Registry.unpublish(manifest, directory),
2569
+ Messages.UNPUBLISH_IN_PROGRESS(manifest.name)
2570
+ );
2415
2571
  }
2416
2572
  };
2417
2573
 
@@ -2439,7 +2595,7 @@ var BuildCommand = class extends AbstractCommand {
2439
2595
  __name(this, "BuildCommand");
2440
2596
  }
2441
2597
  load(program) {
2442
- program.command("build").description("build your game").option("-d, --directory [directory]", "specify the working directory of the command").option("-c, --config [config]", "path to the config file", CONFIG_FILE_NAME).option("--client-entry [clientEntry]", "specify the entry file of the client").option("--server-entry [serverEntry]", "specify the entry file of the server").option("--client-static-dir [clientStaticDir]", "specify the static directory of the client").option("--server-static-dir [serverStaticDir]", "specify the static directory of the server").option("--client-out-dir [clientOutDir]", "specify the output directory of the client").option("--server-out-dir [serverOutDir]", "specify the output directory of the server").option("--editor", "specify if the project must build with editor config").option("--watch", "build app in watching mode", false).action(async (rawOptions) => {
2598
+ program.command("build").description("build your game").option("-d, --directory <directory>", "specify the working directory of the command").option("-c, --config <config>", "path to the config file", CONFIG_FILE_NAME).option("--client-entry <clientEntry>", "specify the entry file of the client").option("--server-entry <serverEntry>", "specify the entry file of the server").option("--client-static-dir <clientStaticDir>", "specify the static directory of the client").option("--server-static-dir <serverStaticDir>", "specify the static directory of the server").option("--client-out-dir <clientOutDir>", "specify the output directory of the client").option("--server-out-dir <serverOutDir>", "specify the output directory of the server").option("--editor", "specify if the project must build with editor config").option("--watch", "build app in watching mode", false).action(async (rawOptions) => {
2443
2599
  const options = AbstractCommand.mapToInput({
2444
2600
  directory: rawOptions.directory,
2445
2601
  config: rawOptions.config,
@@ -2463,13 +2619,13 @@ var CreateCommand = class extends AbstractCommand {
2463
2619
  __name(this, "CreateCommand");
2464
2620
  }
2465
2621
  load(program) {
2466
- program.command("create [type]").description("create nanoforge components or systems").option("-d, --directory [directory]", "specify the working directory of the command").option("-c, --config [config]", "path to the config file", CONFIG_FILE_NAME).option("-n, --name [name]", "name of the component/system").option(
2622
+ program.command("create <type>").description("create nanoforge components or systems").option("-d, --directory <directory>", "specify the working directory of the command").option("-c, --config <config>", "path to the config file", CONFIG_FILE_NAME).option("-n, --name <name>", "name of the component/system").option(
2467
2623
  "-s, --server",
2468
2624
  "install components/systems on server (default install on client)",
2469
2625
  false
2470
2626
  ).option(
2471
- "-p, --path [path]",
2472
- "path to the component/system folder (default: [part]/<components|systems>)"
2627
+ "-p, --path <path>",
2628
+ "path to the component/system folder (default: <part>/<components|systems>)"
2473
2629
  ).action(async (type, rawOptions) => {
2474
2630
  const args = AbstractCommand.mapToInput({
2475
2631
  type
@@ -2492,7 +2648,7 @@ var DevCommand = class extends AbstractCommand {
2492
2648
  __name(this, "DevCommand");
2493
2649
  }
2494
2650
  load(program) {
2495
- program.command("dev").description("run your game in dev mode").option("-d, --directory [directory]", "specify the working directory of the command").option("-c, --config [config]", "path to the config file", CONFIG_FILE_NAME).option("--generate", "generate app from config", false).action(async (rawOptions) => {
2651
+ program.command("dev").description("run your game in dev mode").option("-d, --directory <directory>", "specify the working directory of the command").option("-c, --config <config>", "path to the config file", CONFIG_FILE_NAME).option("--generate", "generate app from config", false).action(async (rawOptions) => {
2496
2652
  const options = AbstractCommand.mapToInput({
2497
2653
  directory: rawOptions.directory,
2498
2654
  config: rawOptions.config,
@@ -2503,13 +2659,35 @@ var DevCommand = class extends AbstractCommand {
2503
2659
  }
2504
2660
  };
2505
2661
 
2662
+ // src/command/commands/editor.command.ts
2663
+ var EditorCommand = class extends AbstractCommand {
2664
+ static {
2665
+ __name(this, "EditorCommand");
2666
+ }
2667
+ load(program) {
2668
+ program.command("editor [path]").description("start the editor").option("-d, --directory <directory>", "specify the working directory of the command").option(
2669
+ "--open",
2670
+ "open the editor on the default web browser (default: true if path is specified, false otherwise)"
2671
+ ).option("--no-open", "do not open the editor on the default web browser").action(async (path, rawOptions) => {
2672
+ const args = AbstractCommand.mapToInput({
2673
+ path
2674
+ });
2675
+ const options = AbstractCommand.mapToInput({
2676
+ directory: rawOptions.directory,
2677
+ open: rawOptions.open
2678
+ });
2679
+ await this.action.run(args, options);
2680
+ });
2681
+ }
2682
+ };
2683
+
2506
2684
  // src/command/commands/generate.command.ts
2507
2685
  var GenerateCommand = class extends AbstractCommand {
2508
2686
  static {
2509
2687
  __name(this, "GenerateCommand");
2510
2688
  }
2511
2689
  load(program) {
2512
- program.command("generate").description("generate nanoforge files from config").option("-d, --directory [directory]", "specify the working directory of the command").option("-c, --config [config]", "path to the config file", CONFIG_FILE_NAME).option("--editor", "specify if the project must generate editor main file").option("--watch", "generate app in watching mode", false).action(async (rawOptions) => {
2690
+ program.command("generate").description("generate nanoforge files from config").option("-d, --directory <directory>", "specify the working directory of the command").option("-c, --config <config>", "path to the config file", CONFIG_FILE_NAME).option("--editor", "specify if the project must generate editor main file").option("--watch", "generate app in watching mode", false).action(async (rawOptions) => {
2513
2691
  const options = AbstractCommand.mapToInput({
2514
2692
  directory: rawOptions.directory,
2515
2693
  config: rawOptions.config,
@@ -2527,7 +2705,7 @@ var InstallCommand = class extends AbstractCommand {
2527
2705
  __name(this, "InstallCommand");
2528
2706
  }
2529
2707
  load(program) {
2530
- program.command("install [names...]").alias("add").description("add Nanoforge components and systems to your project").option("-d, --directory [directory]", "specify the working directory of the command").option("-l, --lib", "install library instead of component/system", false).option(
2708
+ program.command("install [names...]").alias("add").description("add Nanoforge components and systems to your project").option("-d, --directory <directory>", "specify the working directory of the command").option("-l, --lib", "install library instead of component/system", false).option(
2531
2709
  "-s, --server",
2532
2710
  "install components/systems on server (default install on client)",
2533
2711
  false
@@ -2551,7 +2729,7 @@ var LoginCommand = class extends AbstractCommand {
2551
2729
  __name(this, "LoginCommand");
2552
2730
  }
2553
2731
  load(program) {
2554
- program.command("login").description("login to Nanoforge registry").option("-d, --directory [directory]", "specify the working directory of the command").option("-l, --local", "login only for the project", false).option("-k, --api-key <key>", "api key for Nanoforge registry").action(async (rawOptions) => {
2732
+ program.command("login").description("login to Nanoforge registry").option("-d, --directory <directory>", "specify the working directory of the command").option("-l, --local", "login only for the project", false).option("-k, --api-key <key>", "api key for Nanoforge registry").action(async (rawOptions) => {
2555
2733
  const options = AbstractCommand.mapToInput({
2556
2734
  directory: rawOptions.directory,
2557
2735
  local: rawOptions.local,
@@ -2568,7 +2746,7 @@ var LogoutCommand = class extends AbstractCommand {
2568
2746
  __name(this, "LogoutCommand");
2569
2747
  }
2570
2748
  load(program) {
2571
- program.command("logout").description("logout from Nanoforge registry").option("-d, --directory [directory]", "specify the working directory of the command").option("-l, --local", "logout only for the project").action(async (rawOptions) => {
2749
+ program.command("logout").description("logout from Nanoforge registry").option("-d, --directory <directory>", "specify the working directory of the command").option("-l, --local", "logout only for the project").action(async (rawOptions) => {
2572
2750
  const options = AbstractCommand.mapToInput({
2573
2751
  directory: rawOptions.directory,
2574
2752
  local: rawOptions.local
@@ -2584,10 +2762,13 @@ var NewCommand = class extends AbstractCommand {
2584
2762
  __name(this, "NewCommand");
2585
2763
  }
2586
2764
  load(program) {
2587
- program.command("new").description("create a new nanoforge project").option("-d, --directory [directory]", "specify the working directory of the command").option("--name [name]", "specify the name of your project").option(
2588
- "--path [path]",
2765
+ program.command("new").description("create a new nanoforge project").option("-d, --directory <directory>", "specify the working directory of the command").option("--name <name>", "specify the name of your project").option(
2766
+ "--path <path>",
2589
2767
  "specify the relative path where your project will be created (default: name of the project)"
2590
- ).option("--package-manager [packageManager]", "specify the package manager of your project").option("--language [language]", "specify the language of your project").option("--strict", "use strict mode").option("--no-strict", "do not use strict mode").option("--server", "create a server").option("--no-server", "do not create a server").option("--init-functions", "initialize functions").option("--no-init-functions", "do not initialize functions").option("--skip-install", "skip installing dependencies").option("--no-skip-install", "do not skip installing dependencies").option("--docker", "generate docker files").option("--no-docker", "do not generate docker files").option("--no-lint", "do not generate lint files").option("--editor", "do add editor dependencies").action(async (rawOptions) => {
2768
+ ).option("--package-manager <packageManager>", "specify the package manager of your project").option("--language <language>", "specify the language of your project").option("--strict", "use strict mode").option("--no-strict", "do not use strict mode").option("--server", "create a server").option("--no-server", "do not create a server").option("--init-functions", "initialize functions").option("--no-init-functions", "do not initialize functions").option("--skip-install", "skip installing dependencies").option("--no-skip-install", "do not skip installing dependencies").option("--docker", "generate docker files").option("--no-docker", "do not generate docker files").option("--no-lint", "do not generate lint files").option("--editor", "do add editor dependencies").option("--git", "generate git repository").option("--no-git", "do not generate git repository").option(
2769
+ "--git-remote <gitRemote>",
2770
+ "setup git remote to git repository (required if --git is used)"
2771
+ ).option("--no-git-remote", "do not setup git remote to git repository").action(async (rawOptions) => {
2591
2772
  const options = AbstractCommand.mapToInput({
2592
2773
  directory: rawOptions.directory,
2593
2774
  name: rawOptions.name,
@@ -2600,7 +2781,9 @@ var NewCommand = class extends AbstractCommand {
2600
2781
  skipInstall: rawOptions.skipInstall,
2601
2782
  docker: rawOptions.docker,
2602
2783
  lint: rawOptions.lint,
2603
- editor: rawOptions.editor
2784
+ editor: rawOptions.editor,
2785
+ git: rawOptions.git,
2786
+ gitRemote: rawOptions.gitRemote || void 0
2604
2787
  });
2605
2788
  await this.action.run(/* @__PURE__ */ new Map(), options);
2606
2789
  });
@@ -2613,7 +2796,7 @@ var PublishCommand = class extends AbstractCommand {
2613
2796
  __name(this, "PublishCommand");
2614
2797
  }
2615
2798
  load(program) {
2616
- program.command("publish").description("publish package to Nanoforge registry").option("-d, --directory [directory]", "specify the working directory of the command").action(async (rawOptions) => {
2799
+ program.command("publish").description("publish package to Nanoforge registry").option("-d, --directory <directory>", "specify the working directory of the command").action(async (rawOptions) => {
2617
2800
  const options = AbstractCommand.mapToInput({
2618
2801
  directory: rawOptions.directory
2619
2802
  });
@@ -2628,7 +2811,7 @@ var StartCommand = class extends AbstractCommand {
2628
2811
  __name(this, "StartCommand");
2629
2812
  }
2630
2813
  load(program) {
2631
- program.command("start").description("start your game").option("-d, --directory [directory]", "specify the working directory of the command").option("-c, --config [config]", "path to the config file", CONFIG_FILE_NAME).option("-p, --port [port]", "specify the port of the loader (the website to load the game)").option("--client-dir [clientDirectory]", "specify the directory of the client").option("--server-dir [serverDirectory]", "specify the directory of the server").option("--watch", "run app in watching mode", false).option("--cert [cert]", "path to the SSL certificate for HTTPS").option("--key [key]", "path to the SSL key for HTTPS").action(async (rawOptions) => {
2814
+ program.command("start").description("start your game").option("-d, --directory <directory>", "specify the working directory of the command").option("-c, --config <config>", "path to the config file", CONFIG_FILE_NAME).option("-p, --port <port>", "specify the port of the loader (the website to load the game)").option("--client-dir <clientDirectory>", "specify the directory of the client").option("--server-dir <serverDirectory>", "specify the directory of the server").option("--watch", "run app in watching mode", false).option("--cert <cert>", "path to the SSL certificate for HTTPS").option("--key <key>", "path to the SSL key for HTTPS").action(async (rawOptions) => {
2632
2815
  const options = AbstractCommand.mapToInput({
2633
2816
  directory: rawOptions.directory,
2634
2817
  config: rawOptions.config,
@@ -2650,7 +2833,7 @@ var UnpublishCommand = class extends AbstractCommand {
2650
2833
  __name(this, "UnpublishCommand");
2651
2834
  }
2652
2835
  load(program) {
2653
- program.command("unpublish").description("unpublish package to Nanoforge registry").option("-d, --directory [directory]", "specify the working directory of the command").action(async (rawOptions) => {
2836
+ program.command("unpublish").description("unpublish package to Nanoforge registry").option("-d, --directory <directory>", "specify the working directory of the command").action(async (rawOptions) => {
2654
2837
  const options = AbstractCommand.mapToInput({
2655
2838
  directory: rawOptions.directory
2656
2839
  });
@@ -2670,6 +2853,7 @@ var CommandLoader = class {
2670
2853
  new BuildCommand(new BuildAction()).load(program);
2671
2854
  new StartCommand(new StartAction()).load(program);
2672
2855
  new DevCommand(new DevAction()).load(program);
2856
+ new EditorCommand(new EditorAction()).load(program);
2673
2857
  new GenerateCommand(new GenerateAction()).load(program);
2674
2858
  new CreateCommand(new CreateAction()).load(program);
2675
2859
  new LoginCommand(new LoginAction()).load(program);
@@ -2681,8 +2865,8 @@ var CommandLoader = class {
2681
2865
  static handleInvalidCommand(program) {
2682
2866
  program.on("command:*", () => {
2683
2867
  console.error(`
2684
- ${Prefixes.ERROR} Invalid command: ${red6`%s`}`, program.args.join(" "));
2685
- console.log(`See ${red6`--help`} for a list of available commands.
2868
+ ${Prefixes.ERROR} Invalid command: ${red7`%s`}`, program.args.join(" "));
2869
+ console.log(`See ${red7`--help`} for a list of available commands.
2686
2870
  `);
2687
2871
  process.exit(1);
2688
2872
  });