@cloudbase/lowcode-builder 0.1.1 → 0.1.5-mp-beta

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 (47) hide show
  1. package/lib/builder/config/index.d.ts +14 -0
  2. package/lib/builder/config/index.js +16 -1
  3. package/lib/builder/core/index.d.ts +4 -1
  4. package/lib/builder/core/index.js +15 -3
  5. package/lib/builder/h5/copy.js +17 -3
  6. package/lib/builder/mp/BuildContext.d.ts +1 -0
  7. package/lib/builder/mp/index.d.ts +2 -1
  8. package/lib/builder/mp/index.js +65 -53
  9. package/lib/builder/mp/materials.js +12 -14
  10. package/lib/builder/mp/mp_config.js +1 -1
  11. package/lib/builder/mp/wxml.js +5 -1
  12. package/lib/builder/service/webpack.js +10 -10
  13. package/lib/builder/util/common.js +5 -4
  14. package/lib/builder/util/generateFiles.d.ts +33 -0
  15. package/lib/builder/util/generateFiles.js +120 -1
  16. package/lib/builder/util/net.d.ts +20 -1
  17. package/lib/builder/util/net.js +72 -3
  18. package/lib/types.d.ts +1 -0
  19. package/lib/types.js +3 -1
  20. package/package.json +21 -7
  21. package/template/html/index.html.ejs +6 -9
  22. package/template/mp/app/weapps-api.js +17 -45
  23. package/template/mp/app.js +66 -66
  24. package/template/mp/common/weapp-page.js +3 -1
  25. package/template/mp/component/index.js +6 -2
  26. package/template/mp/datasources/config.js.tpl +1 -1
  27. package/template/mp/datasources/datasource-profiles.js.tpl +1 -1
  28. package/template/mp/datasources/index.js +13 -4
  29. package/template/mp/package.json +12 -11
  30. package/template/mp/page/index.js +6 -2
  31. package/template/package.json +4 -2
  32. package/template/src/app/global-api.js +6 -83
  33. package/template/src/app/material-actions.js +15 -13
  34. package/template/src/datasources/index.js +15 -2
  35. package/template/src/index.jsx +1 -1
  36. package/template/webpack/web.prod.js +62 -41
  37. package/lib/generate.d.ts +0 -1
  38. package/lib/generate.js +0 -60
  39. package/lib/tests/build.d.ts +0 -1
  40. package/lib/tests/build.js +0 -19
  41. package/lib/tests/build.test.d.ts +0 -1
  42. package/lib/tests/build.test.js +0 -22
  43. package/lib/tests/data.d.ts +0 -18
  44. package/lib/tests/data.js +0 -94216
  45. package/lib/utils/postProcess copy.d.ts +0 -2
  46. package/lib/utils/postProcess copy.js +0 -27
  47. package/template/src/pages/composite.tpl +0 -151
@@ -20,7 +20,9 @@ const evtListeners = {<% Object.entries(eventHandlers).map(([handlerName, listen
20
20
  key: '<%= l.key %>',
21
21
  handler: <% if (l.type == 'rematch') {%> _handler<%= l.handler %> <%} else if (l.type === 'inline') {%> function({event, lists, forItems}, $comp){ <%= l.handler %> } <%} else {%> <%= l.handler %> <%} %>,
22
22
  data: <%= stringifyObj(l.data, {depth: null}) %>,
23
- boundData: {<% Object.entries(l.boundData).map(([prop, expr])=>{%>'<%= prop %>':($comp, lists, forItems, event) => {const $for=forItems;return <%= expr %>},
23
+ boundData: {<% Object.entries(l.boundData).map(([prop, expr])=>{%>'<%= prop %>':($comp, lists, forItems, event) => {const $for=forItems;return (
24
+ <%= expr %>
25
+ )},
24
26
  <%}) %>}
25
27
  },<%})%>
26
28
  ],<%})%>
@@ -48,7 +50,9 @@ const handler = {<% handlers.forEach(h => {%>
48
50
 
49
51
  const dataBinds = {<% Object.entries(dataBinds).map(([id, widgetBinds])=>{%>
50
52
  <%= id %>: { <% Object.entries(widgetBinds).map(([prop, expr]) => { %>
51
- <%= prop %>: function ($comp, lists, forItems, event) {const $for=forItems; return <%= expr %>; },<% }) %>
53
+ <%= prop %>: function ($comp, lists, forItems, event) {const $for=forItems; return (
54
+ <%= expr %>
55
+ ); },<% }) %>
52
56
  },<%}) %>
53
57
  }
54
58
 
@@ -1,5 +1,5 @@
1
- import dataSourceProfiles from './datasource-profiles'
2
1
  import datasetProfiles from './dataset-profiles'
2
+ const dataSourceProfiles = require('./datasource-profiles.js')
3
3
 
4
4
  /**
5
5
  * 数据源基本配置
@@ -1,4 +1,4 @@
1
1
  /**
2
2
  * 数据源摘要描述数组
3
3
  */
4
- export default <%= datasourceProfiles %>
4
+ module.exports = <%= datasourceProfiles %>
@@ -1,8 +1,16 @@
1
- import {
1
+ import { WEDA_CLOUD_SDK } from '@cloudbase/weda-client'
2
+ const {
2
3
  setConfig,
3
4
  initTcb,
4
- CLOUD_SDK
5
- } from '@cloudbase/weda-cloud-sdk'
5
+ CLOUD_SDK,
6
+ createDataset,
7
+ createStateDataSourceVar,
8
+ generateParamsParser,
9
+ EXTRA_API,
10
+ DS_API,
11
+ DS_SDK
12
+ } = WEDA_CLOUD_SDK
13
+
6
14
  export {
7
15
  createDataset,
8
16
  createStateDataSourceVar,
@@ -11,7 +19,8 @@ export {
11
19
  CLOUD_SDK,
12
20
  DS_API,
13
21
  DS_SDK,
14
- } from '@cloudbase/weda-cloud-sdk'
22
+ setConfig
23
+ }
15
24
 
16
25
  import config from './config'
17
26
 
@@ -1,15 +1,16 @@
1
1
  {
2
2
  "name": "lcap-<%= appId%>",
3
- "version": "1.0.0",
4
- "scripts": { },
3
+ "version": "1.0.8",
4
+ "scripts": {},
5
5
  "dependencies": {
6
- "@cloudbase/weda-cloud-sdk": "stable",
7
- "mobx": "^5.15.4",
8
- "lodash.get": "^4.4.2",
9
- "lodash.set": "^4.3.2",
10
- "miniprogram-gesture": "^1.0.6",
11
- "miniprogram-api-promise": "^1.0.4"<% Object.keys(extraDeps).map(depName => {%>,
12
- "<%= depName%>": "<%= extraDeps[depName]%>"<%})
6
+ "@cloudbase/weda-client": "stable",
7
+ "mobx": "^5.15.4",
8
+ "lodash.get": "^4.4.2",
9
+ "lodash.set": "^4.3.2",
10
+ "miniprogram-gesture": "^1.0.6",
11
+ "miniprogram-api-promise": "^1.0.4"<% Object.keys(extraDeps).map(depName => {%>,
12
+ "<%= depName%>": "<%= extraDeps[depName]%>"<%
13
+ })
13
14
  %>
14
- }
15
- }
15
+ }
16
+ }
@@ -17,14 +17,18 @@ const evtListeners = {<% Object.entries(eventHanlders).map(([handlerName, listen
17
17
  key: '<%= l.key %>',
18
18
  handler: <% if (l.type === 'rematch') {%> handlers.<%= l.handler %> <%} else if (l.type == 'material') {%> function(...args) { return require('../../materials/<%= l.handlerModule %>/actions/<%= l.handler %>/index').default(...args) } <%} else if (l.type == 'inline') {%> function({event, lists, forItems}, $page){const $for = forItems; return <%= l.handler %> } <%} else {%> <%= l.handler %> <%} %>,
19
19
  data: <%= stringifyObj(l.data, {depth: null}) %>,
20
- boundData: {<% Object.entries(l.boundData).map(([prop, expr])=>{%>'<%= prop %>':($page, lists, forItems, event) => {const $for = forItems; return <%= expr %>},
20
+ boundData: {<% Object.entries(l.boundData).map(([prop, expr])=>{%>'<%= prop %>':($page, lists, forItems, event) => {const $for = forItems; return (
21
+ <%= expr %>
22
+ )},
21
23
  <%}) %>}
22
24
  },<%})%>
23
25
  ],<%})%>
24
26
  }
25
27
  const dataBinds = {<% Object.entries(dataBinds).map(([id, widgetBinds])=>{%>
26
28
  <%= id %>: { <% Object.entries(widgetBinds).map(([prop, expr]) => { %>
27
- <%= prop %>: function ($page, lists, forItems, event) {const $for = forItems; return <%= expr %>; },<% }) %>
29
+ <%= prop %>: function ($page, lists, forItems, event) {const $for = forItems; return (
30
+ <%= expr %>
31
+ ); },<% }) %>
28
32
  },<%}) %>
29
33
  }
30
34
 
@@ -6,10 +6,10 @@
6
6
  },
7
7
  "dependencies": {
8
8
  "@cloudbase/js-sdk": "1.5.3-alpha.0",
9
- "@cloudbase/weda-cloud-sdk": "stable",
10
9
  "@tcwd/weapps-core": "2.2.6",
11
10
  "@tcwd/weapps-sdk": "1.2.9",
12
11
  "@zxing/library": "^0.18.6",
12
+ "@cloudbase/weda-client": "stable",
13
13
  "fastclick": "^1.0.6",
14
14
  "lodash": "^4.17.19",
15
15
  "mobx": "^5.15.4",
@@ -54,8 +54,10 @@
54
54
  "mini-css-extract-plugin": "^0.8.0",
55
55
  "hard-source-webpack-plugin": "^0.13.1",
56
56
  "html-webpack-plugin": "^3.2.0",
57
+ "ts-loader": "^8.3.0",
58
+ "typescript": "^4.4.4",
57
59
  "webpack": "^4.41.4",
58
60
  "webpack-cli": "^4.2.0",
59
61
  "webpack-dev-server": "^3.11.0"
60
62
  }
61
- }
63
+ }
@@ -1,6 +1,5 @@
1
1
  import * as sdk from '@tcwd/weapps-sdk';
2
2
  import { createComputed } from 'utils';
3
- import { DS_SDK, CLOUD_SDK, createDataset, EXTRA_API } from '../datasources';
4
3
  import store, { subPackageName } from '../store';
5
4
  import computed from '../store/computed';
6
5
  import common from './common';
@@ -8,6 +7,8 @@ import { formatDate } from '../utils/date';
8
7
  import { getter, setter, _isMobile } from '../utils';
9
8
  import actionMap from './material-actions';
10
9
  import { scanCodeApi } from '../utils/scan-code-action';
10
+ import { createWebApp, ACTIONS_KEY, ROUTER_KEY } from '@cloudbase/weda-client';
11
+ import { createDataset, EXTRA_API } from '../datasources/index'
11
12
 
12
13
  const mainAppKey = '__weappsMainApp';
13
14
  const appGlobal = process.env.isMiniprogram ? getApp() : window;
@@ -20,10 +21,10 @@ export function setCurrentPage(pageCtx) {
20
21
  }
21
22
 
22
23
  function createGlboalApi() {
24
+ const mpApp = createWebApp();
23
25
  const globalAPI = {
24
26
  id: '<%= appId %>',
25
27
  domain: '<%= domain %>',
26
- platform: 'WEB',
27
28
  formActions: {},
28
29
  pages: {},
29
30
  session: {
@@ -34,12 +35,7 @@ function createGlboalApi() {
34
35
  state: store,
35
36
  computed: createComputed(computed.global),
36
37
  common,
37
- dataSources: DS_SDK,
38
- utils: {
39
- formatDate,
40
- get: getter,
41
- set: setter,
42
- },
38
+ ...mpApp
43
39
  // ... other sdk apis & apis from mp
44
40
  }; // The global api exposed to lowcode
45
41
 
@@ -81,8 +77,6 @@ function createGlboalApi() {
81
77
  sdkModsIncluded.forEach((key) => {
82
78
  globalAPI[key] = sdk[key];
83
79
  });
84
- // 避免被wx.cloud 覆盖
85
- globalAPI.cloud = CLOUD_SDK;
86
80
 
87
81
  return globalAPI;
88
82
  }
@@ -103,80 +97,9 @@ function createPageApi() {
103
97
  export const mountAPIs = (sdks) => {
104
98
  Object.keys(sdks).forEach((item) => {
105
99
  let action = sdks[item];
106
-
107
- switch (item) {
108
- case 'showToast': {
109
- action = function (obj) {
110
- if (obj.icon === 'error' && !obj.image) {
111
- return sdks[item]({
112
- ...obj,
113
- image:
114
- 'data:image/svg+xml,%3Csvg%20width%3D%22120%22%20height%3D%22120%22%20viewBox%3D%220,0,24,24%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cpath%20d%3D%22M12%2010.586l5.657-5.657%201.414%201.414L13.414%2012l5.657%205.657-1.414%201.414L12%2013.414l-5.657%205.657-1.414-1.414L10.586%2012%204.929%206.343%206.343%204.93%2012%2010.586z%22%20fill-rule%3D%22evenodd%22%20fill%3D%22white%22%2F%3E%3C%2Fsvg%3E',
115
- });
116
- }
117
- return sdks[item](obj);
118
- };
119
- break;
120
- }
121
- case 'showModal': {
122
- const OFFICIAL_COMPONENT_LIB = 'gsd-h5-react';
123
- const showModal =
124
- actionMap[OFFICIAL_COMPONENT_LIB] &&
125
- actionMap[OFFICIAL_COMPONENT_LIB].showModal;
126
- if (!_isMobile() && showModal) {
127
- action = function (params) {
128
- return showModal({ data: params });
129
- };
130
- }
131
- break;
132
- }
133
- case 'scanCode': {
134
- action = (options) => {
135
- if (
136
- !options ||
137
- (!options.success && !options.fail && !options.complete)
138
- ) {
139
- return new Promise((resolve, reject) => {
140
- scanCodeApi({
141
- ...options,
142
- success: resolve,
143
- fail: reject,
144
- });
145
- });
146
- }
147
- scanCodeApi(options);
148
- };
149
- break;
150
- }
151
- case 'navigateTo':
152
- case 'reLaunch':
153
- case 'redirectTo': {
154
- action = function (obj) {
155
- if (obj.mode === 'web' && process.env.isMiniprogram) {
156
- console.warn('url navigation can only be used in h5 build');
157
- return;
158
- }
159
- const { url, ...restOpts } = obj;
160
- if (obj.mode === 'web') {
161
- if (item === 'navigateTo') {
162
- window.open(url);
163
- } else {
164
- window.location.href = url;
165
- }
166
- } else {
167
- return sdks[item]({
168
- ...restOpts,
169
- pageId: restOpts.pageId
170
- ? restOpts.pageId.replace(/^(\.)?\//, '')
171
- : restOpts.pageId,
172
- });
173
- }
174
- };
175
- break;
176
- }
100
+ if (!(item in ACTIONS_KEY) && !(item in ROUTER_KEY)) {
101
+ app[item] = action;
177
102
  }
178
-
179
- app[item] = action;
180
103
  });
181
104
  return app;
182
105
  };
@@ -1,14 +1,16 @@
1
1
  // Imports all material actions
2
- <% materials.map((material,index) => { if(material.entry){ %>
3
- import <%= _.camelCase(material.name)%>_<%= index%> from 'libraries/<%=material.name%>@<%= material.version %>/<%=material.entry%>';
4
- const <%= _.camelCase(material.name)%>Actions_<%= index%> = <%= _.camelCase(material.name)%>_<%= index%>.actions
5
- <% } else { (material.actions || []).map(act => {%>
6
- import <%= _.camelCase(material.name)%>_<%=act.name%> from 'libraries/<%=material.name%>@<%= material.version %>/actions/<%= act.name %>'
7
- <% }) }}) %>
8
- export default {
9
- <% materials.map((material, index) => {
10
- %> ['<%= material.name%>']:<% if(material.entry){ %> <%=_.camelCase(material.name)%>Actions_<%= index%>,
11
- <% }else{ %> {<% (material.actions || []).map(act => { %>
12
- ['<%= act.name%>']: <%= _.camelCase(material.name)%>_<%=act.name%>,<%})%>
13
- },
14
- <%}}) %>}
2
+ <% materials.map((material,index) => { if(material.entries && material.entries.actions){ %>
3
+ import * as <%= _.camelCase(material.name)%>Actions_<%= index%> from 'libraries/<%=material.name%>@<%= material.version %>/<%=material.entries.actions%>';
4
+ <% } else if(material.entries && material.entries.entry) {%>
5
+ import <%= _.camelCase(material.name)%>_<%= index%> from 'libraries/<%=material.name%>@<%= material.version %>/<%=material.entries.entry%>';
6
+ const <%= _.camelCase(material.name)%>Actions_<%= index%> = <%= _.camelCase(material.name)%>_<%= index%>.actions
7
+ <% } else { (material.actions || []).map(act => {%>
8
+ import <%= _.camelCase(material.name)%>_<%=act.name%> from 'libraries/<%=material.name%>@<%= material.version %>/actions/<%= act.name %>'
9
+ <% }) }}) %>
10
+ export default {
11
+ <% materials.map((material, index) => {
12
+ %> ['<%= material.name%>']:<% if(material.entries && (material.entries.entry || material.entries.actions)){ %> <%=_.camelCase(material.name)%>Actions_<%= index%>,
13
+ <% }else{ %> {<% (material.actions || []).map(act => { %>
14
+ ['<%= act.name%>']: <%= _.camelCase(material.name)%>_<%=act.name%>,<%})%>
15
+ },
16
+ <%}}) %>}
@@ -1,6 +1,18 @@
1
- import { setConfig, initTcb } from '@cloudbase/weda-cloud-sdk/dist/h5';
1
+ import { WEDA_CLOUD_SDK } from '@cloudbase/weda-client'
2
2
  import config from './config';
3
3
 
4
+ const {
5
+ setConfig,
6
+ initTcb,
7
+ CLOUD_SDK,
8
+ createDataset,
9
+ createStateDataSourceVar,
10
+ generateParamsParser,
11
+ EXTRA_API,
12
+ DS_API,
13
+ DS_SDK
14
+ } = WEDA_CLOUD_SDK
15
+
4
16
  export {
5
17
  createDataset,
6
18
  createStateDataSourceVar,
@@ -9,7 +21,8 @@ export {
9
21
  CLOUD_SDK,
10
22
  DS_API,
11
23
  DS_SDK,
12
- } from '@cloudbase/weda-cloud-sdk/dist/h5';
24
+ setConfig
25
+ }
13
26
 
14
27
  setConfig(config);
15
28
  initTcb();
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react'
2
2
  import * as ReactDOM from 'react-dom'
3
- import { setConfig } from '@cloudbase/weda-cloud-sdk/dist/h5'
3
+ import { setConfig } from './datasources/index'
4
4
  import App from './router'
5
5
  import './utils/monitor-jssdk.min'
6
6
  import './index.less'
@@ -6,9 +6,10 @@ const MiniCssExtractPlugin = require('mini-css-extract-plugin');
6
6
  const CopyWebpackPlugin = require('copy-webpack-plugin');
7
7
  const themeVars = require('./themeVars');
8
8
  const HappyPack = require('happypack');
9
- const core = 4;
9
+ const core = 7;
10
10
  const happyThreadPool = HappyPack.ThreadPool({ size: core });
11
11
 
12
+ const TS_LOADER_ID = 'ts-loader';
12
13
  module.exports = function (options) {
13
14
  const {
14
15
  context,
@@ -22,54 +23,69 @@ module.exports = function (options) {
22
23
  definePlugin = {},
23
24
  } = options;
24
25
  const isDevelopment = mode !== 'production';
26
+ const babelLoader = {
27
+ loader: 'babel-loader',
28
+ options: {
29
+ compact: false,
30
+ cacheDirectory: true,
31
+ cwd: context,
32
+ presets: [
33
+ [
34
+ '@babel/preset-env',
35
+ {
36
+ modules: false,
37
+ targets: {
38
+ esmodules: true,
39
+ },
40
+ },
41
+ ],
42
+ '@babel/preset-react',
43
+ ],
44
+ plugins: [
45
+ [
46
+ 'babel-plugin-import',
47
+ {
48
+ libraryName: '@govcloud/gsd-kbone-react',
49
+ libraryDirectory: 'lib/components',
50
+ camel2DashComponentName: false,
51
+ },
52
+ ],
53
+ '@babel/plugin-proposal-class-properties',
54
+ ['@babel/plugin-proposal-decorators', { legacy: true }],
55
+ '@babel/plugin-proposal-export-default-from',
56
+ '@babel/plugin-proposal-export-namespace-from',
57
+ '@babel/plugin-proposal-optional-chaining',
58
+ '@babel/plugin-proposal-partial-application',
59
+ ['@babel/plugin-proposal-pipeline-operator', { proposal: 'minimal' }],
60
+ ].filter(Boolean),
61
+ },
62
+ };
63
+
25
64
  let plugins = [
26
65
  new HappyPack({
27
- id: 'babel',
66
+ id: TS_LOADER_ID,
28
67
  loaders: [
68
+ babelLoader,
29
69
  {
30
- loader: 'babel-loader',
70
+ loader: 'ts-loader',
31
71
  options: {
32
- compact: false,
33
- cacheDirectory: true,
34
- cwd: context,
35
- presets: [
36
- [
37
- '@babel/preset-env',
38
- {
39
- targets: {
40
- esmodules: true,
41
- },
42
- useBuiltIns: 'usage',
43
- corejs: '2.6.12',
44
- },
45
- ],
46
- '@babel/preset-react',
47
- ],
48
- plugins: [
49
- [
50
- 'babel-plugin-import',
51
- {
52
- libraryName: '@govcloud/gsd-kbone-react',
53
- libraryDirectory: 'lib/components',
54
- camel2DashComponentName: false,
55
- },
56
- ],
57
- '@babel/plugin-proposal-class-properties',
58
- ['@babel/plugin-proposal-decorators', { legacy: true }],
59
- '@babel/plugin-proposal-export-default-from',
60
- '@babel/plugin-proposal-export-namespace-from',
61
- '@babel/plugin-proposal-optional-chaining',
62
- '@babel/plugin-proposal-partial-application',
63
- [
64
- '@babel/plugin-proposal-pipeline-operator',
65
- { proposal: 'minimal' },
66
- ],
67
- ].filter(Boolean),
72
+ compilerOptions: {
73
+ target: 'ESNext',
74
+ module: 'ESNext',
75
+ esModuleInterop: true,
76
+ },
77
+ happyPackMode: true,
78
+ transpileOnly: true,
68
79
  },
69
80
  },
70
81
  ],
71
82
  threadPool: happyThreadPool,
72
83
  }),
84
+ new HappyPack({
85
+ id: 'babel',
86
+ loaders: [babelLoader],
87
+ threadPool: happyThreadPool,
88
+ }),
73
89
  new HtmlWebpackPlugin({
74
90
  template: htmlTemplatePath,
75
91
  filename: 'index.html',
@@ -125,7 +141,7 @@ module.exports = function (options) {
125
141
  },
126
142
  devtool: isDevelopment ? 'eval' : false,
127
143
  resolve: {
128
- extensions: ['.js', '.jsx', '.tsx', '.json', '.scss', '.css'],
144
+ extensions: ['.js', '.jsx', '.ts', '.tsx', '.json', '.scss', '.css'],
129
145
  modules: [...resolveModules],
130
146
  symlinks: false,
131
147
  cacheWithContext: false,
@@ -135,10 +151,15 @@ module.exports = function (options) {
135
151
  },
136
152
  module: {
137
153
  rules: [
154
+ {
155
+ test: /\.tsx?$/,
156
+ exclude: /node_modules\/(?!@cloudbase\/weda-ui)|gsd-kbone-react/,
157
+ use: [`happypack/loader?id=${TS_LOADER_ID}`],
158
+ },
138
159
  {
139
160
  test: /\.(js|jsx)$/,
161
+ exclude: /node_modules\/(?!@cloudbase\/weda-ui)|gsd-kbone-react/,
140
162
  use: ['happypack/loader?id=babel'],
141
- exclude: /node_modules\/(?!@cloudbase\/weda-ui)/,
142
163
  },
143
164
  {
144
165
  test: /\.(scss|sass)$/,
package/lib/generate.d.ts DELETED
@@ -1 +0,0 @@
1
- export declare function handleMpPlugins(plugins: any[] | undefined, appBuildDir: string): Promise<void>;
package/lib/generate.js DELETED
@@ -1,60 +0,0 @@
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
- exports.handleMpPlugins = void 0;
7
- const path_1 = __importDefault(require("path"));
8
- const fs_extra_1 = __importDefault(require("fs-extra"));
9
- const core_1 = require("./builder/core");
10
- const lodash_1 = require("lodash");
11
- async function handleMpPlugins(plugins = [], appBuildDir) {
12
- const appBuildMpDir = path_1.default.resolve(appBuildDir, 'dist/mp');
13
- const appBuildNodeModulesDir = path_1.default.resolve(appBuildDir, 'node_modules');
14
- const mpBuildPkgJsonPath = path_1.default.resolve(appBuildMpDir, 'package.json');
15
- const buildPkgJson = fs_extra_1.default.readJsonSync(mpBuildPkgJsonPath);
16
- const sourcePkgJson = fs_extra_1.default.readJsonSync(path_1.default.join(appBuildDir, 'package.json'));
17
- // 合并插件内容
18
- plugins
19
- .filter((plugin) => plugin.type === 'mp')
20
- .forEach((plugin) => {
21
- const mpBuildAppJsonPath = path_1.default.resolve(appBuildMpDir, 'app.json');
22
- const pluginAppJsonPath = path_1.default.resolve(appBuildNodeModulesDir, plugin.module, 'app.json');
23
- // 合并 app.json
24
- mergeSubPackages(mpBuildAppJsonPath, pluginAppJsonPath);
25
- // 加入到包依赖中
26
- buildPkgJson.dependencies[plugin.module] =
27
- sourcePkgJson.dependencies[plugin.module];
28
- });
29
- // 安装
30
- fs_extra_1.default.writeJsonSync(mpBuildPkgJsonPath, buildPkgJson, { spaces: 2 });
31
- console.log('小程序安装依赖', appBuildMpDir);
32
- await (0, core_1.installDep)(appBuildMpDir);
33
- }
34
- exports.handleMpPlugins = handleMpPlugins;
35
- function mergeSubPackages(baseAppJsonPath, mergeAppJsonPath) {
36
- const baseJson = fs_extra_1.default.readJSONSync(baseAppJsonPath);
37
- const mergeJson = fs_extra_1.default.readJSONSync(mergeAppJsonPath);
38
- if (!mergeJson.subpackages)
39
- return;
40
- const newJson = { ...baseJson };
41
- if (!baseJson.subpackages) {
42
- newJson.subpackages = mergeJson.subpackages;
43
- }
44
- else {
45
- mergeJson.subpackages.forEach((mergeItem) => {
46
- // 找到重复的进行合并再去重
47
- const targetItemIdx = newJson.subpackages.findIndex((item) => {
48
- return item.root === mergeItem.root;
49
- });
50
- if (newJson.subpackages[targetItemIdx]) {
51
- const pages = (0, lodash_1.uniq)([].concat(newJson.subpackages[targetItemIdx].pages, mergeItem.pages));
52
- newJson.subpackages[targetItemIdx].pages = pages;
53
- }
54
- else {
55
- newJson.subpackages.push(mergeItem);
56
- }
57
- });
58
- }
59
- fs_extra_1.default.writeJSONSync(baseAppJsonPath, newJson, { spaces: 2 });
60
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,19 +0,0 @@
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
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,22 +0,0 @@
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
- });
@@ -1,18 +0,0 @@
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;