xshell 1.0.134 → 1.0.136
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/builder.d.ts +12 -8
- package/builder.js +35 -19
- package/package.json +1 -1
package/builder.d.ts
CHANGED
|
@@ -22,13 +22,15 @@ export interface Dependency {
|
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
24
|
type DependencyId = 'react' | 'react-dom' | 'lodash' | 'jquery' | 'xterm' | 'swiper' | 'dayjs' | 'antd' | 'antd-icons' | 'vscode-oniguruma' | 'antd-plots' | 'gridstack' | 'quill' | 'monaco' | 'echarts';
|
|
25
|
-
export interface
|
|
25
|
+
export interface HtmlOptions {
|
|
26
26
|
title: string;
|
|
27
|
+
/** `./index.js` 也可以设置 entries 中的其他项, 应填写相对于 .html 的路径 */
|
|
28
|
+
fp_entry?: string;
|
|
27
29
|
device_viewport?: boolean;
|
|
28
|
-
/** 也会在 copy_files
|
|
29
|
-
|
|
30
|
+
/** 也会在 copy_files 中一并被复制,应填写相对于 fpd_root 和 fpd_out 的路径 */
|
|
31
|
+
icon?: string | AssetOption;
|
|
30
32
|
dependencies?: DependencyId[];
|
|
31
|
-
|
|
33
|
+
manifest?: string | AssetOption;
|
|
32
34
|
/** 额外需要加载的脚本 */
|
|
33
35
|
scripts?: {
|
|
34
36
|
/** 在 index.js 之前加载 */
|
|
@@ -44,7 +46,7 @@ export interface HtmlBuildOptions {
|
|
|
44
46
|
interface AssetOption {
|
|
45
47
|
/** 相对 fpd_root 的路径 */
|
|
46
48
|
src: string;
|
|
47
|
-
/** 默认为 {fpd_out}/ 加上
|
|
49
|
+
/** 默认为 {fpd_out}/ 加上 src 中的路径 */
|
|
48
50
|
out?: string;
|
|
49
51
|
}
|
|
50
52
|
type Assets = {
|
|
@@ -72,18 +74,19 @@ export interface BundlerOptions {
|
|
|
72
74
|
license?: {
|
|
73
75
|
ignores?: string[];
|
|
74
76
|
};
|
|
75
|
-
htmls?: Record<string,
|
|
77
|
+
htmls?: Record<string, HtmlOptions>;
|
|
76
78
|
}
|
|
77
79
|
export declare class Bundler {
|
|
78
80
|
name: string;
|
|
79
81
|
fpd_root: string;
|
|
82
|
+
target: 'nodejs' | 'web';
|
|
80
83
|
production: boolean;
|
|
81
84
|
fpd_out: string;
|
|
82
85
|
source_map: boolean;
|
|
83
86
|
dependencies: DependencyId[];
|
|
84
87
|
analyzer: boolean;
|
|
85
88
|
config: Webpack.Configuration;
|
|
86
|
-
htmls?: Record<string,
|
|
89
|
+
htmls?: Record<string, HtmlOptions>;
|
|
87
90
|
assets?: Assets;
|
|
88
91
|
license?: {
|
|
89
92
|
ignores?: string[];
|
|
@@ -121,7 +124,8 @@ export declare class Bundler {
|
|
|
121
124
|
constructor(name: string, target: 'web' | 'nodejs', fpd_root: string, fpd_out: string, fpdt_cache: string, entry: Record<string, string>, { source_map, globals, external_dayjs, externals, htmls, assets, commonjs2, single_chunk, dynamic_import, resolve_alias, assets_stats, analyzer, dts, exclude_modules, cache_version, production, sass, dependencies, license, }?: BundlerOptions);
|
|
122
125
|
build(print?: boolean): Promise<void>;
|
|
123
126
|
close(): Promise<void>;
|
|
124
|
-
|
|
127
|
+
build_all(print?: boolean): Promise<void>;
|
|
128
|
+
build_all_and_close(print?: boolean): Promise<void>;
|
|
125
129
|
build_htmls(print?: {
|
|
126
130
|
info: boolean;
|
|
127
131
|
files: boolean;
|
package/builder.js
CHANGED
|
@@ -97,6 +97,7 @@ const dependencies = {
|
|
|
97
97
|
export class Bundler {
|
|
98
98
|
name;
|
|
99
99
|
fpd_root;
|
|
100
|
+
target;
|
|
100
101
|
production;
|
|
101
102
|
fpd_out;
|
|
102
103
|
source_map;
|
|
@@ -140,6 +141,7 @@ export class Bundler {
|
|
|
140
141
|
this.name = name;
|
|
141
142
|
this.analyzer = analyzer;
|
|
142
143
|
this.production = production;
|
|
144
|
+
this.target = target;
|
|
143
145
|
this.fpd_root = fpd_root;
|
|
144
146
|
this.fpd_out = fpd_out;
|
|
145
147
|
this.source_map = source_map;
|
|
@@ -440,12 +442,25 @@ export class Bundler {
|
|
|
440
442
|
});
|
|
441
443
|
}));
|
|
442
444
|
}
|
|
443
|
-
async
|
|
444
|
-
await
|
|
445
|
-
|
|
445
|
+
async build_all(print = true) {
|
|
446
|
+
await Promise.all([
|
|
447
|
+
this.build(print),
|
|
448
|
+
this.copy_files({ print: { info: print, files: false } }),
|
|
449
|
+
this.target === 'web' && this.build_htmls({ info: print, files: false })
|
|
450
|
+
]);
|
|
451
|
+
}
|
|
452
|
+
async build_all_and_close(print = true) {
|
|
453
|
+
await Promise.all([
|
|
454
|
+
(async () => {
|
|
455
|
+
await this.build(print);
|
|
456
|
+
await this.close();
|
|
457
|
+
})(),
|
|
458
|
+
this.copy_files({ print: { info: print, files: false } }),
|
|
459
|
+
this.target === 'web' && this.build_htmls({ info: print, files: false })
|
|
460
|
+
]);
|
|
446
461
|
}
|
|
447
462
|
async build_htmls(print = { info: true, files: false }) {
|
|
448
|
-
await Promise.all(Object.entries(this.htmls).map(async ([fp_html, { device_viewport: device_width = false,
|
|
463
|
+
await Promise.all(Object.entries(this.htmls).map(async ([fp_html, { fp_entry = './index.js', device_viewport: device_width = false, icon, manifest, dependencies: _dependencies = this.dependencies, title, scripts, mscripts, notice = false, heads, }]) => {
|
|
449
464
|
const html = '<!doctype html>\n' +
|
|
450
465
|
'<html>\n' +
|
|
451
466
|
' <head>\n' +
|
|
@@ -453,12 +468,12 @@ export class Bundler {
|
|
|
453
468
|
" <meta charset='utf-8' />\n" +
|
|
454
469
|
(heads ? heads.map(head => ` ${head}`).join_lines() : '') +
|
|
455
470
|
(device_width ? " <meta name='viewport' content='width=device-width, initial-scale=1.0' />\n" : '') +
|
|
456
|
-
(
|
|
457
|
-
(
|
|
471
|
+
(icon ? ` <link rel='icon' href='${path.relative(`${this.fpd_out}${fp_html}`, `${this.fpd_out}${typeof icon === 'string' ? icon : icon.out}`)}' />\n` : '') +
|
|
472
|
+
(manifest ? ` <link rel='manifest' href='${path.relative(`${this.fpd_out}${fp_html}`, `${this.fpd_out}${typeof manifest === 'string' ? manifest : manifest.out}`)}' />\n` : '') +
|
|
458
473
|
this.resolve_dependency_files(_dependencies, false, { production: this.production }).map(fp => ` <script src='./vendors/${fp}' defer></script>`).join_lines() +
|
|
459
474
|
(scripts?.before ? scripts.before.map(fp => ` <script src='${fp}' defer></script>`).join_lines() : '') +
|
|
460
475
|
(mscripts ? mscripts.map(fp => ` <script src='${fp}' type='module'></script>`).join_lines() : '') +
|
|
461
|
-
|
|
476
|
+
` <script src='${fp_entry}' type='module'></script>\n` +
|
|
462
477
|
(scripts?.after ? scripts.after.map(fp => ` <script src='${fp}' defer></script>`).join_lines() : '') +
|
|
463
478
|
' </head>\n' +
|
|
464
479
|
' <body>\n' +
|
|
@@ -507,26 +522,27 @@ export class Bundler {
|
|
|
507
522
|
console.log(`复制项目文件及依赖到输出目录`);
|
|
508
523
|
if (dependencies)
|
|
509
524
|
await fmkdir(`${fpd_out}vendors/`, { print: false });
|
|
525
|
+
async function fcopy_asset(asset) {
|
|
526
|
+
let src, out;
|
|
527
|
+
if (typeof asset === 'string')
|
|
528
|
+
src = out = asset;
|
|
529
|
+
else
|
|
530
|
+
({ src, out } = asset);
|
|
531
|
+
await fcopy(`${fpd_root}${src}`, `${fpd_out}${out}`, { print: print.files });
|
|
532
|
+
}
|
|
510
533
|
await Promise.all([
|
|
511
534
|
...this.resolve_dependency_files(dependencies, true, { production })
|
|
512
535
|
.map(async (fp) => fcopy(`${fpd_root}node_modules/${fp}`, `${fpd_out}vendors/${fp}`, { print: print.files })),
|
|
513
536
|
...this.resolve_config(assets, production)
|
|
514
|
-
.map(
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
else
|
|
519
|
-
({ src, out } = asset);
|
|
520
|
-
fcopy(`${fpd_root}${src}`, `${fpd_out}${out}`, { print: print.files });
|
|
521
|
-
}),
|
|
522
|
-
...this.htmls ? Object.entries(this.htmls).map(async ([fp_html, { fp_icon, fp_manifest, scripts, mscripts }]) => Promise.all([
|
|
523
|
-
fp_icon,
|
|
524
|
-
fp_manifest,
|
|
537
|
+
.map(fcopy_asset),
|
|
538
|
+
...this.htmls ? Object.entries(this.htmls).map(async ([fp_html, { icon, manifest, scripts, mscripts }]) => Promise.all([
|
|
539
|
+
icon,
|
|
540
|
+
manifest,
|
|
525
541
|
...(scripts?.before || []),
|
|
526
542
|
...(scripts?.after || []),
|
|
527
543
|
...(mscripts || [])
|
|
528
544
|
].filter(not_empty)
|
|
529
|
-
.map(
|
|
545
|
+
.map(fcopy_asset))) : []
|
|
530
546
|
]);
|
|
531
547
|
}
|
|
532
548
|
/** 为空时返回空数组 */
|