@ovipakla/gm-cli 2.0.0 → 2.0.3
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 +116 -28
- package/package.json +1 -1
package/app.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
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,7 +331,7 @@ 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);
|
|
@@ -336,6 +354,7 @@ program
|
|
|
336
354
|
.option('-n, --name <name>', 'The actual file name of the ZIP file that is created')
|
|
337
355
|
.option('-l, --launch', 'launch the executable after building')
|
|
338
356
|
.option('-c, --clean', 'make clean build')
|
|
357
|
+
.option('-p, --projectool', 'Path to ProjectTool.exe')
|
|
339
358
|
.action(function() {
|
|
340
359
|
const packageGM = getPackageGM()
|
|
341
360
|
const targetMap = new Map([ [ 'windows', 'win' ] ])
|
|
@@ -343,9 +362,11 @@ program
|
|
|
343
362
|
const config = {
|
|
344
363
|
runtime: '$GM_CLI_DEFAULT_RUNTIME',
|
|
345
364
|
target: '$GM_CLI_DEFAULT_TARGET',
|
|
365
|
+
projectool: '$GM_CLI_PROJECT_TOOL_PATH',
|
|
346
366
|
clean: 'false',
|
|
347
367
|
launch: 'PackageZip',
|
|
348
368
|
name: packageGM.data.name,
|
|
369
|
+
zip: packageGM.data.name,
|
|
349
370
|
yyp: path.basename(packageGM.data.main).replaceAll("\\", "/"),
|
|
350
371
|
path: path.join(path.dirname(packageGM.file), path.dirname(packageGM.data.main)).replaceAll("\\", "/"),
|
|
351
372
|
};
|
|
@@ -359,6 +380,10 @@ program
|
|
|
359
380
|
config.targetExt = targetMap.get(config.target);
|
|
360
381
|
}
|
|
361
382
|
|
|
383
|
+
if (options.projectool !== undefined) {
|
|
384
|
+
config.projectool = options.projectool;
|
|
385
|
+
}
|
|
386
|
+
|
|
362
387
|
if (options.clean !== undefined) {
|
|
363
388
|
config.clean = 'true';
|
|
364
389
|
}
|
|
@@ -368,7 +393,7 @@ program
|
|
|
368
393
|
}
|
|
369
394
|
|
|
370
395
|
if (options.name !== undefined && typeof options.name === 'string' && options.name.trim() !== '') {
|
|
371
|
-
config.
|
|
396
|
+
config.zip = options.name;
|
|
372
397
|
}
|
|
373
398
|
|
|
374
399
|
const shellScript = `#!/bin/bash
|
|
@@ -448,30 +473,38 @@ program
|
|
|
448
473
|
exit 1
|
|
449
474
|
fi
|
|
450
475
|
|
|
451
|
-
zip_name=${config.
|
|
476
|
+
zip_name=${config.zip}
|
|
452
477
|
echo $zip_name
|
|
453
478
|
if [ -z "$zip_name" ]; then
|
|
454
479
|
log_error "--name must be defined! exit 1"
|
|
455
480
|
exit 1
|
|
456
481
|
fi
|
|
457
482
|
|
|
483
|
+
project_tool=${config.projectool}
|
|
484
|
+
echo $project_tool
|
|
485
|
+
if [ -z "$project_tool" ]; then
|
|
486
|
+
log_error "--projectool must be defined! exit 1"
|
|
487
|
+
exit 1
|
|
488
|
+
fi
|
|
489
|
+
|
|
458
490
|
clean=${config.clean}
|
|
459
491
|
if [ "$clean" = "true" ]; then
|
|
460
492
|
log_info "Clean '$project_path/tmp/igor'"
|
|
461
493
|
rm -rf $project_path/tmp/igor
|
|
462
494
|
|
|
463
|
-
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"
|
|
495
|
+
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"
|
|
464
496
|
$igor_path \
|
|
465
497
|
--runtimePath="$runtime_path" \
|
|
466
498
|
--runtime=$runtime \
|
|
467
499
|
--project="$\{project_path\}/$\{project_yyp\}" \
|
|
500
|
+
--projectool="$\{project_tool\}" \
|
|
468
501
|
-- $target Clean | GREP_COLORS='mt=01;31' grep --color=always -E 'Error : |$'
|
|
469
502
|
fi
|
|
470
503
|
|
|
471
504
|
log_info "Clean '$\{project_path\}/tmp/igor/out'"
|
|
472
505
|
rm -rf $\{project_path\}/tmp/igor/out
|
|
473
506
|
|
|
474
|
-
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"
|
|
507
|
+
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 -- $target ${config.launch}\\\e[0m"
|
|
475
508
|
$igor_path \
|
|
476
509
|
--project="$\{project_path\}/$\{project_yyp\}" \
|
|
477
510
|
--user="$user_path" \
|
|
@@ -481,18 +514,13 @@ program
|
|
|
481
514
|
--temp="$\{project_path\}/tmp/igor/temp" \
|
|
482
515
|
--of="$\{project_path\}/tmp/igor/out/$\{project_name\}.win" \
|
|
483
516
|
--tf="$\{zip_name\}.zip" \
|
|
517
|
+
--projectool="$\{project_tool\}" \
|
|
484
518
|
-- $target ${config.launch} | GREP_COLORS='mt=01;31' grep --color=always -E 'Error : |$'
|
|
485
519
|
|
|
486
520
|
exit 0
|
|
487
521
|
`;
|
|
488
522
|
|
|
489
|
-
|
|
490
|
-
bashProcess.stdin.write(shellScript);
|
|
491
|
-
bashProcess.stdin.end();
|
|
492
|
-
bashProcess.on("exit", (code) => {
|
|
493
|
-
console.log(`Exited with code ${code}`);
|
|
494
|
-
process.exit(code);
|
|
495
|
-
});
|
|
523
|
+
runShellScript(shellScript)
|
|
496
524
|
});
|
|
497
525
|
|
|
498
526
|
program
|
|
@@ -514,11 +542,13 @@ program
|
|
|
514
542
|
const projectPath = process.cwd();
|
|
515
543
|
const propertyDefaultRuntime = await askQuestion('Default runtime [ VM, YYC ]: ');
|
|
516
544
|
const propertyDefaultTarget = await askQuestion('Default target [ windows ]: ');
|
|
545
|
+
const propertyProjectoolPath = await askQuestion('Path to ProjectTool.exe: ');
|
|
517
546
|
const propertyRuntimePath = await askQuestion('Path to gamemaker runtime: ');
|
|
518
547
|
const propertyUserPath = await askQuestion('Path to gamemaker user: ');
|
|
519
548
|
const data = {
|
|
520
549
|
GM_CLI_DEFAULT_RUNTIME: runtimes.includes(propertyDefaultRuntime) ? propertyDefaultRuntime : runtimes[0],
|
|
521
550
|
GM_CLI_DEFAULT_TARGET: runtimes.includes(propertyDefaultTarget) ? propertyDefaultTarget : targets[0],
|
|
551
|
+
GM_CLI_PROJECT_TOOL_PATH: path.normalize(propertyProjectoolPath),
|
|
522
552
|
GM_CLI_RUNTIME_PATH: path.normalize(propertyRuntimePath),
|
|
523
553
|
GM_CLI_USER_PATH: path.normalize(propertyUserPath)
|
|
524
554
|
};
|
|
@@ -642,13 +672,7 @@ program
|
|
|
642
672
|
eval "\$COMMAND" | cat
|
|
643
673
|
`
|
|
644
674
|
|
|
645
|
-
|
|
646
|
-
bashProcess.stdin.write(shellScript);
|
|
647
|
-
bashProcess.stdin.end();
|
|
648
|
-
bashProcess.on("exit", (code) => {
|
|
649
|
-
console.log(`Exited with code ${code}`);
|
|
650
|
-
process.exit(code);
|
|
651
|
-
});
|
|
675
|
+
runShellScript(shellScript)
|
|
652
676
|
})
|
|
653
677
|
|
|
654
678
|
configSet
|
|
@@ -755,9 +779,73 @@ configUnset
|
|
|
755
779
|
}
|
|
756
780
|
|
|
757
781
|
const packageGM = getPackageGM()
|
|
782
|
+
|
|
758
783
|
backupPackageGM(packageGM)
|
|
759
784
|
resolve()
|
|
760
785
|
savePackageGM(packageGM)
|
|
761
786
|
});
|
|
762
787
|
|
|
788
|
+
resource
|
|
789
|
+
.command("create")
|
|
790
|
+
.description("Create a resource")
|
|
791
|
+
.requiredOption("-t, --type <type>", "Resource type")
|
|
792
|
+
.requiredOption("-n, --name <name>", "Resource name")
|
|
793
|
+
.option("-f, --folder <folder>", "Resource folder")
|
|
794
|
+
.action((options) => {
|
|
795
|
+
const packageGM = getPackageGM()
|
|
796
|
+
const yypPath = getYYPPathFromPackageGM(packageGM)
|
|
797
|
+
const folderOption = options.folder !== undefined ? `folder=${options.folder}` : ``
|
|
798
|
+
const shellScript = `yy-gm-cli resourcetool eval "resource create type=${options.type} name=${options.name} ${folderOption}" ${yypPath}`
|
|
799
|
+
runShellScript(shellScript)
|
|
800
|
+
});
|
|
801
|
+
|
|
802
|
+
resource
|
|
803
|
+
.command("update")
|
|
804
|
+
.description("Update a resource property")
|
|
805
|
+
.requiredOption("-e, --expr <expr>", "Resource expression")
|
|
806
|
+
.requiredOption("-v, --value <value>", "New value")
|
|
807
|
+
.action((options) => {
|
|
808
|
+
const packageGM = getPackageGM()
|
|
809
|
+
const yypPath = getYYPPathFromPackageGM(packageGM)
|
|
810
|
+
const shellScript = `yy-gm-cli resourcetool eval "resource set expr=${options.expr} value=${options.value}" ${yypPath}`
|
|
811
|
+
runShellScript(shellScript)
|
|
812
|
+
});
|
|
813
|
+
|
|
814
|
+
resource
|
|
815
|
+
.command("get")
|
|
816
|
+
.description(" a resource")
|
|
817
|
+
.requiredOption("-e, --expr <expr>", "Resource expression")
|
|
818
|
+
.action((options) => {
|
|
819
|
+
const packageGM = getPackageGM()
|
|
820
|
+
const yypPath = getYYPPathFromPackageGM(packageGM)
|
|
821
|
+
const shellScript = `yy-gm-cli resourcetool eval "resource info expr=${options.expr}" ${yypPath}`
|
|
822
|
+
runShellScript(shellScript)
|
|
823
|
+
});
|
|
824
|
+
|
|
825
|
+
resource
|
|
826
|
+
.command("delete")
|
|
827
|
+
.description("Delete a resource")
|
|
828
|
+
.requiredOption("-n, --name <name>", "Resource name")
|
|
829
|
+
.option("--type <type>", "Resource type")
|
|
830
|
+
.action((name, options) => {
|
|
831
|
+
const packageGM = getPackageGM()
|
|
832
|
+
const yypPath = getYYPPathFromPackageGM(packageGM)
|
|
833
|
+
const typeOptions = options.type !== undefined ? `type=${options.type}` : ``
|
|
834
|
+
const shellScript = `yy-gm-cli resourcetool eval "resource delete name=${options.name} ${typeOptions}" ${yypPath}`
|
|
835
|
+
runShellScript(shellScript)
|
|
836
|
+
});
|
|
837
|
+
|
|
838
|
+
resource
|
|
839
|
+
.command("list")
|
|
840
|
+
.description("List resources")
|
|
841
|
+
.option("--type <type>", "Resource type")
|
|
842
|
+
.action((name, options) => {
|
|
843
|
+
const packageGM = getPackageGM()
|
|
844
|
+
const yypPath = getYYPPathFromPackageGM(packageGM)
|
|
845
|
+
const typeOptions = options.type !== undefined ? `type=${options.type}` : ``
|
|
846
|
+
const shellScript = `yy-gm-cli resourcetool eval "resource list ${typeOptions}" ${yypPath}`
|
|
847
|
+
runShellScript(shellScript)
|
|
848
|
+
});
|
|
849
|
+
|
|
850
|
+
|
|
763
851
|
program.parse(process.argv);
|