@cloudbase/lowcode-builder 0.0.2 → 0.1.0

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.
@@ -37,6 +37,7 @@ export interface IBuildWedaApp extends IBaseAppProps {
37
37
  };
38
38
  }
39
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>;
40
+ export declare function cleanComponentDir(): Promise<void>;
40
41
  export declare function installDep(dir: any, opts?: IInstallOpts): Promise<void>;
41
42
  export declare const version: any;
42
43
  export default buildWedaApp;
@@ -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.version = exports.installDep = exports.buildWedaApp = void 0;
6
+ exports.version = exports.installDep = exports.cleanComponentDir = exports.buildWedaApp = void 0;
7
7
  const fs_extra_1 = __importDefault(require("fs-extra"));
8
8
  const webpack_1 = require("../service/webpack");
9
9
  const util_1 = require("../util");
@@ -122,6 +122,10 @@ async function buildWedaApp({ cals, subAppCalsList = [], dependencies = [], appK
122
122
  }
123
123
  }
124
124
  exports.buildWedaApp = buildWedaApp;
125
+ async function cleanComponentDir() {
126
+ return fs_extra_1.default.emptyDir((0, util_1.getCompileDirs)().materialsDir);
127
+ }
128
+ exports.cleanComponentDir = cleanComponentDir;
125
129
  function installDep(dir, opts = {}) {
126
130
  return (0, webpack_1.installDependencies)(dir, opts);
127
131
  }
@@ -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,19 @@
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 common_1 = require("../src/builder/types/common");
11
+ const outPath = path_1.default.resolve(__dirname, '.temp');
12
+ fs_extra_1.default.emptyDirSync(outPath);
13
+ (0, index_1.buildWedaApp)({
14
+ ...data_1.default,
15
+ buildTypeList: [common_1.BuildType.WEB],
16
+ output: { path: outPath },
17
+ }).then((dir) => {
18
+ console.log(dir);
19
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,22 @@
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 common_1 = require("../lib/builder/types/common");
11
+ describe('build', () => {
12
+ it('needs tests', async () => {
13
+ const outPath = path_1.default.resolve(__dirname, './temp');
14
+ fs_extra_1.default.emptyDir(outPath);
15
+ let dir = await (0, index_1.buildWedaApp)({
16
+ ...data_1.default,
17
+ buildTypeList: [common_1.BuildType.WEB],
18
+ output: { path: outPath },
19
+ });
20
+ console.log(dir);
21
+ });
22
+ });
@@ -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;