@cloudbase/lowcode-builder 1.9.4 → 1.9.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  export declare function generatePackageDependencies({ importJSSDK, mode, officialLibVersion, uin, }: {
2
- importJSSDK: boolean;
3
2
  mode: 'lib' | string;
3
+ importJSSDK?: boolean;
4
4
  officialLibVersion?: string;
5
5
  uin?: string;
6
6
  }): {
@@ -9,3 +9,11 @@ export declare function generatePackageDependencies({ importJSSDK, mode, officia
9
9
  'lodash.get': string;
10
10
  'lodash.set': string;
11
11
  };
12
+ export declare function generateLibDependencies(mode: 'mp' | 'h5', officialLibVersion?: any): {};
13
+ export declare function generateSystemPackageDependencies({ importJSSDK }: {
14
+ importJSSDK: any;
15
+ }): {
16
+ '@cloudbase/adapter-wx_mp': string;
17
+ '@cloudbase/auth': string;
18
+ '@cloudbase/ai': string;
19
+ };
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generatePackageDependencies = void 0;
3
+ exports.generateSystemPackageDependencies = exports.generateLibDependencies = exports.generatePackageDependencies = void 0;
4
4
  const cals_1 = require("@cloudbase/cals");
5
- const CLOUDBASE_VERSION = '2.6.6-beta.0';
5
+ const CLOUDBASE_VERSION = '2.8.15-beta.0';
6
6
  const BASE_DEPS = {
7
7
  'miniprogram-gesture': '^1.0.6',
8
8
  mobx: '^5',
@@ -13,27 +13,24 @@ const BASE_DEPS = {
13
13
  * 注意锁版本
14
14
  */
15
15
  const CLOUDBASE_DEPS = {
16
- '@cloudbase/auth': CLOUDBASE_VERSION,
17
16
  '@cloudbase/weda-client': '1.1.6',
18
- '@cloudbase/weda-cloud-sdk': '1.0.78',
17
+ '@cloudbase/weda-cloud-sdk': '1.0.86',
18
+ };
19
+ const COMPONENT_DEPS = {
20
+ '@cloudbase/lowcode-render': '^1.1.4',
21
+ };
22
+ const SYS_CLOUDBASE_DEPS = {
23
+ '@cloudbase/adapter-wx_mp': '^1.0.3',
24
+ '@cloudbase/auth': CLOUDBASE_VERSION,
25
+ '@cloudbase/ai': CLOUDBASE_VERSION,
19
26
  };
20
27
  function generatePackageDependencies({ importJSSDK, mode, officialLibVersion, uin, }) {
21
28
  const deps = {};
22
- if (importJSSDK) {
23
- deps['@cloudbase/js-sdk'] = CLOUDBASE_VERSION;
24
- }
25
29
  if (mode === 'lib') {
26
- // eslint-disable-next-line no-restricted-syntax
27
- for (const key in CLOUDBASE_DEPS) {
28
- const version = CLOUDBASE_DEPS[key];
29
- /**
30
- * lib 模式下采用松散的引用
31
- */
32
- deps[key] = /^\d/.test(version) ? `^${version}` : version;
33
- }
34
- if (officialLibVersion) {
35
- deps[cals_1.OFFICIAL_LIB_MP_NPM_PACKAGENAME] = officialLibVersion;
30
+ if (importJSSDK) {
31
+ deps['@cloudbase/js-sdk'] = CLOUDBASE_VERSION;
36
32
  }
33
+ Object.assign(deps, generateLibDependencies('mp', officialLibVersion));
37
34
  }
38
35
  else {
39
36
  for (const key in CLOUDBASE_DEPS) {
@@ -46,3 +43,28 @@ function generatePackageDependencies({ importJSSDK, mode, officialLibVersion, ui
46
43
  };
47
44
  }
48
45
  exports.generatePackageDependencies = generatePackageDependencies;
46
+ function generateLibDependencies(mode, officialLibVersion) {
47
+ const deps = {};
48
+ const modeDeps = mode === 'mp' ? { ...CLOUDBASE_DEPS, ...SYS_CLOUDBASE_DEPS } : COMPONENT_DEPS;
49
+ for (const key in modeDeps) {
50
+ const version = modeDeps[key];
51
+ deps[key] = /^\d/.test(version) ? `^${version}` : version;
52
+ }
53
+ if (officialLibVersion) {
54
+ const officialLibPackageName = mode === 'mp' ? cals_1.OFFICIAL_LIB_MP_NPM_PACKAGENAME : cals_1.OFFICIAL_LIB_NPM_PACKAGENAME;
55
+ deps[officialLibPackageName] = officialLibVersion;
56
+ }
57
+ return deps;
58
+ }
59
+ exports.generateLibDependencies = generateLibDependencies;
60
+ function generateSystemPackageDependencies({ importJSSDK }) {
61
+ const deps = {};
62
+ if (importJSSDK) {
63
+ deps['@cloudbase/js-sdk'] = CLOUDBASE_VERSION;
64
+ }
65
+ return {
66
+ ...deps,
67
+ ...SYS_CLOUDBASE_DEPS,
68
+ };
69
+ }
70
+ exports.generateSystemPackageDependencies = generateSystemPackageDependencies;
@@ -1,5 +1,5 @@
1
1
  export { REPLACE_SIGN, MP_CONFIG_MODULE_NAME, KBONE_PAGE_KEYS, npmRegistry, remConfig, rpxConfig, OFFICIAL_LIB_KEY, } from '@cloudbase/lowcode-generator/lib/generator/config/index';
2
- export { generatePackageDependencies } from './dependencies';
2
+ export { generatePackageDependencies, generateLibDependencies, generateSystemPackageDependencies, } from './dependencies';
3
3
  export declare const sharedMaterialsDir: string;
4
4
  export declare const appTemplateDir: string;
5
5
  export declare const materialsDirName = "materials";
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.getPrivatelinkJsUrl = exports.REPEATER = exports.generateCdnEndpoints = exports.CDN_ENDPONTS_CONFIG = exports.systemSubpackageMiniprogramDir = exports.cloudbaseMiniprogramDir = exports.miniprogramDir = exports.RUNTIME_CONFIG_URL = exports.systemSubpackageMiniprogramURL = exports.cloudbaseMiniprogramURL = exports.miniprogramURL = exports.materialsDirName = exports.appTemplateDir = exports.sharedMaterialsDir = exports.generatePackageDependencies = exports.OFFICIAL_LIB_KEY = exports.rpxConfig = exports.remConfig = exports.npmRegistry = exports.KBONE_PAGE_KEYS = exports.MP_CONFIG_MODULE_NAME = exports.REPLACE_SIGN = void 0;
29
+ exports.getPrivatelinkJsUrl = exports.REPEATER = exports.generateCdnEndpoints = exports.CDN_ENDPONTS_CONFIG = exports.systemSubpackageMiniprogramDir = exports.cloudbaseMiniprogramDir = exports.miniprogramDir = exports.RUNTIME_CONFIG_URL = exports.systemSubpackageMiniprogramURL = exports.cloudbaseMiniprogramURL = exports.miniprogramURL = exports.materialsDirName = exports.appTemplateDir = exports.sharedMaterialsDir = exports.generateSystemPackageDependencies = exports.generateLibDependencies = exports.generatePackageDependencies = exports.OFFICIAL_LIB_KEY = exports.rpxConfig = exports.remConfig = exports.npmRegistry = exports.KBONE_PAGE_KEYS = exports.MP_CONFIG_MODULE_NAME = exports.REPLACE_SIGN = void 0;
30
30
  const path = __importStar(require("path"));
31
31
  const os_1 = __importDefault(require("os"));
32
32
  const index_1 = require("@cloudbase/lowcode-generator/lib/generator/config/index");
@@ -40,6 +40,8 @@ Object.defineProperty(exports, "rpxConfig", { enumerable: true, get: function ()
40
40
  Object.defineProperty(exports, "OFFICIAL_LIB_KEY", { enumerable: true, get: function () { return index_2.OFFICIAL_LIB_KEY; } });
41
41
  var dependencies_1 = require("./dependencies");
42
42
  Object.defineProperty(exports, "generatePackageDependencies", { enumerable: true, get: function () { return dependencies_1.generatePackageDependencies; } });
43
+ Object.defineProperty(exports, "generateLibDependencies", { enumerable: true, get: function () { return dependencies_1.generateLibDependencies; } });
44
+ Object.defineProperty(exports, "generateSystemPackageDependencies", { enumerable: true, get: function () { return dependencies_1.generateSystemPackageDependencies; } });
43
45
  exports.sharedMaterialsDir = path.join(os_1.default.homedir(), '.weapps-materials');
44
46
  exports.appTemplateDir = path.resolve(__dirname, '../../../template');
45
47
  exports.materialsDirName = 'materials'; // materials diretory of current project
@@ -48,8 +50,8 @@ exports.materialsDirName = 'materials'; // materials diretory of current project
48
50
  * 存放在大账号:100015939275。访问地址:https://console.cloud.tencent.com/cos/bucket?bucket=comp-public-replace-1303824488&region=ap-shanghai&path=%252Flcap-builder%252F
49
51
  */
50
52
  const COMP_PUBLIC_DOMAIN = 'comp-public-replace-1303824488-cos.weda.tencent.com';
51
- exports.miniprogramURL = `https://${COMP_PUBLIC_DOMAIN}/lcap-builder/miniprogram_npm.1.9.4.zip`;
52
- exports.cloudbaseMiniprogramURL = `https://${COMP_PUBLIC_DOMAIN}/lcap-builder/cloudbase_miniprogram_npm.1.9.4.zip`;
53
+ exports.miniprogramURL = `https://${COMP_PUBLIC_DOMAIN}/lcap-builder/miniprogram_npm.1.9.5.zip`;
54
+ exports.cloudbaseMiniprogramURL = `https://${COMP_PUBLIC_DOMAIN}/lcap-builder/cloudbase_miniprogram_npm.1.9.5.zip`;
53
55
  exports.systemSubpackageMiniprogramURL = `https://${COMP_PUBLIC_DOMAIN}/lcap-builder/wd_system_miniprogram_npm.zip`;
54
56
  exports.RUNTIME_CONFIG_URL = `https://${COMP_PUBLIC_DOMAIN}/release_config/runtime/exp_runtime.json`;
55
57
  /**
@@ -4,6 +4,7 @@ import { DEPLOY_MODE, RUNTIME } from '../../types';
4
4
  import { IPlatformApp } from '@cloudbase/cals';
5
5
  import { ICDN_ENDPOINTS_COFIG } from '../config';
6
6
  import { ICommonBuildContext } from '../mp/BuildContext';
7
+ export { buildBlock } from '../h5/block2component';
7
8
  interface IBaseAppProps {
8
9
  appKey: string;
9
10
  dependencies?: IMaterialItem[];
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.buildComposite = exports.normalizeInputs = exports.getCompileDirs = exports.downloadZip = exports.strToBuf = exports.fileToZip = exports.getFiles = exports.version = exports.cleanComponentDir = exports.buildWedaApp = exports.buildWedaConfig = void 0;
6
+ exports.buildComposite = exports.normalizeInputs = exports.getCompileDirs = exports.downloadZip = exports.strToBuf = exports.fileToZip = exports.getFiles = exports.version = exports.cleanComponentDir = exports.buildWedaApp = exports.buildWedaConfig = exports.buildBlock = void 0;
7
7
  const fs_extra_1 = __importDefault(require("fs-extra"));
8
8
  const path_1 = __importDefault(require("path"));
9
9
  const util_1 = require("../util");
@@ -18,6 +18,8 @@ const config_1 = require("../config");
18
18
  const axios_1 = __importDefault(require("axios"));
19
19
  const materials_1 = require("../mp/materials");
20
20
  const common_3 = require("@cloudbase/lowcode-generator/lib/generator/types/common");
21
+ var block2component_1 = require("../h5/block2component");
22
+ Object.defineProperty(exports, "buildBlock", { enumerable: true, get: function () { return block2component_1.buildBlock; } });
21
23
  const pkg = require('../../../package.json');
22
24
  async function buildWedaConfig({ output, domain = undefined, isPrivateMode = undefined, endpointType = undefined, buildTypeList = [common_1.BuildType.WEB], }) {
23
25
  if ((0, common_1.buildAsWebByBuildType)(buildTypeList)) {
@@ -0,0 +1,2 @@
1
+ import { RUNTIME } from '../../types';
2
+ export declare function buildBlock(buildDir: any, dependencies: any, runtime?: RUNTIME): Promise<any>;
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildBlock = void 0;
4
+ const cals_1 = require("@cloudbase/cals");
5
+ const util_1 = require("../util");
6
+ const types_1 = require("../../types");
7
+ const material_1 = require("./material");
8
+ const config_1 = require("../config");
9
+ const generate_1 = require("./generate");
10
+ async function buildBlock(buildDir, dependencies, runtime = types_1.RUNTIME.NONE) {
11
+ var _a, _b;
12
+ const { materialsDir } = (0, util_1.getCompileDirs)();
13
+ let usedComps;
14
+ const composite = dependencies.find((lib) => lib.isComposite);
15
+ if (composite) {
16
+ let id = 0;
17
+ const cals = {
18
+ items: [
19
+ {
20
+ id: '$page',
21
+ type: 'PAGE',
22
+ items: ((_b = (_a = composite.components) === null || _a === void 0 ? void 0 : _a.map) === null || _b === void 0 ? void 0 : _b.call(_a, (component) => {
23
+ id += 1;
24
+ return {
25
+ id: `id${id}`,
26
+ module: composite.name,
27
+ component: component.name,
28
+ attributes: {},
29
+ };
30
+ })) || [],
31
+ },
32
+ ],
33
+ };
34
+ usedComps = (0, cals_1.getUsedComps)([cals], dependencies, { streamline: true, withAction: true });
35
+ }
36
+ let processedDependencies = await (0, material_1.runHandleMaterial)(buildDir, dependencies.filter((lib) => {
37
+ var _a, _b;
38
+ // 注意需要包涵官方的(gsd),部分平台方法需要由其补充
39
+ return lib.name !== config_1.OFFICIAL_LIB_KEY && !!(((_a = usedComps.component) === null || _a === void 0 ? void 0 : _a[lib.name]) || ((_b = usedComps.action) === null || _b === void 0 ? void 0 : _b[lib.name]));
40
+ }),
41
+ // [dependence, ...dependencies],
42
+ materialsDir, runtime);
43
+ const officialDependence = dependencies.find((lib) => lib.name === config_1.OFFICIAL_LIB_KEY);
44
+ const componentDeps = (0, config_1.generateLibDependencies)('h5', officialDependence === null || officialDependence === void 0 ? void 0 : officialDependence.version);
45
+ processedDependencies.push(officialDependence);
46
+ try {
47
+ await (0, generate_1.generateBlockFiles)({
48
+ dependencies: processedDependencies,
49
+ appBuildDir: buildDir,
50
+ componentDeps,
51
+ });
52
+ }
53
+ catch (error) {
54
+ throw error;
55
+ }
56
+ return buildDir;
57
+ }
58
+ exports.buildBlock = buildBlock;
@@ -7,6 +7,7 @@ import { ICommonBuildContext } from '../mp/BuildContext';
7
7
  * 该函数从 @govcloud/generate 取到需要的模版文件
8
8
  */
9
9
  export declare function generateProjectFiles(buildData: BuildAppProps): Promise<void>;
10
+ export declare function generateBlockFiles(buildData: any): Promise<void>;
10
11
  export declare function generateHTML({ buildContext, appId, envId, description, appBuildDir, externalResources, mode, devTool, isBuildApp, buildTypeList, cdnEndpoints,
11
12
  /**
12
13
  * 由于存量兜底逻辑存在
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.generateThemeVarsFile = exports.handleAssets = exports.generateHTML = exports.generateProjectFiles = void 0;
6
+ exports.generateThemeVarsFile = exports.handleAssets = exports.generateHTML = exports.generateBlockFiles = exports.generateProjectFiles = void 0;
7
7
  const lowcode_generator_1 = require("@cloudbase/lowcode-generator");
8
8
  const generateFiles_1 = require("../util/generateFiles");
9
9
  const path_1 = __importDefault(require("path"));
@@ -26,6 +26,20 @@ async function generateProjectFiles(buildData) {
26
26
  }));
27
27
  }
28
28
  exports.generateProjectFiles = generateProjectFiles;
29
+ async function generateBlockFiles(buildData) {
30
+ const { dependencies, appBuildDir, componentDeps } = buildData;
31
+ const fileCodeMap = {};
32
+ await (0, lowcode_generator_1.generateCompositeComponent)(dependencies, './', fileCodeMap, componentDeps);
33
+ try {
34
+ await Promise.all(Object.keys(fileCodeMap).map(async (filePath) => {
35
+ await (0, generateFiles_1.writeFile)(path_1.default.join(appBuildDir || '', filePath), fileCodeMap[filePath].code);
36
+ }));
37
+ }
38
+ catch (error) {
39
+ throw error;
40
+ }
41
+ }
42
+ exports.generateBlockFiles = generateBlockFiles;
29
43
  async function generateHTML({ buildContext, appId, envId, description = '', appBuildDir, externalResources = [], mode, devTool, isBuildApp, buildTypeList, cdnEndpoints,
30
44
  /**
31
45
  * 由于存量兜底逻辑存在
@@ -1,3 +1,3 @@
1
1
  import { IMaterialItem } from '@cloudbase/lowcode-generator/lib/weapps-core';
2
2
  import { RUNTIME } from '../../types';
3
- export declare function runHandleMaterial(appBuildDir: string, dependencies: IMaterialItem[] | undefined, materialsDir: string, runtime?: RUNTIME, ignoreInstall?: boolean): Promise<any[]>;
3
+ export declare function runHandleMaterial(appBuildDir: string, dependencies: IMaterialItem[] | undefined, materialsDir: string, runtime?: RUNTIME, ignoreInstall?: boolean): Promise<IMaterialItem[]>;
@@ -48,7 +48,7 @@ async function runHandleMaterial(appBuildDir, dependencies = [], materialsDir, r
48
48
  runtime,
49
49
  ignoreInstall,
50
50
  });
51
- return allMaterials.concat(compositeDependencies);
51
+ return compositeDependencies.concat(allMaterials);
52
52
  // TODO: 确认这里是否需要生成复合组件
53
53
  // await handleCompositeComponent({ dependencies, appBuildDir });
54
54
  }
@@ -213,7 +213,6 @@ async function generateWxMp({ buildContext: _buildContext, weapps, calses, deplo
213
213
  appId,
214
214
  extraDeps: {
215
215
  ...(0, index_1.generatePackageDependencies)({
216
- importJSSDK: endpointType === 'tcb-api',
217
216
  mode: 'app',
218
217
  uin: buildContext.uin,
219
218
  }),
@@ -259,8 +258,16 @@ async function generateWxMp({ buildContext: _buildContext, weapps, calses, deplo
259
258
  // 生成上报 & 系统子包模块模块
260
259
  const subpackageRootPath = path_1.default.join(localWedaRoot, 'packages', '$wd_system');
261
260
  const sysSubpackageFileData = {
262
- 'package.json': { cdnEndpoints, privatelink: !!buildContext.privatelinkConfig },
263
- 'index.js.tpl': { cdnEndpoints, privatelink: !!buildContext.privatelinkConfig },
261
+ 'package.json': {
262
+ cdnEndpoints,
263
+ privatelink: !!buildContext.privatelinkConfig,
264
+ extraDeps: (0, index_1.generateSystemPackageDependencies)({ importJSSDK: endpointType === 'tcb-api' }),
265
+ },
266
+ 'index.js.tpl': {
267
+ cdnEndpoints,
268
+ privatelink: !!buildContext.privatelinkConfig,
269
+ importJSSDK: endpointType === 'tcb-api',
270
+ },
264
271
  };
265
272
  console.log(`Generating ${em('system subpackage')} files`);
266
273
  function copyFilterTplRecursiveSync(src, dest, options) {
@@ -388,7 +395,6 @@ async function generateWxMp({ buildContext: _buildContext, weapps, calses, deplo
388
395
  appId,
389
396
  extraDeps: {
390
397
  ...(0, index_1.generatePackageDependencies)({
391
- importJSSDK: endpointType === 'tcb-api',
392
398
  mode: 'app',
393
399
  uin: buildContext.uin,
394
400
  }),
@@ -219,7 +219,7 @@ function createTemplateQuery(ctx, query = {}) {
219
219
  map[key] = {
220
220
  ...rest,
221
221
  handler: item.type === cals_1.EQueryType.GeneralFunc
222
- ? `(__data__,__params__) => (${(_b = (_a = handler['code']) === null || _a === void 0 ? void 0 : _a.replace) === null || _b === void 0 ? void 0 : _b.call(_a, /;\s*$/, '')})({params:__params__,data:__data__})`
222
+ ? `(__data__,__params__) => (\n${(_b = (_a = handler['code']) === null || _a === void 0 ? void 0 : _a.replace) === null || _b === void 0 ? void 0 : _b.call(_a, /;\s*$/, '')}\n)({params:__params__,data:__data__})`
223
223
  : `(...args) => $app.${handler === null || handler === void 0 ? void 0 : handler.name}(...args)`,
224
224
  data: staticProps,
225
225
  dataBinds: boundProps,
@@ -51,7 +51,7 @@ export declare function getMainAppDataByList(allAppDataList: IWebRuntimeAppData[
51
51
  export declare function getHomePageInstance(pageInstanceList: any): any;
52
52
  export declare function getPageName(name: string): string;
53
53
  export declare function downloadAndInstallDependencies(dependencies: IMaterialItem[] | undefined, materialsDir: string, installOptions?: IInstallOpts): Promise<void>;
54
- export declare function downloadDependencies(targetDir: string, srcZipUrl: string): Promise<void>;
54
+ export declare function downloadDependencies(targetDir: string, srcZipUrl: string, useBash?: boolean): Promise<void>;
55
55
  /**
56
56
  *
57
57
  * @param targetDir 目标目录
@@ -141,7 +141,7 @@ async function downloadAndInstallDependencies(dependencies = [], materialsDir, i
141
141
  }
142
142
  // 如果需要下载素材
143
143
  if (!(await fs_extra_1.default.pathExists(targetDir))) {
144
- const matched = srcZipUrl.match(/\/(cg-.*?)\//);
144
+ const matched = srcZipUrl === null || srcZipUrl === void 0 ? void 0 : srcZipUrl.match(/\/(cg-.*?)\//);
145
145
  const { appBuildDir } = (0, util_1.getCompileDirs)('app');
146
146
  if ((matched === null || matched === void 0 ? void 0 : matched[1]) && fs_extra_1.default.existsSync(path_1.default.resolve(appBuildDir, `.component_cache/web/${matched[1]}@${version}`))) {
147
147
  console.log(`link ${name}@${version} ...`);
@@ -162,7 +162,7 @@ async function downloadAndInstallDependencies(dependencies = [], materialsDir, i
162
162
  }
163
163
  else {
164
164
  console.log(`下载${name}@${version} ...`);
165
- await downloadDependencies(targetDir, srcZipUrl);
165
+ await downloadDependencies(targetDir, srcZipUrl, /^cloudbase-/.test(process.env.CCI_CURRENT_TEAM || ''));
166
166
  }
167
167
  }
168
168
  // 同步依赖
@@ -171,57 +171,54 @@ async function downloadAndInstallDependencies(dependencies = [], materialsDir, i
171
171
  // );
172
172
  // item.dependencies = packageJson.dependencies || {};
173
173
  }));
174
- await Promise.all(dependencies.map(async (item) => {
175
- const { name, version, srcZipUrl } = item;
176
- const materialNameVersion = `${name}@${version}`;
177
- const targetDir = path_1.default.join(materialsDir, materialNameVersion);
178
- console.log(`处理${name}@${version}依赖 ...`);
179
- await installDependencies(targetDir, {
180
- ...installOptions,
181
- isDependence: true,
182
- ignoreInstall: (0, common_2.isOfficialComponentLib)(name, version) || (installOptions === null || installOptions === void 0 ? void 0 : installOptions.ignoreInstall),
183
- dependenceMeta: {
184
- name,
185
- version,
186
- downloadUrl: srcZipUrl,
187
- },
188
- });
189
- }));
174
+ if (!process.env.IS_WEB_WORKER) {
175
+ await Promise.all(dependencies.map(async (item) => {
176
+ const { name, version, srcZipUrl } = item;
177
+ const materialNameVersion = `${name}@${version}`;
178
+ const targetDir = path_1.default.join(materialsDir, materialNameVersion);
179
+ console.log(`处理${name}@${version}依赖 ...`);
180
+ await installDependencies(targetDir, {
181
+ ...installOptions,
182
+ isDependence: true,
183
+ ignoreInstall: (0, common_2.isOfficialComponentLib)(name, version) || (installOptions === null || installOptions === void 0 ? void 0 : installOptions.ignoreInstall),
184
+ dependenceMeta: {
185
+ name,
186
+ version,
187
+ downloadUrl: srcZipUrl,
188
+ },
189
+ });
190
+ }));
191
+ }
190
192
  }
191
193
  exports.downloadAndInstallDependencies = downloadAndInstallDependencies;
192
- async function downloadDependencies(targetDir, srcZipUrl) {
194
+ async function downloadDependencies(targetDir, srcZipUrl, useBash = false) {
193
195
  const isExist = fs_extra_1.default.existsSync(path_1.default.join(targetDir, 'package.json'));
194
196
  if (isExist || !srcZipUrl) {
195
197
  return;
196
198
  }
197
199
  try {
198
- let response = await (0, axios_1.default)({
199
- url: srcZipUrl,
200
- responseType: 'stream',
201
- // proxy: false
202
- });
203
- await fs_extra_1.default.ensureDir(targetDir);
204
- // let download = spawn(
205
- // 'curl',
206
- // ['-fsSL', srcZipUrl, '-o', `${targetDir}.zip`],
207
- // {
208
- // stdio: 'inherit',
209
- // }
210
- // );
211
- // await promisifyProcess(download);
212
- const tag = `uncompress ${srcZipUrl}`;
213
- console.time(tag);
214
- await compressing_1.default.zip.uncompress(response.data, targetDir);
215
- // let unzip = spawn(
216
- // 'unzip',
217
- // ['-q', '-o', `${targetDir}.zip`, '-d', targetDir],
218
- // {
219
- // stdio: 'inherit',
220
- // }
221
- // );
222
- // await promisifyProcess(unzip);
223
- // await fs.remove(`${targetDir}.zip`);
224
- console.timeEnd(tag);
200
+ if (useBash) {
201
+ const tag = `bash ${srcZipUrl}`;
202
+ console.time(tag);
203
+ await fs_extra_1.default.ensureDir(targetDir);
204
+ await spawnPromise(`wget -qO- ${srcZipUrl} | tar xvz -C ${targetDir}`, [], {
205
+ cwd: process.cwd(),
206
+ stdio: undefined,
207
+ });
208
+ console.timeEnd(tag);
209
+ }
210
+ else {
211
+ let response = await (0, axios_1.default)({
212
+ url: srcZipUrl,
213
+ responseType: 'stream',
214
+ // proxy: false
215
+ });
216
+ const tag = `uncompress ${srcZipUrl}`;
217
+ await fs_extra_1.default.ensureDir(targetDir);
218
+ console.time(tag);
219
+ await compressing_1.default.zip.uncompress(response.data, targetDir);
220
+ console.timeEnd(tag);
221
+ }
225
222
  }
226
223
  catch (e) {
227
224
  console.error(`Fail to download weapps material package ${srcZipUrl}`, e);
@@ -364,3 +361,22 @@ async function downloadAssets(targetDir, assetUrl) {
364
361
  });
365
362
  }
366
363
  exports.downloadAssets = downloadAssets;
364
+ async function spawnPromise(command, args, options) {
365
+ return new Promise((resolve, reject) => {
366
+ var _a, _b;
367
+ const cm = (0, cross_spawn_1.default)(command, args, Object.assign({
368
+ shell: true,
369
+ stdio: 'inherit',
370
+ }, options));
371
+ let stdout = '';
372
+ (_a = cm.stdout) === null || _a === void 0 ? void 0 : _a.on('data', (data) => {
373
+ stdout += data;
374
+ });
375
+ let stderr = '';
376
+ (_b = cm.stderr) === null || _b === void 0 ? void 0 : _b.on('data', (data) => {
377
+ stderr += data;
378
+ });
379
+ cm.on('error', reject);
380
+ cm.on('close', (code) => (code === 0 ? resolve(stdout) : reject(stderr)));
381
+ });
382
+ }