@cloudbase/lowcode-builder 0.0.1 → 0.0.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.
@@ -12,7 +12,6 @@ export interface IBaseAppProps {
12
12
  devTool?: string;
13
13
  watch?: boolean;
14
14
  generateMpType?: GenerateMpType;
15
- generateMpPath?: string;
16
15
  plugins?: IPlugin[];
17
16
  domain: string;
18
17
  extraData?: IExtraData;
@@ -20,8 +19,9 @@ export interface IBaseAppProps {
20
19
  export interface BuildAppProps extends IBaseAppProps {
21
20
  mainAppSerializeData?: IWeAppData;
22
21
  subAppSerializeDataList?: IWeAppData[];
22
+ generateMpPath?: string;
23
23
  }
24
- export declare function buildWedaApp({ cals, subAppCalsList, dependencies, appKey, runtime, ignoreInstall, buildTypeList, mode, devTool, deployOptions, generateMpType, generateMpPath, plugins, extraData, resourceAppId, domain, output, }: IBaseAppProps & {
24
+ export interface IBuildWedaApp extends IBaseAppProps {
25
25
  cals: IPlatformApp;
26
26
  subAppCalsList?: IPlatformApp[];
27
27
  deployOptions?: {
@@ -35,7 +35,8 @@ export declare function buildWedaApp({ cals, subAppCalsList, dependencies, appKe
35
35
  output?: {
36
36
  path?: string;
37
37
  };
38
- }, cb?: WebpackBuildCallBack): Promise<string | undefined>;
38
+ }
39
+ export declare function buildWedaApp({ cals, subAppCalsList, dependencies, appKey, runtime, ignoreInstall, buildTypeList, mode, devTool, deployOptions, generateMpType, plugins, extraData, resourceAppId, domain, output, }: IBuildWedaApp, cb?: WebpackBuildCallBack): Promise<string | undefined>;
39
40
  export declare function installDep(dir: any, opts?: IInstallOpts): Promise<void>;
40
41
  export declare const version: any;
41
42
  export default buildWedaApp;
@@ -17,7 +17,7 @@ const chalk_1 = __importDefault(require("chalk"));
17
17
  const common_2 = require("../../utils/common");
18
18
  const postProcess_1 = require("../../utils/postProcess");
19
19
  const pkg = require('../../../package.json');
20
- 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, generateMpPath = '', plugins = [], extraData = {
20
+ 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 = {
21
21
  isComposite: false,
22
22
  compProps: {},
23
23
  }, resourceAppId = undefined, domain = '', output, }, cb) {
@@ -33,16 +33,13 @@ async function buildWedaApp({ cals, subAppCalsList = [], dependencies = [], appK
33
33
  console.log('domain', domain);
34
34
  console.log('应用名', appKey);
35
35
  console.log('生成模式', generateMpType);
36
- if (generateMpType === common_1.GenerateMpType.SUBPACKAGE) {
37
- console.log('主包项目路径', generateMpPath);
38
- }
39
36
  let appBuildDir = (output === null || output === void 0 ? void 0 : output.path) ||
40
37
  (runtime === types_1.RUNTIME.CI
41
38
  ? (_a = (0, util_1.getCompileDirs)('app')) === null || _a === void 0 ? void 0 : _a.appBuildDir
42
39
  : (_b = (0, util_1.getCompileDirs)(appKey)) === null || _b === void 0 ? void 0 : _b.appBuildDir);
43
40
  const startTime = Date.now();
44
41
  if (buildTypeList.includes(common_1.BuildType.MP)) {
45
- appBuildDir = path_1.default.join(appBuildDir, 'mp');
42
+ appBuildDir = (output === null || output === void 0 ? void 0 : output.path) || path_1.default.join(appBuildDir, 'mp');
46
43
  const isMixMode = generateMpType === common_1.GenerateMpType.SUBPACKAGE;
47
44
  const apps = [mainAppSerializeData, ...subAppSerializeDataList];
48
45
  try {
@@ -66,16 +63,15 @@ async function buildWedaApp({ cals, subAppCalsList = [], dependencies = [], appK
66
63
  // 如果是混合模式,则将特定的目录复制到工程下
67
64
  // 针对 app.json / package.json 则采用 merge 的操作
68
65
  if (isMixMode) {
69
- generateMpPath = appBuildDir;
70
- console.log(chalk_1.default.green('【混合模式】'), generateMpPath);
66
+ console.log(chalk_1.default.green('【混合模式】'), appBuildDir);
71
67
  await (0, mixMode_1.handleMixMode)({
72
68
  apps,
73
- generateMpPath,
69
+ generateMpPath: appBuildDir,
74
70
  miniprogramRoot: result.miniprogramRoot,
75
71
  plugins,
76
72
  });
77
73
  }
78
- const outDir = isMixMode && generateMpPath ? generateMpPath : appBuildDir;
74
+ const outDir = appBuildDir;
79
75
  let projectJsonPath = path_1.default.resolve(outDir, 'project.config.json');
80
76
  await (0, postProcess_1.postprocessProjectConfig)(projectJsonPath, {
81
77
  appid: deployOptions === null || deployOptions === void 0 ? void 0 : deployOptions.mpAppId,
@@ -303,6 +303,7 @@ async function generatePkg(weapp, appRoot, ctx, pageConfigs) {
303
303
  const wxml = (0, wxml_1.generateWxml)(page.componentInstances, `Page ${rootPath ? path_1.default.join(rootPath, 'pages') : ''}/${page.id}`, wxmlDataPrefix, { ...ctx, rootPath, isPage: true }, usingComponents, componentGenerics);
304
304
  const pageFileName = (0, lodash_1.get)(pageConfigs, `${page.id}.pageFileName`, 'index');
305
305
  const pageFileData = {
306
+ [`api.js|api.js`]: {},
306
307
  [`index.js|${pageFileName}.js`]: {
307
308
  widgetProps: (0, util_2.createWidgetProps)(page.componentInstances, ctx),
308
309
  pageUUID: rootPath ? `${rootPath}/${page.id}` : page.id,
@@ -22,12 +22,18 @@ async function writeCode2file(mod, lowcodeRootDir, opts = {}, themeCode, ctx) {
22
22
  const relativeRoot = (ctx === null || ctx === void 0 ? void 0 : ctx.isMixMode) && ctx.rootPath
23
23
  ? path_1.default.relative(ctx.rootPath, '') + '/'
24
24
  : '';
25
- let weappsApiPrefix = `import { app, process } from '${relativeRoot}${baseDir}/app/weapps-api'`; // windows compatibility
26
- code = weappsApiPrefix + '\n' + code;
25
+ let weappsApiPrefix = [
26
+ `import { app, process } from '${relativeRoot}${baseDir}/app/weapps-api';`,
27
+ 'const $app = app;',
28
+ ]; // windows compatibility
29
+ if (pageId !== 'global') {
30
+ weappsApiPrefix.push(`import { $page } from '${relativeRoot}${baseDir}/pages/${pageId}/api.js'`);
31
+ }
32
+ code = `${weappsApiPrefix.join('\n')}\n${code}`;
27
33
  }
28
34
  else {
29
35
  // Generate component lowcode
30
- code = `import process from '${mod.type === 'handler-fn' ? '../' : ''}../../../../common/process'\nimport app from '${mod.type === 'handler-fn' ? '../' : ''}../../../../common/weapp-sdk'\n${code.replace(/\$comp/g, weapps_core_1.COMPONENT_API_PREFIX)}`;
36
+ code = `import process from '${mod.type === 'handler-fn' ? '../' : ''}../../../../common/process'\nimport app from '${mod.type === 'handler-fn' ? '../' : ''}../../../../common/weapp-sdk'\nconst $app = app;\n${code.replace(/\$comp/g, weapps_core_1.COMPONENT_API_PREFIX)};`;
31
37
  }
32
38
  }
33
39
  else {
@@ -44,7 +50,7 @@ async function writeCode2file(mod, lowcodeRootDir, opts = {}, themeCode, ctx) {
44
50
  }
45
51
  }
46
52
  if (pageId) {
47
- code = handle$page(code);
53
+ // code = handle$page(code);
48
54
  }
49
55
  await (0, generateFiles_1.writeFile)(file, code);
50
56
  }
@@ -159,19 +159,17 @@ async function installMaterials(projDir, usedComps, weapps, ctx) {
159
159
  });
160
160
  });
161
161
  // #2 Generate composited libs
162
- compositedLibs.map(async (lib) => {
162
+ await Promise.all(compositedLibs.map(async (lib) => {
163
163
  console.log('Generate composited library ' + lib.name);
164
164
  await (0, util_4.writeLibCommonRes2file)(lib, path.join(ctx.projDir, config_1.materialsDirName, lib.name, 'libCommonRes'));
165
- return lib.components.map((cmp) => {
166
- weappsList.forEach((app) => {
167
- generateCompositeComponent(cmp, {
168
- ...ctx,
169
- // 只生成在主目录中,减少冗余
170
- // rootPath: app.rootPath || '', // 主包是没有 rootPath 的
171
- }, lib.compLibCommonResource);
172
- });
173
- });
174
- });
165
+ await Promise.all(lib.components.map(async (cmp) => {
166
+ return generateCompositeComponent(cmp, {
167
+ ...ctx,
168
+ // 只生成在主目录中,减少冗余
169
+ // rootPath: app.rootPath || '', // 主包是没有 rootPath 的
170
+ }, lib.compLibCommonResource);
171
+ }));
172
+ }));
175
173
  }
176
174
  exports.installMaterials = installMaterials;
177
175
  // 递归查询复合组件所使用的组件
@@ -62,7 +62,7 @@ async function generateFiles(appFileData, srcDir, dstDir, ctx) {
62
62
  exports.default = generateFiles;
63
63
  async function writeFile(outFile, content) {
64
64
  const generated = generatedFileContents[outFile];
65
- if (generated === content) {
65
+ if (generated === content && fs_extra_1.default.existsSync(outFile)) {
66
66
  return false;
67
67
  }
68
68
  // console.log(outFile);
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,17 @@
1
+ 'use strict';
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const index_1 = require("../index");
7
+ const data_1 = __importDefault(require("./data"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const fs_extra_1 = __importDefault(require("fs-extra"));
10
+ const outPath = path_1.default.resolve(__dirname, '.temp');
11
+ fs_extra_1.default.emptyDirSync(outPath);
12
+ (0, index_1.buildWedaApp)({
13
+ ...data_1.default,
14
+ output: { path: outPath },
15
+ }).then((dir) => {
16
+ console.log(dir);
17
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,20 @@
1
+ 'use strict';
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const index_1 = require("../index");
7
+ const data_1 = __importDefault(require("./data"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const fs_extra_1 = __importDefault(require("fs-extra"));
10
+ describe('build', () => {
11
+ it('needs tests', async () => {
12
+ const outPath = path_1.default.resolve(__dirname, './temp');
13
+ fs_extra_1.default.emptyDir(outPath);
14
+ let dir = await (0, index_1.buildWedaApp)({
15
+ ...data_1.default,
16
+ output: { path: outPath },
17
+ });
18
+ console.log(dir);
19
+ });
20
+ });
@@ -0,0 +1,18 @@
1
+ import { BuildType } from '../builder/types/common';
2
+ import { DEPLOY_MODE } from '../types';
3
+ export declare const test: {
4
+ appKey: string;
5
+ cals: any;
6
+ subAppCalsList: never[];
7
+ dependencies: any[];
8
+ buildTypeList: BuildType[];
9
+ deployOptions: {
10
+ mode: DEPLOY_MODE;
11
+ mpAppId: string;
12
+ targetMpAppId: string;
13
+ };
14
+ domain: string;
15
+ resourceAppId: string;
16
+ };
17
+ declare const _default: any;
18
+ export default _default;