@cloudbase/lowcode-builder 1.3.15 → 1.4.1

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.
File without changes
File without changes
@@ -59,7 +59,7 @@ exports.CDN_ENDPONTS_CONFIG = {
59
59
  common: '',
60
60
  cloudbase: '//static.cloudbase.net',
61
61
  cdngo: 'https://qbase.cdn-go.cn',
62
- aegis: 'https://cdn-go.cn',
62
+ aegis: 'https://tam.cdn-go.cn',
63
63
  };
64
64
  function generateCdnEndpoints(endpoints = exports.CDN_ENDPONTS_CONFIG) {
65
65
  for (const key in exports.CDN_ENDPONTS_CONFIG) {
@@ -40,6 +40,13 @@ export interface IBuildWedaApp extends IBaseAppProps {
40
40
  isPrivateMode?: boolean;
41
41
  endpointType?: 'tcb-api' | 'wechat-service';
42
42
  }
43
+ export declare function buildWedaConfig({ output, domain, isPrivateMode, endpointType, buildTypeList, }: {
44
+ output: Required<IBuildWedaApp['output']>;
45
+ domain?: string;
46
+ isPrivateMode?: boolean;
47
+ endpointType?: IBuildWedaApp['endpointType'];
48
+ buildTypeList?: IBuildWedaApp['buildTypeList'];
49
+ }): Promise<void>;
43
50
  export declare function buildWedaApp({ cals, subAppCalsList, dependencies, appKey, runtime, ignoreInstall, buildTypeList, mode, devTool, deployOptions, generateMpType, plugins, extraData, resourceAppId, domain, output, isBrowserMpBuilder, cdnEndpoints, isPrivateMode, endpointType, }: IBuildWedaApp, cb?: WebpackBuildCallBack): Promise<string | undefined>;
44
51
  export declare function cleanComponentDir(): Promise<void>;
45
52
  export declare const version: any;
@@ -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.normalizeInputs = exports.getCompileDirs = exports.downloadZip = exports.strToBuf = exports.fileToZip = exports.getFiles = exports.version = exports.cleanComponentDir = exports.buildWedaApp = void 0;
6
+ exports.normalizeInputs = exports.getCompileDirs = exports.downloadZip = exports.strToBuf = exports.fileToZip = exports.getFiles = exports.version = exports.cleanComponentDir = exports.buildWedaApp = exports.buildWedaConfig = void 0;
7
7
  const fs_extra_1 = __importDefault(require("fs-extra"));
8
8
  const chalk_1 = __importDefault(require("chalk"));
9
9
  const path_1 = __importDefault(require("path"));
@@ -18,6 +18,45 @@ const postProcess_1 = require("../../utils/postProcess");
18
18
  const cals_1 = require("@cloudbase/cals");
19
19
  const net_1 = require("../util/net");
20
20
  const pkg = require('../../../package.json');
21
+ async function buildWedaConfig({ output, domain = undefined, isPrivateMode = undefined, endpointType = undefined, buildTypeList = [common_1.BuildType.WEB], }) {
22
+ if ((0, common_1.buildAsWebByBuildType)(buildTypeList)) {
23
+ throw new Error('构建类型仅支持 MP');
24
+ }
25
+ let outDir = output === null || output === void 0 ? void 0 : output.path;
26
+ if (!outDir) {
27
+ throw new Error('无效的项目输出路径');
28
+ }
29
+ let miniprogramRoot = outDir;
30
+ let projectJsonPath = path_1.default.resolve(outDir, 'project.config.json');
31
+ if (fs_extra_1.default.existsSync(projectJsonPath)) {
32
+ const projectConfigJson = await fs_extra_1.default.readJson(projectJsonPath);
33
+ miniprogramRoot = path_1.default.join(outDir, projectConfigJson.miniprogramRoot || '/');
34
+ }
35
+ const configPath = path_1.default.resolve(miniprogramRoot, 'common/config.js');
36
+ let data = { domain, isPrivateMode, endpointType };
37
+ if (fs_extra_1.default.existsSync(configPath)) {
38
+ try {
39
+ let config = require(configPath);
40
+ let current = {};
41
+ if (config.__esModule) {
42
+ current = config.default || {};
43
+ }
44
+ else {
45
+ current = config || {};
46
+ }
47
+ for (const key in data) {
48
+ if (data[key] === undefined) {
49
+ data[key] = current[key];
50
+ }
51
+ }
52
+ }
53
+ catch (e) {
54
+ console.error('parse current file error, overwrite current config', e);
55
+ }
56
+ }
57
+ await (0, index_1.generateConfig)(data, outDir);
58
+ }
59
+ exports.buildWedaConfig = buildWedaConfig;
21
60
  async function buildWedaApp({ cals, subAppCalsList = [], dependencies = [], appKey = 'test', runtime = types_1.RUNTIME.NONE, ignoreInstall = false, buildTypeList = [common_1.BuildType.WEB], mode = common_1.WebpackModeType.PRODUCTION, devTool = 'webpack', deployOptions = { mode: types_1.DEPLOY_MODE.PREVIEW }, generateMpType = common_1.GenerateMpType.APP, plugins = [], extraData = {
22
61
  isComposite: false,
23
62
  compProps: {},
@@ -74,14 +74,15 @@ async function handleAssets({ appBuildDir, buildTypeList, assets, }) {
74
74
  if (assetsArr && assetsArr.length > 0) {
75
75
  if (buildTypeList.includes('app')) {
76
76
  const targetDir = path_1.default.resolve(appBuildDir, './assets');
77
- assetsArr.forEach(async (assetUrl) => {
77
+ await Promise.all(assetsArr.map(async (assetUrl) => {
78
78
  console.log('============>>>>>> getWebpackWebBuildParams assetUrl', assetUrl);
79
79
  if (assetUrl) {
80
80
  const fileName = (0, common_1.getFileNameByUrl)(assetUrl);
81
81
  jsApis.push(`./${fileName}`);
82
82
  await (0, webpack_1.downloadAssets)(targetDir, assetUrl);
83
+ return `./${fileName}`;
83
84
  }
84
- });
85
+ }));
85
86
  }
86
87
  else {
87
88
  jsApis = jsApis.concat(assetsArr);
@@ -17,6 +17,11 @@ export declare function generateWxMp({ buildContext, weapps, plugins, deployMode
17
17
  }): Promise<{
18
18
  miniprogramRoot: string;
19
19
  }>;
20
+ export declare function generateConfig(data: {
21
+ domain?: string;
22
+ isPrivateMode?: boolean;
23
+ endpointType?: IBuildContext['endpointType'] | '';
24
+ }, root: string): Promise<void>;
20
25
  export declare function writeLowCodeFiles(ctx: IBuildContext, appData: IWeAppData, outDir: string): Promise<void>;
21
26
  /**
22
27
  * TODO: 与 cals 里的实现进行整合
@@ -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.handleUsedComponents = exports.writeLowCodeFiles = exports.generateWxMp = void 0;
29
+ exports.handleUsedComponents = exports.writeLowCodeFiles = exports.generateConfig = exports.generateWxMp = void 0;
30
30
  const chalk_1 = __importDefault(require("chalk"));
31
31
  const path_1 = __importDefault(require("path"));
32
32
  const util_1 = require("util");
@@ -76,7 +76,7 @@ async function generateWxMp({ buildContext, weapps, plugins, deployMode, options
76
76
  'project.config.json': { content: projConfig },
77
77
  };
78
78
  console.log(`Generating ${em('project')} files`);
79
- await (0, generateFiles_1.default)(buildContext, projectFileData, templateDir, projDir);
79
+ await (0, generateFiles_1.default)(projectFileData, templateDir, projDir);
80
80
  }
81
81
  // #2 生成主包
82
82
  await generatePkg({ ...buildContext, rootPath: mainAppData.rootPath }, mainAppData, path_1.default.join(projDir, '/'), pageConfigs[0]);
@@ -94,12 +94,15 @@ async function generateWxMp({ buildContext, weapps, plugins, deployMode, options
94
94
  let appJsContent = await fs.readFile(appJsPath);
95
95
  await (0, generateFiles_1.writeFile)(appJsPath, `import { app as wedaApp } from './app/weapps-api'\n${appJsContent}`);
96
96
  }
97
+ await generateConfig({
98
+ domain,
99
+ isPrivateMode,
100
+ endpointType,
101
+ }, miniprogramRoot);
97
102
  appFileData = {
98
103
  ...appFileData,
99
104
  'common/style.js': {},
100
- 'common/utils.wxs': {
101
- domain,
102
- },
105
+ 'common/utils.wxs': {},
103
106
  'common/util.js': {
104
107
  isAdminPortal: (0, common_1.buildAsAdminPortalByBuildType)(buildTypeList),
105
108
  },
@@ -164,7 +167,7 @@ async function generateWxMp({ buildContext, weapps, plugins, deployMode, options
164
167
  };
165
168
  }
166
169
  console.log(`Generating ${em('miniprogramRoot')} files`);
167
- await (0, generateFiles_1.default)(buildContext, appFileData, templateDir, miniprogramRoot);
170
+ await (0, generateFiles_1.default)(appFileData, templateDir, miniprogramRoot);
168
171
  // 若项目目录与小程序根目录不同,则拷贝素材到小程序根目录
169
172
  if (miniprogramRoot !== path_1.default.join(projDir, '/') && fs.existsSync(path_1.default.join(projDir, config_1.materialsDirName))) {
170
173
  console.log(`Move ${em(config_1.materialsDirName)} from` + `${projDir} to ${miniprogramRoot}`);
@@ -180,9 +183,6 @@ async function generateWxMp({ buildContext, weapps, plugins, deployMode, options
180
183
  resourceAppid: !!options.isCrossAccount ? options.resourceAppId : '',
181
184
  isProd: deployMode === types_1.DEPLOY_MODE.UPLOAD,
182
185
  clientID: (_a = mainAppData.extra) === null || _a === void 0 ? void 0 : _a.clientId,
183
- isPrivateMode,
184
- endpointType,
185
- tcbApiOrigin: endpointType === 'tcb-api' && isPrivateMode && domain ? `https://${domain}` : '',
186
186
  },
187
187
  'datasources/datasource-profiles.js.tpl': {
188
188
  datasourceProfiles: (0, util_3.JsonToStringWithVariableName)((0, lowcode_generator_1.getDatasourceProfiles)(
@@ -196,7 +196,7 @@ async function generateWxMp({ buildContext, weapps, plugins, deployMode, options
196
196
  },
197
197
  };
198
198
  console.log(`Generating ${em('datasources')} files`);
199
- await (0, generateFiles_1.default)(buildContext, datasourceFileData, templateDir, miniprogramRoot);
199
+ await (0, generateFiles_1.default)(datasourceFileData, templateDir, miniprogramRoot);
200
200
  }
201
201
  // 生成子包
202
202
  await Promise.all(weapps.map(async (app, index) => {
@@ -214,7 +214,7 @@ async function generateWxMp({ buildContext, weapps, plugins, deployMode, options
214
214
  // 生成package.json
215
215
  let packageJsonPath = path_1.default.join(subpackageRootPath, 'package.json');
216
216
  if (!fs.existsSync(packageJsonPath)) {
217
- await (0, generateFiles_1.default)(buildContext, {
217
+ await (0, generateFiles_1.default)({
218
218
  'package.json': {
219
219
  appId,
220
220
  importJSSDK: endpointType === 'tcb-api',
@@ -283,6 +283,20 @@ async function generateWxMp({ buildContext, weapps, plugins, deployMode, options
283
283
  }
284
284
  }
285
285
  exports.generateWxMp = generateWxMp;
286
+ async function generateConfig(data, root) {
287
+ const { domain = '', isPrivateMode = false, endpointType = '' } = data;
288
+ await (0, generateFiles_1.default)({
289
+ 'common/config.js': {
290
+ domain,
291
+ isPrivateMode,
292
+ endpointType,
293
+ },
294
+ 'common/config.wxs': {
295
+ domain,
296
+ },
297
+ }, templateDir, root);
298
+ }
299
+ exports.generateConfig = generateConfig;
286
300
  async function generatePkg(ctx, weapp, appRoot, pageConfigs) {
287
301
  const wxmlDataPrefix = (0, mp_1.getWxmlDataPrefix)(!ctx.isProduction);
288
302
  console.log(`Generating ${em(weapp.rootPath ? 'subApp' : 'app')} to ${appRoot}`);
@@ -348,7 +362,7 @@ async function generatePkg(ctx, weapp, appRoot, pageConfigs) {
348
362
  },
349
363
  };
350
364
  // Generating file by template and data
351
- await (0, generateFiles_1.default)(ctx, pageFileData, `${templateDir}/page`, path_1.default.join(appRoot, 'pages', page.id));
365
+ await (0, generateFiles_1.default)(pageFileData, `${templateDir}/page`, path_1.default.join(appRoot, 'pages', page.id));
352
366
  }));
353
367
  // #3 writing lowcode files
354
368
  await writeLowCodeFiles(ctx, weapp, appRoot);
@@ -366,7 +380,6 @@ async function generateFramework(ctx, appData, outDir) {
366
380
  subLevelPath: '',
367
381
  subPackageName: '',
368
382
  importor: (0, util_3.generateLowcodeImportor)([]),
369
- domain: ctx.domain || '',
370
383
  appConfig: JSON.stringify({}),
371
384
  },
372
385
  };
@@ -392,14 +405,12 @@ async function generateFramework(ctx, appData, outDir) {
392
405
  'app/app-global.js': {},
393
406
  'app/weapps-api.js': {
394
407
  appId: ctx.appId,
395
- domain: ctx.domain || '',
396
408
  subLevelPath: appData.rootPath ? `${path_1.default.posix.relative(`${appData.rootPath}`, '')}/` : '',
397
409
  subPackageName: appData.rootPath || '',
398
410
  importor,
399
411
  appConfig: (0, util_3.JsonToStringWithVariableName)({
400
412
  id: ctx.appId,
401
413
  envId: appData.envId,
402
- staticResourceDomain: ctx.domain || '',
403
414
  envVersion: (ctx === null || ctx === void 0 ? void 0 : ctx.isProduction) ? 'production' : 'preview',
404
415
  pages: appData.pageInstanceList
405
416
  .sort((item) => (item.isHome ? -1 : 1))
@@ -411,7 +422,7 @@ async function generateFramework(ctx, appData, outDir) {
411
422
  },
412
423
  'app/common.js': {
413
424
  mods: appData.lowCodes
414
- .filter((m) => m.type === cals_1.ECodeType.NORMAL_MODULE && m.name !== '____index____')
425
+ .filter((m) => m.type === cals_1.ECodeType.NORMAL_MODULE && m.name !== cals_1.ECodeName.PLACEHOLDER)
415
426
  .map((m) => m.name)
416
427
  .sort(),
417
428
  },
@@ -419,7 +430,7 @@ async function generateFramework(ctx, appData, outDir) {
419
430
  }
420
431
  }
421
432
  console.log('Generate app framework');
422
- await (0, generateFiles_1.default)(ctx, fileData, templateDir, outDir);
433
+ await (0, generateFiles_1.default)(fileData, templateDir, outDir);
423
434
  }
424
435
  async function writeLowCodeFiles(ctx, appData, outDir) {
425
436
  console.log(`Writing ${em('lowcode')} files:`);
@@ -313,7 +313,7 @@ async function generateCompositeComponent(ctx, compositedComp, compLibCommonReso
313
313
  },
314
314
  };
315
315
  // Generating file by template and data
316
- await (0, generateFiles_1.default)(compositeCtx, pageFileData, `${templateDir}/component`, outDir);
316
+ await (0, generateFiles_1.default)(pageFileData, `${templateDir}/component`, outDir);
317
317
  // #3 writing lowcode files
318
318
  /**
319
319
  * 低码没有开放 index 类别,直接去掉
@@ -200,8 +200,10 @@ function generateDataContainerListeners() {
200
200
  {
201
201
  trigger: 'onDataChange',
202
202
  jsCode: `({event})=>{
203
- app.utils.set(event.currentTarget._scope, 'dataContext.data', event?.detail?.data);
204
- app.utils.set(event.currentTarget._scope, 'dataContext.state', event?.detail?.state);
203
+ if(event.currentTarget) {
204
+ app.utils.set(event.currentTarget._scope, 'dataContext.data', event?.detail?.data);
205
+ app.utils.set(event.currentTarget._scope, 'dataContext.state', event?.detail?.state);
206
+ }
205
207
  }`,
206
208
  type: weapps_core_1.ActionType.Inline,
207
209
  data: {},
@@ -1,8 +1,7 @@
1
1
  /// <reference types="node" />
2
- import { IBuildContext } from '../mp/BuildContext';
3
2
  import { OutputType } from 'jszip';
4
3
  export declare const generatedFileContents: {};
5
- export default function generateFiles(ctx: IBuildContext, appFileData: any, srcDir: string, dstDir: string): Promise<string[]>;
4
+ export default function generateFiles(appFileData: any, srcDir: string, dstDir: string): Promise<string[]>;
6
5
  export declare function writeFile(outFile: string, content: string): Promise<boolean>;
7
6
  export declare function removeFile(file: string): void;
8
7
  /**
@@ -35,7 +35,7 @@ const glob_1 = __importDefault(require("glob"));
35
35
  const jszip_1 = __importDefault(require("jszip"));
36
36
  const buffer_1 = require("buffer");
37
37
  exports.generatedFileContents = {}; // generated files for incrmental build
38
- async function generateFiles(ctx, appFileData, srcDir, dstDir) {
38
+ async function generateFiles(appFileData, srcDir, dstDir) {
39
39
  const filesGenerated = [];
40
40
  // Generating file by template and data
41
41
  for (const file in appFileData) {
@@ -46,18 +46,6 @@ async function generateFiles(ctx, appFileData, srcDir, dstDir) {
46
46
  encoding: 'utf8',
47
47
  });
48
48
  let generatedCode = (0, lodash_1.template)(tplStr, { interpolate: /<%=([\s\S]+?)%>/ })(appFileData[file]);
49
- // 混合模式下,引用公共路径要多增加一层,并加多一层命名
50
- // 混合子包直接在对应目录上生成,而不采用替换的方式 @royhyang
51
- // if (ctx?.isMixMode && ctx?.rootPath) {
52
- // generatedCode = generatedCode.replace(
53
- // /..\/..\/..\/common\//g,
54
- // '../../../../common/'
55
- // )
56
- // generatedCode = generatedCode.replace(
57
- // /..\/..\/..\/app\//g,
58
- // '../../../../app/'
59
- // )
60
- // }
61
49
  const outFile = path_1.default.resolve(dstDir, outFileName.replace(/\.tpl$/, ''));
62
50
  if (await writeFile(outFile, generatedCode)) {
63
51
  filesGenerated.push(outFileName);