pake-cli 2.1.0 โ 2.1.1
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/dist/cli.js +37 -27
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import ora from 'ora';
|
|
1
2
|
import log from 'loglevel';
|
|
2
3
|
import { InvalidArgumentError, program } from 'commander';
|
|
3
4
|
import fsExtra from 'fs-extra';
|
|
@@ -15,7 +16,6 @@ import shelljs from 'shelljs';
|
|
|
15
16
|
import dns from 'dns';
|
|
16
17
|
import http from 'http';
|
|
17
18
|
import { promisify } from 'util';
|
|
18
|
-
import ora from 'ora';
|
|
19
19
|
import updateNotifier from 'update-notifier';
|
|
20
20
|
import fs from 'fs';
|
|
21
21
|
|
|
@@ -42,10 +42,10 @@ const currentModulePath = fileURLToPath(import.meta.url);
|
|
|
42
42
|
// Resolve the parent directory of the current module
|
|
43
43
|
const npmDirectory = path.join(path.dirname(currentModulePath), '..');
|
|
44
44
|
|
|
45
|
-
const { platform: platform$
|
|
46
|
-
const IS_MAC = platform$
|
|
47
|
-
const IS_WIN = platform$
|
|
48
|
-
const IS_LINUX = platform$
|
|
45
|
+
const { platform: platform$2 } = process;
|
|
46
|
+
const IS_MAC = platform$2 === 'darwin';
|
|
47
|
+
const IS_WIN = platform$2 === 'win32';
|
|
48
|
+
const IS_LINUX = platform$2 === 'linux';
|
|
49
49
|
|
|
50
50
|
async function handleIcon(options) {
|
|
51
51
|
if (options.icon) {
|
|
@@ -64,9 +64,7 @@ async function handleIcon(options) {
|
|
|
64
64
|
}
|
|
65
65
|
async function downloadIcon(iconUrl) {
|
|
66
66
|
try {
|
|
67
|
-
const iconResponse = await axios.get(iconUrl, {
|
|
68
|
-
responseType: 'arraybuffer',
|
|
69
|
-
});
|
|
67
|
+
const iconResponse = await axios.get(iconUrl, { responseType: 'arraybuffer' });
|
|
70
68
|
const iconData = await iconResponse.data;
|
|
71
69
|
if (!iconData) {
|
|
72
70
|
return null;
|
|
@@ -347,9 +345,9 @@ const platformConfigs = {
|
|
|
347
345
|
darwin: MacConf,
|
|
348
346
|
linux: LinuxConf
|
|
349
347
|
};
|
|
350
|
-
const { platform } = process;
|
|
348
|
+
const { platform: platform$1 } = process;
|
|
351
349
|
// @ts-ignore
|
|
352
|
-
const platformConfig = platformConfigs[platform];
|
|
350
|
+
const platformConfig = platformConfigs[platform$1];
|
|
353
351
|
let tauriConfig = {
|
|
354
352
|
tauri: {
|
|
355
353
|
...CommonConf.tauri,
|
|
@@ -378,7 +376,8 @@ const ping = async (host) => {
|
|
|
378
376
|
const lookup = promisify(dns.lookup);
|
|
379
377
|
const ip = await lookup(host);
|
|
380
378
|
const start = new Date();
|
|
381
|
-
|
|
379
|
+
// Prevent timeouts from affecting user experience.
|
|
380
|
+
const requestPromise = new Promise((resolve, reject) => {
|
|
382
381
|
const req = http.get(`http://${ip.address}`, (res) => {
|
|
383
382
|
const delay = new Date().getTime() - start.getTime();
|
|
384
383
|
res.resume();
|
|
@@ -388,6 +387,12 @@ const ping = async (host) => {
|
|
|
388
387
|
reject(err);
|
|
389
388
|
});
|
|
390
389
|
});
|
|
390
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
391
|
+
setTimeout(() => {
|
|
392
|
+
reject(new Error('Request timed out after 3 seconds'));
|
|
393
|
+
}, 3000);
|
|
394
|
+
});
|
|
395
|
+
return Promise.race([requestPromise, timeoutPromise]);
|
|
391
396
|
};
|
|
392
397
|
async function isChinaDomain(domain) {
|
|
393
398
|
try {
|
|
@@ -395,18 +400,18 @@ async function isChinaDomain(domain) {
|
|
|
395
400
|
return await isChinaIP(ip, domain);
|
|
396
401
|
}
|
|
397
402
|
catch (error) {
|
|
398
|
-
logger.
|
|
403
|
+
logger.debug(`${domain} can't be parse!`);
|
|
399
404
|
return false;
|
|
400
405
|
}
|
|
401
406
|
}
|
|
402
407
|
async function isChinaIP(ip, domain) {
|
|
403
408
|
try {
|
|
404
409
|
const delay = await ping(ip);
|
|
405
|
-
logger.
|
|
410
|
+
logger.debug(`${domain} latency is ${delay} ms`);
|
|
406
411
|
return delay > 500;
|
|
407
412
|
}
|
|
408
413
|
catch (error) {
|
|
409
|
-
logger.
|
|
414
|
+
logger.debug(`ping ${domain} failed!`);
|
|
410
415
|
return false;
|
|
411
416
|
}
|
|
412
417
|
}
|
|
@@ -457,6 +462,8 @@ class BaseBuilder {
|
|
|
457
462
|
}
|
|
458
463
|
}
|
|
459
464
|
async runBuildCommand(directory, command) {
|
|
465
|
+
const spinner = ora('Building...').start();
|
|
466
|
+
setTimeout(() => spinner.succeed(), 5000);
|
|
460
467
|
const isChina = await isChinaDomain("www.npmjs.com");
|
|
461
468
|
if (isChina) {
|
|
462
469
|
logger.info("Located in China, using npm/Rust CN mirror.");
|
|
@@ -557,19 +564,19 @@ async function mergeConfig(url, options, tauriConf) {
|
|
|
557
564
|
const platformIconMap = {
|
|
558
565
|
win32: {
|
|
559
566
|
fileExt: '.ico',
|
|
560
|
-
path: `png/${name.toLowerCase()}
|
|
567
|
+
path: `png/${name.toLowerCase()}_256.ico`,
|
|
561
568
|
defaultIcon: 'png/icon_256.ico',
|
|
562
569
|
message: 'Windows icon must be .ico and 256x256px.',
|
|
563
570
|
},
|
|
564
571
|
linux: {
|
|
565
572
|
fileExt: '.png',
|
|
566
|
-
path: `png/${name.toLowerCase()}
|
|
573
|
+
path: `png/${name.toLowerCase()}_512.png`,
|
|
567
574
|
defaultIcon: 'png/icon_512.png',
|
|
568
575
|
message: 'Linux icon must be .png and 512x512px.',
|
|
569
576
|
},
|
|
570
577
|
darwin: {
|
|
571
578
|
fileExt: '.icns',
|
|
572
|
-
path: `icons/${name.toLowerCase()}
|
|
579
|
+
path: `icons/${name.toLowerCase()}.icns`,
|
|
573
580
|
defaultIcon: 'icons/icon.icns',
|
|
574
581
|
message: 'MacOS icon must be .icns type.',
|
|
575
582
|
},
|
|
@@ -718,23 +725,24 @@ class LinuxBuilder extends BaseBuilder {
|
|
|
718
725
|
}
|
|
719
726
|
}
|
|
720
727
|
|
|
728
|
+
const { platform } = process;
|
|
729
|
+
const buildersMap = {
|
|
730
|
+
darwin: MacBuilder,
|
|
731
|
+
win32: WinBuilder,
|
|
732
|
+
linux: LinuxBuilder,
|
|
733
|
+
};
|
|
721
734
|
class BuilderProvider {
|
|
722
735
|
static create() {
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
if (IS_WIN) {
|
|
727
|
-
return new WinBuilder();
|
|
728
|
-
}
|
|
729
|
-
if (IS_LINUX) {
|
|
730
|
-
return new LinuxBuilder();
|
|
736
|
+
const Builder = buildersMap[platform];
|
|
737
|
+
if (!Builder) {
|
|
738
|
+
throw new Error('The current system is not supported!');
|
|
731
739
|
}
|
|
732
|
-
|
|
740
|
+
return new Builder();
|
|
733
741
|
}
|
|
734
742
|
}
|
|
735
743
|
|
|
736
744
|
var name = "pake-cli";
|
|
737
|
-
var version = "2.1.
|
|
745
|
+
var version = "2.1.1";
|
|
738
746
|
var description = "๐คฑ๐ป Turn any webpage into a desktop app with Rust. ๐คฑ๐ป ๅพ็ฎๅ็็จ Rust ๆๅ
็ฝ้กต็ๆๅพๅฐ็ๆก้ข Appใ";
|
|
739
747
|
var engines = {
|
|
740
748
|
node: ">=16.0.0"
|
|
@@ -907,9 +915,11 @@ program
|
|
|
907
915
|
if (options.debug) {
|
|
908
916
|
log.setLevel('debug');
|
|
909
917
|
}
|
|
918
|
+
const spinner = ora('Preparing...').start();
|
|
910
919
|
const builder = BuilderProvider.create();
|
|
911
920
|
await builder.prepare();
|
|
912
921
|
const appOptions = await handleOptions(options, url);
|
|
922
|
+
spinner.succeed();
|
|
913
923
|
log.debug('PakeAppOptions', appOptions);
|
|
914
924
|
await builder.build(url, appOptions);
|
|
915
925
|
});
|
package/package.json
CHANGED