@ovipakla/gm-cli 2.0.1 → 2.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/app.js +129 -28
- package/package.json +1 -1
package/app.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
#! /usr/bin/env node
|
|
1
|
+
#! /usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import { watch, sync } from './GMFileWatcher.js';
|
|
4
|
-
import path from 'path';
|
|
4
|
+
import path from 'node:path';
|
|
5
5
|
import { Command } from 'commander';
|
|
6
6
|
import { spawn, execSync } from 'child_process';
|
|
7
7
|
import fs from 'fs';
|
|
8
8
|
import readline from 'readline';
|
|
9
|
+
import { fileURLToPath } from "node:url";
|
|
9
10
|
|
|
10
11
|
function findFileUpwardsSync(filename, maxLevels = 99) {
|
|
11
12
|
let currentDir = process.cwd();
|
|
@@ -38,6 +39,10 @@ function getPackageGM() {
|
|
|
38
39
|
}
|
|
39
40
|
}
|
|
40
41
|
|
|
42
|
+
function getYYPPathFromPackageGM(packageGM) {
|
|
43
|
+
return path.join(path.dirname(packageGM.file), packageGM.data.main).replaceAll("\\", "/");
|
|
44
|
+
}
|
|
45
|
+
|
|
41
46
|
function backupPackageGM(packageGM) {
|
|
42
47
|
console.log(`📝 Backup package-gm.json: ${packageGM.file}.old`);
|
|
43
48
|
fs.copyFileSync(packageGM.file, `${packageGM.file}.old`);
|
|
@@ -86,8 +91,22 @@ function getPSMonitorRAMCommand(processName, interval, name) {
|
|
|
86
91
|
return psCommand
|
|
87
92
|
}
|
|
88
93
|
|
|
94
|
+
function runShellScript(scriptData) {
|
|
95
|
+
const bashProcess = spawn("bash", ["-s"], { stdio: ["pipe", "inherit", "inherit"] });
|
|
96
|
+
bashProcess.stdin.write(`#!/bin/bash\nset -Eeuo pipefail\n${scriptData}`);
|
|
97
|
+
bashProcess.stdin.end();
|
|
98
|
+
bashProcess.on("close", (code) => {
|
|
99
|
+
console.log(`Exited with code ${code}`);
|
|
100
|
+
process.exit(code);
|
|
101
|
+
});
|
|
102
|
+
return bashProcess
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
const packageJson = JSON.parse(fs.readFileSync(path.join(path.dirname(fileURLToPath(import.meta.url)), "package.json"), "utf-8"));
|
|
107
|
+
|
|
89
108
|
const program = new Command()
|
|
90
|
-
.version(
|
|
109
|
+
.version(packageJson.version, '-v, --version, ', 'output the current version');
|
|
91
110
|
|
|
92
111
|
const config = program
|
|
93
112
|
.command('config')
|
|
@@ -101,6 +120,11 @@ const configUnset = config
|
|
|
101
120
|
.command('unset')
|
|
102
121
|
.description('Unset config values');
|
|
103
122
|
|
|
123
|
+
const resource = program
|
|
124
|
+
.command("resource")
|
|
125
|
+
.description("Manage resources");
|
|
126
|
+
|
|
127
|
+
|
|
104
128
|
program
|
|
105
129
|
.command('init')
|
|
106
130
|
.description('CLI creator for package-gm.json')
|
|
@@ -252,13 +276,7 @@ program
|
|
|
252
276
|
|
|
253
277
|
${scriptData}
|
|
254
278
|
`;
|
|
255
|
-
|
|
256
|
-
bashProcess.stdin.write(shellScript);
|
|
257
|
-
bashProcess.stdin.end();
|
|
258
|
-
bashProcess.on("exit", (code) => {
|
|
259
|
-
console.log(`Exited with code ${code}`);
|
|
260
|
-
process.exit(code);
|
|
261
|
-
});
|
|
279
|
+
runShellScript(shellScript)
|
|
262
280
|
});
|
|
263
281
|
|
|
264
282
|
program
|
|
@@ -313,12 +331,23 @@ program
|
|
|
313
331
|
const envPath = path.dirname(envFile).replaceAll("\\", "/");
|
|
314
332
|
const envMap = parseEnvFile(envFile);
|
|
315
333
|
const projectPath = path.dirname(path.join(path.dirname(packageGM.file), packageGM.data.main.replaceAll("\\", "/")));
|
|
316
|
-
const yypPath =
|
|
334
|
+
const yypPath = getYYPPathFromPackageGM(packageGM)
|
|
317
335
|
const yypOldPath = `${yypPath}.old`
|
|
318
336
|
const yyp = fs.readFileSync(yypPath, "utf8");
|
|
319
337
|
console.log(`📝 Backup yyp:`, yypOldPath);
|
|
320
338
|
fs.copyFileSync(yypPath, yypOldPath);
|
|
321
339
|
|
|
340
|
+
|
|
341
|
+
const vsDevCmdPath = envMap.get("GM_CLI_VS_DEV_CMD_PATH")
|
|
342
|
+
if (vsDevCmdPath !== undefined) {
|
|
343
|
+
const localSettings = path.join(path.normalize(path.dirname(yypPath)), "local_settings.json").replaceAll("\\", "/")
|
|
344
|
+
const localSettingsJson = {
|
|
345
|
+
"machine.Platform Settings.Windows.visual_studio_path": vsDevCmdPath
|
|
346
|
+
}
|
|
347
|
+
fs.writeFileSync(localSettings, JSON.stringify(localSettingsJson, null, 2), "utf8");
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
|
|
322
351
|
const datafilesPath = path.join(projectPath, "datafiles").replaceAll("\\", "/")
|
|
323
352
|
const datafiles = getFilesRecursively(datafilesPath, datafilesPath)
|
|
324
353
|
const replaced = yyp.replace(/"IncludedFiles"\s*:\s*\[(.*?)\]/s, `"IncludedFiles":[
|
|
@@ -336,6 +365,7 @@ program
|
|
|
336
365
|
.option('-n, --name <name>', 'The actual file name of the ZIP file that is created')
|
|
337
366
|
.option('-l, --launch', 'launch the executable after building')
|
|
338
367
|
.option('-c, --clean', 'make clean build')
|
|
368
|
+
.option('-p, --projectool', 'Path to ProjectTool.exe')
|
|
339
369
|
.action(function() {
|
|
340
370
|
const packageGM = getPackageGM()
|
|
341
371
|
const targetMap = new Map([ [ 'windows', 'win' ] ])
|
|
@@ -343,6 +373,7 @@ program
|
|
|
343
373
|
const config = {
|
|
344
374
|
runtime: '$GM_CLI_DEFAULT_RUNTIME',
|
|
345
375
|
target: '$GM_CLI_DEFAULT_TARGET',
|
|
376
|
+
projectool: '$GM_CLI_PROJECT_TOOL_PATH',
|
|
346
377
|
clean: 'false',
|
|
347
378
|
launch: 'PackageZip',
|
|
348
379
|
name: packageGM.data.name,
|
|
@@ -360,6 +391,10 @@ program
|
|
|
360
391
|
config.targetExt = targetMap.get(config.target);
|
|
361
392
|
}
|
|
362
393
|
|
|
394
|
+
if (options.projectool !== undefined) {
|
|
395
|
+
config.projectool = options.projectool;
|
|
396
|
+
}
|
|
397
|
+
|
|
363
398
|
if (options.clean !== undefined) {
|
|
364
399
|
config.clean = 'true';
|
|
365
400
|
}
|
|
@@ -456,23 +491,31 @@ program
|
|
|
456
491
|
exit 1
|
|
457
492
|
fi
|
|
458
493
|
|
|
494
|
+
project_tool=${config.projectool}
|
|
495
|
+
echo $project_tool
|
|
496
|
+
if [ -z "$project_tool" ]; then
|
|
497
|
+
log_error "--projectool must be defined! exit 1"
|
|
498
|
+
exit 1
|
|
499
|
+
fi
|
|
500
|
+
|
|
459
501
|
clean=${config.clean}
|
|
460
502
|
if [ "$clean" = "true" ]; then
|
|
461
503
|
log_info "Clean '$project_path/tmp/igor'"
|
|
462
504
|
rm -rf $project_path/tmp/igor
|
|
463
505
|
|
|
464
|
-
log_info "Execute shell command:\n\\\e[33m$igor_path \\ \n --runtimePath="$runtime_path" \\ \n --runtime=$runtime \\ \n --project="$\{project_path\}/$\{project_yyp\}" \\ \n -- $target Clean\n\\\e[0m"
|
|
506
|
+
log_info "Execute shell command:\n\\\e[33m$igor_path \\ \n --runtimePath="$runtime_path" \\ \n --runtime=$runtime \\ \n --project="$\{project_path\}/$\{project_yyp\}" \\ \n --projectool="$\{project_tool\}" \\ \n -- $target Clean\n\\\e[0m"
|
|
465
507
|
$igor_path \
|
|
466
508
|
--runtimePath="$runtime_path" \
|
|
467
509
|
--runtime=$runtime \
|
|
468
510
|
--project="$\{project_path\}/$\{project_yyp\}" \
|
|
511
|
+
--projectool="$\{project_tool\}" \
|
|
469
512
|
-- $target Clean | GREP_COLORS='mt=01;31' grep --color=always -E 'Error : |$'
|
|
470
513
|
fi
|
|
471
514
|
|
|
472
515
|
log_info "Clean '$\{project_path\}/tmp/igor/out'"
|
|
473
516
|
rm -rf $\{project_path\}/tmp/igor/out
|
|
474
517
|
|
|
475
|
-
log_info "Execute shell command:\n\\\e[33m$igor_path \\ \n --project="$\{project_path\}/$\{project_yyp\}" \\ \n --user="$user_path" \\ \n --runtimePath="$runtime_path" \\ \n --runtime=$runtime \\ \n --cache="$\{project_path\}/tmp/igor/cache" \\ \n --temp="$\{project_path\}/tmp/igor/temp" \\ \n --of="$\{project_path\}/tmp/igor/out/$\{project_name\}.win" \\ \n --tf="$\{zip_name\}.zip" \\ \n -- $target ${config.launch}\\\e[0m"
|
|
518
|
+
log_info "Execute shell command:\n\\\e[33m$igor_path \\ \n --project="$\{project_path\}/$\{project_yyp\}" \\ \n --user="$user_path" \\ \n --runtimePath="$runtime_path" \\ \n --runtime=$runtime \\ \n --cache="$\{project_path\}/tmp/igor/cache" \\ \n --temp="$\{project_path\}/tmp/igor/temp" \\ \n --of="$\{project_path\}/tmp/igor/out/$\{project_name\}.win" \\ \n --tf="$\{zip_name\}.zip" \\ \n --projectool="$\{project_tool\}" \\ \n --uf="$user_path" \\ \n -- $target ${config.launch}\\\e[0m"
|
|
476
519
|
$igor_path \
|
|
477
520
|
--project="$\{project_path\}/$\{project_yyp\}" \
|
|
478
521
|
--user="$user_path" \
|
|
@@ -482,18 +525,14 @@ program
|
|
|
482
525
|
--temp="$\{project_path\}/tmp/igor/temp" \
|
|
483
526
|
--of="$\{project_path\}/tmp/igor/out/$\{project_name\}.win" \
|
|
484
527
|
--tf="$\{zip_name\}.zip" \
|
|
528
|
+
--projectool="$\{project_tool\}" \
|
|
529
|
+
--uf="$user_path" \
|
|
485
530
|
-- $target ${config.launch} | GREP_COLORS='mt=01;31' grep --color=always -E 'Error : |$'
|
|
486
531
|
|
|
487
532
|
exit 0
|
|
488
533
|
`;
|
|
489
534
|
|
|
490
|
-
|
|
491
|
-
bashProcess.stdin.write(shellScript);
|
|
492
|
-
bashProcess.stdin.end();
|
|
493
|
-
bashProcess.on("exit", (code) => {
|
|
494
|
-
console.log(`Exited with code ${code}`);
|
|
495
|
-
process.exit(code);
|
|
496
|
-
});
|
|
535
|
+
runShellScript(shellScript)
|
|
497
536
|
});
|
|
498
537
|
|
|
499
538
|
program
|
|
@@ -515,13 +554,17 @@ program
|
|
|
515
554
|
const projectPath = process.cwd();
|
|
516
555
|
const propertyDefaultRuntime = await askQuestion('Default runtime [ VM, YYC ]: ');
|
|
517
556
|
const propertyDefaultTarget = await askQuestion('Default target [ windows ]: ');
|
|
557
|
+
const propertyProjectoolPath = await askQuestion('Path to ProjectTool.exe: ');
|
|
518
558
|
const propertyRuntimePath = await askQuestion('Path to gamemaker runtime: ');
|
|
519
559
|
const propertyUserPath = await askQuestion('Path to gamemaker user: ');
|
|
560
|
+
const propertyVsDevCmdPath = await askQuestion('Path to VsDevCmd.bat: ');
|
|
520
561
|
const data = {
|
|
521
562
|
GM_CLI_DEFAULT_RUNTIME: runtimes.includes(propertyDefaultRuntime) ? propertyDefaultRuntime : runtimes[0],
|
|
522
563
|
GM_CLI_DEFAULT_TARGET: runtimes.includes(propertyDefaultTarget) ? propertyDefaultTarget : targets[0],
|
|
564
|
+
GM_CLI_PROJECT_TOOL_PATH: path.normalize(propertyProjectoolPath),
|
|
523
565
|
GM_CLI_RUNTIME_PATH: path.normalize(propertyRuntimePath),
|
|
524
|
-
GM_CLI_USER_PATH: path.normalize(propertyUserPath)
|
|
566
|
+
GM_CLI_USER_PATH: path.normalize(propertyUserPath),
|
|
567
|
+
GM_CLI_VS_DEV_CMD_PATH: path.normalize(propertyVsDevCmdPath),
|
|
525
568
|
};
|
|
526
569
|
|
|
527
570
|
const filePath = path.join(projectPath, '.gm-cli.env');
|
|
@@ -643,13 +686,7 @@ program
|
|
|
643
686
|
eval "\$COMMAND" | cat
|
|
644
687
|
`
|
|
645
688
|
|
|
646
|
-
|
|
647
|
-
bashProcess.stdin.write(shellScript);
|
|
648
|
-
bashProcess.stdin.end();
|
|
649
|
-
bashProcess.on("exit", (code) => {
|
|
650
|
-
console.log(`Exited with code ${code}`);
|
|
651
|
-
process.exit(code);
|
|
652
|
-
});
|
|
689
|
+
runShellScript(shellScript)
|
|
653
690
|
})
|
|
654
691
|
|
|
655
692
|
configSet
|
|
@@ -756,9 +793,73 @@ configUnset
|
|
|
756
793
|
}
|
|
757
794
|
|
|
758
795
|
const packageGM = getPackageGM()
|
|
796
|
+
|
|
759
797
|
backupPackageGM(packageGM)
|
|
760
798
|
resolve()
|
|
761
799
|
savePackageGM(packageGM)
|
|
762
800
|
});
|
|
763
801
|
|
|
802
|
+
resource
|
|
803
|
+
.command("create")
|
|
804
|
+
.description("Create a resource")
|
|
805
|
+
.requiredOption("-t, --type <type>", "Resource type")
|
|
806
|
+
.requiredOption("-n, --name <name>", "Resource name")
|
|
807
|
+
.option("-f, --folder <folder>", "Resource folder")
|
|
808
|
+
.action((options) => {
|
|
809
|
+
const packageGM = getPackageGM()
|
|
810
|
+
const yypPath = getYYPPathFromPackageGM(packageGM)
|
|
811
|
+
const folderOption = options.folder !== undefined ? `folder=${options.folder}` : ``
|
|
812
|
+
const shellScript = `yy-gm-cli resourcetool eval "resource create type=${options.type} name=${options.name} ${folderOption}" ${yypPath}`
|
|
813
|
+
runShellScript(shellScript)
|
|
814
|
+
});
|
|
815
|
+
|
|
816
|
+
resource
|
|
817
|
+
.command("update")
|
|
818
|
+
.description("Update a resource property")
|
|
819
|
+
.requiredOption("-e, --expr <expr>", "Resource expression")
|
|
820
|
+
.requiredOption("-v, --value <value>", "New value")
|
|
821
|
+
.action((options) => {
|
|
822
|
+
const packageGM = getPackageGM()
|
|
823
|
+
const yypPath = getYYPPathFromPackageGM(packageGM)
|
|
824
|
+
const shellScript = `yy-gm-cli resourcetool eval "resource set expr=${options.expr} value=${options.value}" ${yypPath}`
|
|
825
|
+
runShellScript(shellScript)
|
|
826
|
+
});
|
|
827
|
+
|
|
828
|
+
resource
|
|
829
|
+
.command("get")
|
|
830
|
+
.description(" a resource")
|
|
831
|
+
.requiredOption("-e, --expr <expr>", "Resource expression")
|
|
832
|
+
.action((options) => {
|
|
833
|
+
const packageGM = getPackageGM()
|
|
834
|
+
const yypPath = getYYPPathFromPackageGM(packageGM)
|
|
835
|
+
const shellScript = `yy-gm-cli resourcetool eval "resource info expr=${options.expr}" ${yypPath}`
|
|
836
|
+
runShellScript(shellScript)
|
|
837
|
+
});
|
|
838
|
+
|
|
839
|
+
resource
|
|
840
|
+
.command("delete")
|
|
841
|
+
.description("Delete a resource")
|
|
842
|
+
.requiredOption("-n, --name <name>", "Resource name")
|
|
843
|
+
.option("--type <type>", "Resource type")
|
|
844
|
+
.action((options) => {
|
|
845
|
+
const packageGM = getPackageGM()
|
|
846
|
+
const yypPath = getYYPPathFromPackageGM(packageGM)
|
|
847
|
+
const typeOptions = options.type !== undefined ? `type=${options.type}` : ``
|
|
848
|
+
const shellScript = `yy-gm-cli resourcetool eval "resource delete name=${options.name} ${typeOptions}" ${yypPath}`
|
|
849
|
+
runShellScript(shellScript)
|
|
850
|
+
});
|
|
851
|
+
|
|
852
|
+
resource
|
|
853
|
+
.command("list")
|
|
854
|
+
.description("List resources")
|
|
855
|
+
.option("--type <type>", "Resource type")
|
|
856
|
+
.action((options) => {
|
|
857
|
+
const packageGM = getPackageGM()
|
|
858
|
+
const yypPath = getYYPPathFromPackageGM(packageGM)
|
|
859
|
+
const typeOptions = options.type !== undefined ? `type=${options.type}` : ``
|
|
860
|
+
const shellScript = `yy-gm-cli resourcetool eval "resource list ${typeOptions}" ${yypPath}`
|
|
861
|
+
runShellScript(shellScript)
|
|
862
|
+
});
|
|
863
|
+
|
|
864
|
+
|
|
764
865
|
program.parse(process.argv);
|