clidesk 0.1.5 → 0.1.7

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/bin/clidesk.js CHANGED
@@ -1,6 +1,17 @@
1
1
  #!/usr/bin/env node
2
2
  // CliDesk npm launcher.
3
3
  //
4
+ // Default flow (clidesk):
5
+ // - Copy binaries to runtime cache
6
+ // - Spawn clidesk.exe directly (detached)
7
+ // - Return terminal prompt immediately
8
+ // - No terminal menu, no launcher interactive
9
+ //
10
+ // --wait: Use native launcher with --no-menu, keep terminal attached
11
+ // --debug-launch: Print debug info then launch app
12
+ // --version: Print npm package version
13
+ // --update: Run npm i -g clidesk@latest
14
+ //
4
15
  // The package stores signed binaries in vendor/, but it never runs them from
5
16
  // node_modules. Each package version is copied to a runtime cache first so npm
6
17
  // can update or uninstall the global package without Windows keeping vendor/
@@ -8,10 +19,10 @@
8
19
 
9
20
  const fs = require('fs');
10
21
  const path = require('path');
11
- const { execFileSync, spawn } = require('child_process');
22
+ const { execFileSync, spawn, execSync } = require('child_process');
12
23
 
13
24
  const args = process.argv.slice(2);
14
- const debug = args.includes('--debug-launch');
25
+ const hasFlag = (flag) => args.includes(flag);
15
26
 
16
27
  const packageRoot = path.resolve(__dirname, '..');
17
28
  const pkg = require(path.join(packageRoot, 'package.json'));
@@ -32,8 +43,8 @@ const vendorLauncher = path.join(vendorDir, 'clidesk-launcher.exe');
32
43
 
33
44
  const runtimeApp = path.join(runtimeDir, 'clidesk.exe');
34
45
  const runtimeLauncher = path.join(runtimeDir, 'clidesk-launcher.exe');
35
- const latestVersion = readLatestVersion();
36
- const updateAvailable = latestVersion ? isVersionNewer(latestVersion, version) : false;
46
+
47
+ // ── Helpers ────────────────────────────────────────────────────
37
48
 
38
49
  function ensureFileExists(filePath, label) {
39
50
  if (!fs.existsSync(filePath)) {
@@ -65,16 +76,7 @@ function copyIfMissing(src, dest) {
65
76
  }
66
77
  }
67
78
 
68
- function printDebugInfo() {
69
- console.log('[CliDesk] packageRoot:', packageRoot);
70
- console.log('[CliDesk] vendorDir:', vendorDir);
71
- console.log('[CliDesk] runtimeDir:', runtimeDir);
72
- console.log('[CliDesk] launcherPath:', runtimeLauncher);
73
- console.log('[CliDesk] appPath:', runtimeApp);
74
- console.log('[CliDesk] version:', version);
75
- console.log('[CliDesk] latestVersion:', latestVersion || '(unknown)');
76
- console.log('[CliDesk] updateAvailable:', updateAvailable ? 'true' : 'false');
77
- }
79
+ // ── Version helpers ────────────────────────────────────────────
78
80
 
79
81
  function readLatestVersion() {
80
82
  try {
@@ -134,22 +136,69 @@ function parseVersion(value) {
134
136
  return parts;
135
137
  }
136
138
 
137
- function main() {
138
- copyIfMissing(vendorApp, runtimeApp);
139
- copyIfMissing(vendorLauncher, runtimeLauncher);
139
+ // ── Actions ────────────────────────────────────────────────────
140
+
141
+ function actionVersion() {
142
+ console.log(version);
143
+ process.exit(0);
144
+ }
140
145
 
141
- if (debug) {
142
- printDebugInfo();
146
+ function actionUpdate() {
147
+ console.log('[CliDesk] Cập nhật clidesk từ npm...');
148
+ try {
149
+ execSync('npm i -g clidesk@latest', {
150
+ stdio: 'inherit',
151
+ windowsHide: true,
152
+ });
153
+ console.log('[CliDesk] Cập nhật hoàn tất. Chạy clidesk để dùng bản mới.');
154
+ } catch (err) {
155
+ console.error('[CliDesk] Cập nhật thất bại.');
156
+ console.error(err.message || err);
157
+ process.exit(1);
143
158
  }
159
+ }
160
+
161
+ function printDebugInfo() {
162
+ const latestVersion = readLatestVersion();
163
+ const updateAvailable = latestVersion ? isVersionNewer(latestVersion, version) : false;
164
+
165
+ console.log('[CliDesk] packageRoot:', packageRoot);
166
+ console.log('[CliDesk] vendorDir:', vendorDir);
167
+ console.log('[CliDesk] runtimeDir:', runtimeDir);
168
+ console.log('[CliDesk] launcherPath:', runtimeLauncher);
169
+ console.log('[CliDesk] appPath:', runtimeApp);
170
+ console.log('[CliDesk] version:', version);
171
+ console.log('[CliDesk] latestVersion:', latestVersion || '(unknown)');
172
+ console.log('[CliDesk] updateAvailable:', updateAvailable ? 'true' : 'false');
173
+ }
144
174
 
145
- const child = spawn(runtimeLauncher, args, {
175
+ function actionDebugLaunch() {
176
+ printDebugInfo();
177
+ // After debug info, launch app directly (detached) so terminal is free
178
+ console.log('[CliDesk] Khởi động CliDesk...');
179
+ const child = spawn(runtimeApp, [], {
146
180
  cwd: runtimeDir,
147
181
  env: {
148
182
  ...process.env,
149
183
  CLIDESK_VERSION: version,
150
- CLIDESK_LATEST_VERSION: latestVersion || '',
151
- CLIDESK_UPDATE_AVAILABLE: updateAvailable ? '1' : '0',
152
- CLIDESK_UPDATE_COMMAND: 'npm i -g clidesk',
184
+ CLIDESK_LAUNCH_LANG: '',
185
+ },
186
+ detached: true,
187
+ stdio: 'ignore',
188
+ windowsHide: true,
189
+ });
190
+ child.unref();
191
+ process.exit(0);
192
+ }
193
+
194
+ function actionWait() {
195
+ // Use native launcher with --no-menu flag for Job Object lifecycle
196
+ const child = spawn(runtimeLauncher, ['--no-menu'], {
197
+ cwd: runtimeDir,
198
+ env: {
199
+ ...process.env,
200
+ CLIDESK_VERSION: version,
201
+ CLIDESK_LAUNCH_LANG: '',
153
202
  },
154
203
  stdio: 'inherit',
155
204
  windowsHide: false,
@@ -161,18 +210,68 @@ function main() {
161
210
 
162
211
  child.on('error', (err) => {
163
212
  console.error('[CliDesk] Không thể chạy launcher:', err.message);
164
- console.error('[CliDesk] Path:', runtimeLauncher);
165
213
  process.exit(1);
166
214
  });
167
215
  }
168
216
 
217
+ function actionDefault() {
218
+ // Copy binaries to runtime cache
219
+ copyIfMissing(vendorApp, runtimeApp);
220
+ copyIfMissing(vendorLauncher, runtimeLauncher);
221
+
222
+ // Spawn app directly (detached), no launcher, no terminal menu
223
+ const child = spawn(runtimeApp, [], {
224
+ cwd: runtimeDir,
225
+ env: {
226
+ ...process.env,
227
+ CLIDESK_VERSION: version,
228
+ CLIDESK_LAUNCH_LANG: '',
229
+ },
230
+ detached: true,
231
+ stdio: 'ignore',
232
+ windowsHide: true,
233
+ });
234
+ child.unref();
235
+ process.exit(0);
236
+ }
237
+
238
+ // ── Main ───────────────────────────────────────────────────────
239
+
240
+ function main() {
241
+ // Handle flags that don't need binaries
242
+ if (hasFlag('--version') || hasFlag('-v')) {
243
+ actionVersion();
244
+ }
245
+
246
+ if (hasFlag('--update')) {
247
+ actionUpdate();
248
+ }
249
+
250
+ // Ensure binaries exist in runtime cache
251
+ try {
252
+ copyIfMissing(vendorApp, runtimeApp);
253
+ copyIfMissing(vendorLauncher, runtimeLauncher);
254
+ } catch (err) {
255
+ console.error('[CliDesk] Không thể chuẩn bị runtime CliDesk.');
256
+ console.error('[CliDesk] Lỗi:', err && err.message ? err.message : err);
257
+ process.exit(1);
258
+ }
259
+
260
+ if (hasFlag('--debug-launch')) {
261
+ actionDebugLaunch();
262
+ }
263
+
264
+ if (hasFlag('--wait')) {
265
+ actionWait();
266
+ }
267
+
268
+ // Default: launch app detached, return prompt immediately
269
+ actionDefault();
270
+ }
271
+
169
272
  try {
170
273
  main();
171
274
  } catch (err) {
172
- console.error('[CliDesk] Không thể chuẩn bị runtime CliDesk.');
173
- console.error('[CliDesk] Lỗi:', err && err.message ? err.message : err);
174
- if (debug) {
175
- printDebugInfo();
176
- }
275
+ console.error('[CliDesk] Lỗi không xác định:', err && err.message ? err.message : err);
177
276
  process.exit(1);
178
277
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clidesk",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "CliDesk desktop app launcher — install with npm i -g clidesk",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
Binary file
Binary file