@nanoforge-dev/cli 1.1.0 → 1.1.1
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/command.loader.js +71 -34
- package/dist/command.loader.js.map +1 -1
- package/dist/nf.js +81 -36
- package/package.json +25 -17
package/dist/command.loader.js
CHANGED
|
@@ -96,7 +96,7 @@ var Prefixes = {
|
|
|
96
96
|
import * as ansis from "ansis";
|
|
97
97
|
import { watch } from "chokidar";
|
|
98
98
|
import * as console2 from "console";
|
|
99
|
-
import { dirname, join as
|
|
99
|
+
import { dirname, join as join3 } from "path";
|
|
100
100
|
|
|
101
101
|
// src/lib/input/base-inputs.ts
|
|
102
102
|
var getStringInput = /* @__PURE__ */ __name((input2, field) => {
|
|
@@ -237,7 +237,7 @@ var getInstallNamesInputOrAsk = /* @__PURE__ */ __name((inputs) => {
|
|
|
237
237
|
}, "getInstallNamesInputOrAsk");
|
|
238
238
|
|
|
239
239
|
// src/lib/package-manager/package-manager.factory.ts
|
|
240
|
-
import
|
|
240
|
+
import fs2 from "fs";
|
|
241
241
|
import { resolve as resolve2 } from "path";
|
|
242
242
|
|
|
243
243
|
// src/lib/runner/runner.factory.ts
|
|
@@ -311,7 +311,8 @@ var BunRunner = class extends AbstractRunner {
|
|
|
311
311
|
};
|
|
312
312
|
|
|
313
313
|
// src/lib/utils/path.ts
|
|
314
|
-
import
|
|
314
|
+
import fs from "fs";
|
|
315
|
+
import { join, resolve } from "path";
|
|
315
316
|
var getCwd = /* @__PURE__ */ __name((directory) => {
|
|
316
317
|
return resolve(directory);
|
|
317
318
|
}, "getCwd");
|
|
@@ -320,9 +321,19 @@ var getModulePath = /* @__PURE__ */ __name((name, removeLast = false) => {
|
|
|
320
321
|
if (removeLast) return path.split("/").slice(0, -1).join("/");
|
|
321
322
|
return path;
|
|
322
323
|
}, "getModulePath");
|
|
323
|
-
var
|
|
324
|
-
|
|
325
|
-
|
|
324
|
+
var resolveCLINodeBinaryPath = /* @__PURE__ */ __name((name) => {
|
|
325
|
+
let base = join(getModulePath(".", true), "..");
|
|
326
|
+
while (base.length >= 1) {
|
|
327
|
+
const path = join(base, "node_modules", ".bin", name);
|
|
328
|
+
try {
|
|
329
|
+
fs.accessSync(path);
|
|
330
|
+
return path;
|
|
331
|
+
} catch {
|
|
332
|
+
base = join(base, "..");
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
throw new Error("Could not find module path");
|
|
336
|
+
}, "resolveCLINodeBinaryPath");
|
|
326
337
|
|
|
327
338
|
// src/lib/runner/runners/local-bun.runner.ts
|
|
328
339
|
var LocalBunRunner = class extends AbstractRunner {
|
|
@@ -330,7 +341,7 @@ var LocalBunRunner = class extends AbstractRunner {
|
|
|
330
341
|
__name(this, "LocalBunRunner");
|
|
331
342
|
}
|
|
332
343
|
constructor() {
|
|
333
|
-
super(
|
|
344
|
+
super(resolveCLINodeBinaryPath("bun"));
|
|
334
345
|
}
|
|
335
346
|
};
|
|
336
347
|
|
|
@@ -512,7 +523,7 @@ var AbstractPackageManager = class {
|
|
|
512
523
|
}
|
|
513
524
|
async runDev(directory, command, env2 = {}, flags = [], collect = true) {
|
|
514
525
|
try {
|
|
515
|
-
const commandArgs = [this.cli.
|
|
526
|
+
const commandArgs = [this.cli.exec, command, ...flags];
|
|
516
527
|
await this.runner.run(commandArgs, collect, getCwd(directory), env2);
|
|
517
528
|
return true;
|
|
518
529
|
} catch {
|
|
@@ -590,6 +601,7 @@ var BunPackageManager = class extends AbstractPackageManager {
|
|
|
590
601
|
add: "add",
|
|
591
602
|
update: "update",
|
|
592
603
|
remove: "remove",
|
|
604
|
+
exec: "exec",
|
|
593
605
|
run: "run",
|
|
594
606
|
saveFlag: "--save",
|
|
595
607
|
saveDevFlag: "--dev",
|
|
@@ -615,6 +627,7 @@ var LocalBunPackageManager = class extends AbstractPackageManager {
|
|
|
615
627
|
add: "add",
|
|
616
628
|
update: "update",
|
|
617
629
|
remove: "remove",
|
|
630
|
+
exec: "exec",
|
|
618
631
|
run: "run",
|
|
619
632
|
build: "build",
|
|
620
633
|
runFile: "run",
|
|
@@ -642,6 +655,7 @@ var NpmPackageManager = class extends AbstractPackageManager {
|
|
|
642
655
|
add: "install",
|
|
643
656
|
update: "update",
|
|
644
657
|
remove: "uninstall",
|
|
658
|
+
exec: "exec",
|
|
645
659
|
run: "run",
|
|
646
660
|
saveFlag: "--save",
|
|
647
661
|
saveDevFlag: "--save-dev",
|
|
@@ -667,6 +681,7 @@ var PnpmPackageManager = class extends AbstractPackageManager {
|
|
|
667
681
|
add: "add",
|
|
668
682
|
update: "update",
|
|
669
683
|
remove: "remove",
|
|
684
|
+
exec: "exec",
|
|
670
685
|
run: "run",
|
|
671
686
|
saveFlag: "-P",
|
|
672
687
|
saveDevFlag: "-D",
|
|
@@ -692,6 +707,7 @@ var YarnPackageManager = class extends AbstractPackageManager {
|
|
|
692
707
|
add: "add",
|
|
693
708
|
update: "update",
|
|
694
709
|
remove: "remove",
|
|
710
|
+
exec: "exec",
|
|
695
711
|
run: "run",
|
|
696
712
|
saveFlag: "",
|
|
697
713
|
saveDevFlag: "-D",
|
|
@@ -724,7 +740,7 @@ var PackageManagerFactory = class {
|
|
|
724
740
|
static async find(directory = ".") {
|
|
725
741
|
const DEFAULT_PACKAGE_MANAGER = "npm" /* NPM */;
|
|
726
742
|
try {
|
|
727
|
-
const files = await
|
|
743
|
+
const files = await fs2.promises.readdir(resolve2(directory));
|
|
728
744
|
if (files.includes("bun.lock")) {
|
|
729
745
|
return this.create("bun" /* BUN */);
|
|
730
746
|
}
|
|
@@ -867,7 +883,7 @@ __decorateClass([
|
|
|
867
883
|
import { plainToInstance } from "class-transformer";
|
|
868
884
|
import { validate } from "class-validator";
|
|
869
885
|
import { existsSync, readFileSync } from "fs";
|
|
870
|
-
import { join } from "path";
|
|
886
|
+
import { join as join2 } from "path";
|
|
871
887
|
|
|
872
888
|
// src/lib/utils/object.ts
|
|
873
889
|
var isObject = /* @__PURE__ */ __name((item) => {
|
|
@@ -922,10 +938,10 @@ var CONFIG_DEFAULTS = {
|
|
|
922
938
|
var config;
|
|
923
939
|
var getConfigPath = /* @__PURE__ */ __name((directory, name) => {
|
|
924
940
|
if (name) {
|
|
925
|
-
return
|
|
941
|
+
return join2(directory, name);
|
|
926
942
|
} else {
|
|
927
943
|
for (const n of ["nanoforge.config.json"]) {
|
|
928
|
-
const path =
|
|
944
|
+
const path = join2(directory, n);
|
|
929
945
|
if (existsSync(path)) return path;
|
|
930
946
|
}
|
|
931
947
|
throw new Error(`Unsupported config: ${name}`);
|
|
@@ -997,8 +1013,11 @@ var BuildAction = class extends AbstractAction {
|
|
|
997
1013
|
console2.info();
|
|
998
1014
|
return;
|
|
999
1015
|
}
|
|
1000
|
-
if (!res)
|
|
1001
|
-
|
|
1016
|
+
if (!res) {
|
|
1017
|
+
console2.info(Messages.BUILD_FAILED);
|
|
1018
|
+
process.exit(1);
|
|
1019
|
+
}
|
|
1020
|
+
console2.info(Messages.BUILD_SUCCESS);
|
|
1002
1021
|
process.exit(0);
|
|
1003
1022
|
} catch (e) {
|
|
1004
1023
|
console2.error(e);
|
|
@@ -1039,7 +1058,7 @@ var buildPart = /* @__PURE__ */ __name(async (name, part, directory, options) =>
|
|
|
1039
1058
|
}
|
|
1040
1059
|
}, "build");
|
|
1041
1060
|
if (options?.watch)
|
|
1042
|
-
watch(dirname(
|
|
1061
|
+
watch(dirname(join3(getCwd(directory), part.entry))).on("change", () => build(true));
|
|
1043
1062
|
return await build();
|
|
1044
1063
|
}, "buildPart");
|
|
1045
1064
|
|
|
@@ -1082,7 +1101,7 @@ var runAction = /* @__PURE__ */ __name(async (command, params, directory, stdout
|
|
|
1082
1101
|
|
|
1083
1102
|
// src/action/actions/generate.action.ts
|
|
1084
1103
|
import * as console3 from "console";
|
|
1085
|
-
import { join as
|
|
1104
|
+
import { join as join4 } from "path";
|
|
1086
1105
|
|
|
1087
1106
|
// src/lib/schematics/abstract.collection.ts
|
|
1088
1107
|
var AbstractCollection = class {
|
|
@@ -1210,7 +1229,7 @@ var SchematicOption = class {
|
|
|
1210
1229
|
}
|
|
1211
1230
|
} else if (typeof this.value === "boolean") {
|
|
1212
1231
|
const str = normalizedName;
|
|
1213
|
-
return this.value ? [`--${str}`] : [
|
|
1232
|
+
return this.value ? [`--${str}=true`] : [`--${str}=false`];
|
|
1214
1233
|
} else if (Array.isArray(this.value)) {
|
|
1215
1234
|
return this.value.reduce(
|
|
1216
1235
|
(old, option) => [
|
|
@@ -1323,7 +1342,7 @@ var generateFiles = /* @__PURE__ */ __name(async (values, directory, watch3) =>
|
|
|
1323
1342
|
language: values.language,
|
|
1324
1343
|
initFunctions: values.initFunctions
|
|
1325
1344
|
},
|
|
1326
|
-
watch3 ?
|
|
1345
|
+
watch3 ? join4(getCwd(directory), values.directory, ".nanoforge", "client.save.json") : void 0
|
|
1327
1346
|
);
|
|
1328
1347
|
if (values.server) {
|
|
1329
1348
|
await executeSchematic(
|
|
@@ -1337,7 +1356,7 @@ var generateFiles = /* @__PURE__ */ __name(async (values, directory, watch3) =>
|
|
|
1337
1356
|
language: values.language,
|
|
1338
1357
|
initFunctions: values.initFunctions
|
|
1339
1358
|
},
|
|
1340
|
-
|
|
1359
|
+
join4(getCwd(directory), values.directory, ".nanoforge", "server.save.json")
|
|
1341
1360
|
);
|
|
1342
1361
|
}
|
|
1343
1362
|
}, "generateFiles");
|
|
@@ -1366,17 +1385,20 @@ var InstallAction = class extends AbstractAction {
|
|
|
1366
1385
|
var installPackages = /* @__PURE__ */ __name(async (names, directory) => {
|
|
1367
1386
|
try {
|
|
1368
1387
|
const packageManager = await PackageManagerFactory.find(directory);
|
|
1369
|
-
await packageManager.addProduction(directory, names);
|
|
1388
|
+
const res = await packageManager.addProduction(directory, names);
|
|
1389
|
+
if (!res) process3.exit(1);
|
|
1370
1390
|
} catch (error4) {
|
|
1371
1391
|
if (error4 && error4.message) {
|
|
1372
1392
|
console.error(ansis3.red(error4.message));
|
|
1373
1393
|
}
|
|
1394
|
+
process3.exit(1);
|
|
1374
1395
|
}
|
|
1375
1396
|
}, "installPackages");
|
|
1376
1397
|
|
|
1377
1398
|
// src/action/actions/new.action.ts
|
|
1378
1399
|
import * as ansis4 from "ansis";
|
|
1379
1400
|
import console4 from "console";
|
|
1401
|
+
import * as process4 from "process";
|
|
1380
1402
|
|
|
1381
1403
|
// src/lib/input/inputs/new/init-functions.input.ts
|
|
1382
1404
|
var getNewInitFunctionsWithDefault = /* @__PURE__ */ __name((inputs) => {
|
|
@@ -1479,10 +1501,10 @@ var NewAction = class extends AbstractAction {
|
|
|
1479
1501
|
if (!values.skipInstall) await runInstall(directory, values.packageManager);
|
|
1480
1502
|
console4.info();
|
|
1481
1503
|
console4.info(Messages.NEW_SUCCESS);
|
|
1482
|
-
|
|
1504
|
+
process4.exit(0);
|
|
1483
1505
|
} catch {
|
|
1484
1506
|
console4.error(Messages.NEW_FAILED);
|
|
1485
|
-
|
|
1507
|
+
process4.exit(1);
|
|
1486
1508
|
}
|
|
1487
1509
|
}
|
|
1488
1510
|
};
|
|
@@ -1556,13 +1578,15 @@ var runInstall = /* @__PURE__ */ __name(async (directory, pkgManagerName) => {
|
|
|
1556
1578
|
if (error4 && error4.message) {
|
|
1557
1579
|
console4.error(ansis4.red(error4.message));
|
|
1558
1580
|
}
|
|
1581
|
+
process4.exit(1);
|
|
1559
1582
|
}
|
|
1560
1583
|
}, "runInstall");
|
|
1561
1584
|
|
|
1562
1585
|
// src/action/actions/start.action.ts
|
|
1563
1586
|
import * as ansis5 from "ansis";
|
|
1564
1587
|
import * as console5 from "console";
|
|
1565
|
-
import
|
|
1588
|
+
import * as process5 from "process";
|
|
1589
|
+
import { join as join5 } from "path";
|
|
1566
1590
|
var StartAction = class extends AbstractAction {
|
|
1567
1591
|
static {
|
|
1568
1592
|
__name(this, "StartAction");
|
|
@@ -1576,30 +1600,41 @@ var StartAction = class extends AbstractAction {
|
|
|
1576
1600
|
const clientDir = config2.client.runtime.dir;
|
|
1577
1601
|
const serverDir = config2.server.runtime.dir;
|
|
1578
1602
|
const clientPort = getStringInputWithDefault(options, "clientPort", config2.client.port);
|
|
1603
|
+
const cert = getStringInput(options, "cert");
|
|
1604
|
+
const key = getStringInput(options, "key");
|
|
1579
1605
|
const watch3 = getWatchInput(options);
|
|
1580
1606
|
await Promise.all([
|
|
1581
1607
|
config2.server.enable ? this.startServer(directory, serverDir, watch3) : void 0,
|
|
1582
|
-
this.startClient(
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1608
|
+
this.startClient(
|
|
1609
|
+
clientPort,
|
|
1610
|
+
directory,
|
|
1611
|
+
clientDir,
|
|
1612
|
+
{
|
|
1613
|
+
watch: watch3,
|
|
1614
|
+
serverGameDir: config2.server.enable ? serverDir : void 0
|
|
1615
|
+
},
|
|
1616
|
+
cert,
|
|
1617
|
+
key
|
|
1618
|
+
)
|
|
1586
1619
|
]);
|
|
1587
|
-
|
|
1620
|
+
process5.exit(0);
|
|
1588
1621
|
} catch (e) {
|
|
1589
1622
|
console5.error(e);
|
|
1590
|
-
|
|
1623
|
+
process5.exit(1);
|
|
1591
1624
|
}
|
|
1592
1625
|
}
|
|
1593
|
-
async startClient(port, directory, gameDir, options) {
|
|
1626
|
+
async startClient(port, directory, gameDir, options, cert, key) {
|
|
1594
1627
|
const path = getModulePath("@nanoforge-dev/loader-client/package.json", true);
|
|
1595
1628
|
const params = {
|
|
1596
1629
|
PORT: port,
|
|
1597
|
-
GAME_DIR: getCwd(
|
|
1630
|
+
GAME_DIR: getCwd(join5(directory, gameDir)),
|
|
1631
|
+
CERT: cert ? join5(getCwd(directory), cert) : void 0,
|
|
1632
|
+
KEY: key ? join5(getCwd(directory), key) : void 0
|
|
1598
1633
|
};
|
|
1599
1634
|
if (options?.watch) {
|
|
1600
1635
|
params["WATCH"] = "true";
|
|
1601
1636
|
if (options?.serverGameDir) {
|
|
1602
|
-
params["WATCH_SERVER_GAME_DIR"] = getCwd(
|
|
1637
|
+
params["WATCH_SERVER_GAME_DIR"] = getCwd(join5(directory, options.serverGameDir));
|
|
1603
1638
|
}
|
|
1604
1639
|
}
|
|
1605
1640
|
return runPart("Client", path, params);
|
|
@@ -1607,7 +1642,7 @@ var StartAction = class extends AbstractAction {
|
|
|
1607
1642
|
startServer(directory, gameDir, watch3) {
|
|
1608
1643
|
const path = getModulePath("@nanoforge-dev/loader-server/package.json", true);
|
|
1609
1644
|
const params = {
|
|
1610
|
-
GAME_DIR: getCwd(
|
|
1645
|
+
GAME_DIR: getCwd(join5(directory, gameDir))
|
|
1611
1646
|
};
|
|
1612
1647
|
if (watch3) params["WATCH"] = "true";
|
|
1613
1648
|
return runPart("Server", path, params);
|
|
@@ -1735,7 +1770,7 @@ var StartCommand = class extends AbstractCommand {
|
|
|
1735
1770
|
program.command("start").description("start your game").option("-d, --directory [directory]", "specify the directory of your project").option("-c, --config [config]", "path to the config file", "nanoforge.config.json").option(
|
|
1736
1771
|
"-p, --client-port [clientPort]",
|
|
1737
1772
|
"specify the port of the loader (the website to load the game)"
|
|
1738
|
-
).option("--game-exposure-port [gameExposurePort]", "specify the port of the game exposure").option("--server-port [serverPort]", "specify the port of the server").option("--watch", "run app in watching mode", false).action(async (rawOptions) => {
|
|
1773
|
+
).option("--game-exposure-port [gameExposurePort]", "specify the port of the game exposure").option("--server-port [serverPort]", "specify the port 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) => {
|
|
1739
1774
|
const options = /* @__PURE__ */ new Map();
|
|
1740
1775
|
options.set("directory", { value: rawOptions.directory });
|
|
1741
1776
|
options.set("config", { value: rawOptions.config });
|
|
@@ -1745,6 +1780,8 @@ var StartCommand = class extends AbstractCommand {
|
|
|
1745
1780
|
});
|
|
1746
1781
|
options.set("serverPort", { value: rawOptions.serverPort });
|
|
1747
1782
|
options.set("watch", { value: rawOptions.watch });
|
|
1783
|
+
options.set("cert", { value: rawOptions.cert });
|
|
1784
|
+
options.set("key", { value: rawOptions.key });
|
|
1748
1785
|
const args = /* @__PURE__ */ new Map();
|
|
1749
1786
|
await this.action.handle(args, options);
|
|
1750
1787
|
});
|