pake-cli 2.0.7 → 2.1.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/dist/cli.js CHANGED
@@ -1,2113 +1,197 @@
1
- import * as Commander from 'commander';
2
- import { program } from 'commander';
3
1
  import log from 'loglevel';
4
- import url, { fileURLToPath } from 'url';
5
- import isurl from 'is-url';
6
- import fs from 'fs';
7
- import prompts from 'prompts';
2
+ import { InvalidArgumentError, program } from 'commander';
3
+ import fsExtra from 'fs-extra';
8
4
  import path from 'path';
9
- import fs$1 from 'fs/promises';
10
- import fs2 from 'fs-extra';
11
- import chalk from 'chalk';
12
- import crypto from 'crypto';
13
5
  import axios from 'axios';
14
- import { fileTypeFromBuffer } from 'file-type';
15
6
  import { dir } from 'tmp-promise';
16
- import ora from 'ora';
7
+ import { fileTypeFromBuffer } from 'file-type';
8
+ import chalk from 'chalk';
9
+ import { fileURLToPath } from 'url';
10
+ import psl from 'psl';
11
+ import isUrl from 'is-url';
12
+ import crypto from 'crypto';
13
+ import prompts from 'prompts';
17
14
  import shelljs from 'shelljs';
18
- import { promisify } from 'util';
19
15
  import dns from 'dns';
20
16
  import http from 'http';
17
+ import { promisify } from 'util';
18
+ import ora from 'ora';
21
19
  import updateNotifier from 'update-notifier';
20
+ import fs from 'fs';
22
21
 
23
- /******************************************************************************
24
- Copyright (c) Microsoft Corporation.
25
-
26
- Permission to use, copy, modify, and/or distribute this software for any
27
- purpose with or without fee is hereby granted.
28
-
29
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
30
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
31
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
32
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
33
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
34
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
35
- PERFORMANCE OF THIS SOFTWARE.
36
- ***************************************************************************** */
37
- /* global Reflect, Promise */
38
-
39
-
40
- function __awaiter(thisArg, _arguments, P, generator) {
41
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
42
- return new (P || (P = Promise))(function (resolve, reject) {
43
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
44
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
45
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
46
- step((generator = generator.apply(thisArg, _arguments || [])).next());
47
- });
48
- }
49
-
50
- const DEFAULT_PAKE_OPTIONS = {
51
- icon: '',
52
- height: 780,
53
- width: 1200,
54
- fullscreen: false,
55
- resizable: true,
56
- transparent: false,
57
- userAgent: '',
58
- showMenu: false,
59
- showSystemTray: false,
60
- multiArch: false,
61
- targets: 'deb',
62
- iterCopyFile: false,
63
- systemTrayIcon: '',
64
- debug: false,
65
- };
66
-
67
- const tlds = [
68
- "aaa",
69
- "aarp",
70
- "abarth",
71
- "abb",
72
- "abbott",
73
- "abbvie",
74
- "abc",
75
- "able",
76
- "abogado",
77
- "abudhabi",
78
- "ac",
79
- "academy",
80
- "accenture",
81
- "accountant",
82
- "accountants",
83
- "aco",
84
- "actor",
85
- "ad",
86
- "adac",
87
- "ads",
88
- "adult",
89
- "ae",
90
- "aeg",
91
- "aero",
92
- "aetna",
93
- "af",
94
- "afl",
95
- "africa",
96
- "ag",
97
- "agakhan",
98
- "agency",
99
- "ai",
100
- "aig",
101
- "airbus",
102
- "airforce",
103
- "airtel",
104
- "akdn",
105
- "al",
106
- "alfaromeo",
107
- "alibaba",
108
- "alipay",
109
- "allfinanz",
110
- "allstate",
111
- "ally",
112
- "alsace",
113
- "alstom",
114
- "am",
115
- "amazon",
116
- "americanexpress",
117
- "americanfamily",
118
- "amex",
119
- "amfam",
120
- "amica",
121
- "amsterdam",
122
- "analytics",
123
- "android",
124
- "anquan",
125
- "anz",
126
- "ao",
127
- "aol",
128
- "apartments",
129
- "app",
130
- "apple",
131
- "aq",
132
- "aquarelle",
133
- "ar",
134
- "arab",
135
- "aramco",
136
- "archi",
137
- "army",
138
- "arpa",
139
- "art",
140
- "arte",
141
- "as",
142
- "asda",
143
- "asia",
144
- "associates",
145
- "at",
146
- "athleta",
147
- "attorney",
148
- "au",
149
- "auction",
150
- "audi",
151
- "audible",
152
- "audio",
153
- "auspost",
154
- "author",
155
- "auto",
156
- "autos",
157
- "avianca",
158
- "aw",
159
- "aws",
160
- "ax",
161
- "axa",
162
- "az",
163
- "azure",
164
- "ba",
165
- "baby",
166
- "baidu",
167
- "banamex",
168
- "bananarepublic",
169
- "band",
170
- "bank",
171
- "bar",
172
- "barcelona",
173
- "barclaycard",
174
- "barclays",
175
- "barefoot",
176
- "bargains",
177
- "baseball",
178
- "basketball",
179
- "bauhaus",
180
- "bayern",
181
- "bb",
182
- "bbc",
183
- "bbt",
184
- "bbva",
185
- "bcg",
186
- "bcn",
187
- "bd",
188
- "be",
189
- "beats",
190
- "beauty",
191
- "beer",
192
- "bentley",
193
- "berlin",
194
- "best",
195
- "bestbuy",
196
- "bet",
197
- "bf",
198
- "bg",
199
- "bh",
200
- "bharti",
201
- "bi",
202
- "bible",
203
- "bid",
204
- "bike",
205
- "bing",
206
- "bingo",
207
- "bio",
208
- "biz",
209
- "bj",
210
- "black",
211
- "blackfriday",
212
- "blockbuster",
213
- "blog",
214
- "bloomberg",
215
- "blue",
216
- "bm",
217
- "bms",
218
- "bmw",
219
- "bn",
220
- "bnpparibas",
221
- "bo",
222
- "boats",
223
- "boehringer",
224
- "bofa",
225
- "bom",
226
- "bond",
227
- "boo",
228
- "book",
229
- "booking",
230
- "bosch",
231
- "bostik",
232
- "boston",
233
- "bot",
234
- "boutique",
235
- "box",
236
- "br",
237
- "bradesco",
238
- "bridgestone",
239
- "broadway",
240
- "broker",
241
- "brother",
242
- "brussels",
243
- "bs",
244
- "bt",
245
- "build",
246
- "builders",
247
- "business",
248
- "buy",
249
- "buzz",
250
- "bv",
251
- "bw",
252
- "by",
253
- "bz",
254
- "bzh",
255
- "ca",
256
- "cab",
257
- "cafe",
258
- "cal",
259
- "call",
260
- "calvinklein",
261
- "cam",
262
- "camera",
263
- "camp",
264
- "canon",
265
- "capetown",
266
- "capital",
267
- "capitalone",
268
- "car",
269
- "caravan",
270
- "cards",
271
- "care",
272
- "career",
273
- "careers",
274
- "cars",
275
- "casa",
276
- "case",
277
- "cash",
278
- "casino",
279
- "cat",
280
- "catering",
281
- "catholic",
282
- "cba",
283
- "cbn",
284
- "cbre",
285
- "cbs",
286
- "cc",
287
- "cd",
288
- "center",
289
- "ceo",
290
- "cern",
291
- "cf",
292
- "cfa",
293
- "cfd",
294
- "cg",
295
- "ch",
296
- "chanel",
297
- "channel",
298
- "charity",
299
- "chase",
300
- "chat",
301
- "cheap",
302
- "chintai",
303
- "christmas",
304
- "chrome",
305
- "church",
306
- "ci",
307
- "cipriani",
308
- "circle",
309
- "cisco",
310
- "citadel",
311
- "citi",
312
- "citic",
313
- "city",
314
- "cityeats",
315
- "ck",
316
- "cl",
317
- "claims",
318
- "cleaning",
319
- "click",
320
- "clinic",
321
- "clinique",
322
- "clothing",
323
- "cloud",
324
- "club",
325
- "clubmed",
326
- "cm",
327
- "cn",
328
- "co",
329
- "coach",
330
- "codes",
331
- "coffee",
332
- "college",
333
- "cologne",
334
- "com",
335
- "comcast",
336
- "commbank",
337
- "community",
338
- "company",
339
- "compare",
340
- "computer",
341
- "comsec",
342
- "condos",
343
- "construction",
344
- "consulting",
345
- "contact",
346
- "contractors",
347
- "cooking",
348
- "cookingchannel",
349
- "cool",
350
- "coop",
351
- "corsica",
352
- "country",
353
- "coupon",
354
- "coupons",
355
- "courses",
356
- "cpa",
357
- "cr",
358
- "credit",
359
- "creditcard",
360
- "creditunion",
361
- "cricket",
362
- "crown",
363
- "crs",
364
- "cruise",
365
- "cruises",
366
- "cu",
367
- "cuisinella",
368
- "cv",
369
- "cw",
370
- "cx",
371
- "cy",
372
- "cymru",
373
- "cyou",
374
- "cz",
375
- "dabur",
376
- "dad",
377
- "dance",
378
- "data",
379
- "date",
380
- "dating",
381
- "datsun",
382
- "day",
383
- "dclk",
384
- "dds",
385
- "de",
386
- "deal",
387
- "dealer",
388
- "deals",
389
- "degree",
390
- "delivery",
391
- "dell",
392
- "deloitte",
393
- "delta",
394
- "democrat",
395
- "dental",
396
- "dentist",
397
- "desi",
398
- "design",
399
- "dev",
400
- "dhl",
401
- "diamonds",
402
- "diet",
403
- "digital",
404
- "direct",
405
- "directory",
406
- "discount",
407
- "discover",
408
- "dish",
409
- "diy",
410
- "dj",
411
- "dk",
412
- "dm",
413
- "dnp",
414
- "do",
415
- "docs",
416
- "doctor",
417
- "dog",
418
- "domains",
419
- "dot",
420
- "download",
421
- "drive",
422
- "dtv",
423
- "dubai",
424
- "dunlop",
425
- "dupont",
426
- "durban",
427
- "dvag",
428
- "dvr",
429
- "dz",
430
- "earth",
431
- "eat",
432
- "ec",
433
- "eco",
434
- "edeka",
435
- "edu",
436
- "education",
437
- "ee",
438
- "eg",
439
- "email",
440
- "emerck",
441
- "energy",
442
- "engineer",
443
- "engineering",
444
- "enterprises",
445
- "epson",
446
- "equipment",
447
- "er",
448
- "ericsson",
449
- "erni",
450
- "es",
451
- "esq",
452
- "estate",
453
- "et",
454
- "etisalat",
455
- "eu",
456
- "eurovision",
457
- "eus",
458
- "events",
459
- "exchange",
460
- "expert",
461
- "exposed",
462
- "express",
463
- "extraspace",
464
- "fage",
465
- "fail",
466
- "fairwinds",
467
- "faith",
468
- "family",
469
- "fan",
470
- "fans",
471
- "farm",
472
- "farmers",
473
- "fashion",
474
- "fast",
475
- "fedex",
476
- "feedback",
477
- "ferrari",
478
- "ferrero",
479
- "fi",
480
- "fiat",
481
- "fidelity",
482
- "fido",
483
- "film",
484
- "final",
485
- "finance",
486
- "financial",
487
- "fire",
488
- "firestone",
489
- "firmdale",
490
- "fish",
491
- "fishing",
492
- "fit",
493
- "fitness",
494
- "fj",
495
- "fk",
496
- "flickr",
497
- "flights",
498
- "flir",
499
- "florist",
500
- "flowers",
501
- "fly",
502
- "fm",
503
- "fo",
504
- "foo",
505
- "food",
506
- "foodnetwork",
507
- "football",
508
- "ford",
509
- "forex",
510
- "forsale",
511
- "forum",
512
- "foundation",
513
- "fox",
514
- "fr",
515
- "free",
516
- "fresenius",
517
- "frl",
518
- "frogans",
519
- "frontdoor",
520
- "frontier",
521
- "ftr",
522
- "fujitsu",
523
- "fun",
524
- "fund",
525
- "furniture",
526
- "futbol",
527
- "fyi",
528
- "ga",
529
- "gal",
530
- "gallery",
531
- "gallo",
532
- "gallup",
533
- "game",
534
- "games",
535
- "gap",
536
- "garden",
537
- "gay",
538
- "gb",
539
- "gbiz",
540
- "gd",
541
- "gdn",
542
- "ge",
543
- "gea",
544
- "gent",
545
- "genting",
546
- "george",
547
- "gf",
548
- "gg",
549
- "ggee",
550
- "gh",
551
- "gi",
552
- "gift",
553
- "gifts",
554
- "gives",
555
- "giving",
556
- "gl",
557
- "glass",
558
- "gle",
559
- "global",
560
- "globo",
561
- "gm",
562
- "gmail",
563
- "gmbh",
564
- "gmo",
565
- "gmx",
566
- "gn",
567
- "godaddy",
568
- "gold",
569
- "goldpoint",
570
- "golf",
571
- "goo",
572
- "goodyear",
573
- "goog",
574
- "google",
575
- "gop",
576
- "got",
577
- "gov",
578
- "gp",
579
- "gq",
580
- "gr",
581
- "grainger",
582
- "graphics",
583
- "gratis",
584
- "green",
585
- "gripe",
586
- "grocery",
587
- "group",
588
- "gs",
589
- "gt",
590
- "gu",
591
- "guardian",
592
- "gucci",
593
- "guge",
594
- "guide",
595
- "guitars",
596
- "guru",
597
- "gw",
598
- "gy",
599
- "hair",
600
- "hamburg",
601
- "hangout",
602
- "haus",
603
- "hbo",
604
- "hdfc",
605
- "hdfcbank",
606
- "health",
607
- "healthcare",
608
- "help",
609
- "helsinki",
610
- "here",
611
- "hermes",
612
- "hgtv",
613
- "hiphop",
614
- "hisamitsu",
615
- "hitachi",
616
- "hiv",
617
- "hk",
618
- "hkt",
619
- "hm",
620
- "hn",
621
- "hockey",
622
- "holdings",
623
- "holiday",
624
- "homedepot",
625
- "homegoods",
626
- "homes",
627
- "homesense",
628
- "honda",
629
- "horse",
630
- "hospital",
631
- "host",
632
- "hosting",
633
- "hot",
634
- "hoteles",
635
- "hotels",
636
- "hotmail",
637
- "house",
638
- "how",
639
- "hr",
640
- "hsbc",
641
- "ht",
642
- "hu",
643
- "hughes",
644
- "hyatt",
645
- "hyundai",
646
- "ibm",
647
- "icbc",
648
- "ice",
649
- "icu",
650
- "id",
651
- "ie",
652
- "ieee",
653
- "ifm",
654
- "ikano",
655
- "il",
656
- "im",
657
- "imamat",
658
- "imdb",
659
- "immo",
660
- "immobilien",
661
- "in",
662
- "inc",
663
- "industries",
664
- "infiniti",
665
- "info",
666
- "ing",
667
- "ink",
668
- "institute",
669
- "insurance",
670
- "insure",
671
- "int",
672
- "international",
673
- "intuit",
674
- "investments",
675
- "io",
676
- "ipiranga",
677
- "iq",
678
- "ir",
679
- "irish",
680
- "is",
681
- "ismaili",
682
- "ist",
683
- "istanbul",
684
- "it",
685
- "itau",
686
- "itv",
687
- "jaguar",
688
- "java",
689
- "jcb",
690
- "je",
691
- "jeep",
692
- "jetzt",
693
- "jewelry",
694
- "jio",
695
- "jll",
696
- "jm",
697
- "jmp",
698
- "jnj",
699
- "jo",
700
- "jobs",
701
- "joburg",
702
- "jot",
703
- "joy",
704
- "jp",
705
- "jpmorgan",
706
- "jprs",
707
- "juegos",
708
- "juniper",
709
- "kaufen",
710
- "kddi",
711
- "ke",
712
- "kerryhotels",
713
- "kerrylogistics",
714
- "kerryproperties",
715
- "kfh",
716
- "kg",
717
- "kh",
718
- "ki",
719
- "kia",
720
- "kids",
721
- "kim",
722
- "kinder",
723
- "kindle",
724
- "kitchen",
725
- "kiwi",
726
- "km",
727
- "kn",
728
- "koeln",
729
- "komatsu",
730
- "kosher",
731
- "kp",
732
- "kpmg",
733
- "kpn",
734
- "kr",
735
- "krd",
736
- "kred",
737
- "kuokgroup",
738
- "kw",
739
- "ky",
740
- "kyoto",
741
- "kz",
742
- "la",
743
- "lacaixa",
744
- "lamborghini",
745
- "lamer",
746
- "lancaster",
747
- "lancia",
748
- "land",
749
- "landrover",
750
- "lanxess",
751
- "lasalle",
752
- "lat",
753
- "latino",
754
- "latrobe",
755
- "law",
756
- "lawyer",
757
- "lb",
758
- "lc",
759
- "lds",
760
- "lease",
761
- "leclerc",
762
- "lefrak",
763
- "legal",
764
- "lego",
765
- "lexus",
766
- "lgbt",
767
- "li",
768
- "lidl",
769
- "life",
770
- "lifeinsurance",
771
- "lifestyle",
772
- "lighting",
773
- "like",
774
- "lilly",
775
- "limited",
776
- "limo",
777
- "lincoln",
778
- "linde",
779
- "link",
780
- "lipsy",
781
- "live",
782
- "living",
783
- "lk",
784
- "llc",
785
- "llp",
786
- "loan",
787
- "loans",
788
- "locker",
789
- "locus",
790
- "loft",
791
- "lol",
792
- "london",
793
- "lotte",
794
- "lotto",
795
- "love",
796
- "lpl",
797
- "lplfinancial",
798
- "lr",
799
- "ls",
800
- "lt",
801
- "ltd",
802
- "ltda",
803
- "lu",
804
- "lundbeck",
805
- "luxe",
806
- "luxury",
807
- "lv",
808
- "ly",
809
- "ma",
810
- "macys",
811
- "madrid",
812
- "maif",
813
- "maison",
814
- "makeup",
815
- "man",
816
- "management",
817
- "mango",
818
- "map",
819
- "market",
820
- "marketing",
821
- "markets",
822
- "marriott",
823
- "marshalls",
824
- "maserati",
825
- "mattel",
826
- "mba",
827
- "mc",
828
- "mckinsey",
829
- "md",
830
- "me",
831
- "med",
832
- "media",
833
- "meet",
834
- "melbourne",
835
- "meme",
836
- "memorial",
837
- "men",
838
- "menu",
839
- "merckmsd",
840
- "mg",
841
- "mh",
842
- "miami",
843
- "microsoft",
844
- "mil",
845
- "mini",
846
- "mint",
847
- "mit",
848
- "mitsubishi",
849
- "mk",
850
- "ml",
851
- "mlb",
852
- "mls",
853
- "mm",
854
- "mma",
855
- "mn",
856
- "mo",
857
- "mobi",
858
- "mobile",
859
- "moda",
860
- "moe",
861
- "moi",
862
- "mom",
863
- "monash",
864
- "money",
865
- "monster",
866
- "mormon",
867
- "mortgage",
868
- "moscow",
869
- "moto",
870
- "motorcycles",
871
- "mov",
872
- "movie",
873
- "mp",
874
- "mq",
875
- "mr",
876
- "ms",
877
- "msd",
878
- "mt",
879
- "mtn",
880
- "mtr",
881
- "mu",
882
- "museum",
883
- "music",
884
- "mutual",
885
- "mv",
886
- "mw",
887
- "mx",
888
- "my",
889
- "mz",
890
- "na",
891
- "nab",
892
- "nagoya",
893
- "name",
894
- "natura",
895
- "navy",
896
- "nba",
897
- "nc",
898
- "ne",
899
- "nec",
900
- "net",
901
- "netbank",
902
- "netflix",
903
- "network",
904
- "neustar",
905
- "new",
906
- "news",
907
- "next",
908
- "nextdirect",
909
- "nexus",
910
- "nf",
911
- "nfl",
912
- "ng",
913
- "ngo",
914
- "nhk",
915
- "ni",
916
- "nico",
917
- "nike",
918
- "nikon",
919
- "ninja",
920
- "nissan",
921
- "nissay",
922
- "nl",
923
- "no",
924
- "nokia",
925
- "northwesternmutual",
926
- "norton",
927
- "now",
928
- "nowruz",
929
- "nowtv",
930
- "np",
931
- "nr",
932
- "nra",
933
- "nrw",
934
- "ntt",
935
- "nu",
936
- "nyc",
937
- "nz",
938
- "obi",
939
- "observer",
940
- "office",
941
- "okinawa",
942
- "olayan",
943
- "olayangroup",
944
- "oldnavy",
945
- "ollo",
946
- "om",
947
- "omega",
948
- "one",
949
- "ong",
950
- "onl",
951
- "online",
952
- "ooo",
953
- "open",
954
- "oracle",
955
- "orange",
956
- "org",
957
- "organic",
958
- "origins",
959
- "osaka",
960
- "otsuka",
961
- "ott",
962
- "ovh",
963
- "pa",
964
- "page",
965
- "panasonic",
966
- "paris",
967
- "pars",
968
- "partners",
969
- "parts",
970
- "party",
971
- "passagens",
972
- "pay",
973
- "pccw",
974
- "pe",
975
- "pet",
976
- "pf",
977
- "pfizer",
978
- "pg",
979
- "ph",
980
- "pharmacy",
981
- "phd",
982
- "philips",
983
- "phone",
984
- "photo",
985
- "photography",
986
- "photos",
987
- "physio",
988
- "pics",
989
- "pictet",
990
- "pictures",
991
- "pid",
992
- "pin",
993
- "ping",
994
- "pink",
995
- "pioneer",
996
- "pizza",
997
- "pk",
998
- "pl",
999
- "place",
1000
- "play",
1001
- "playstation",
1002
- "plumbing",
1003
- "plus",
1004
- "pm",
1005
- "pn",
1006
- "pnc",
1007
- "pohl",
1008
- "poker",
1009
- "politie",
1010
- "porn",
1011
- "post",
1012
- "pr",
1013
- "pramerica",
1014
- "praxi",
1015
- "press",
1016
- "prime",
1017
- "pro",
1018
- "prod",
1019
- "productions",
1020
- "prof",
1021
- "progressive",
1022
- "promo",
1023
- "properties",
1024
- "property",
1025
- "protection",
1026
- "pru",
1027
- "prudential",
1028
- "ps",
1029
- "pt",
1030
- "pub",
1031
- "pw",
1032
- "pwc",
1033
- "py",
1034
- "qa",
1035
- "qpon",
1036
- "quebec",
1037
- "quest",
1038
- "racing",
1039
- "radio",
1040
- "re",
1041
- "read",
1042
- "realestate",
1043
- "realtor",
1044
- "realty",
1045
- "recipes",
1046
- "red",
1047
- "redstone",
1048
- "redumbrella",
1049
- "rehab",
1050
- "reise",
1051
- "reisen",
1052
- "reit",
1053
- "reliance",
1054
- "ren",
1055
- "rent",
1056
- "rentals",
1057
- "repair",
1058
- "report",
1059
- "republican",
1060
- "rest",
1061
- "restaurant",
1062
- "review",
1063
- "reviews",
1064
- "rexroth",
1065
- "rich",
1066
- "richardli",
1067
- "ricoh",
1068
- "ril",
1069
- "rio",
1070
- "rip",
1071
- "ro",
1072
- "rocher",
1073
- "rocks",
1074
- "rodeo",
1075
- "rogers",
1076
- "room",
1077
- "rs",
1078
- "rsvp",
1079
- "ru",
1080
- "rugby",
1081
- "ruhr",
1082
- "run",
1083
- "rw",
1084
- "rwe",
1085
- "ryukyu",
1086
- "sa",
1087
- "saarland",
1088
- "safe",
1089
- "safety",
1090
- "sakura",
1091
- "sale",
1092
- "salon",
1093
- "samsclub",
1094
- "samsung",
1095
- "sandvik",
1096
- "sandvikcoromant",
1097
- "sanofi",
1098
- "sap",
1099
- "sarl",
1100
- "sas",
1101
- "save",
1102
- "saxo",
1103
- "sb",
1104
- "sbi",
1105
- "sbs",
1106
- "sc",
1107
- "sca",
1108
- "scb",
1109
- "schaeffler",
1110
- "schmidt",
1111
- "scholarships",
1112
- "school",
1113
- "schule",
1114
- "schwarz",
1115
- "science",
1116
- "scot",
1117
- "sd",
1118
- "se",
1119
- "search",
1120
- "seat",
1121
- "secure",
1122
- "security",
1123
- "seek",
1124
- "select",
1125
- "sener",
1126
- "services",
1127
- "ses",
1128
- "seven",
1129
- "sew",
1130
- "sex",
1131
- "sexy",
1132
- "sfr",
1133
- "sg",
1134
- "sh",
1135
- "shangrila",
1136
- "sharp",
1137
- "shaw",
1138
- "shell",
1139
- "shia",
1140
- "shiksha",
1141
- "shoes",
1142
- "shop",
1143
- "shopping",
1144
- "shouji",
1145
- "show",
1146
- "showtime",
1147
- "si",
1148
- "silk",
1149
- "sina",
1150
- "singles",
1151
- "site",
1152
- "sj",
1153
- "sk",
1154
- "ski",
1155
- "skin",
1156
- "sky",
1157
- "skype",
1158
- "sl",
1159
- "sling",
1160
- "sm",
1161
- "smart",
1162
- "smile",
1163
- "sn",
1164
- "sncf",
1165
- "so",
1166
- "soccer",
1167
- "social",
1168
- "softbank",
1169
- "software",
1170
- "sohu",
1171
- "solar",
1172
- "solutions",
1173
- "song",
1174
- "sony",
1175
- "soy",
1176
- "spa",
1177
- "space",
1178
- "sport",
1179
- "spot",
1180
- "sr",
1181
- "srl",
1182
- "ss",
1183
- "st",
1184
- "stada",
1185
- "staples",
1186
- "star",
1187
- "statebank",
1188
- "statefarm",
1189
- "stc",
1190
- "stcgroup",
1191
- "stockholm",
1192
- "storage",
1193
- "store",
1194
- "stream",
1195
- "studio",
1196
- "study",
1197
- "style",
1198
- "su",
1199
- "sucks",
1200
- "supplies",
1201
- "supply",
1202
- "support",
1203
- "surf",
1204
- "surgery",
1205
- "suzuki",
1206
- "sv",
1207
- "swatch",
1208
- "swiss",
1209
- "sx",
1210
- "sy",
1211
- "sydney",
1212
- "systems",
1213
- "sz",
1214
- "tab",
1215
- "taipei",
1216
- "talk",
1217
- "taobao",
1218
- "target",
1219
- "tatamotors",
1220
- "tatar",
1221
- "tattoo",
1222
- "tax",
1223
- "taxi",
1224
- "tc",
1225
- "tci",
1226
- "td",
1227
- "tdk",
1228
- "team",
1229
- "tech",
1230
- "technology",
1231
- "tel",
1232
- "temasek",
1233
- "tennis",
1234
- "teva",
1235
- "tf",
1236
- "tg",
1237
- "th",
1238
- "thd",
1239
- "theater",
1240
- "theatre",
1241
- "tiaa",
1242
- "tickets",
1243
- "tienda",
1244
- "tiffany",
1245
- "tips",
1246
- "tires",
1247
- "tirol",
1248
- "tj",
1249
- "tjmaxx",
1250
- "tjx",
1251
- "tk",
1252
- "tkmaxx",
1253
- "tl",
1254
- "tm",
1255
- "tmall",
1256
- "tn",
1257
- "to",
1258
- "today",
1259
- "tokyo",
1260
- "tools",
1261
- "top",
1262
- "toray",
1263
- "toshiba",
1264
- "total",
1265
- "tours",
1266
- "town",
1267
- "toyota",
1268
- "toys",
1269
- "tr",
1270
- "trade",
1271
- "trading",
1272
- "training",
1273
- "travel",
1274
- "travelchannel",
1275
- "travelers",
1276
- "travelersinsurance",
1277
- "trust",
1278
- "trv",
1279
- "tt",
1280
- "tube",
1281
- "tui",
1282
- "tunes",
1283
- "tushu",
1284
- "tv",
1285
- "tvs",
1286
- "tw",
1287
- "tz",
1288
- "ua",
1289
- "ubank",
1290
- "ubs",
1291
- "ug",
1292
- "uk",
1293
- "unicom",
1294
- "university",
1295
- "uno",
1296
- "uol",
1297
- "ups",
1298
- "us",
1299
- "uy",
1300
- "uz",
1301
- "va",
1302
- "vacations",
1303
- "vana",
1304
- "vanguard",
1305
- "vc",
1306
- "ve",
1307
- "vegas",
1308
- "ventures",
1309
- "verisign",
1310
- "vermögensberater",
1311
- "vermögensberatung",
1312
- "versicherung",
1313
- "vet",
1314
- "vg",
1315
- "vi",
1316
- "viajes",
1317
- "video",
1318
- "vig",
1319
- "viking",
1320
- "villas",
1321
- "vin",
1322
- "vip",
1323
- "virgin",
1324
- "visa",
1325
- "vision",
1326
- "viva",
1327
- "vivo",
1328
- "vlaanderen",
1329
- "vn",
1330
- "vodka",
1331
- "volkswagen",
1332
- "volvo",
1333
- "vote",
1334
- "voting",
1335
- "voto",
1336
- "voyage",
1337
- "vu",
1338
- "vuelos",
1339
- "wales",
1340
- "walmart",
1341
- "walter",
1342
- "wang",
1343
- "wanggou",
1344
- "watch",
1345
- "watches",
1346
- "weather",
1347
- "weatherchannel",
1348
- "webcam",
1349
- "weber",
1350
- "website",
1351
- "wed",
1352
- "wedding",
1353
- "weibo",
1354
- "weir",
1355
- "wf",
1356
- "whoswho",
1357
- "wien",
1358
- "wiki",
1359
- "williamhill",
1360
- "win",
1361
- "windows",
1362
- "wine",
1363
- "winners",
1364
- "wme",
1365
- "wolterskluwer",
1366
- "woodside",
1367
- "work",
1368
- "works",
1369
- "world",
1370
- "wow",
1371
- "ws",
1372
- "wtc",
1373
- "wtf",
1374
- "xbox",
1375
- "xerox",
1376
- "xfinity",
1377
- "xihuan",
1378
- "xin",
1379
- "xxx",
1380
- "xyz",
1381
- "yachts",
1382
- "yahoo",
1383
- "yamaxun",
1384
- "yandex",
1385
- "ye",
1386
- "yodobashi",
1387
- "yoga",
1388
- "yokohama",
1389
- "you",
1390
- "youtube",
1391
- "yt",
1392
- "yun",
1393
- "za",
1394
- "zappos",
1395
- "zara",
1396
- "zero",
1397
- "zip",
1398
- "zm",
1399
- "zone",
1400
- "zuerich",
1401
- "zw",
1402
- "ελ",
1403
- "ευ",
1404
- "бг",
1405
- "бел",
1406
- "дети",
1407
- "ею",
1408
- "католик",
1409
- "ком",
1410
- "мкд",
1411
- "мон",
1412
- "москва",
1413
- "онлайн",
1414
- "орг",
1415
- "рус",
1416
- "рф",
1417
- "сайт",
1418
- "срб",
1419
- "укр",
1420
- "қаз",
1421
- "հայ",
1422
- "ישראל",
1423
- "קום",
1424
- "ابوظبي",
1425
- "اتصالات",
1426
- "ارامكو",
1427
- "الاردن",
1428
- "البحرين",
1429
- "الجزائر",
1430
- "السعودية",
1431
- "العليان",
1432
- "المغرب",
1433
- "امارات",
1434
- "ایران",
1435
- "بارت",
1436
- "بازار",
1437
- "بيتك",
1438
- "بھارت",
1439
- "تونس",
1440
- "سودان",
1441
- "سورية",
1442
- "شبكة",
1443
- "عراق",
1444
- "عرب",
1445
- "عمان",
1446
- "فلسطين",
1447
- "قطر",
1448
- "كاثوليك",
1449
- "كوم",
1450
- "مصر",
1451
- "مليسيا",
1452
- "موريتانيا",
1453
- "موقع",
1454
- "همراه",
1455
- "پاکستان",
1456
- "ڀارت",
1457
- "कॉम",
1458
- "नेट",
1459
- "भारत",
1460
- "भारतम्",
1461
- "भारोत",
1462
- "संगठन",
1463
- "বাংলা",
1464
- "ভারত",
1465
- "ভাৰত",
1466
- "ਭਾਰਤ",
1467
- "ભારત",
1468
- "ଭାରତ",
1469
- "இந்தியா",
1470
- "இலங்கை",
1471
- "சிங்கப்பூர்",
1472
- "భారత్",
1473
- "ಭಾರತ",
1474
- "ഭാരതം",
1475
- "ලංකා",
1476
- "คอม",
1477
- "ไทย",
1478
- "ລາວ",
1479
- "გე",
1480
- "みんな",
1481
- "アマゾン",
1482
- "クラウド",
1483
- "グーグル",
1484
- "コム",
1485
- "ストア",
1486
- "セール",
1487
- "ファッション",
1488
- "ポイント",
1489
- "世界",
1490
- "中信",
1491
- "中国",
1492
- "中國",
1493
- "中文网",
1494
- "亚马逊",
1495
- "企业",
1496
- "佛山",
1497
- "信息",
1498
- "健康",
1499
- "八卦",
1500
- "公司",
1501
- "公益",
1502
- "台湾",
1503
- "台灣",
1504
- "商城",
1505
- "商店",
1506
- "商标",
1507
- "嘉里",
1508
- "嘉里大酒店",
1509
- "在线",
1510
- "大拿",
1511
- "天主教",
1512
- "娱乐",
1513
- "家電",
1514
- "广东",
1515
- "微博",
1516
- "慈善",
1517
- "我爱你",
1518
- "手机",
1519
- "招聘",
1520
- "政务",
1521
- "政府",
1522
- "新加坡",
1523
- "新闻",
1524
- "时尚",
1525
- "書籍",
1526
- "机构",
1527
- "淡马锡",
1528
- "游戏",
1529
- "澳門",
1530
- "点看",
1531
- "移动",
1532
- "组织机构",
1533
- "网址",
1534
- "网店",
1535
- "网站",
1536
- "网络",
1537
- "联通",
1538
- "诺基亚",
1539
- "谷歌",
1540
- "购物",
1541
- "通販",
1542
- "集团",
1543
- "電訊盈科",
1544
- "飞利浦",
1545
- "食品",
1546
- "餐厅",
1547
- "香格里拉",
1548
- "香港",
1549
- "닷넷",
1550
- "닷컴",
1551
- "삼성",
1552
- "한국",
1553
- ];
1554
-
1555
- function getDomain(inputUrl) {
1556
- const parsed = url.parse(inputUrl).host;
1557
- var parts = parsed.split('.');
1558
- if (parts[0] === 'www' && parts[1] !== 'com') {
1559
- parts.shift();
1560
- }
1561
- var ln = parts.length, i = ln, minLength = parts[parts.length - 1].length, part;
1562
- // iterate backwards
1563
- while ((part = parts[--i])) {
1564
- // stop when we find a non-TLD part
1565
- if (i === 0 || // 'asia.com' (last remaining must be the SLD)
1566
- i < ln - 2 || // TLDs only span 2 levels
1567
- part.length < minLength || // 'www.cn.com' (valid TLD as second-level domain)
1568
- tlds.indexOf(part) < 0 // officialy not a TLD
1569
- ) {
1570
- return part;
1571
- }
1572
- }
1573
- }
1574
- function appendProtocol(inputUrl) {
1575
- const parsed = url.parse(inputUrl);
1576
- if (!parsed.protocol) {
1577
- const urlWithProtocol = `https://${inputUrl}`;
1578
- return urlWithProtocol;
1579
- }
1580
- return inputUrl;
1581
- }
1582
- function normalizeUrl(urlToNormalize) {
1583
- const urlWithProtocol = appendProtocol(urlToNormalize);
1584
- if (isurl(urlWithProtocol)) {
1585
- return urlWithProtocol;
1586
- }
1587
- else {
1588
- throw new Error(`Your url "${urlWithProtocol}" is invalid`);
1589
- }
1590
- }
1591
-
1592
- function validateNumberInput(value) {
1593
- const parsedValue = Number(value);
1594
- if (isNaN(parsedValue)) {
1595
- throw new Commander.InvalidArgumentError('Not a number.');
1596
- }
1597
- return parsedValue;
1598
- }
1599
- function validateUrlInput(url) {
1600
- if (!fs.existsSync(url)) {
1601
- try {
1602
- return normalizeUrl(url);
1603
- }
1604
- catch (error) {
1605
- throw new Commander.InvalidArgumentError(error.message);
1606
- }
1607
- }
1608
- else {
1609
- return url;
1610
- }
1611
- }
1612
-
1613
- const npmDirectory = path.join(path.dirname(fileURLToPath(import.meta.url)), '..');
1614
-
1615
- const logger = {
1616
- info(...msg) {
1617
- log.info(...msg.map((m) => chalk.blue.bold(m)));
1618
- },
1619
- debug(...msg) {
1620
- log.debug(...msg);
1621
- },
1622
- error(...msg) {
1623
- log.error(...msg.map((m) => chalk.red.bold(m)));
1624
- },
1625
- warn(...msg) {
1626
- log.info(...msg.map((m) => chalk.yellow.bold(m)));
1627
- },
1628
- success(...msg) {
1629
- log.info(...msg.map((m) => chalk.green.bold(m)));
1630
- }
22
+ const logger = {
23
+ info(...msg) {
24
+ log.info(...msg.map((m) => chalk.blue.bold(m)));
25
+ },
26
+ debug(...msg) {
27
+ log.debug(...msg);
28
+ },
29
+ error(...msg) {
30
+ log.error(...msg.map((m) => chalk.red.bold(m)));
31
+ },
32
+ warn(...msg) {
33
+ log.info(...msg.map((m) => chalk.yellow.bold(m)));
34
+ },
35
+ success(...msg) {
36
+ log.info(...msg.map((m) => chalk.green.bold(m)));
37
+ }
1631
38
  };
1632
39
 
1633
- function promptText(message, initial) {
1634
- return __awaiter(this, void 0, void 0, function* () {
1635
- const response = yield prompts({
1636
- type: 'text',
1637
- name: 'content',
1638
- message,
1639
- initial,
1640
- });
1641
- return response.content;
1642
- });
1643
- }
1644
- function setSecurityConfigWithUrl(tauriConfig, url) {
1645
- const myURL = new URL(url);
1646
- const hostname = myURL.hostname;
1647
- tauriConfig.tauri.security.dangerousRemoteDomainIpcAccess[0].domain = hostname;
1648
- }
1649
- function mergeTauriConfig(url, options, tauriConf) {
1650
- return __awaiter(this, void 0, void 0, function* () {
1651
- const { width, height, fullscreen, transparent, resizable, userAgent, showMenu, showSystemTray, systemTrayIcon, iterCopyFile, identifier, name, } = options;
1652
- const tauriConfWindowOptions = {
1653
- width,
1654
- height,
1655
- fullscreen,
1656
- transparent,
1657
- resizable,
1658
- };
1659
- // Package name is valid ?
1660
- // for Linux, package name must be a-z, 0-9 or "-", not allow to A-Z and other
1661
- if (process.platform === "linux") {
1662
- const reg = new RegExp(/[0-9]*[a-z]+[0-9]*\-?[0-9]*[a-z]*[0-9]*\-?[0-9]*[a-z]*[0-9]*/);
1663
- if (!reg.test(name) || reg.exec(name)[0].length != name.length) {
1664
- logger.error("package name is illegal, it must be lowercase letters, numbers, dashes, and it must contain the lowercase letters.");
1665
- logger.error("E.g com-123-xxx, 123pan, pan123,weread, we-read");
1666
- process.exit();
1667
- }
1668
- }
1669
- if (process.platform === "win32" || process.platform === "darwin") {
1670
- const reg = new RegExp(/([0-9]*[a-zA-Z]+[0-9]*)+/);
1671
- if (!reg.test(name) || reg.exec(name)[0].length != name.length) {
1672
- logger.error("package name is illegal, it must be letters, numbers, and it must contain the letters");
1673
- logger.error("E.g 123pan,123Pan Pan123,weread, WeRead, WERead");
1674
- process.exit();
1675
- }
1676
- }
1677
- // logger.warn(JSON.stringify(tauriConf.pake.windows, null, 4));
1678
- Object.assign(tauriConf.pake.windows[0], Object.assign({ url }, tauriConfWindowOptions));
1679
- tauriConf.package.productName = name;
1680
- tauriConf.tauri.bundle.identifier = identifier;
1681
- // 判断一下url类型,是文件还是网站
1682
- // 如果是文件,并且开启了递归拷贝功能,则需要将该文件以及所在文件夹下的所有文件拷贝到src目录下,否则只拷贝单个文件。
1683
- const url_exists = yield fs$1.stat(url)
1684
- .then(() => true)
1685
- .catch(() => false);
1686
- if (url_exists) {
1687
- logger.warn("you input may a local file");
1688
- tauriConf.pake.windows[0].url_type = "local";
1689
- const file_name = path.basename(url);
1690
- const dir_name = path.dirname(url);
1691
- if (!iterCopyFile) {
1692
- const url_path = path.join(npmDirectory, "dist/", file_name);
1693
- yield fs$1.copyFile(url, url_path);
1694
- }
1695
- else {
1696
- const old_dir = path.join(npmDirectory, "dist/");
1697
- const new_dir = path.join(npmDirectory, "dist_bak/");
1698
- fs2.moveSync(old_dir, new_dir, { "overwrite": true });
1699
- fs2.copySync(dir_name, old_dir, { "overwrite": true });
1700
- // logger.warn("dir name", dir_name);
1701
- // 将dist_bak里面的cli.js和about_pake.html拷贝回去
1702
- const cli_path = path.join(new_dir, "cli.js");
1703
- const cli_path_target = path.join(old_dir, "cli.js");
1704
- const about_pake_path = path.join(new_dir, "about_pake.html");
1705
- const about_pake_path_target = path.join(old_dir, "about_pake.html");
1706
- fs$1.copyFile(cli_path, cli_path_target);
1707
- fs$1.copyFile(about_pake_path, about_pake_path_target);
1708
- }
1709
- tauriConf.pake.windows[0].url = file_name;
1710
- tauriConf.pake.windows[0].url_type = "local";
1711
- }
1712
- else {
1713
- tauriConf.pake.windows[0].url_type = "web";
1714
- }
1715
- // 处理user-agent
1716
- if (userAgent.length > 0) {
1717
- if (process.platform === "win32") {
1718
- tauriConf.pake.user_agent.windows = userAgent;
1719
- }
1720
- if (process.platform === "linux") {
1721
- tauriConf.pake.user_agent.linux = userAgent;
1722
- }
1723
- if (process.platform === "darwin") {
1724
- tauriConf.pake.user_agent.macos = userAgent;
1725
- }
1726
- }
1727
- // 处理菜单栏
1728
- if (showMenu) {
1729
- if (process.platform === "win32") {
1730
- tauriConf.pake.menu.windows = true;
1731
- }
1732
- if (process.platform === "linux") {
1733
- tauriConf.pake.menu.linux = true;
1734
- }
1735
- if (process.platform === "darwin") {
1736
- tauriConf.pake.menu.macos = true;
1737
- }
1738
- }
1739
- else {
1740
- if (process.platform === "win32") {
1741
- tauriConf.pake.menu.windows = false;
1742
- }
1743
- if (process.platform === "linux") {
1744
- tauriConf.pake.menu.linux = false;
1745
- }
1746
- if (process.platform === "darwin") {
1747
- tauriConf.pake.menu.macos = false;
1748
- }
1749
- }
1750
- // 处理托盘
1751
- if (showSystemTray) {
1752
- if (process.platform === "win32") {
1753
- tauriConf.pake.system_tray.windows = true;
1754
- }
1755
- if (process.platform === "linux") {
1756
- tauriConf.pake.system_tray.linux = true;
1757
- }
1758
- if (process.platform === "darwin") {
1759
- tauriConf.pake.system_tray.macos = true;
1760
- }
1761
- }
1762
- else {
1763
- if (process.platform === "win32") {
1764
- tauriConf.pake.system_tray.windows = false;
1765
- }
1766
- if (process.platform === "linux") {
1767
- tauriConf.pake.system_tray.linux = false;
1768
- }
1769
- if (process.platform === "darwin") {
1770
- tauriConf.pake.system_tray.macos = false;
1771
- }
1772
- }
1773
- // 处理targets 暂时只对linux开放
1774
- if (process.platform === "linux") {
1775
- delete tauriConf.tauri.bundle.deb.files;
1776
- if (["all", "deb", "appimage"].includes(options.targets)) {
1777
- if (options.targets === "all") {
1778
- tauriConf.tauri.bundle.targets = ["deb", "appimage"];
1779
- }
1780
- else {
1781
- tauriConf.tauri.bundle.targets = [options.targets];
1782
- }
1783
- }
1784
- else {
1785
- logger.warn("targets must be 'all', 'deb', 'appimage', we will use default 'all'");
1786
- }
1787
- }
1788
- // 处理应用图标
1789
- const exists = yield fs$1.stat(options.icon)
1790
- .then(() => true)
1791
- .catch(() => false);
1792
- if (exists) {
1793
- let updateIconPath = true;
1794
- let customIconExt = path.extname(options.icon).toLowerCase();
1795
- if (process.platform === "win32") {
1796
- if (customIconExt === ".ico") {
1797
- const ico_path = path.join(npmDirectory, `src-tauri/png/${name.toLowerCase()}_32.ico`);
1798
- tauriConf.tauri.bundle.resources = [`png/${name.toLowerCase()}_32.ico`];
1799
- yield fs$1.copyFile(options.icon, ico_path);
1800
- }
1801
- else {
1802
- updateIconPath = false;
1803
- logger.warn(`icon file in Windows must be 256 * 256 pix with .ico type, but you give ${customIconExt}`);
1804
- tauriConf.tauri.bundle.icon = ["png/icon_256.ico"];
1805
- }
1806
- }
1807
- if (process.platform === "linux") {
1808
- if (customIconExt != ".png") {
1809
- updateIconPath = false;
1810
- logger.warn(`icon file in Linux must be 512 * 512 pix with .png type, but you give ${customIconExt}`);
1811
- tauriConf.tauri.bundle.icon = ["png/icon_512.png"];
1812
- }
1813
- }
1814
- if (process.platform === "darwin" && customIconExt !== ".icns") {
1815
- updateIconPath = false;
1816
- logger.warn(`icon file in MacOS must be .icns type, but you give ${customIconExt}`);
1817
- tauriConf.tauri.bundle.icon = ["icons/icon.icns"];
1818
- }
1819
- if (updateIconPath) {
1820
- tauriConf.tauri.bundle.icon = [options.icon];
1821
- }
1822
- else {
1823
- logger.warn(`icon file will not change with default.`);
1824
- }
1825
- }
1826
- else {
1827
- logger.warn("the custom icon path may not exists. we will use default icon to replace it");
1828
- if (process.platform === "win32") {
1829
- tauriConf.tauri.bundle.icon = ["png/icon_256.ico"];
1830
- }
1831
- if (process.platform === "linux") {
1832
- tauriConf.tauri.bundle.icon = ["png/icon_512.png"];
1833
- }
1834
- if (process.platform === "darwin") {
1835
- tauriConf.tauri.bundle.icon = ["icons/icon.icns"];
1836
- }
1837
- }
1838
- // 处理托盘自定义图标
1839
- let useDefaultIcon = true; // 是否使用默认托盘图标
1840
- if (systemTrayIcon.length > 0) {
1841
- const icon_exists = yield fs$1.stat(systemTrayIcon)
1842
- .then(() => true)
1843
- .catch(() => false);
1844
- if (icon_exists) {
1845
- // 需要判断图标格式,默认只支持ico和png两种
1846
- let iconExt = path.extname(systemTrayIcon).toLowerCase();
1847
- if (iconExt == ".png" || iconExt == ".ico") {
1848
- useDefaultIcon = false;
1849
- const trayIcoPath = path.join(npmDirectory, `src-tauri/png/${name.toLowerCase()}${iconExt}`);
1850
- tauriConf.tauri.systemTray.iconPath = `png/${name.toLowerCase()}${iconExt}`;
1851
- yield fs$1.copyFile(systemTrayIcon, trayIcoPath);
1852
- }
1853
- else {
1854
- logger.warn(`file type for system tray icon mut be .ico or .png , but you give ${iconExt}`);
1855
- logger.warn(`system tray icon file will not change with default.`);
1856
- }
1857
- }
1858
- else {
1859
- logger.warn(`${systemTrayIcon} not exists!`);
1860
- logger.warn(`system tray icon file will not change with default.`);
1861
- }
1862
- }
1863
- // 处理托盘默认图标
1864
- if (useDefaultIcon) {
1865
- if (process.platform === "linux" || process.platform === "win32") {
1866
- tauriConf.tauri.systemTray.iconPath = tauriConf.tauri.bundle.icon[0];
1867
- }
1868
- else {
1869
- tauriConf.tauri.systemTray.iconPath = "png/icon_512.png";
1870
- }
1871
- }
1872
- // 设置安全调用 window.__TAURI__ 的安全域名为设置的应用域名
1873
- setSecurityConfigWithUrl(tauriConf, url);
1874
- // 保存配置文件
1875
- let configPath = "";
1876
- switch (process.platform) {
1877
- case "win32": {
1878
- configPath = path.join(npmDirectory, 'src-tauri/tauri.windows.conf.json');
1879
- break;
1880
- }
1881
- case "darwin": {
1882
- configPath = path.join(npmDirectory, 'src-tauri/tauri.macos.conf.json');
1883
- break;
1884
- }
1885
- case "linux": {
1886
- configPath = path.join(npmDirectory, 'src-tauri/tauri.linux.conf.json');
1887
- break;
1888
- }
1889
- }
1890
- let bundleConf = { tauri: { bundle: tauriConf.tauri.bundle } };
1891
- yield fs$1.writeFile(configPath, Buffer.from(JSON.stringify(bundleConf, null, 4), 'utf-8'));
1892
- const pakeConfigPath = path.join(npmDirectory, 'src-tauri/pake.json');
1893
- yield fs$1.writeFile(pakeConfigPath, Buffer.from(JSON.stringify(tauriConf.pake, null, 4), 'utf-8'));
1894
- // logger.info("tauri config", JSON.stringify(tauriConf.build));
1895
- let tauriConf2 = JSON.parse(JSON.stringify(tauriConf));
1896
- delete tauriConf2.pake;
1897
- delete tauriConf2.tauri.bundle;
1898
- const configJsonPath = path.join(npmDirectory, 'src-tauri/tauri.conf.json');
1899
- yield fs$1.writeFile(configJsonPath, Buffer.from(JSON.stringify(tauriConf2, null, 4), 'utf-8'));
1900
- });
1901
- }
1902
-
1903
- function getIdentifier(name, url) {
1904
- const hash = crypto.createHash('md5');
1905
- hash.update(url);
1906
- const postFixHash = hash.digest('hex').substring(0, 6);
1907
- return `pake-${postFixHash}`;
1908
- }
40
+ // Convert the current module URL to a file path
41
+ const currentModulePath = fileURLToPath(import.meta.url);
42
+ // Resolve the parent directory of the current module
43
+ const npmDirectory = path.join(path.dirname(currentModulePath), '..');
1909
44
 
1910
- const IS_MAC = process.platform === 'darwin';
1911
- const IS_WIN = process.platform === 'win32';
1912
- const IS_LINUX = process.platform === 'linux';
45
+ const { platform: platform$1 } = process;
46
+ const IS_MAC = platform$1 === 'darwin';
47
+ const IS_WIN = platform$1 === 'win32';
48
+ const IS_LINUX = platform$1 === 'linux';
1913
49
 
1914
- function handleIcon(options, url) {
1915
- return __awaiter(this, void 0, void 0, function* () {
1916
- if (options.icon) {
1917
- if (options.icon.startsWith('http')) {
1918
- return downloadIcon(options.icon);
1919
- }
1920
- else {
1921
- return path.resolve(options.icon);
1922
- }
1923
- }
1924
- if (!options.icon) {
1925
- return getDefaultIcon();
1926
- }
1927
- });
1928
- }
1929
- function getDefaultIcon() {
1930
- return __awaiter(this, void 0, void 0, function* () {
1931
- logger.info('You have not provided an app icon, use the default icon.(use --icon option to assign an icon)');
1932
- let iconPath = 'src-tauri/icons/icon.icns';
1933
- if (IS_WIN) {
1934
- iconPath = 'src-tauri/png/icon_256.ico';
1935
- }
1936
- else if (IS_LINUX) {
1937
- iconPath = 'src-tauri/png/icon_512.png';
1938
- }
1939
- return path.join(npmDirectory, iconPath);
1940
- });
1941
- }
1942
- // export async function getIconFromPageUrl(url: string) {
1943
- // const icon = await pageIcon(url);
1944
- // console.log(icon);
1945
- // if (icon.ext === '.ico') {
1946
- // const a = await ICO.parse(icon.data);
1947
- // icon.data = Buffer.from(a[0].buffer);
1948
- // }
1949
- // const iconDir = (await dir()).path;
1950
- // const iconPath = path.join(iconDir, `/icon.icns`);
1951
- // const out = png2icons.createICNS(icon.data, png2icons.BILINEAR, 0);
1952
- // await fs.writeFile(iconPath, out);
1953
- // return iconPath;
1954
- // }
1955
- // export async function getIconFromMacosIcons(name: string) {
1956
- // const data = {
1957
- // query: name,
1958
- // filters: 'approved:true',
1959
- // hitsPerPage: 10,
1960
- // page: 1,
1961
- // };
1962
- // const res = await axios.post('https://p1txh7zfb3-2.algolianet.com/1/indexes/macOSicons/query?x-algolia-agent=Algolia%20for%20JavaScript%20(4.13.1)%3B%20Browser', data, {
1963
- // headers: {
1964
- // 'x-algolia-api-key': '0ba04276e457028f3e11e38696eab32c',
1965
- // 'x-algolia-application-id': 'P1TXH7ZFB3',
1966
- // },
1967
- // });
1968
- // if (!res.data.hits.length) {
1969
- // return '';
1970
- // } else {
1971
- // return downloadIcon(res.data.hits[0].icnsUrl);
1972
- // }
1973
- // }
1974
- function downloadIcon(iconUrl) {
1975
- return __awaiter(this, void 0, void 0, function* () {
1976
- let iconResponse;
1977
- try {
1978
- iconResponse = yield axios.get(iconUrl, {
1979
- responseType: 'arraybuffer',
1980
- });
1981
- }
1982
- catch (error) {
1983
- if (error.response && error.response.status === 404) {
1984
- return null;
1985
- }
1986
- throw error;
1987
- }
1988
- const iconData = yield iconResponse.data;
1989
- if (!iconData) {
1990
- return null;
1991
- }
1992
- const fileDetails = yield fileTypeFromBuffer(iconData);
1993
- if (!fileDetails) {
1994
- return null;
1995
- }
1996
- const { path } = yield dir();
1997
- const iconPath = `${path}/icon.${fileDetails.ext}`;
1998
- yield fs$1.writeFile(iconPath, iconData);
1999
- return iconPath;
2000
- });
50
+ async function handleIcon(options) {
51
+ if (options.icon) {
52
+ if (options.icon.startsWith('http')) {
53
+ return downloadIcon(options.icon);
54
+ }
55
+ else {
56
+ return path.resolve(options.icon);
57
+ }
58
+ }
59
+ else {
60
+ logger.info('No app icon provided, default icon used. Use --icon option to assign an icon.');
61
+ const iconPath = IS_WIN ? 'src-tauri/png/icon_256.ico' : IS_LINUX ? 'src-tauri/png/icon_512.png' : 'src-tauri/icons/icon.icns';
62
+ return path.join(npmDirectory, iconPath);
63
+ }
64
+ }
65
+ async function downloadIcon(iconUrl) {
66
+ try {
67
+ const iconResponse = await axios.get(iconUrl, {
68
+ responseType: 'arraybuffer',
69
+ });
70
+ const iconData = await iconResponse.data;
71
+ if (!iconData) {
72
+ return null;
73
+ }
74
+ const fileDetails = await fileTypeFromBuffer(iconData);
75
+ if (!fileDetails) {
76
+ return null;
77
+ }
78
+ const { path: tempPath } = await dir();
79
+ const iconPath = `${tempPath}/icon.${fileDetails.ext}`;
80
+ await fsExtra.outputFile(iconPath, iconData);
81
+ return iconPath;
82
+ }
83
+ catch (error) {
84
+ if (error.response && error.response.status === 404) {
85
+ return null;
86
+ }
87
+ throw error;
88
+ }
2001
89
  }
2002
90
 
2003
- function handleOptions(options, url) {
2004
- return __awaiter(this, void 0, void 0, function* () {
2005
- const appOptions = Object.assign(Object.assign({}, options), { identifier: '' });
2006
- const url_exists = yield fs$1.stat(url)
2007
- .then(() => true)
2008
- .catch(() => false);
2009
- if (!appOptions.name) {
2010
- if (!url_exists) {
2011
- appOptions.name = yield promptText('please input your application name', getDomain(url));
2012
- }
2013
- else {
2014
- appOptions.name = yield promptText('please input your application name', "");
2015
- }
2016
- }
2017
- appOptions.identifier = getIdentifier(appOptions.name, url);
2018
- appOptions.icon = yield handleIcon(appOptions);
2019
- return appOptions;
2020
- });
91
+ // Extracts the domain from a given URL.
92
+ function getDomain(inputUrl) {
93
+ try {
94
+ const url = new URL(inputUrl);
95
+ // Use PSL to parse domain names.
96
+ const parsed = psl.parse(url.hostname);
97
+ // If domain is available, split it and return the SLD.
98
+ if ("domain" in parsed && parsed.domain) {
99
+ return parsed.domain.split('.')[0];
100
+ }
101
+ else {
102
+ return null;
103
+ }
104
+ }
105
+ catch (error) {
106
+ return null;
107
+ }
108
+ }
109
+ // Appends 'https://' protocol to the URL if not present.
110
+ function appendProtocol(inputUrl) {
111
+ try {
112
+ new URL(inputUrl);
113
+ return inputUrl;
114
+ }
115
+ catch {
116
+ return `https://${inputUrl}`;
117
+ }
118
+ }
119
+ // Normalizes the URL by ensuring it has a protocol and is valid.
120
+ function normalizeUrl(urlToNormalize) {
121
+ const urlWithProtocol = appendProtocol(urlToNormalize);
122
+ if (isUrl(urlWithProtocol)) {
123
+ return urlWithProtocol;
124
+ }
125
+ else {
126
+ throw new Error(`Your url "${urlWithProtocol}" is invalid`);
127
+ }
2021
128
  }
2022
129
 
2023
- function shellExec(command) {
2024
- return new Promise((resolve, reject) => {
2025
- shelljs.exec(command, { async: true, silent: false, cwd: npmDirectory }, (code) => {
2026
- if (code === 0) {
2027
- resolve(0);
2028
- }
2029
- else {
2030
- reject(new Error(`${code}`));
2031
- }
2032
- });
2033
- });
130
+ // Generates an identifier based on the given URL.
131
+ function getIdentifier(url) {
132
+ const postFixHash = crypto.createHash('md5')
133
+ .update(url)
134
+ .digest('hex')
135
+ .substring(0, 6);
136
+ return `pake-${postFixHash}`;
137
+ }
138
+ async function promptText(message, initial) {
139
+ const response = await prompts({
140
+ type: 'text',
141
+ name: 'content',
142
+ message,
143
+ initial,
144
+ });
145
+ return response.content;
2034
146
  }
2035
147
 
2036
- const ping = (host) => __awaiter(void 0, void 0, void 0, function* () {
2037
- const lookup = promisify(dns.lookup);
2038
- const ip = yield lookup(host);
2039
- const start = new Date();
2040
- return new Promise((resolve, reject) => {
2041
- const req = http.get(`http://${ip.address}`, (res) => {
2042
- const delay = new Date().getTime() - start.getTime();
2043
- res.resume();
2044
- resolve(delay);
2045
- });
2046
- req.on('error', (err) => {
2047
- reject(err);
2048
- });
2049
- });
2050
- });
2051
- const resolve = promisify(dns.resolve);
2052
- function isChinaDomain(domain) {
2053
- return __awaiter(this, void 0, void 0, function* () {
2054
- try {
2055
- // 解析域名为IP地址
2056
- const [ip] = yield resolve(domain);
2057
- return yield isChinaIP(ip, domain);
2058
- }
2059
- catch (error) {
2060
- // 域名无法解析,返回false
2061
- logger.info(`${domain} can't be parse!`);
2062
- return false;
2063
- }
2064
- });
2065
- }
2066
- function isChinaIP(ip, domain) {
2067
- return __awaiter(this, void 0, void 0, function* () {
2068
- try {
2069
- const delay = yield ping(ip);
2070
- logger.info(`${domain} latency is ${delay} ms`);
2071
- // 判断延迟是否超过500ms
2072
- return delay > 500;
2073
- }
2074
- catch (error) {
2075
- // 命令执行出错,返回false
2076
- logger.info(`ping ${domain} failed!`);
2077
- return false;
2078
- }
2079
- });
148
+ async function handleOptions(options, url) {
149
+ const appOptions = {
150
+ ...options,
151
+ identifier: getIdentifier(url),
152
+ };
153
+ let urlExists = await fsExtra.pathExists(url);
154
+ if (!appOptions.name) {
155
+ const defaultName = urlExists ? "" : getDomain(url);
156
+ const promptMessage = 'Enter your application name';
157
+ appOptions.name = await promptText(promptMessage, defaultName);
158
+ }
159
+ appOptions.icon = await handleIcon(appOptions);
160
+ return appOptions;
2080
161
  }
2081
162
 
2082
- function installRust() {
2083
- return __awaiter(this, void 0, void 0, function* () {
2084
- const is_china = yield isChinaDomain("sh.rustup.rs");
2085
- let RustInstallScriptFocMac = "";
2086
- if (is_china) {
2087
- logger.info("it's in China, use rust cn mirror to install rust");
2088
- RustInstallScriptFocMac =
2089
- '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';
2090
- }
2091
- else {
2092
- RustInstallScriptFocMac =
2093
- "curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y";
2094
- }
2095
- const RustInstallScriptForWin = 'winget install --id Rustlang.Rustup';
2096
- const spinner = ora('Downloading Rust').start();
2097
- try {
2098
- yield shellExec(IS_WIN ? RustInstallScriptForWin : RustInstallScriptFocMac);
2099
- spinner.succeed();
2100
- }
2101
- catch (error) {
2102
- console.error('install rust return code', error.message);
2103
- spinner.fail();
2104
- process.exit(1);
2105
- }
2106
- });
2107
- }
2108
- function checkRustInstalled() {
2109
- return shelljs.exec('rustc --version', { silent: true }).code === 0;
2110
- }
163
+ var windows = [
164
+ {
165
+ url: "https://weread.qq.com/",
166
+ transparent: true,
167
+ fullscreen: false,
168
+ width: 1200,
169
+ height: 780,
170
+ resizable: true,
171
+ url_type: "web"
172
+ }
173
+ ];
174
+ var user_agent = {
175
+ 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",
176
+ linux: "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36",
177
+ windows: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36"
178
+ };
179
+ var menu = {
180
+ macos: true,
181
+ linux: false,
182
+ windows: false
183
+ };
184
+ var system_tray = {
185
+ macos: false,
186
+ linux: true,
187
+ windows: true
188
+ };
189
+ var pakeConf = {
190
+ windows: windows,
191
+ user_agent: user_agent,
192
+ menu: menu,
193
+ system_tray: system_tray
194
+ };
2111
195
 
2112
196
  var tauri$3 = {
2113
197
  security: {
@@ -2155,39 +239,6 @@ var CommonConf = {
2155
239
  build: build
2156
240
  };
2157
241
 
2158
- var windows = [
2159
- {
2160
- url: "https://weread.qq.com/",
2161
- transparent: true,
2162
- fullscreen: false,
2163
- width: 1200,
2164
- height: 780,
2165
- resizable: true,
2166
- url_type: "web"
2167
- }
2168
- ];
2169
- var user_agent = {
2170
- 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",
2171
- linux: "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36",
2172
- windows: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36"
2173
- };
2174
- var menu = {
2175
- macos: true,
2176
- linux: false,
2177
- windows: false
2178
- };
2179
- var system_tray = {
2180
- macos: false,
2181
- linux: true,
2182
- windows: true
2183
- };
2184
- var pakeConf = {
2185
- windows: windows,
2186
- user_agent: user_agent,
2187
- menu: menu,
2188
- system_tray: system_tray
2189
- };
2190
-
2191
242
  var tauri$2 = {
2192
243
  bundle: {
2193
244
  icon: [
@@ -2291,263 +342,399 @@ var LinuxConf = {
2291
342
  tauri: tauri
2292
343
  };
2293
344
 
2294
- let tauriConf = {
2295
- package: CommonConf.package,
2296
- tauri: CommonConf.tauri,
2297
- build: CommonConf.build,
2298
- pake: pakeConf
345
+ const platformConfigs = {
346
+ win32: WinConf,
347
+ darwin: MacConf,
348
+ linux: LinuxConf
349
+ };
350
+ const { platform } = process;
351
+ // @ts-ignore
352
+ const platformConfig = platformConfigs[platform];
353
+ let tauriConfig = {
354
+ tauri: {
355
+ ...CommonConf.tauri,
356
+ bundle: platformConfig.tauri.bundle,
357
+ },
358
+ package: CommonConf.package,
359
+ build: CommonConf.build,
360
+ pake: pakeConf
2299
361
  };
2300
- switch (process.platform) {
2301
- case "win32": {
2302
- tauriConf.tauri.bundle = WinConf.tauri.bundle;
2303
- break;
2304
- }
2305
- case "darwin": {
2306
- tauriConf.tauri.bundle = MacConf.tauri.bundle;
2307
- break;
2308
- }
2309
- case "linux": {
2310
- tauriConf.tauri.bundle = LinuxConf.tauri.bundle;
2311
- break;
2312
- }
362
+
363
+ function shellExec(command) {
364
+ return new Promise((resolve, reject) => {
365
+ shelljs.exec(command, { async: true, silent: false, cwd: npmDirectory }, (code) => {
366
+ if (code === 0) {
367
+ resolve(0);
368
+ }
369
+ else {
370
+ reject(new Error(`${code}`));
371
+ }
372
+ });
373
+ });
374
+ }
375
+
376
+ const resolve = promisify(dns.resolve);
377
+ const ping = async (host) => {
378
+ const lookup = promisify(dns.lookup);
379
+ const ip = await lookup(host);
380
+ const start = new Date();
381
+ return new Promise((resolve, reject) => {
382
+ const req = http.get(`http://${ip.address}`, (res) => {
383
+ const delay = new Date().getTime() - start.getTime();
384
+ res.resume();
385
+ resolve(delay);
386
+ });
387
+ req.on('error', (err) => {
388
+ reject(err);
389
+ });
390
+ });
391
+ };
392
+ async function isChinaDomain(domain) {
393
+ try {
394
+ const [ip] = await resolve(domain);
395
+ return await isChinaIP(ip, domain);
396
+ }
397
+ catch (error) {
398
+ logger.info(`${domain} can't be parse!`);
399
+ return false;
400
+ }
401
+ }
402
+ async function isChinaIP(ip, domain) {
403
+ try {
404
+ const delay = await ping(ip);
405
+ logger.info(`${domain} latency is ${delay} ms`);
406
+ return delay > 500;
407
+ }
408
+ catch (error) {
409
+ logger.info(`ping ${domain} failed!`);
410
+ return false;
411
+ }
412
+ }
413
+
414
+ async function installRust() {
415
+ const isInChina = await isChinaDomain("sh.rustup.rs");
416
+ const rustInstallScriptForMac = isInChina
417
+ ? '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'
418
+ : "curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y";
419
+ const rustInstallScriptForWindows = 'winget install --id Rustlang.Rustup';
420
+ const spinner = ora('Downloading Rust').start();
421
+ try {
422
+ await shellExec(IS_WIN ? rustInstallScriptForWindows : rustInstallScriptForMac);
423
+ spinner.succeed();
424
+ }
425
+ catch (error) {
426
+ console.error('Error installing Rust:', error.message);
427
+ spinner.fail();
428
+ //@ts-ignore
429
+ process.exit(1);
430
+ }
431
+ }
432
+ function checkRustInstalled() {
433
+ return shelljs.exec('rustc --version', { silent: true }).code === 0;
2313
434
  }
2314
435
 
2315
- class MacBuilder {
2316
- prepare() {
2317
- return __awaiter(this, void 0, void 0, function* () {
2318
- if (checkRustInstalled()) {
2319
- return;
2320
- }
2321
- const res = yield prompts({
2322
- type: 'confirm',
2323
- message: 'We detected that you have not installed Rust. Install it now?',
2324
- name: 'value',
2325
- });
2326
- if (res.value) {
2327
- // TODO 国内有可能会超时
2328
- yield installRust();
2329
- }
2330
- else {
2331
- log.error('Error: Pake need Rust to package your webapp!!!');
2332
- process.exit(2);
2333
- }
2334
- });
2335
- }
2336
- build(url, options) {
2337
- return __awaiter(this, void 0, void 0, function* () {
2338
- log.debug('PakeAppOptions', options);
2339
- const { name } = options;
2340
- yield mergeTauriConfig(url, options, tauriConf);
2341
- let dmgName;
2342
- if (options.multiArch) {
2343
- const isChina = yield isChinaDomain("www.npmjs.com");
2344
- if (isChina) {
2345
- logger.info("it's in China, use npm/rust cn mirror");
2346
- const rust_project_dir = path.join(npmDirectory, 'src-tauri', ".cargo");
2347
- const e1 = fs$1.access(rust_project_dir);
2348
- if (e1) {
2349
- yield fs$1.mkdir(rust_project_dir, { recursive: true });
2350
- }
2351
- const project_cn_conf = path.join(npmDirectory, "src-tauri", "cn_config.bak");
2352
- const project_conf = path.join(rust_project_dir, "config");
2353
- fs$1.copyFile(project_cn_conf, project_conf);
2354
- yield shellExec(`cd "${npmDirectory}" && npm install --registry=https://registry.npmmirror.com && npm run build:mac`);
2355
- }
2356
- else {
2357
- yield shellExec(`cd "${npmDirectory}" && npm install && npm run build:mac`);
2358
- }
2359
- dmgName = `${name}_${tauriConf.package.version}_universal.dmg`;
2360
- }
2361
- else {
2362
- const isChina = isChinaDomain("www.npmjs.com");
2363
- if (isChina) {
2364
- yield shellExec(`cd ${npmDirectory} && npm install --registry=https://registry.npmmirror.com && npm run build`);
2365
- }
2366
- else {
2367
- yield shellExec(`cd ${npmDirectory} && npm install && npm run build`);
2368
- }
2369
- let arch = "x64";
2370
- if (process.arch === "arm64") {
2371
- arch = "aarch64";
2372
- }
2373
- else {
2374
- arch = process.arch;
2375
- }
2376
- dmgName = `${name}_${tauriConf.package.version}_${arch}.dmg`;
2377
- }
2378
- const appPath = this.getBuildAppPath(npmDirectory, dmgName, options.multiArch);
2379
- const distPath = path.resolve(`${name}.dmg`);
2380
- yield fs$1.copyFile(appPath, distPath);
2381
- yield fs$1.unlink(appPath);
2382
- logger.success('Build success!');
2383
- logger.success('You can find the app installer in', distPath);
2384
- });
2385
- }
2386
- getBuildAppPath(npmDirectory, dmgName, multiArch) {
2387
- let dmgPath;
2388
- if (multiArch) {
2389
- dmgPath = 'src-tauri/target/universal-apple-darwin/release/bundle/dmg';
2390
- }
2391
- else {
2392
- dmgPath = 'src-tauri/target/release/bundle/dmg';
2393
- }
2394
- return path.join(npmDirectory, dmgPath, dmgName);
2395
- }
436
+ class BaseBuilder {
437
+ async prepare() {
438
+ // Windows and Linux need to install necessary build tools.
439
+ if (!IS_MAC) {
440
+ logger.info('Install Rust and required build tools to build the app.');
441
+ logger.info('See more in https://tauri.app/v1/guides/getting-started/prerequisites#installing.');
442
+ }
443
+ if (checkRustInstalled()) {
444
+ return;
445
+ }
446
+ const res = await prompts({
447
+ type: 'confirm',
448
+ message: 'Rust not detected. Install now?',
449
+ name: 'value',
450
+ });
451
+ if (res.value) {
452
+ await installRust();
453
+ }
454
+ else {
455
+ logger.error('Error: Rust required to package your webapp!');
456
+ process.exit(2);
457
+ }
458
+ }
459
+ async runBuildCommand(directory, command) {
460
+ const isChina = await isChinaDomain("www.npmjs.com");
461
+ if (isChina) {
462
+ logger.info("Located in China, using npm/Rust CN mirror.");
463
+ const rustProjectDir = path.join(directory, 'src-tauri', ".cargo");
464
+ await fsExtra.ensureDir(rustProjectDir);
465
+ const projectCnConf = path.join(directory, "src-tauri", "rust_proxy.toml");
466
+ const projectConf = path.join(rustProjectDir, "config");
467
+ await fsExtra.copy(projectCnConf, projectConf);
468
+ await shellExec(`cd "${directory}" && npm install --registry=https://registry.npmmirror.com && ${command}`);
469
+ }
470
+ else {
471
+ await shellExec(`cd "${directory}" && npm install && ${command}`);
472
+ }
473
+ }
2396
474
  }
2397
475
 
2398
- class WinBuilder {
2399
- prepare() {
2400
- return __awaiter(this, void 0, void 0, function* () {
2401
- logger.info('To build the Windows app, you need to install Rust and VS Build Tools.');
2402
- logger.info('See more in https://tauri.app/v1/guides/getting-started/prerequisites#installing\n');
2403
- if (checkRustInstalled()) {
2404
- return;
2405
- }
2406
- const res = yield prompts({
2407
- type: 'confirm',
2408
- message: 'We detected that you have not installed Rust. Install it now?',
2409
- name: 'value',
2410
- });
2411
- if (res.value) {
2412
- // TODO 国内有可能会超时
2413
- yield installRust();
2414
- }
2415
- else {
2416
- logger.error('Error: Pake needs Rust to package your webapp!!!');
2417
- process.exit(2);
2418
- }
2419
- });
2420
- }
2421
- build(url, options) {
2422
- return __awaiter(this, void 0, void 0, function* () {
2423
- logger.debug('PakeAppOptions', options);
2424
- const { name } = options;
2425
- yield mergeTauriConfig(url, options, tauriConf);
2426
- const isChina = yield isChinaDomain("www.npmjs.com");
2427
- if (isChina) {
2428
- logger.info("it's in China, use npm/rust cn mirror");
2429
- const rust_project_dir = path.join(npmDirectory, 'src-tauri', ".cargo");
2430
- const e1 = fs$1.access(rust_project_dir);
2431
- if (e1) {
2432
- yield fs$1.mkdir(rust_project_dir, { recursive: true });
2433
- }
2434
- const project_cn_conf = path.join(npmDirectory, "src-tauri", "cn_config.bak");
2435
- const project_conf = path.join(rust_project_dir, "config");
2436
- fs$1.copyFile(project_cn_conf, project_conf);
2437
- yield shellExec(`cd "${npmDirectory}" && npm install --registry=https://registry.npmmirror.com && npm run build`);
2438
- }
2439
- else {
2440
- yield shellExec(`cd "${npmDirectory}" && npm install && npm run build`);
2441
- }
2442
- const language = tauriConf.tauri.bundle.windows.wix.language[0];
2443
- const arch = process.arch;
2444
- const msiName = `${name}_${tauriConf.package.version}_${arch}_${language}.msi`;
2445
- const appPath = this.getBuildedAppPath(npmDirectory, msiName);
2446
- const distPath = path.resolve(`${name}.msi`);
2447
- yield fs$1.copyFile(appPath, distPath);
2448
- yield fs$1.unlink(appPath);
2449
- logger.success('Build success!');
2450
- logger.success('You can find the app installer in', distPath);
2451
- });
2452
- }
2453
- getBuildedAppPath(npmDirectory, dmgName) {
2454
- return path.join(npmDirectory, 'src-tauri/target/release/bundle/msi', dmgName);
2455
- }
476
+ async function mergeConfig(url, options, tauriConf) {
477
+ const { width, height, fullscreen, transparent, resizable, userAgent, showMenu, showSystemTray, systemTrayIcon, iterCopyFile, identifier, name, } = options;
478
+ const { platform } = process;
479
+ // Set Windows parameters.
480
+ const tauriConfWindowOptions = {
481
+ width,
482
+ height,
483
+ fullscreen,
484
+ transparent,
485
+ resizable,
486
+ };
487
+ Object.assign(tauriConf.pake.windows[0], { url, ...tauriConfWindowOptions });
488
+ // Determine whether the package name is valid.
489
+ // for Linux, package name must be a-z, 0-9 or "-", not allow to A-Z and other
490
+ const platformRegexMapping = {
491
+ linux: /[0-9]*[a-z]+[0-9]*\-?[0-9]*[a-z]*[0-9]*\-?[0-9]*[a-z]*[0-9]*/,
492
+ default: /([0-9]*[a-zA-Z]+[0-9]*)+/,
493
+ };
494
+ const reg = platformRegexMapping[platform] || platformRegexMapping.default;
495
+ const nameCheck = reg.test(name) && reg.exec(name)[0].length === name.length;
496
+ if (!nameCheck) {
497
+ const errorMsg = platform === 'linux'
498
+ ? `Package name is invalid. It 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.`
499
+ : `Package name is invalid. It should only include letters and numbers, and must contain at least one letter. Examples: 123pan, 123Pan, Pan123, weread, WeRead, WERead.`;
500
+ logger.error(errorMsg);
501
+ process.exit();
502
+ }
503
+ tauriConf.package.productName = name;
504
+ tauriConf.tauri.bundle.identifier = identifier;
505
+ // Judge the type of URL, whether it is a file or a website.
506
+ // If it is a file and the recursive copy function is enabled then the file and all files in its parent folder need to be copied to the "src" directory. Otherwise, only the single file will be copied.
507
+ const urlExists = await fsExtra.pathExists(url);
508
+ if (urlExists) {
509
+ logger.warn('Your input might be a local file.');
510
+ tauriConf.pake.windows[0].url_type = 'local';
511
+ const fileName = path.basename(url);
512
+ const dirName = path.dirname(url);
513
+ const distDir = path.join(npmDirectory, 'dist');
514
+ const distBakDir = path.join(npmDirectory, 'dist_bak');
515
+ if (!iterCopyFile) {
516
+ const urlPath = path.join(distDir, fileName);
517
+ await fsExtra.copy(url, urlPath);
518
+ }
519
+ else {
520
+ fsExtra.moveSync(distDir, distBakDir, { overwrite: true });
521
+ fsExtra.copySync(dirName, distDir, { overwrite: true });
522
+ const filesToCopyBack = ['cli.js', 'about_pake.html'];
523
+ await Promise.all(filesToCopyBack.map((file) => fsExtra.copy(path.join(distBakDir, file), path.join(distDir, file))));
524
+ }
525
+ tauriConf.pake.windows[0].url = fileName;
526
+ tauriConf.pake.windows[0].url_type = 'local';
527
+ }
528
+ else {
529
+ tauriConf.pake.windows[0].url_type = 'web';
530
+ // Set the secure domain for calling window.__TAURI__ to the application domain that has been set.
531
+ tauriConf.tauri.security.dangerousRemoteDomainIpcAccess[0].domain =
532
+ new URL(url).hostname;
533
+ }
534
+ const platformMap = {
535
+ win32: 'windows',
536
+ linux: 'linux',
537
+ darwin: 'macos',
538
+ };
539
+ const currentPlatform = platformMap[platform];
540
+ if (userAgent.length > 0) {
541
+ tauriConf.pake.user_agent[currentPlatform] = userAgent;
542
+ }
543
+ tauriConf.pake.menu[currentPlatform] = showMenu;
544
+ tauriConf.pake.system_tray[currentPlatform] = showSystemTray;
545
+ // Processing targets are currently only open to Linux.
546
+ if (platform === 'linux') {
547
+ delete tauriConf.tauri.bundle.deb.files;
548
+ const validTargets = ['all', 'deb', 'appimage'];
549
+ if (validTargets.includes(options.targets)) {
550
+ tauriConf.tauri.bundle.targets = options.targets === 'all' ? ['deb', 'appimage'] : [options.targets];
551
+ }
552
+ else {
553
+ logger.warn(`The target must be one of ${validTargets.join(', ')}, the default 'deb' will be used.`);
554
+ }
555
+ }
556
+ // Set icon.
557
+ const platformIconMap = {
558
+ win32: {
559
+ fileExt: '.ico',
560
+ path: `png/${name.toLowerCase()}_32.ico`,
561
+ defaultIcon: 'png/icon_256.ico',
562
+ message: 'Windows icon must be .ico and 256x256px.',
563
+ },
564
+ linux: {
565
+ fileExt: '.png',
566
+ path: `png/${name.toLowerCase()}_32.png`,
567
+ defaultIcon: 'png/icon_512.png',
568
+ message: 'Linux icon must be .png and 512x512px.',
569
+ },
570
+ darwin: {
571
+ fileExt: '.icns',
572
+ path: `icons/${name.toLowerCase()}_32.icns`,
573
+ defaultIcon: 'icons/icon.icns',
574
+ message: 'MacOS icon must be .icns type.',
575
+ },
576
+ };
577
+ const iconInfo = platformIconMap[platform];
578
+ const exists = await fsExtra.pathExists(options.icon);
579
+ if (exists) {
580
+ let updateIconPath = true;
581
+ let customIconExt = path.extname(options.icon).toLowerCase();
582
+ if (customIconExt !== iconInfo.fileExt) {
583
+ updateIconPath = false;
584
+ logger.warn(`${iconInfo.message}, but you give ${customIconExt}`);
585
+ tauriConf.tauri.bundle.icon = [iconInfo.defaultIcon];
586
+ }
587
+ else {
588
+ const iconPath = path.join(npmDirectory, 'src-tauri/', iconInfo.path);
589
+ tauriConf.tauri.bundle.resources = [iconInfo.path];
590
+ await fsExtra.copy(options.icon, iconPath);
591
+ }
592
+ if (updateIconPath) {
593
+ tauriConf.tauri.bundle.icon = [options.icon];
594
+ }
595
+ else {
596
+ logger.warn(`Icon will remain as default.`);
597
+ }
598
+ }
599
+ else {
600
+ logger.warn('Custom icon path may be invalid. Default icon will be used instead.');
601
+ tauriConf.tauri.bundle.icon = [iconInfo.defaultIcon];
602
+ }
603
+ // Set tray icon path.
604
+ let trayIconPath = platform === 'darwin' ? 'png/icon_512.png' : tauriConf.tauri.bundle.icon[0];
605
+ if (systemTrayIcon.length > 0) {
606
+ try {
607
+ await fsExtra.pathExists(systemTrayIcon);
608
+ // 需要判断图标格式,默认只支持ico和png两种
609
+ let iconExt = path.extname(systemTrayIcon).toLowerCase();
610
+ if (iconExt == '.png' || iconExt == '.ico') {
611
+ const trayIcoPath = path.join(npmDirectory, `src-tauri/png/${name.toLowerCase()}${iconExt}`);
612
+ trayIconPath = `png/${name.toLowerCase()}${iconExt}`;
613
+ await fsExtra.copy(systemTrayIcon, trayIcoPath);
614
+ }
615
+ else {
616
+ logger.warn(`System tray icon must be .ico or .png, but you provided ${iconExt}.`);
617
+ logger.warn(`Default system tray icon will be used.`);
618
+ }
619
+ }
620
+ catch {
621
+ logger.warn(`${systemTrayIcon} not exists!`);
622
+ logger.warn(`Default system tray icon will remain unchanged.`);
623
+ }
624
+ }
625
+ tauriConf.tauri.systemTray.iconPath = trayIconPath;
626
+ // Save config file.
627
+ const platformConfigPaths = {
628
+ win32: 'src-tauri/tauri.windows.conf.json',
629
+ darwin: 'src-tauri/tauri.macos.conf.json',
630
+ linux: 'src-tauri/tauri.linux.conf.json',
631
+ };
632
+ const configPath = path.join(npmDirectory, platformConfigPaths[platform]);
633
+ const bundleConf = { tauri: { bundle: tauriConf.tauri.bundle } };
634
+ await fsExtra.writeJson(configPath, bundleConf, { spaces: 4 });
635
+ const pakeConfigPath = path.join(npmDirectory, 'src-tauri/pake.json');
636
+ await fsExtra.writeJson(pakeConfigPath, tauriConf.pake, { spaces: 4 });
637
+ let tauriConf2 = JSON.parse(JSON.stringify(tauriConf));
638
+ delete tauriConf2.pake;
639
+ delete tauriConf2.tauri.bundle;
640
+ const configJsonPath = path.join(npmDirectory, 'src-tauri/tauri.conf.json');
641
+ await fsExtra.writeJson(configJsonPath, tauriConf2, { spaces: 4 });
2456
642
  }
2457
643
 
2458
- class LinuxBuilder {
2459
- prepare() {
2460
- return __awaiter(this, void 0, void 0, function* () {
2461
- logger.info('To build the Linux app, you need to install Rust and Linux package');
2462
- logger.info('See more in https://tauri.app/v1/guides/getting-started/prerequisites#installing\n');
2463
- if (checkRustInstalled()) {
2464
- return;
2465
- }
2466
- const res = yield prompts({
2467
- type: 'confirm',
2468
- message: 'We detected that you have not installed Rust. Install it now?',
2469
- name: 'value',
2470
- });
2471
- if (res.value) {
2472
- // TODO 国内有可能会超时
2473
- yield installRust();
2474
- }
2475
- else {
2476
- logger.error('Error: Pake needs Rust to package your webapp!!!');
2477
- process.exit(2);
2478
- }
2479
- });
2480
- }
2481
- build(url, options) {
2482
- return __awaiter(this, void 0, void 0, function* () {
2483
- logger.debug('PakeAppOptions', options);
2484
- const { name } = options;
2485
- yield mergeTauriConfig(url, options, tauriConf);
2486
- const isChina = yield isChinaDomain("www.npmjs.com");
2487
- if (isChina) {
2488
- logger.info("it's in China, use npm/rust cn mirror");
2489
- const rust_project_dir = path.join(npmDirectory, 'src-tauri', ".cargo");
2490
- const e1 = fs$1.access(rust_project_dir);
2491
- if (e1) {
2492
- yield fs$1.mkdir(rust_project_dir, { recursive: true });
2493
- }
2494
- const project_cn_conf = path.join(npmDirectory, "src-tauri", "cn_config.bak");
2495
- const project_conf = path.join(rust_project_dir, "config");
2496
- fs$1.copyFile(project_cn_conf, project_conf);
2497
- yield shellExec(`cd "${npmDirectory}" && npm install --registry=https://registry.npmmirror.com && npm run build`);
2498
- }
2499
- else {
2500
- yield shellExec(`cd "${npmDirectory}" && npm install && npm run build`);
2501
- }
2502
- let arch;
2503
- if (process.arch === "x64") {
2504
- arch = "amd64";
2505
- }
2506
- else {
2507
- arch = process.arch;
2508
- }
2509
- if (options.targets === "deb" || options.targets === "all") {
2510
- const debName = `${name}_${tauriConf.package.version}_${arch}.deb`;
2511
- const appPath = this.getBuildAppPath(npmDirectory, "deb", debName);
2512
- const distPath = path.resolve(`${name}.deb`);
2513
- yield fs$1.copyFile(appPath, distPath);
2514
- yield fs$1.unlink(appPath);
2515
- logger.success('Build Deb success!');
2516
- logger.success('You can find the deb app installer in', distPath);
2517
- }
2518
- if (options.targets === "appimage" || options.targets === "all") {
2519
- const appImageName = `${name}_${tauriConf.package.version}_${arch}.AppImage`;
2520
- const appImagePath = this.getBuildAppPath(npmDirectory, "appimage", appImageName);
2521
- const distAppPath = path.resolve(`${name}.AppImage`);
2522
- yield fs$1.copyFile(appImagePath, distAppPath);
2523
- yield fs$1.unlink(appImagePath);
2524
- logger.success('Build AppImage success!');
2525
- logger.success('You can find the AppImage app installer in', distAppPath);
2526
- }
2527
- });
2528
- }
2529
- getBuildAppPath(npmDirectory, packageType, packageName) {
2530
- return path.join(npmDirectory, 'src-tauri/target/release/bundle/', packageType, packageName);
2531
- }
644
+ class MacBuilder extends BaseBuilder {
645
+ async build(url, options) {
646
+ const { name } = options;
647
+ await mergeConfig(url, options, tauriConfig);
648
+ let dmgName;
649
+ if (options.multiArch) {
650
+ await this.runBuildCommand(npmDirectory, 'npm run build:mac');
651
+ dmgName = `${name}_${tauriConfig.package.version}_universal.dmg`;
652
+ }
653
+ else {
654
+ await this.runBuildCommand(npmDirectory, 'npm run build');
655
+ let arch = process.arch === "arm64" ? "aarch64" : process.arch;
656
+ dmgName = `${name}_${tauriConfig.package.version}_${arch}.dmg`;
657
+ }
658
+ const appPath = this.getBuildAppPath(npmDirectory, dmgName, options.multiArch);
659
+ const distPath = path.resolve(`${name}.dmg`);
660
+ await fsExtra.copy(appPath, distPath);
661
+ await fsExtra.remove(appPath);
662
+ logger.success('Build success!');
663
+ logger.success('App installer located in', distPath);
664
+ }
665
+ getBuildAppPath(npmDirectory, dmgName, multiArch) {
666
+ const dmgPath = multiArch ? 'src-tauri/target/universal-apple-darwin/release/bundle/dmg' : 'src-tauri/target/release/bundle/dmg';
667
+ return path.join(npmDirectory, dmgPath, dmgName);
668
+ }
2532
669
  }
2533
670
 
2534
- class BuilderFactory {
2535
- static create() {
2536
- if (IS_MAC) {
2537
- return new MacBuilder();
2538
- }
2539
- if (IS_WIN) {
2540
- return new WinBuilder();
2541
- }
2542
- if (IS_LINUX) {
2543
- return new LinuxBuilder();
2544
- }
2545
- throw new Error('The current system does not support!!');
2546
- }
671
+ class WinBuilder extends BaseBuilder {
672
+ async build(url, options) {
673
+ const { name } = options;
674
+ await mergeConfig(url, options, tauriConfig);
675
+ await this.runBuildCommand(npmDirectory, 'npm run build');
676
+ const language = tauriConfig.tauri.bundle.windows.wix.language[0];
677
+ const arch = process.arch;
678
+ const msiName = `${name}_${tauriConfig.package.version}_${arch}_${language}.msi`;
679
+ const appPath = this.getBuildAppPath(npmDirectory, msiName);
680
+ const distPath = path.resolve(`${name}.msi`);
681
+ await fsExtra.copy(appPath, distPath);
682
+ await fsExtra.remove(appPath);
683
+ logger.success('Build success!');
684
+ logger.success('App installer located in', distPath);
685
+ }
686
+ getBuildAppPath(npmDirectory, msiName) {
687
+ return path.join(npmDirectory, 'src-tauri/target/release/bundle/msi', msiName);
688
+ }
689
+ }
690
+
691
+ class LinuxBuilder extends BaseBuilder {
692
+ async build(url, options) {
693
+ const { name } = options;
694
+ await mergeConfig(url, options, tauriConfig);
695
+ await this.runBuildCommand(npmDirectory, 'npm run build');
696
+ const arch = process.arch === "x64" ? "amd64" : process.arch;
697
+ if (options.targets === "deb" || options.targets === "all") {
698
+ const debName = `${name}_${tauriConfig.package.version}_${arch}.deb`;
699
+ const appPath = this.getBuildAppPath(npmDirectory, "deb", debName);
700
+ const distPath = path.resolve(`${name}.deb`);
701
+ await fsExtra.copy(appPath, distPath);
702
+ await fsExtra.remove(appPath);
703
+ logger.success('Build Deb success!');
704
+ logger.success('Deb app installer located in', distPath);
705
+ }
706
+ if (options.targets === "appimage" || options.targets === "all") {
707
+ const appImageName = `${name}_${tauriConfig.package.version}_${arch}.AppImage`;
708
+ const appImagePath = this.getBuildAppPath(npmDirectory, "appimage", appImageName);
709
+ const distAppPath = path.resolve(`${name}.AppImage`);
710
+ await fsExtra.copy(appImagePath, distAppPath);
711
+ await fsExtra.remove(appImagePath);
712
+ logger.success('Build AppImage success!');
713
+ logger.success('AppImage installer located in', distAppPath);
714
+ }
715
+ }
716
+ getBuildAppPath(npmDirectory, packageType, packageName) {
717
+ return path.join(npmDirectory, 'src-tauri/target/release/bundle/', packageType, packageName);
718
+ }
719
+ }
720
+
721
+ class BuilderProvider {
722
+ static create() {
723
+ if (IS_MAC) {
724
+ return new MacBuilder();
725
+ }
726
+ if (IS_WIN) {
727
+ return new WinBuilder();
728
+ }
729
+ if (IS_LINUX) {
730
+ return new LinuxBuilder();
731
+ }
732
+ throw new Error('The current system is not supported!');
733
+ }
2547
734
  }
2548
735
 
2549
736
  var name = "pake-cli";
2550
- var version = "2.0.7";
737
+ var version = "2.1.0";
2551
738
  var description = "🤱🏻 Turn any webpage into a desktop app with Rust. 🤱🏻 很简单的用 Rust 打包网页生成很小的桌面 App。";
2552
739
  var engines = {
2553
740
  node: ">=16.0.0"
@@ -2594,7 +781,7 @@ var exports = "./dist/pake.js";
2594
781
  var license = "MIT";
2595
782
  var dependencies = {
2596
783
  "@tauri-apps/api": "^1.4.0",
2597
- "@tauri-apps/cli": "1.3.1",
784
+ "@tauri-apps/cli": "^1.4.0",
2598
785
  axios: "^1.1.3",
2599
786
  chalk: "^5.1.2",
2600
787
  commander: "^11.0.0",
@@ -2604,6 +791,7 @@ var dependencies = {
2604
791
  loglevel: "^1.8.1",
2605
792
  ora: "^6.1.2",
2606
793
  prompts: "^2.4.2",
794
+ psl: "^1.9.0",
2607
795
  shelljs: "^0.8.5",
2608
796
  "tmp-promise": "^3.0.3",
2609
797
  "update-notifier": "^6.0.2"
@@ -2611,19 +799,20 @@ var dependencies = {
2611
799
  var devDependencies = {
2612
800
  "@rollup/plugin-alias": "^4.0.2",
2613
801
  "@rollup/plugin-commonjs": "^23.0.2",
2614
- "@rollup/plugin-json": "^5.0.1",
802
+ "@rollup/plugin-json": "^5.0.2",
2615
803
  "@rollup/plugin-terser": "^0.1.0",
2616
- "@rollup/plugin-typescript": "^9.0.2",
2617
804
  "@types/fs-extra": "^9.0.13",
2618
805
  "@types/is-url": "^1.2.30",
2619
806
  "@types/page-icon": "^0.3.4",
2620
807
  "@types/prompts": "^2.4.1",
808
+ "@types/psl": "^1.1.0",
2621
809
  "@types/shelljs": "^0.8.11",
2622
810
  "@types/tmp": "^0.2.3",
2623
811
  "@types/update-notifier": "^6.0.1",
2624
812
  "app-root-path": "^3.1.0",
2625
813
  "cross-env": "^7.0.3",
2626
814
  rollup: "^3.3.0",
815
+ "rollup-plugin-typescript2": "^0.34.1",
2627
816
  tslib: "^2.4.1",
2628
817
  typescript: "^4.9.3"
2629
818
  };
@@ -2645,46 +834,83 @@ var packageJson = {
2645
834
  devDependencies: devDependencies
2646
835
  };
2647
836
 
2648
- function checkUpdateTips() {
2649
- return __awaiter(this, void 0, void 0, function* () {
2650
- updateNotifier({ pkg: packageJson }).notify();
2651
- });
837
+ async function checkUpdateTips() {
838
+ updateNotifier({ pkg: packageJson }).notify();
2652
839
  }
2653
840
 
2654
- program.version(packageJson.version).description('A cli application can package a web page to desktop application.');
2655
- program
2656
- .showHelpAfterError()
2657
- .argument('[url]', 'the web url you want to package', validateUrlInput)
2658
- .option('--name <string>', 'application name')
2659
- .option('--icon <string>', 'application icon', DEFAULT_PAKE_OPTIONS.icon)
2660
- .option('--height <number>', 'window height', validateNumberInput, DEFAULT_PAKE_OPTIONS.height)
2661
- .option('--width <number>', 'window width', validateNumberInput, DEFAULT_PAKE_OPTIONS.width)
2662
- .option('--no-resizable', 'whether the window can be resizable', DEFAULT_PAKE_OPTIONS.resizable)
2663
- .option('--fullscreen', 'makes the packaged app start in full screen', DEFAULT_PAKE_OPTIONS.fullscreen)
2664
- .option('--transparent', 'transparent title bar', DEFAULT_PAKE_OPTIONS.transparent)
2665
- .option('--user-agent <string>', 'custom user agent', DEFAULT_PAKE_OPTIONS.userAgent)
2666
- .option('--show-menu', 'show menu in app', DEFAULT_PAKE_OPTIONS.showMenu)
2667
- .option('--show-system-tray', 'show system tray in app', DEFAULT_PAKE_OPTIONS.showSystemTray)
2668
- .option('--system-tray-icon <string>', 'custom system tray icon', DEFAULT_PAKE_OPTIONS.systemTrayIcon)
2669
- .option('--iter-copy-file', 'copy all static file to pake app when url is a local file', DEFAULT_PAKE_OPTIONS.iterCopyFile)
2670
- .option('-m, --multi-arch', "available for Mac only, and supports both Intel and M1", DEFAULT_PAKE_OPTIONS.multiArch)
2671
- .option('--targets <string>', 'only for linux, default is "deb", option "appaimge" or "all"(deb & appimage)', DEFAULT_PAKE_OPTIONS.targets)
2672
- .option('--debug', 'debug', DEFAULT_PAKE_OPTIONS.transparent)
2673
- .action((url, options) => __awaiter(void 0, void 0, void 0, function* () {
2674
- checkUpdateTips();
2675
- if (!url) {
2676
- // 直接 pake 不需要出现url提示
2677
- program.help();
2678
- }
2679
- log.setDefaultLevel('info');
2680
- if (options.debug) {
2681
- log.setLevel('debug');
2682
- }
2683
- const builder = BuilderFactory.create();
2684
- yield builder.prepare();
2685
- // logger.warn("you input url is ", url);
2686
- const appOptions = yield handleOptions(options, url);
2687
- // logger.info(JSON.stringify(appOptions, null, 4));
2688
- builder.build(url, appOptions);
2689
- }));
841
+ function validateNumberInput(value) {
842
+ const parsedValue = Number(value);
843
+ if (isNaN(parsedValue)) {
844
+ throw new InvalidArgumentError('Not a number.');
845
+ }
846
+ return parsedValue;
847
+ }
848
+ function validateUrlInput(url) {
849
+ const isFile = fs.existsSync(url);
850
+ if (!isFile) {
851
+ try {
852
+ return normalizeUrl(url);
853
+ }
854
+ catch (error) {
855
+ throw new InvalidArgumentError(error.message);
856
+ }
857
+ }
858
+ return url;
859
+ }
860
+
861
+ const DEFAULT_PAKE_OPTIONS = {
862
+ icon: '',
863
+ height: 780,
864
+ width: 1200,
865
+ fullscreen: false,
866
+ resizable: true,
867
+ transparent: false,
868
+ userAgent: '',
869
+ showMenu: false,
870
+ showSystemTray: false,
871
+ multiArch: false,
872
+ targets: 'deb',
873
+ iterCopyFile: false,
874
+ systemTrayIcon: '',
875
+ debug: false,
876
+ };
877
+
878
+ program
879
+ .version(packageJson.version)
880
+ .description('A CLI that can turn any webpage into a desktop app with Rust.')
881
+ .showHelpAfterError();
882
+ program
883
+ .argument('[url]', 'The web URL you want to package', validateUrlInput)
884
+ .option('--name <string>', 'Application name')
885
+ .option('--icon <string>', 'Application icon', DEFAULT_PAKE_OPTIONS.icon)
886
+ .option('--height <number>', 'Window height', validateNumberInput, DEFAULT_PAKE_OPTIONS.height)
887
+ .option('--width <number>', 'Window width', validateNumberInput, DEFAULT_PAKE_OPTIONS.width)
888
+ .option('--no-resizable', 'Whether the window can be resizable', DEFAULT_PAKE_OPTIONS.resizable)
889
+ .option('--fullscreen', 'Start the packaged app in full screen', DEFAULT_PAKE_OPTIONS.fullscreen)
890
+ .option('--transparent', 'Transparent title bar', DEFAULT_PAKE_OPTIONS.transparent)
891
+ .option('--user-agent <string>', 'Custom user agent', DEFAULT_PAKE_OPTIONS.userAgent)
892
+ .option('--show-menu', 'Show menu in app', DEFAULT_PAKE_OPTIONS.showMenu)
893
+ .option('--show-system-tray', 'Show system tray in app', DEFAULT_PAKE_OPTIONS.showSystemTray)
894
+ .option('--system-tray-icon <string>', 'Custom system tray icon', DEFAULT_PAKE_OPTIONS.systemTrayIcon)
895
+ .option('--iter-copy-file', 'Copy files to app when URL is a local file', DEFAULT_PAKE_OPTIONS.iterCopyFile)
896
+ .option('--multi-arch', 'Available for Mac only, supports both Intel and M1', DEFAULT_PAKE_OPTIONS.multiArch)
897
+ .option('--targets <string>', 'Only for Linux, option "deb", "appimage" or "all"', DEFAULT_PAKE_OPTIONS.targets)
898
+ .option('--debug', 'Debug mode', DEFAULT_PAKE_OPTIONS.debug)
899
+ .action(async (url, options) => {
900
+ //Check for update prompt
901
+ await checkUpdateTips();
902
+ // If no URL is provided, display help information
903
+ if (!url) {
904
+ program.help();
905
+ }
906
+ log.setDefaultLevel('info');
907
+ if (options.debug) {
908
+ log.setLevel('debug');
909
+ }
910
+ const builder = BuilderProvider.create();
911
+ await builder.prepare();
912
+ const appOptions = await handleOptions(options, url);
913
+ log.debug('PakeAppOptions', appOptions);
914
+ await builder.build(url, appOptions);
915
+ });
2690
916
  program.parse();