xshell 1.0.135 → 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.
Files changed (3) hide show
  1. package/builder.d.ts +9 -7
  2. package/builder.js +17 -16
  3. 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 HtmlBuildOptions {
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
- fp_icon?: string;
30
+ /** 也会在 copy_files 中一并被复制,应填写相对于 fpd_root 和 fpd_out 的路径 */
31
+ icon?: string | AssetOption;
30
32
  dependencies?: DependencyId[];
31
- fp_manifest?: string;
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}/ 加上 srcs 中的路径 */
49
+ /** 默认为 {fpd_out}/ 加上 src 中的路径 */
48
50
  out?: string;
49
51
  }
50
52
  type Assets = {
@@ -72,7 +74,7 @@ export interface BundlerOptions {
72
74
  license?: {
73
75
  ignores?: string[];
74
76
  };
75
- htmls?: Record<string, HtmlBuildOptions>;
77
+ htmls?: Record<string, HtmlOptions>;
76
78
  }
77
79
  export declare class Bundler {
78
80
  name: string;
@@ -84,7 +86,7 @@ export declare class Bundler {
84
86
  dependencies: DependencyId[];
85
87
  analyzer: boolean;
86
88
  config: Webpack.Configuration;
87
- htmls?: Record<string, HtmlBuildOptions>;
89
+ htmls?: Record<string, HtmlOptions>;
88
90
  assets?: Assets;
89
91
  license?: {
90
92
  ignores?: string[];
package/builder.js CHANGED
@@ -460,7 +460,7 @@ export class Bundler {
460
460
  ]);
461
461
  }
462
462
  async build_htmls(print = { info: true, files: false }) {
463
- await Promise.all(Object.entries(this.htmls).map(async ([fp_html, { device_viewport: device_width = false, fp_icon, fp_manifest, dependencies: _dependencies = this.dependencies, title, scripts, mscripts, notice = false, heads, }]) => {
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, }]) => {
464
464
  const html = '<!doctype html>\n' +
465
465
  '<html>\n' +
466
466
  ' <head>\n' +
@@ -468,12 +468,12 @@ export class Bundler {
468
468
  " <meta charset='utf-8' />\n" +
469
469
  (heads ? heads.map(head => ` ${head}`).join_lines() : '') +
470
470
  (device_width ? " <meta name='viewport' content='width=device-width, initial-scale=1.0' />\n" : '') +
471
- (fp_icon ? ` <link rel='icon' href='${fp_icon}' />\n` : '') +
472
- (fp_manifest ? ` <link rel='manifest' href='${fp_manifest}' />\n` : '') +
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` : '') +
473
473
  this.resolve_dependency_files(_dependencies, false, { production: this.production }).map(fp => ` <script src='./vendors/${fp}' defer></script>`).join_lines() +
474
474
  (scripts?.before ? scripts.before.map(fp => ` <script src='${fp}' defer></script>`).join_lines() : '') +
475
475
  (mscripts ? mscripts.map(fp => ` <script src='${fp}' type='module'></script>`).join_lines() : '') +
476
- " <script src='./index.js' type='module'></script>\n" +
476
+ ` <script src='${fp_entry}' type='module'></script>\n` +
477
477
  (scripts?.after ? scripts.after.map(fp => ` <script src='${fp}' defer></script>`).join_lines() : '') +
478
478
  ' </head>\n' +
479
479
  ' <body>\n' +
@@ -522,26 +522,27 @@ export class Bundler {
522
522
  console.log(`复制项目文件及依赖到输出目录`);
523
523
  if (dependencies)
524
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
+ }
525
533
  await Promise.all([
526
534
  ...this.resolve_dependency_files(dependencies, true, { production })
527
535
  .map(async (fp) => fcopy(`${fpd_root}node_modules/${fp}`, `${fpd_out}vendors/${fp}`, { print: print.files })),
528
536
  ...this.resolve_config(assets, production)
529
- .map(async (asset) => {
530
- let src, out;
531
- if (typeof asset === 'string')
532
- src = out = asset;
533
- else
534
- ({ src, out } = asset);
535
- fcopy(`${fpd_root}${src}`, `${fpd_out}${out}`, { print: print.files });
536
- }),
537
- ...this.htmls ? Object.entries(this.htmls).map(async ([fp_html, { fp_icon, fp_manifest, scripts, mscripts }]) => Promise.all([
538
- fp_icon,
539
- 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,
540
541
  ...(scripts?.before || []),
541
542
  ...(scripts?.after || []),
542
543
  ...(mscripts || [])
543
544
  ].filter(not_empty)
544
- .map(fp => fcopy(path.resolve(`${fpd_root}${fp_html}`.fdir, fp), path.resolve(`${fpd_out}${fp_html}`.fdir, fp), { print: print.files })))) : []
545
+ .map(fcopy_asset))) : []
545
546
  ]);
546
547
  }
547
548
  /** 为空时返回空数组 */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xshell",
3
- "version": "1.0.135",
3
+ "version": "1.0.136",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "bin": {