pake-cli 2.2.6 → 2.3.0

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/README.md CHANGED
@@ -226,6 +226,13 @@ Pake's development can not be without these Hackers. They contributed a lot of c
226
226
  <sub><b>Pan93412</b></sub>
227
227
  </a>
228
228
  </td>
229
+ <td align="center">
230
+ <a href="https://github.com/jeasonnow">
231
+ <img src="https://avatars.githubusercontent.com/u/16950207?v=4" width="90;" alt="jeasonnow"/>
232
+ <br />
233
+ <sub><b>Santree</b></sub>
234
+ </a>
235
+ </td>
229
236
  <td align="center">
230
237
  <a href="https://github.com/wanghanzhen">
231
238
  <img src="https://avatars.githubusercontent.com/u/25301012?v=4" width="90;" alt="wanghanzhen"/>
@@ -246,15 +253,15 @@ Pake's development can not be without these Hackers. They contributed a lot of c
246
253
  <br />
247
254
  <sub><b>Essesoul</b></sub>
248
255
  </a>
249
- </td>
256
+ </td></tr>
257
+ <tr>
250
258
  <td align="center">
251
259
  <a href="https://github.com/AielloChan">
252
260
  <img src="https://avatars.githubusercontent.com/u/7900765?v=4" width="90;" alt="AielloChan"/>
253
261
  <br />
254
262
  <sub><b>Aiello</b></sub>
255
263
  </a>
256
- </td></tr>
257
- <tr>
264
+ </td>
258
265
  <td align="center">
259
266
  <a href="https://github.com/m1911star">
260
267
  <img src="https://avatars.githubusercontent.com/u/4948120?v=4" width="90;" alt="m1911star"/>
@@ -269,13 +276,6 @@ Pake's development can not be without these Hackers. They contributed a lot of c
269
276
  <sub><b>Pake Actions</b></sub>
270
277
  </a>
271
278
  </td>
272
- <td align="center">
273
- <a href="https://github.com/jeasonnow">
274
- <img src="https://avatars.githubusercontent.com/u/16950207?v=4" width="90;" alt="jeasonnow"/>
275
- <br />
276
- <sub><b>Santree</b></sub>
277
- </a>
278
- </td>
279
279
  <td align="center">
280
280
  <a href="https://github.com/QingZ11">
281
281
  <img src="https://avatars.githubusercontent.com/u/38887077?v=4" width="90;" alt="QingZ11"/>
package/dist/cli.js CHANGED
@@ -11,17 +11,17 @@ import { fileURLToPath } from 'url';
11
11
  import dns from 'dns';
12
12
  import http from 'http';
13
13
  import { promisify } from 'util';
14
+ import fs from 'fs';
14
15
  import updateNotifier from 'update-notifier';
15
16
  import axios from 'axios';
16
17
  import { dir } from 'tmp-promise';
17
18
  import { fileTypeFromBuffer } from 'file-type';
18
19
  import psl from 'psl';
19
20
  import isUrl from 'is-url';
20
- import fs from 'fs';
21
21
 
22
22
  var name = "pake-cli";
23
- var version = "2.2.6";
24
- var description = "🤱🏻 Turn any webpage into a desktop app with Rust. 🤱🏻 很简单的用 Rust 打包网页生成很小的桌面 App。";
23
+ var version = "2.3.0";
24
+ var description = "🤱🏻 Turn any webpage into a desktop app with Rust. 🤱🏻 利用 Rust 轻松构建轻量级多端桌面应用。";
25
25
  var engines = {
26
26
  node: ">=16.0.0"
27
27
  };
@@ -53,12 +53,14 @@ var scripts = {
53
53
  start: "npm run dev",
54
54
  dev: "npm run tauri dev",
55
55
  build: "npm run tauri build --release",
56
+ "build:debug": "npm run tauri build -- --debug",
56
57
  "build:mac": "npm run tauri build -- --target universal-apple-darwin",
57
58
  "build:all-unix": "chmod +x ./script/build.sh && ./script/build.sh",
58
59
  "build:all-windows": "pwsh ./script/build.ps1",
59
60
  analyze: "cd src-tauri && cargo bloat --release --crates",
60
61
  tauri: "tauri",
61
62
  cli: "rollup -c rollup.config.js --watch",
63
+ "cli:dev": "cross-env NODE_ENV=development rollup -c rollup.config.js -w",
62
64
  "cli:build": "cross-env NODE_ENV=production rollup -c rollup.config.js",
63
65
  prepublishOnly: "npm run cli:build"
64
66
  };
@@ -86,6 +88,7 @@ var devDependencies = {
86
88
  "@rollup/plugin-alias": "^4.0.2",
87
89
  "@rollup/plugin-commonjs": "^23.0.2",
88
90
  "@rollup/plugin-json": "^5.0.2",
91
+ "@rollup/plugin-replace": "^5.0.2",
89
92
  "@rollup/plugin-terser": "^0.1.0",
90
93
  "@types/fs-extra": "^9.0.13",
91
94
  "@types/is-url": "^1.2.30",
@@ -137,7 +140,7 @@ var user_agent = {
137
140
  windows: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36"
138
141
  };
139
142
  var menu = {
140
- macos: true,
143
+ macos: false,
141
144
  linux: false,
142
145
  windows: false
143
146
  };
@@ -146,11 +149,14 @@ var system_tray = {
146
149
  linux: true,
147
150
  windows: true
148
151
  };
152
+ var inject = [
153
+ ];
149
154
  var pakeConf = {
150
155
  windows: windows,
151
156
  user_agent: user_agent,
152
157
  menu: menu,
153
- system_tray: system_tray
158
+ system_tray: system_tray,
159
+ inject: inject
154
160
  };
155
161
 
156
162
  var tauri$3 = {
@@ -170,7 +176,7 @@ var tauri$3 = {
170
176
  active: false
171
177
  },
172
178
  systemTray: {
173
- iconPath: "png/weread_512.png",
179
+ iconPath: "png/icon_512.png",
174
180
  iconAsTemplate: true
175
181
  },
176
182
  allowlist: {
@@ -357,7 +363,8 @@ const IS_LINUX = platform$1 === 'linux';
357
363
  // Convert the current module URL to a file path
358
364
  const currentModulePath = fileURLToPath(import.meta.url);
359
365
  // Resolve the parent directory of the current module
360
- const npmDirectory = path.join(path.dirname(currentModulePath), '..');
366
+ const npmDirectory = path.join(path.dirname(currentModulePath), '..');
367
+ const tauriConfigDirectory = path.join(npmDirectory, 'src-tauri');
361
368
 
362
369
  function shellExec(command) {
363
370
  return new Promise((resolve, reject) => {
@@ -457,8 +464,20 @@ function checkRustInstalled() {
457
464
  return shelljs.exec('rustc --version', { silent: true }).code === 0;
458
465
  }
459
466
 
467
+ async function combineFiles(files, output) {
468
+ const contents = files.map(file => {
469
+ const fileContent = fs.readFileSync(file);
470
+ if (file.endsWith('.css')) {
471
+ return "window.addEventListener('DOMContentLoaded', (_event) => { const css = `" + fileContent + "`; const style = document.createElement('style'); style.innerHTML = css; document.head.appendChild(style); });";
472
+ }
473
+ return "window.addEventListener('DOMContentLoaded', (_event) => { " + fileContent + " });";
474
+ });
475
+ fs.writeFileSync(output, contents.join('\n'));
476
+ return files;
477
+ }
478
+
460
479
  async function mergeConfig(url, options, tauriConf) {
461
- const { width, height, fullscreen, transparent, userAgent, showMenu, showSystemTray, systemTrayIcon, iterCopyFile, identifier, name, resizable = true, } = options;
480
+ const { width, height, fullscreen, transparent, userAgent, showMenu, showSystemTray, systemTrayIcon, iterCopyFile, identifier, name, resizable = true, inject, safeDomain, } = options;
462
481
  const { platform } = process;
463
482
  // Set Windows parameters.
464
483
  const tauriConfWindowOptions = {
@@ -496,7 +515,23 @@ async function mergeConfig(url, options, tauriConf) {
496
515
  else {
497
516
  tauriConf.pake.windows[0].url_type = 'web';
498
517
  // Set the secure domain for calling window.__TAURI__ to the application domain that has been set.
499
- tauriConf.tauri.security.dangerousRemoteDomainIpcAccess[0].domain = new URL(url).hostname;
518
+ tauriConf.tauri.security.dangerousRemoteDomainIpcAccess = [
519
+ {
520
+ domain: new URL(url).hostname,
521
+ windows: ['pake'],
522
+ enableTauriAPI: true,
523
+ },
524
+ ];
525
+ }
526
+ if (safeDomain.length > 0) {
527
+ tauriConf.tauri.security.dangerousRemoteDomainIpcAccess = [
528
+ ...tauriConf.tauri.security.dangerousRemoteDomainIpcAccess,
529
+ ...safeDomain.map(domain => ({
530
+ domain,
531
+ windows: ['pake'],
532
+ enableTauriAPI: true,
533
+ })),
534
+ ];
500
535
  }
501
536
  const platformMap = {
502
537
  win32: 'windows',
@@ -514,8 +549,7 @@ async function mergeConfig(url, options, tauriConf) {
514
549
  delete tauriConf.tauri.bundle.deb.files;
515
550
  const validTargets = ['all', 'deb', 'appimage'];
516
551
  if (validTargets.includes(options.targets)) {
517
- tauriConf.tauri.bundle.targets =
518
- options.targets === 'all' ? ['deb', 'appimage'] : [options.targets];
552
+ tauriConf.tauri.bundle.targets = options.targets === 'all' ? ['deb', 'appimage'] : [options.targets];
519
553
  }
520
554
  else {
521
555
  logger.warn(`✼ The target must be one of ${validTargets.join(', ')}, the default 'deb' will be used.`);
@@ -591,22 +625,37 @@ async function mergeConfig(url, options, tauriConf) {
591
625
  }
592
626
  }
593
627
  tauriConf.tauri.systemTray.iconPath = trayIconPath;
628
+ const injectFilePath = path.join(npmDirectory, `src-tauri/src/inject/custom.js`);
629
+ // inject js or css files
630
+ if (inject?.length > 0) {
631
+ if (!inject.every(item => item.endsWith('.css') || item.endsWith('.js'))) {
632
+ logger.error('The injected file must be in either CSS or JS format.');
633
+ return;
634
+ }
635
+ const files = inject.map(filepath => path.isAbsolute(filepath) ? filepath : path.join(process.cwd(), filepath));
636
+ tauriConf.pake.inject = files;
637
+ await combineFiles(files, injectFilePath);
638
+ }
639
+ else {
640
+ tauriConf.pake.inject = [];
641
+ await fsExtra.writeFile(injectFilePath, '');
642
+ }
594
643
  // Save config file.
595
644
  const platformConfigPaths = {
596
- win32: 'src-tauri/tauri.windows.conf.json',
597
- darwin: 'src-tauri/tauri.macos.conf.json',
598
- linux: 'src-tauri/tauri.linux.conf.json',
645
+ win32: 'tauri.windows.conf.json',
646
+ darwin: 'tauri.macos.conf.json',
647
+ linux: 'tauri.linux.conf.json',
599
648
  };
600
- const configPath = path.join(npmDirectory, platformConfigPaths[platform]);
649
+ const configPath = path.join(tauriConfigDirectory, platformConfigPaths[platform]);
601
650
  const bundleConf = { tauri: { bundle: tauriConf.tauri.bundle } };
602
- await fsExtra.writeJson(configPath, bundleConf, { spaces: 4 });
603
- const pakeConfigPath = path.join(npmDirectory, 'src-tauri/pake.json');
604
- await fsExtra.writeJson(pakeConfigPath, tauriConf.pake, { spaces: 4 });
651
+ await fsExtra.outputJSON(configPath, bundleConf, { spaces: 4 });
652
+ const pakeConfigPath = path.join(tauriConfigDirectory, 'pake.json');
653
+ await fsExtra.outputJSON(pakeConfigPath, tauriConf.pake, { spaces: 4 });
605
654
  let tauriConf2 = JSON.parse(JSON.stringify(tauriConf));
606
655
  delete tauriConf2.pake;
607
656
  delete tauriConf2.tauri.bundle;
608
- const configJsonPath = path.join(npmDirectory, 'src-tauri/tauri.conf.json');
609
- await fsExtra.writeJson(configJsonPath, tauriConf2, { spaces: 4 });
657
+ const configJsonPath = path.join(tauriConfigDirectory, 'tauri.conf.json');
658
+ await fsExtra.outputJSON(configJsonPath, tauriConf2, { spaces: 4 });
610
659
  }
611
660
 
612
661
  class BaseBuilder {
@@ -657,6 +706,9 @@ class BaseBuilder {
657
706
  async build(url) {
658
707
  await this.buildAndCopy(url, this.options.targets);
659
708
  }
709
+ async start(url) {
710
+ await mergeConfig(url, this.options, tauriConfig);
711
+ }
660
712
  async buildAndCopy(url, target) {
661
713
  const { name } = this.options;
662
714
  await mergeConfig(url, this.options, tauriConfig);
@@ -678,7 +730,8 @@ class BaseBuilder {
678
730
  return target;
679
731
  }
680
732
  getBuildCommand() {
681
- return 'npm run build';
733
+ // the debug option should support `--debug` and `--release`
734
+ return this.options.debug ? 'npm run build:debug' : 'npm run build';
682
735
  }
683
736
  getBasePath() {
684
737
  return 'src-tauri/target/release/bundle/';
@@ -784,6 +837,8 @@ const DEFAULT_PAKE_OPTIONS = {
784
837
  iterCopyFile: false,
785
838
  systemTrayIcon: '',
786
839
  debug: false,
840
+ inject: [],
841
+ safeDomain: [],
787
842
  };
788
843
 
789
844
  async function checkUpdateTips() {
@@ -825,8 +880,8 @@ async function downloadIcon(iconUrl) {
825
880
  let iconPath = `${tempPath}/icon.${fileDetails.ext}`;
826
881
  // Fix this for linux
827
882
  if (IS_LINUX) {
828
- iconPath = 'icon.png';
829
- await fsExtra.outputFile(`${npmDirectory}/${iconPath}`, iconData);
883
+ iconPath = 'png/linux_temp.png';
884
+ await fsExtra.outputFile(`${npmDirectory}/src-tauri/${iconPath}`, iconData);
830
885
  }
831
886
  else {
832
887
  await fsExtra.outputFile(iconPath, iconData);
@@ -974,6 +1029,8 @@ program
974
1029
  .option('--iter-copy-file', 'Copy files when URL is a local file', DEFAULT_PAKE_OPTIONS.iterCopyFile)
975
1030
  .option('--multi-arch', 'Only for Mac, supports both Intel and M1', DEFAULT_PAKE_OPTIONS.multiArch)
976
1031
  .option('--targets <string>', 'Only for Linux, option "deb" or "appimage"', DEFAULT_PAKE_OPTIONS.targets)
1032
+ .option('--inject [injects...]', 'Injection of .js or .css Files', DEFAULT_PAKE_OPTIONS.inject)
1033
+ .option('--safe-domain [domains...]', 'Domains that Require Security Configuration"', DEFAULT_PAKE_OPTIONS.safeDomain)
977
1034
  .option('--debug', 'Debug mode', DEFAULT_PAKE_OPTIONS.debug)
978
1035
  .version(packageJson.version, '-v, --version', 'Output the current version')
979
1036
  .action(async (url, options) => {
package/dist/dev.js CHANGED
@@ -35,12 +35,13 @@ const DEFAULT_PAKE_OPTIONS = {
35
35
  inject: [],
36
36
  safeDomain: [],
37
37
  };
38
- // just for cli development
38
+ // Just for cli development
39
39
  const DEFAULT_DEV_PAKE_OPTIONS = {
40
40
  ...DEFAULT_PAKE_OPTIONS,
41
- url: 'https://zbook.lol',
42
- name: 'Zbook',
43
- safeDomain: ['zbook.eu.org']
41
+ url: 'https://weread.qq.com',
42
+ name: 'WeRead',
43
+ safeDomain: ['weread.qq.com'],
44
+ transparent: true,
44
45
  };
45
46
 
46
47
  const logger = {
@@ -133,7 +134,15 @@ async function downloadIcon(iconUrl) {
133
134
  return null;
134
135
  }
135
136
  const { path: tempPath } = await dir();
136
- const iconPath = `${tempPath}/icon.${fileDetails.ext}`;
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
+ }
137
146
  await fsExtra.outputFile(iconPath, iconData);
138
147
  spinner.succeed(chalk.green('Icon downloaded successfully!'));
139
148
  return iconPath;
@@ -213,8 +222,8 @@ async function handleOptions(options, url) {
213
222
 
214
223
  var windows = [
215
224
  {
216
- url: "https://zbook.lol",
217
- transparent: false,
225
+ url: "https://weread.qq.com/",
226
+ transparent: true,
218
227
  fullscreen: false,
219
228
  width: 1200,
220
229
  height: 780,
@@ -252,14 +261,7 @@ var tauri$3 = {
252
261
  csp: null,
253
262
  dangerousRemoteDomainIpcAccess: [
254
263
  {
255
- domain: "zbook.lol",
256
- windows: [
257
- "pake"
258
- ],
259
- enableTauriAPI: true
260
- },
261
- {
262
- domain: "zbook.eu.org",
264
+ domain: "weread.qq.com",
263
265
  windows: [
264
266
  "pake"
265
267
  ],
@@ -292,11 +294,11 @@ var build = {
292
294
  beforeDevCommand: ""
293
295
  };
294
296
  var CommonConf = {
295
- tauri: tauri$3,
296
297
  "package": {
297
- productName: "Zbook",
298
+ productName: "WeRead",
298
299
  version: "1.0.0"
299
300
  },
301
+ tauri: tauri$3,
300
302
  build: build
301
303
  };
302
304
 
@@ -340,9 +342,9 @@ var WinConf = {
340
342
  var tauri$1 = {
341
343
  bundle: {
342
344
  icon: [
343
- "/Users/tw93/www/pake/src-tauri/icons/icon.icns"
345
+ "icons/weread.icns"
344
346
  ],
345
- identifier: "com.pake.79ba20",
347
+ identifier: "com.pake.weread",
346
348
  active: true,
347
349
  category: "DeveloperTool",
348
350
  copyright: "",
@@ -358,7 +360,6 @@ var tauri$1 = {
358
360
  signingIdentity: null
359
361
  },
360
362
  resources: [
361
- "icons/zbook.icns"
362
363
  ],
363
364
  shortDescription: "",
364
365
  targets: [
@@ -481,8 +482,9 @@ async function isChinaIP(ip, domain) {
481
482
  }
482
483
 
483
484
  async function installRust() {
485
+ const isActions = process.env.GITHUB_ACTIONS;
484
486
  const isInChina = await isChinaDomain('sh.rustup.rs');
485
- const rustInstallScriptForMac = isInChina
487
+ const rustInstallScriptForMac = isInChina && !isActions
486
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'
487
489
  : "curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y";
488
490
  const rustInstallScriptForWindows = 'winget install --id Rustlang.Rustup';
@@ -662,7 +664,7 @@ async function mergeConfig(url, options, tauriConf) {
662
664
  }
663
665
  }
664
666
  tauriConf.tauri.systemTray.iconPath = trayIconPath;
665
- const injectFilePath = path.join(npmDirectory, `src-tauri/src/inject/_INJECT_.js`);
667
+ const injectFilePath = path.join(npmDirectory, `src-tauri/src/inject/custom.js`);
666
668
  // inject js or css files
667
669
  if (inject?.length > 0) {
668
670
  if (!inject.every(item => item.endsWith('.css') || item.endsWith('.js'))) {