@ovipakla/gm-cli 2.0.1 → 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.
Files changed (2) hide show
  1. package/app.js +113 -26
  2. 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('2.0.1', '-v, --version, ', 'output the current 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
- const bashProcess = spawn("bash", ["-s"], { stdio: ["pipe", "inherit", "inherit"] });
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 = path.join(path.dirname(packageGM.file), packageGM.data.main.replaceAll("\\", "/"));
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,6 +362,7 @@ 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,
@@ -360,6 +380,10 @@ program
360
380
  config.targetExt = targetMap.get(config.target);
361
381
  }
362
382
 
383
+ if (options.projectool !== undefined) {
384
+ config.projectool = options.projectool;
385
+ }
386
+
363
387
  if (options.clean !== undefined) {
364
388
  config.clean = 'true';
365
389
  }
@@ -456,23 +480,31 @@ program
456
480
  exit 1
457
481
  fi
458
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
+
459
490
  clean=${config.clean}
460
491
  if [ "$clean" = "true" ]; then
461
492
  log_info "Clean '$project_path/tmp/igor'"
462
493
  rm -rf $project_path/tmp/igor
463
494
 
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"
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"
465
496
  $igor_path \
466
497
  --runtimePath="$runtime_path" \
467
498
  --runtime=$runtime \
468
499
  --project="$\{project_path\}/$\{project_yyp\}" \
500
+ --projectool="$\{project_tool\}" \
469
501
  -- $target Clean | GREP_COLORS='mt=01;31' grep --color=always -E 'Error : |$'
470
502
  fi
471
503
 
472
504
  log_info "Clean '$\{project_path\}/tmp/igor/out'"
473
505
  rm -rf $\{project_path\}/tmp/igor/out
474
506
 
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"
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"
476
508
  $igor_path \
477
509
  --project="$\{project_path\}/$\{project_yyp\}" \
478
510
  --user="$user_path" \
@@ -482,18 +514,13 @@ program
482
514
  --temp="$\{project_path\}/tmp/igor/temp" \
483
515
  --of="$\{project_path\}/tmp/igor/out/$\{project_name\}.win" \
484
516
  --tf="$\{zip_name\}.zip" \
517
+ --projectool="$\{project_tool\}" \
485
518
  -- $target ${config.launch} | GREP_COLORS='mt=01;31' grep --color=always -E 'Error : |$'
486
519
 
487
520
  exit 0
488
521
  `;
489
522
 
490
- const bashProcess = spawn("bash", ["-s"], { stdio: ["pipe", "inherit", "inherit"] });
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
- });
523
+ runShellScript(shellScript)
497
524
  });
498
525
 
499
526
  program
@@ -515,11 +542,13 @@ program
515
542
  const projectPath = process.cwd();
516
543
  const propertyDefaultRuntime = await askQuestion('Default runtime [ VM, YYC ]: ');
517
544
  const propertyDefaultTarget = await askQuestion('Default target [ windows ]: ');
545
+ const propertyProjectoolPath = await askQuestion('Path to ProjectTool.exe: ');
518
546
  const propertyRuntimePath = await askQuestion('Path to gamemaker runtime: ');
519
547
  const propertyUserPath = await askQuestion('Path to gamemaker user: ');
520
548
  const data = {
521
549
  GM_CLI_DEFAULT_RUNTIME: runtimes.includes(propertyDefaultRuntime) ? propertyDefaultRuntime : runtimes[0],
522
550
  GM_CLI_DEFAULT_TARGET: runtimes.includes(propertyDefaultTarget) ? propertyDefaultTarget : targets[0],
551
+ GM_CLI_PROJECT_TOOL_PATH: path.normalize(propertyProjectoolPath),
523
552
  GM_CLI_RUNTIME_PATH: path.normalize(propertyRuntimePath),
524
553
  GM_CLI_USER_PATH: path.normalize(propertyUserPath)
525
554
  };
@@ -643,13 +672,7 @@ program
643
672
  eval "\$COMMAND" | cat
644
673
  `
645
674
 
646
- const bashProcess = spawn("bash", ["-s"], { stdio: ["pipe", "inherit", "inherit"] });
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
- });
675
+ runShellScript(shellScript)
653
676
  })
654
677
 
655
678
  configSet
@@ -756,9 +779,73 @@ configUnset
756
779
  }
757
780
 
758
781
  const packageGM = getPackageGM()
782
+
759
783
  backupPackageGM(packageGM)
760
784
  resolve()
761
785
  savePackageGM(packageGM)
762
786
  });
763
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
+
764
851
  program.parse(process.argv);
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "2.0.1",
6
+ "version": "2.0.3",
7
7
  "description": "Gamemaker CLI toolkit. Watch &amp; sync gml sources with yyp project.",
8
8
  "main": "app.js",
9
9
  "scripts": {},