pake-cli 2.3.3 → 2.3.5

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 (67) hide show
  1. package/README.md +7 -0
  2. package/dist/cli.js +729 -729
  3. package/dist/dev.js +873 -0
  4. package/dist/dev.js.map +1 -0
  5. package/package.json +27 -27
  6. package/src-tauri/Cargo.lock +102 -48
  7. package/src-tauri/Cargo.toml +4 -4
  8. package/src-tauri/pake.json +1 -1
  9. package/src-tauri/src/app/menu.rs +1 -1
  10. package/src-tauri/src/app/window.rs +7 -1
  11. package/src-tauri/src/inject/event.js +1 -5
  12. package/src-tauri/src/inject/style.js +122 -95
  13. package/dist/LICENSE +0 -21
  14. package/dist/css/aria-ng-4a38f3a4ab.min.css +0 -4
  15. package/dist/css/bootstrap-3.4.1.min.css +0 -5
  16. package/dist/css/plugins-ccac6fc3fc.min.css +0 -19
  17. package/dist/favicon.ico +0 -0
  18. package/dist/favicon.png +0 -0
  19. package/dist/fonts/fontawesome-webfont.eot +0 -0
  20. package/dist/fonts/fontawesome-webfont.svg +0 -2671
  21. package/dist/fonts/fontawesome-webfont.ttf +0 -0
  22. package/dist/fonts/fontawesome-webfont.woff +0 -0
  23. package/dist/fonts/fontawesome-webfont.woff2 +0 -0
  24. package/dist/index.html +0 -1
  25. package/dist/js/angular-packages-1.6.10.min.js +0 -472
  26. package/dist/js/aria-ng-a0b72e89e6.min.js +0 -5
  27. package/dist/js/bootstrap-3.4.1.min.js +0 -6
  28. package/dist/js/echarts-common-3.8.5.min.js +0 -1
  29. package/dist/js/jquery-3.3.1.min.js +0 -2
  30. package/dist/js/moment-with-locales-2.29.4.min.js +0 -1
  31. package/dist/js/plugins-b3cb190423.min.js +0 -49
  32. package/dist/langs/zh_Hans.txt +0 -714
  33. package/dist/langs/zh_Hant.txt +0 -714
  34. package/dist/robots.txt +0 -4
  35. package/dist/tileicon.png +0 -0
  36. package/dist/touchicon.png +0 -0
  37. package/src-tauri/icons/figma.icns +0 -0
  38. package/src-tauri/icons/gpt.icns +0 -0
  39. package/src-tauri/icons/myshell.icns +0 -0
  40. package/src-tauri/icons/zbook.icns +0 -0
  41. package/src-tauri/png/code_256.ico +0 -0
  42. package/src-tauri/png/code_32.ico +0 -0
  43. package/src-tauri/png/code_512.png +0 -0
  44. package/src-tauri/png/gpt_256.ico +0 -0
  45. package/src-tauri/png/gpt_32.ico +0 -0
  46. package/src-tauri/png/gpt_512.png +0 -0
  47. package/src-tauri/png/loop_256.ico +0 -0
  48. package/src-tauri/png/loop_32.ico +0 -0
  49. package/src-tauri/png/loop_512.png +0 -0
  50. package/src-tauri/png/myshell_256.ico +0 -0
  51. package/src-tauri/png/myshell_32.ico +0 -0
  52. package/src-tauri/png/myshell_512.png +0 -0
  53. package/src-tauri/png/tool_256.ico +0 -0
  54. package/src-tauri/png/tool_32.ico +0 -0
  55. package/src-tauri/png/tool_512.png +0 -0
  56. package/src-tauri/png/witeboard_256.ico +0 -0
  57. package/src-tauri/png/witeboard_32.ico +0 -0
  58. package/src-tauri/png/witeboard_512.png +0 -0
  59. package/src-tauri/png/xapi_256.ico +0 -0
  60. package/src-tauri/png/xapi_32.ico +0 -0
  61. package/src-tauri/png/xapi_512.png +0 -0
  62. package/src-tauri/png/yuque_256.ico +0 -0
  63. package/src-tauri/png/yuque_32.ico +0 -0
  64. package/src-tauri/png/yuque_512.png +0 -0
  65. package/src-tauri/png/zlibrary_256.ico +0 -0
  66. package/src-tauri/png/zlibrary_32.ico +0 -0
  67. package/src-tauri/png/zlibrary_512.png +0 -0
package/dist/dev.js ADDED
@@ -0,0 +1,873 @@
1
+ import log from 'loglevel';
2
+ import fsExtra from 'fs-extra';
3
+ import chalk from 'chalk';
4
+ import path from 'path';
5
+ import axios from 'axios';
6
+ import { dir } from 'tmp-promise';
7
+ import { fileURLToPath } from 'url';
8
+ import crypto from 'crypto';
9
+ import prompts from 'prompts';
10
+ import ora from 'ora';
11
+ import { fileTypeFromBuffer } from 'file-type';
12
+ import psl from 'psl';
13
+ import 'is-url';
14
+ import shelljs from 'shelljs';
15
+ import dns from 'dns';
16
+ import http from 'http';
17
+ import { promisify } from 'util';
18
+ import fs from 'fs';
19
+
20
+ const DEFAULT_PAKE_OPTIONS = {
21
+ icon: '',
22
+ height: 780,
23
+ width: 1200,
24
+ fullscreen: false,
25
+ resizable: true,
26
+ transparent: false,
27
+ userAgent: '',
28
+ showMenu: false,
29
+ showSystemTray: true,
30
+ multiArch: false,
31
+ targets: 'deb',
32
+ iterCopyFile: false,
33
+ systemTrayIcon: '',
34
+ debug: false,
35
+ inject: [],
36
+ safeDomain: [],
37
+ };
38
+ // Just for cli development
39
+ const DEFAULT_DEV_PAKE_OPTIONS = {
40
+ ...DEFAULT_PAKE_OPTIONS,
41
+ url: 'https://weread.qq.com',
42
+ name: 'WeRead',
43
+ safeDomain: ['weread.qq.com'],
44
+ transparent: true,
45
+ };
46
+
47
+ const logger = {
48
+ info(...msg) {
49
+ log.info(...msg.map(m => chalk.white(m)));
50
+ },
51
+ debug(...msg) {
52
+ log.debug(...msg);
53
+ },
54
+ error(...msg) {
55
+ log.error(...msg.map(m => chalk.red(m)));
56
+ },
57
+ warn(...msg) {
58
+ log.info(...msg.map(m => chalk.yellow(m)));
59
+ },
60
+ success(...msg) {
61
+ log.info(...msg.map(m => chalk.green(m)));
62
+ },
63
+ };
64
+
65
+ // Convert the current module URL to a file path
66
+ const currentModulePath = fileURLToPath(import.meta.url);
67
+ // Resolve the parent directory of the current module
68
+ const npmDirectory = path.join(path.dirname(currentModulePath), '..');
69
+ const tauriConfigDirectory = path.join(npmDirectory, 'src-tauri');
70
+
71
+ const { platform: platform$2 } = process;
72
+ const IS_MAC = platform$2 === 'darwin';
73
+ const IS_WIN = platform$2 === 'win32';
74
+ const IS_LINUX = platform$2 === 'linux';
75
+
76
+ // Generates an identifier based on the given URL.
77
+ function getIdentifier(url) {
78
+ const postFixHash = crypto.createHash('md5').update(url).digest('hex').substring(0, 6);
79
+ return `com.pake.${postFixHash}`;
80
+ }
81
+ async function promptText(message, initial) {
82
+ const response = await prompts({
83
+ type: 'text',
84
+ name: 'content',
85
+ message,
86
+ initial,
87
+ });
88
+ return response.content;
89
+ }
90
+ function capitalizeFirstLetter(string) {
91
+ return string.charAt(0).toUpperCase() + string.slice(1);
92
+ }
93
+ function getSpinner(text) {
94
+ const loadingType = {
95
+ interval: 80,
96
+ frames: ['✦', '✶', '✺', '✵', '✸', '✹', '✺'],
97
+ };
98
+ return ora({
99
+ text: `${chalk.cyan(text)}\n`,
100
+ spinner: loadingType,
101
+ color: 'cyan',
102
+ }).start();
103
+ }
104
+
105
+ async function handleIcon(options) {
106
+ if (options.icon) {
107
+ if (options.icon.startsWith('http')) {
108
+ return downloadIcon(options.icon);
109
+ }
110
+ else {
111
+ return path.resolve(options.icon);
112
+ }
113
+ }
114
+ else {
115
+ logger.warn('✼ No icon given, default in use. For a custom icon, use --icon option.');
116
+ const iconPath = IS_WIN
117
+ ? 'src-tauri/png/icon_256.ico'
118
+ : IS_LINUX
119
+ ? 'src-tauri/png/icon_512.png'
120
+ : 'src-tauri/icons/icon.icns';
121
+ return path.join(npmDirectory, iconPath);
122
+ }
123
+ }
124
+ async function downloadIcon(iconUrl) {
125
+ const spinner = getSpinner('Downloading icon...');
126
+ try {
127
+ const iconResponse = await axios.get(iconUrl, { responseType: 'arraybuffer' });
128
+ const iconData = await iconResponse.data;
129
+ if (!iconData) {
130
+ return null;
131
+ }
132
+ const fileDetails = await fileTypeFromBuffer(iconData);
133
+ if (!fileDetails) {
134
+ return null;
135
+ }
136
+ const { path: tempPath } = await dir();
137
+ let iconPath = `${tempPath}/icon.${fileDetails.ext}`;
138
+ // Fix this for linux
139
+ if (IS_LINUX) {
140
+ iconPath = 'png/linux_temp.png';
141
+ await fsExtra.outputFile(`${npmDirectory}/src-tauri/${iconPath}`, iconData);
142
+ }
143
+ else {
144
+ await fsExtra.outputFile(iconPath, iconData);
145
+ }
146
+ await fsExtra.outputFile(iconPath, iconData);
147
+ spinner.succeed(chalk.green('Icon downloaded successfully!'));
148
+ return iconPath;
149
+ }
150
+ catch (error) {
151
+ spinner.fail(chalk.red('Icon download failed!'));
152
+ if (error.response && error.response.status === 404) {
153
+ return null;
154
+ }
155
+ throw error;
156
+ }
157
+ }
158
+
159
+ // Extracts the domain from a given URL.
160
+ function getDomain(inputUrl) {
161
+ try {
162
+ const url = new URL(inputUrl);
163
+ // Use PSL to parse domain names.
164
+ const parsed = psl.parse(url.hostname);
165
+ // If domain is available, split it and return the SLD.
166
+ if ('domain' in parsed && parsed.domain) {
167
+ return parsed.domain.split('.')[0];
168
+ }
169
+ else {
170
+ return null;
171
+ }
172
+ }
173
+ catch (error) {
174
+ return null;
175
+ }
176
+ }
177
+
178
+ function resolveAppName(name, platform) {
179
+ const domain = getDomain(name) || 'pake';
180
+ return platform !== 'linux' ? capitalizeFirstLetter(domain) : domain;
181
+ }
182
+ function isValidName(name, platform) {
183
+ const platformRegexMapping = {
184
+ linux: /^[a-z0-9]+(-[a-z0-9]+)*$/,
185
+ default: /^[a-zA-Z0-9]+$/,
186
+ };
187
+ const reg = platformRegexMapping[platform] || platformRegexMapping.default;
188
+ return !!name && reg.test(name);
189
+ }
190
+ async function handleOptions(options, url) {
191
+ const { platform } = process;
192
+ const isActions = process.env.GITHUB_ACTIONS;
193
+ let name = options.name;
194
+ const pathExists = await fsExtra.pathExists(url);
195
+ if (!options.name) {
196
+ const defaultName = pathExists ? '' : resolveAppName(url, platform);
197
+ const promptMessage = 'Enter your application name';
198
+ const namePrompt = await promptText(promptMessage, defaultName);
199
+ name = namePrompt || defaultName;
200
+ }
201
+ if (!isValidName(name, platform)) {
202
+ const LINUX_NAME_ERROR = `✕ name should only include lowercase letters, numbers, and dashes, and must contain at least one lowercase letter. Examples: com-123-xxx, 123pan, pan123, weread, we-read.`;
203
+ const DEFAULT_NAME_ERROR = `✕ Name should only include letters and numbers, and must contain at least one letter. Examples: 123pan, 123Pan, Pan123, weread, WeRead, WERead.`;
204
+ const errorMsg = platform === 'linux' ? LINUX_NAME_ERROR : DEFAULT_NAME_ERROR;
205
+ logger.error(errorMsg);
206
+ if (isActions) {
207
+ name = resolveAppName(url, platform);
208
+ logger.warn(`✼ Inside github actions, use the default name: ${name}`);
209
+ }
210
+ else {
211
+ process.exit(1);
212
+ }
213
+ }
214
+ const appOptions = {
215
+ ...options,
216
+ name,
217
+ identifier: getIdentifier(url),
218
+ };
219
+ appOptions.icon = await handleIcon(appOptions);
220
+ return appOptions;
221
+ }
222
+
223
+ var windows = [
224
+ {
225
+ url: "https://weread.qq.com/",
226
+ transparent: true,
227
+ fullscreen: false,
228
+ width: 1200,
229
+ height: 780,
230
+ resizable: true,
231
+ url_type: "web"
232
+ }
233
+ ];
234
+ var user_agent = {
235
+ macos: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.1 Safari/605.1.15",
236
+ linux: "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36",
237
+ windows: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36"
238
+ };
239
+ var menu = {
240
+ macos: false,
241
+ linux: false,
242
+ windows: false
243
+ };
244
+ var system_tray = {
245
+ macos: false,
246
+ linux: true,
247
+ windows: true
248
+ };
249
+ var inject = [
250
+ ];
251
+ var pakeConf = {
252
+ windows: windows,
253
+ user_agent: user_agent,
254
+ menu: menu,
255
+ system_tray: system_tray,
256
+ inject: inject
257
+ };
258
+
259
+ var tauri$3 = {
260
+ security: {
261
+ csp: null,
262
+ dangerousRemoteDomainIpcAccess: [
263
+ {
264
+ domain: "weread.qq.com",
265
+ windows: [
266
+ "pake"
267
+ ],
268
+ enableTauriAPI: true
269
+ }
270
+ ]
271
+ },
272
+ updater: {
273
+ active: false
274
+ },
275
+ systemTray: {
276
+ iconPath: "png/icon_512.png",
277
+ iconAsTemplate: true
278
+ },
279
+ allowlist: {
280
+ all: true,
281
+ fs: {
282
+ all: true,
283
+ scope: [
284
+ "$DOWNLOAD/*"
285
+ ]
286
+ }
287
+ }
288
+ };
289
+ var build = {
290
+ withGlobalTauri: true,
291
+ devPath: "../dist",
292
+ distDir: "../dist",
293
+ beforeBuildCommand: "",
294
+ beforeDevCommand: ""
295
+ };
296
+ var CommonConf = {
297
+ "package": {
298
+ productName: "WeRead",
299
+ version: "1.0.0"
300
+ },
301
+ tauri: tauri$3,
302
+ build: build
303
+ };
304
+
305
+ var tauri$2 = {
306
+ bundle: {
307
+ icon: [
308
+ "png/weread_256.ico",
309
+ "png/weread_32.ico"
310
+ ],
311
+ identifier: "com.pake.weread",
312
+ active: true,
313
+ category: "DeveloperTool",
314
+ copyright: "",
315
+ externalBin: [
316
+ ],
317
+ longDescription: "",
318
+ resources: [
319
+ "png/weread_32.ico"
320
+ ],
321
+ shortDescription: "",
322
+ targets: [
323
+ "msi"
324
+ ],
325
+ windows: {
326
+ certificateThumbprint: null,
327
+ digestAlgorithm: "sha256",
328
+ timestampUrl: "",
329
+ wix: {
330
+ language: [
331
+ "en-US"
332
+ ],
333
+ template: "assets/main.wxs"
334
+ }
335
+ }
336
+ }
337
+ };
338
+ var WinConf = {
339
+ tauri: tauri$2
340
+ };
341
+
342
+ var tauri$1 = {
343
+ bundle: {
344
+ icon: [
345
+ "icons/weread.icns"
346
+ ],
347
+ identifier: "com.pake.weread",
348
+ active: true,
349
+ category: "DeveloperTool",
350
+ copyright: "",
351
+ externalBin: [
352
+ ],
353
+ longDescription: "",
354
+ macOS: {
355
+ entitlements: null,
356
+ exceptionDomain: "",
357
+ frameworks: [
358
+ ],
359
+ providerShortName: null,
360
+ signingIdentity: null
361
+ },
362
+ resources: [
363
+ ],
364
+ shortDescription: "",
365
+ targets: [
366
+ "dmg"
367
+ ]
368
+ }
369
+ };
370
+ var MacConf = {
371
+ tauri: tauri$1
372
+ };
373
+
374
+ var tauri = {
375
+ bundle: {
376
+ icon: [
377
+ "png/weread_512.png"
378
+ ],
379
+ identifier: "com.pake.weread",
380
+ active: true,
381
+ category: "DeveloperTool",
382
+ copyright: "",
383
+ deb: {
384
+ depends: [
385
+ "curl",
386
+ "wget"
387
+ ],
388
+ files: {
389
+ "/usr/share/applications/com-pake-weread.desktop": "assets/com-pake-weread.desktop"
390
+ }
391
+ },
392
+ externalBin: [
393
+ ],
394
+ longDescription: "",
395
+ resources: [
396
+ ],
397
+ shortDescription: "",
398
+ targets: [
399
+ "deb",
400
+ "appimage"
401
+ ]
402
+ }
403
+ };
404
+ var LinuxConf = {
405
+ tauri: tauri
406
+ };
407
+
408
+ const platformConfigs = {
409
+ win32: WinConf,
410
+ darwin: MacConf,
411
+ linux: LinuxConf,
412
+ };
413
+ const { platform: platform$1 } = process;
414
+ // @ts-ignore
415
+ const platformConfig = platformConfigs[platform$1];
416
+ let tauriConfig = {
417
+ tauri: {
418
+ ...CommonConf.tauri,
419
+ bundle: platformConfig.tauri.bundle,
420
+ },
421
+ package: CommonConf.package,
422
+ build: CommonConf.build,
423
+ pake: pakeConf,
424
+ };
425
+
426
+ function shellExec(command) {
427
+ return new Promise((resolve, reject) => {
428
+ shelljs.exec(command, { async: true, silent: false, cwd: npmDirectory }, code => {
429
+ if (code === 0) {
430
+ resolve(0);
431
+ }
432
+ else {
433
+ reject(new Error(`${code}`));
434
+ }
435
+ });
436
+ });
437
+ }
438
+
439
+ const resolve = promisify(dns.resolve);
440
+ const ping = async (host) => {
441
+ const lookup = promisify(dns.lookup);
442
+ const ip = await lookup(host);
443
+ const start = new Date();
444
+ // Prevent timeouts from affecting user experience.
445
+ const requestPromise = new Promise((resolve, reject) => {
446
+ const req = http.get(`http://${ip.address}`, res => {
447
+ const delay = new Date().getTime() - start.getTime();
448
+ res.resume();
449
+ resolve(delay);
450
+ });
451
+ req.on('error', err => {
452
+ reject(err);
453
+ });
454
+ });
455
+ const timeoutPromise = new Promise((_, reject) => {
456
+ setTimeout(() => {
457
+ reject(new Error('Request timed out after 3 seconds'));
458
+ }, 1000);
459
+ });
460
+ return Promise.race([requestPromise, timeoutPromise]);
461
+ };
462
+ async function isChinaDomain(domain) {
463
+ try {
464
+ const [ip] = await resolve(domain);
465
+ return await isChinaIP(ip, domain);
466
+ }
467
+ catch (error) {
468
+ logger.debug(`${domain} can't be parse!`);
469
+ return true;
470
+ }
471
+ }
472
+ async function isChinaIP(ip, domain) {
473
+ try {
474
+ const delay = await ping(ip);
475
+ logger.debug(`${domain} latency is ${delay} ms`);
476
+ return delay > 1000;
477
+ }
478
+ catch (error) {
479
+ logger.debug(`ping ${domain} failed!`);
480
+ return true;
481
+ }
482
+ }
483
+
484
+ async function installRust() {
485
+ const isActions = process.env.GITHUB_ACTIONS;
486
+ const isInChina = await isChinaDomain('sh.rustup.rs');
487
+ const rustInstallScriptForMac = isInChina && !isActions
488
+ ? 'export RUSTUP_DIST_SERVER="https://rsproxy.cn" && export RUSTUP_UPDATE_ROOT="https://rsproxy.cn/rustup" && curl --proto "=https" --tlsv1.2 -sSf https://rsproxy.cn/rustup-init.sh | sh'
489
+ : "curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y";
490
+ const rustInstallScriptForWindows = 'winget install --id Rustlang.Rustup';
491
+ const spinner = getSpinner('Downloading Rust...');
492
+ try {
493
+ await shellExec(IS_WIN ? rustInstallScriptForWindows : rustInstallScriptForMac);
494
+ spinner.succeed(chalk.green('Rust installed successfully!'));
495
+ }
496
+ catch (error) {
497
+ console.error('Error installing Rust:', error.message);
498
+ spinner.fail(chalk.red('Rust installation failed!'));
499
+ process.exit(1);
500
+ }
501
+ }
502
+ function checkRustInstalled() {
503
+ return shelljs.exec('rustc --version', { silent: true }).code === 0;
504
+ }
505
+
506
+ async function combineFiles(files, output) {
507
+ const contents = files.map(file => {
508
+ const fileContent = fs.readFileSync(file);
509
+ if (file.endsWith('.css')) {
510
+ return "window.addEventListener('DOMContentLoaded', (_event) => { const css = `" + fileContent + "`; const style = document.createElement('style'); style.innerHTML = css; document.head.appendChild(style); });";
511
+ }
512
+ return "window.addEventListener('DOMContentLoaded', (_event) => { " + fileContent + " });";
513
+ });
514
+ fs.writeFileSync(output, contents.join('\n'));
515
+ return files;
516
+ }
517
+
518
+ async function mergeConfig(url, options, tauriConf) {
519
+ const { width, height, fullscreen, transparent, userAgent, showMenu, showSystemTray, systemTrayIcon, iterCopyFile, identifier, name, resizable = true, inject, safeDomain, } = options;
520
+ const { platform } = process;
521
+ // Set Windows parameters.
522
+ const tauriConfWindowOptions = {
523
+ width,
524
+ height,
525
+ fullscreen,
526
+ transparent,
527
+ resizable,
528
+ };
529
+ Object.assign(tauriConf.pake.windows[0], { url, ...tauriConfWindowOptions });
530
+ tauriConf.package.productName = name;
531
+ tauriConf.tauri.bundle.identifier = identifier;
532
+ //Judge the type of URL, whether it is a file or a website.
533
+ const pathExists = await fsExtra.pathExists(url);
534
+ if (pathExists) {
535
+ logger.warn('✼ Your input might be a local file.');
536
+ tauriConf.pake.windows[0].url_type = 'local';
537
+ const fileName = path.basename(url);
538
+ const dirName = path.dirname(url);
539
+ const distDir = path.join(npmDirectory, 'dist');
540
+ const distBakDir = path.join(npmDirectory, 'dist_bak');
541
+ if (!iterCopyFile) {
542
+ const urlPath = path.join(distDir, fileName);
543
+ await fsExtra.copy(url, urlPath);
544
+ }
545
+ else {
546
+ fsExtra.moveSync(distDir, distBakDir, { overwrite: true });
547
+ fsExtra.copySync(dirName, distDir, { overwrite: true });
548
+ const filesToCopyBack = ['cli.js', 'about_pake.html'];
549
+ await Promise.all(filesToCopyBack.map(file => fsExtra.copy(path.join(distBakDir, file), path.join(distDir, file))));
550
+ }
551
+ tauriConf.pake.windows[0].url = fileName;
552
+ tauriConf.pake.windows[0].url_type = 'local';
553
+ }
554
+ else {
555
+ tauriConf.pake.windows[0].url_type = 'web';
556
+ // Set the secure domain for calling window.__TAURI__ to the application domain that has been set.
557
+ tauriConf.tauri.security.dangerousRemoteDomainIpcAccess = [
558
+ {
559
+ domain: new URL(url).hostname,
560
+ windows: ['pake'],
561
+ enableTauriAPI: true,
562
+ },
563
+ ];
564
+ }
565
+ if (safeDomain.length > 0) {
566
+ tauriConf.tauri.security.dangerousRemoteDomainIpcAccess = [
567
+ ...tauriConf.tauri.security.dangerousRemoteDomainIpcAccess,
568
+ ...safeDomain.map(domain => ({
569
+ domain,
570
+ windows: ['pake'],
571
+ enableTauriAPI: true,
572
+ })),
573
+ ];
574
+ }
575
+ const platformMap = {
576
+ win32: 'windows',
577
+ linux: 'linux',
578
+ darwin: 'macos',
579
+ };
580
+ const currentPlatform = platformMap[platform];
581
+ if (userAgent.length > 0) {
582
+ tauriConf.pake.user_agent[currentPlatform] = userAgent;
583
+ }
584
+ tauriConf.pake.menu[currentPlatform] = showMenu;
585
+ tauriConf.pake.system_tray[currentPlatform] = showSystemTray;
586
+ // Processing targets are currently only open to Linux.
587
+ if (platform === 'linux') {
588
+ delete tauriConf.tauri.bundle.deb.files;
589
+ const validTargets = ['all', 'deb', 'appimage'];
590
+ if (validTargets.includes(options.targets)) {
591
+ tauriConf.tauri.bundle.targets = options.targets === 'all' ? ['deb', 'appimage'] : [options.targets];
592
+ }
593
+ else {
594
+ logger.warn(`✼ The target must be one of ${validTargets.join(', ')}, the default 'deb' will be used.`);
595
+ }
596
+ }
597
+ // Set icon.
598
+ const platformIconMap = {
599
+ win32: {
600
+ fileExt: '.ico',
601
+ path: `png/${name.toLowerCase()}_256.ico`,
602
+ defaultIcon: 'png/icon_256.ico',
603
+ message: 'Windows icon must be .ico and 256x256px.',
604
+ },
605
+ linux: {
606
+ fileExt: '.png',
607
+ path: `png/${name.toLowerCase()}_512.png`,
608
+ defaultIcon: 'png/icon_512.png',
609
+ message: 'Linux icon must be .png and 512x512px.',
610
+ },
611
+ darwin: {
612
+ fileExt: '.icns',
613
+ path: `icons/${name.toLowerCase()}.icns`,
614
+ defaultIcon: 'icons/icon.icns',
615
+ message: 'macOS icon must be .icns type.',
616
+ },
617
+ };
618
+ const iconInfo = platformIconMap[platform];
619
+ const exists = await fsExtra.pathExists(options.icon);
620
+ if (exists) {
621
+ let updateIconPath = true;
622
+ let customIconExt = path.extname(options.icon).toLowerCase();
623
+ if (customIconExt !== iconInfo.fileExt) {
624
+ updateIconPath = false;
625
+ logger.warn(`✼ ${iconInfo.message}, but you give ${customIconExt}`);
626
+ tauriConf.tauri.bundle.icon = [iconInfo.defaultIcon];
627
+ }
628
+ else {
629
+ const iconPath = path.join(npmDirectory, 'src-tauri/', iconInfo.path);
630
+ tauriConf.tauri.bundle.resources = [iconInfo.path];
631
+ await fsExtra.copy(options.icon, iconPath);
632
+ }
633
+ if (updateIconPath) {
634
+ tauriConf.tauri.bundle.icon = [options.icon];
635
+ }
636
+ else {
637
+ logger.warn(`✼ Icon will remain as default.`);
638
+ }
639
+ }
640
+ else {
641
+ logger.warn('✼ Custom icon path may be invalid, default icon will be used instead.');
642
+ tauriConf.tauri.bundle.icon = [iconInfo.defaultIcon];
643
+ }
644
+ // Set tray icon path.
645
+ let trayIconPath = platform === 'darwin' ? 'png/icon_512.png' : tauriConf.tauri.bundle.icon[0];
646
+ if (systemTrayIcon.length > 0) {
647
+ try {
648
+ await fsExtra.pathExists(systemTrayIcon);
649
+ // 需要判断图标格式,默认只支持ico和png两种
650
+ let iconExt = path.extname(systemTrayIcon).toLowerCase();
651
+ if (iconExt == '.png' || iconExt == '.ico') {
652
+ const trayIcoPath = path.join(npmDirectory, `src-tauri/png/${name.toLowerCase()}${iconExt}`);
653
+ trayIconPath = `png/${name.toLowerCase()}${iconExt}`;
654
+ await fsExtra.copy(systemTrayIcon, trayIcoPath);
655
+ }
656
+ else {
657
+ logger.warn(`✼ System tray icon must be .ico or .png, but you provided ${iconExt}.`);
658
+ logger.warn(`✼ Default system tray icon will be used.`);
659
+ }
660
+ }
661
+ catch {
662
+ logger.warn(`✼ ${systemTrayIcon} not exists!`);
663
+ logger.warn(`✼ Default system tray icon will remain unchanged.`);
664
+ }
665
+ }
666
+ tauriConf.tauri.systemTray.iconPath = trayIconPath;
667
+ const injectFilePath = path.join(npmDirectory, `src-tauri/src/inject/custom.js`);
668
+ // inject js or css files
669
+ if (inject?.length > 0) {
670
+ if (!inject.every(item => item.endsWith('.css') || item.endsWith('.js'))) {
671
+ logger.error('The injected file must be in either CSS or JS format.');
672
+ return;
673
+ }
674
+ const files = inject.map(filepath => path.isAbsolute(filepath) ? filepath : path.join(process.cwd(), filepath));
675
+ tauriConf.pake.inject = files;
676
+ await combineFiles(files, injectFilePath);
677
+ }
678
+ else {
679
+ tauriConf.pake.inject = [];
680
+ await fsExtra.writeFile(injectFilePath, '');
681
+ }
682
+ // Save config file.
683
+ const platformConfigPaths = {
684
+ win32: 'tauri.windows.conf.json',
685
+ darwin: 'tauri.macos.conf.json',
686
+ linux: 'tauri.linux.conf.json',
687
+ };
688
+ const configPath = path.join(tauriConfigDirectory, platformConfigPaths[platform]);
689
+ const bundleConf = { tauri: { bundle: tauriConf.tauri.bundle } };
690
+ await fsExtra.outputJSON(configPath, bundleConf, { spaces: 4 });
691
+ const pakeConfigPath = path.join(tauriConfigDirectory, 'pake.json');
692
+ await fsExtra.outputJSON(pakeConfigPath, tauriConf.pake, { spaces: 4 });
693
+ let tauriConf2 = JSON.parse(JSON.stringify(tauriConf));
694
+ delete tauriConf2.pake;
695
+ delete tauriConf2.tauri.bundle;
696
+ const configJsonPath = path.join(tauriConfigDirectory, 'tauri.conf.json');
697
+ await fsExtra.outputJSON(configJsonPath, tauriConf2, { spaces: 4 });
698
+ }
699
+
700
+ class BaseBuilder {
701
+ constructor(options) {
702
+ this.options = options;
703
+ }
704
+ async prepare() {
705
+ const tauriSrcPath = path.join(npmDirectory, 'src-tauri');
706
+ const tauriTargetPath = path.join(tauriSrcPath, 'target');
707
+ const tauriTargetPathExists = await fsExtra.pathExists(tauriTargetPath);
708
+ if (!IS_MAC && !tauriTargetPathExists) {
709
+ logger.warn('✼ The first use requires installing system dependencies.');
710
+ logger.warn('✼ See more in https://tauri.app/v1/guides/getting-started/prerequisites.');
711
+ }
712
+ if (!checkRustInstalled()) {
713
+ const res = await prompts({
714
+ type: 'confirm',
715
+ message: 'Rust not detected. Install now?',
716
+ name: 'value',
717
+ });
718
+ if (res.value) {
719
+ await installRust();
720
+ }
721
+ else {
722
+ logger.error('✕ Rust required to package your webapp.');
723
+ process.exit(0);
724
+ }
725
+ }
726
+ const isChina = await isChinaDomain('www.npmjs.com');
727
+ const spinner = getSpinner('Installing package...');
728
+ const rustProjectDir = path.join(tauriSrcPath, '.cargo');
729
+ const projectConf = path.join(rustProjectDir, 'config');
730
+ await fsExtra.ensureDir(rustProjectDir);
731
+ if (isChina) {
732
+ logger.info('✺ Located in China, using npm/rsProxy CN mirror.');
733
+ const projectCnConf = path.join(tauriSrcPath, 'rust_proxy.toml');
734
+ await fsExtra.copy(projectCnConf, projectConf);
735
+ await shellExec(`cd "${npmDirectory}" && npm install --registry=https://registry.npmmirror.com`);
736
+ }
737
+ else {
738
+ await shellExec(`cd "${npmDirectory}" && npm install`);
739
+ }
740
+ spinner.succeed(chalk.green('Package installed!'));
741
+ if (!tauriTargetPathExists) {
742
+ logger.warn('✼ The first packaging may be slow, please be patient and wait, it will be faster afterwards.');
743
+ }
744
+ }
745
+ async build(url) {
746
+ await this.buildAndCopy(url, this.options.targets);
747
+ }
748
+ async start(url) {
749
+ await mergeConfig(url, this.options, tauriConfig);
750
+ }
751
+ async buildAndCopy(url, target) {
752
+ const { name } = this.options;
753
+ await mergeConfig(url, this.options, tauriConfig);
754
+ // Build app
755
+ const spinner = getSpinner('Building app...');
756
+ setTimeout(() => spinner.stop(), 3000);
757
+ await shellExec(`cd "${npmDirectory}" && ${this.getBuildCommand()}`);
758
+ // Copy app
759
+ const fileName = this.getFileName();
760
+ const fileType = this.getFileType(target);
761
+ const appPath = this.getBuildAppPath(npmDirectory, fileName, fileType);
762
+ const distPath = path.resolve(`${name}.${fileType}`);
763
+ await fsExtra.copy(appPath, distPath);
764
+ await fsExtra.remove(appPath);
765
+ logger.success('✔ Build success!');
766
+ logger.success('✔ App installer located in', distPath);
767
+ }
768
+ getFileType(target) {
769
+ return target;
770
+ }
771
+ getBuildCommand() {
772
+ // the debug option should support `--debug` and `--release`
773
+ return this.options.debug ? 'npm run build:debug' : 'npm run build';
774
+ }
775
+ getBasePath() {
776
+ return 'src-tauri/target/release/bundle/';
777
+ }
778
+ getBuildAppPath(npmDirectory, fileName, fileType) {
779
+ return path.join(npmDirectory, this.getBasePath(), fileType.toLowerCase(), `${fileName}.${fileType}`);
780
+ }
781
+ }
782
+
783
+ class MacBuilder extends BaseBuilder {
784
+ constructor(options) {
785
+ super(options);
786
+ this.options.targets = 'dmg';
787
+ }
788
+ getFileName() {
789
+ const { name } = this.options;
790
+ let arch;
791
+ if (this.options.multiArch) {
792
+ arch = 'universal';
793
+ }
794
+ else {
795
+ arch = process.arch === 'arm64' ? 'aarch64' : process.arch;
796
+ }
797
+ return `${name}_${tauriConfig.package.version}_${arch}`;
798
+ }
799
+ getBuildCommand() {
800
+ return this.options.multiArch ? 'npm run build:mac' : super.getBuildCommand();
801
+ }
802
+ getBasePath() {
803
+ return this.options.multiArch
804
+ ? 'src-tauri/target/universal-apple-darwin/release/bundle'
805
+ : super.getBasePath();
806
+ }
807
+ }
808
+
809
+ class WinBuilder extends BaseBuilder {
810
+ constructor(options) {
811
+ super(options);
812
+ this.options.targets = 'msi';
813
+ }
814
+ getFileName() {
815
+ const { name } = this.options;
816
+ const { arch } = process;
817
+ const language = tauriConfig.tauri.bundle.windows.wix.language[0];
818
+ return `${name}_${tauriConfig.package.version}_${arch}_${language}`;
819
+ }
820
+ }
821
+
822
+ class LinuxBuilder extends BaseBuilder {
823
+ constructor(options) {
824
+ super(options);
825
+ }
826
+ getFileName() {
827
+ const { name } = this.options;
828
+ const arch = process.arch === 'x64' ? 'amd64' : process.arch;
829
+ return `${name}_${tauriConfig.package.version}_${arch}`;
830
+ }
831
+ // Customize it, considering that there are all targets.
832
+ async build(url) {
833
+ const targetTypes = ['deb', 'appimage'];
834
+ for (const target of targetTypes) {
835
+ if (this.options.targets === target || this.options.targets === 'all') {
836
+ await this.buildAndCopy(url, target);
837
+ }
838
+ }
839
+ }
840
+ getFileType(target) {
841
+ if (target === 'appimage') {
842
+ return 'AppImage';
843
+ }
844
+ return super.getFileType(target);
845
+ }
846
+ }
847
+
848
+ const { platform } = process;
849
+ const buildersMap = {
850
+ darwin: MacBuilder,
851
+ win32: WinBuilder,
852
+ linux: LinuxBuilder,
853
+ };
854
+ class BuilderProvider {
855
+ static create(options) {
856
+ const Builder = buildersMap[platform];
857
+ if (!Builder) {
858
+ throw new Error('The current system is not supported!');
859
+ }
860
+ return new Builder(options);
861
+ }
862
+ }
863
+
864
+ async function startBuild() {
865
+ log.setDefaultLevel('debug');
866
+ const appOptions = await handleOptions(DEFAULT_DEV_PAKE_OPTIONS, DEFAULT_DEV_PAKE_OPTIONS.url);
867
+ log.debug('PakeAppOptions', appOptions);
868
+ const builder = BuilderProvider.create(appOptions);
869
+ await builder.prepare();
870
+ await builder.start(DEFAULT_DEV_PAKE_OPTIONS.url);
871
+ }
872
+ startBuild();
873
+ //# sourceMappingURL=dev.js.map