@ovipakla/gm-cli 1.0.1 → 1.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 (3) hide show
  1. package/GMFileWatcher.js +19 -8
  2. package/app.js +12 -5
  3. package/package.json +1 -1
package/GMFileWatcher.js CHANGED
@@ -28,7 +28,7 @@ class GMModule {
28
28
  watcher: chokidar.watch(entry.dir, hook)
29
29
  }));
30
30
 
31
- console.log(`♻️ Watching [${dir}] for changes...`);
31
+ console.log(`🔍️ Watching [${dir}] for changes...`);
32
32
  }
33
33
 
34
34
  createWatcher(subdir, hook) {
@@ -69,6 +69,15 @@ function defaultWatcherHook() {
69
69
  };
70
70
  }
71
71
 
72
+ function syncWatcherHook() {
73
+ return {
74
+ ignored: /[\/\\]\./,
75
+ persistent: false,
76
+ ignoreInitial: true,
77
+ depth: 99,
78
+ };
79
+ }
80
+
72
81
  /* ---------------------------------------------------------
73
82
  * GMFileWatcher
74
83
  * --------------------------------------------------------- */
@@ -88,16 +97,16 @@ class GMFileWatcher {
88
97
 
89
98
  initializeWatchedModules(dependencies) {
90
99
  return dependencies.map(([name, version]) => {
91
- const gmModule = this.parseModule(name, version);
100
+ const gmModule = this.parseModule(name, version, true);
92
101
  this.syncModuleFiles(name, gmModule.dir, gmModule.objectWatchers, gmModule.sceneWatchers);
93
102
  return gmModule;
94
103
  });
95
104
  }
96
105
 
97
106
  initializeSyncModules(dependencies) {
98
- dependencies.forEach(([name]) => {
99
- const modulePath = path.join(this.modulesDirPath, name);
100
- this.syncModuleFiles(name, modulePath);
107
+ dependencies.forEach(([name, version]) => {
108
+ const gmModule = this.parseModule(name, version, false);
109
+ this.syncModuleFiles(name, gmModule.dir, gmModule.objectWatchers, gmModule.sceneWatchers);
101
110
  });
102
111
  return [];
103
112
  }
@@ -171,8 +180,10 @@ class GMFileWatcher {
171
180
  /* ---------------------------------------------
172
181
  * Watcher handlers
173
182
  * --------------------------------------------- */
174
- parseModule(name, version) {
175
- const gmModule = new GMModule(resolvePath(path.join(this.modulesDirName, name)), version);
183
+ parseModule(name, version, watch = true) {
184
+ const gmModule = new GMModule(resolvePath(path.join(this.modulesDirName, name)), version, watch
185
+ ? defaultWatcherHook()
186
+ : syncWatcherHook());
176
187
 
177
188
  const moduleFilter = (p, module) =>
178
189
  path.normalize(p).includes(path.normalize(module.dir));
@@ -288,7 +299,7 @@ class GMFileWatcher {
288
299
  const existing = fs.readFileSync(dst, 'utf8');
289
300
  if (existing !== script.content) {
290
301
  const result = removeZeroFields(diffStats(existing.split('\n'), script.content.split('\n')))
291
- console.log(`➡️ Save ${script.name}.${extension}:`, result);
302
+ console.log(`📝 Save ${script.name}.${extension}:`, result);
292
303
  fs.writeFileSync(dst, script.content, { encoding: 'utf8', flag: 'w' });
293
304
  }
294
305
 
package/app.js CHANGED
@@ -77,40 +77,47 @@ program.command('sync')
77
77
  });
78
78
  program.command('install')
79
79
  .description('Install dependencies listed in package-gm.json to gm_modules folder')
80
+ .option('-c, --clean', 'remove existing gm_modules')
80
81
  .action(function() {
82
+ const options = this.opts();
83
+ const clean = options.clean !== undefined;
81
84
  const packageJsonPath = 'package-gm.json';
82
85
  const modulesDir = 'gm_modules';
83
86
 
84
87
  if (!fs.existsSync(modulesDir)) {
85
88
  fs.mkdirSync(modulesDir);
89
+ } else if (clean) {
90
+ fs.rmdirSync(modulesDir, { recursive: true });
91
+ fs.mkdirSync(modulesDir);
86
92
  }
87
93
 
88
94
  const packageData = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
89
95
  const dependencies = packageData.dependencies;
90
96
  Object.entries(dependencies).forEach(([key, dependency]) => {
97
+ console.log(`\n📦️ Install ${key}\n===========${"=".repeat(key.length)}`)
91
98
  const modulePath = path.join(modulesDir, key);
92
99
  if (fs.existsSync(modulePath)) {
93
100
  try {
94
101
  execSync('git rev-parse --is-inside-work-tree', { cwd: modulePath, stdio: 'ignore' });
95
- console.log(`Syncing ${modulePath} to revision ${dependency.revision}`);
102
+ console.log(`🌐 Syncing ${modulePath} to revision ${dependency.revision}`);
96
103
  execSync('git reset --hard HEAD', { cwd: modulePath, stdio: 'inherit' });
97
104
  execSync('git clean -fdx -e', { cwd: modulePath, stdio: 'inherit' });
98
105
  execSync(`git checkout ${dependency.revision}`, { cwd: modulePath, stdio: 'inherit' });
99
106
  } catch (error) {
100
- console.log(`Removing ${modulePath} because it's not a git repository`);
107
+ console.log(`🗑️ Removing ${modulePath} because it's not a git repository`);
101
108
  fs.rmSync(modulePath, { recursive: true, force: true });
102
- console.log(`Initializing ${modulePath} to revision ${dependency.revision}`);
109
+ console.log(`🔧 Initializing ${modulePath} to revision ${dependency.revision}`);
103
110
  execSync(`git clone ${dependency.remote} ${modulePath}`, { stdio: 'inherit' });
104
111
  execSync(`git checkout ${dependency.revision}`, { cwd: modulePath, stdio: 'inherit' });
105
112
  }
106
113
  } else {
107
- console.log(`Initializing ${modulePath} to revision ${dependency.revision}`);
114
+ console.log(`🔧 Initializing ${modulePath} to revision ${dependency.revision}`);
108
115
  execSync(`git clone ${dependency.remote} ${modulePath}`, { stdio: 'inherit' });
109
116
  execSync(`git checkout ${dependency.revision}`, { cwd: modulePath, stdio: 'inherit' });
110
117
  }
111
118
  });
112
119
 
113
- console.log('All dependencies processed.');
120
+ console.log('\n\n✅ All dependencies processed.');
114
121
  process.exit(0);
115
122
  })
116
123
  program.command('run')
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.0.1",
6
+ "version": "1.0.3",
7
7
  "description": "Gamemaker CLI toolkit. Watch & sync gml sources with yyp project.",
8
8
  "main": "app.js",
9
9
  "scripts": {},