@cloudbase/cals 0.3.33-alpha.0 → 0.3.33-alpha.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.
@@ -19,7 +19,7 @@ export declare function codeToCals(codeList: ICodeItem[]): IPlatformApp;
19
19
  /**
20
20
  * 指定目录下的文件转代码
21
21
  */
22
- export declare function fileToCode(dirPath: string): Promise<ICodeItem[]>;
22
+ export declare function fileToCode(dirPath: string, onlyPath?: boolean): Promise<ICodeItem[]>;
23
23
  /**
24
24
  * 指定代码内容是否存在冲突未解决
25
25
  */
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../parser/cals/utils/code/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAiC,MAAM,mBAAmB,CAAC;AAMhF,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,YAAY,GAAG,SAAS,EAAE,CA4I9D;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,SAAS,EAAE,GAAG,YAAY,CAiI9D;AAED;;GAEG;AACH,wBAAsB,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC,CAqBtE;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEvD;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,MAAM,CA6BlF"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../parser/cals/utils/code/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAiC,MAAM,mBAAmB,CAAC;AAMhF,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,YAAY,GAAG,SAAS,EAAE,CA8J9D;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,SAAS,EAAE,GAAG,YAAY,CAmI9D;AAED;;GAEG;AACH,wBAAsB,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,GAAE,OAAe,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC,CAqBjG;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEvD;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,MAAM,CA6BlF"}
@@ -80,10 +80,7 @@ function calsToCode(calsJSON) {
80
80
  /**
81
81
  * 生成 page.json
82
82
  */
83
- codeList.push({
84
- path: `${pagePath}/page.json`,
85
- code: JSON.stringify(pageItem.items, null, 2),
86
- });
83
+ addCodeItem(`${pagePath}/page.json`, JSON.stringify(pageItem.items, null, 2));
87
84
  /**
88
85
  * 生成页面代码
89
86
  */
@@ -93,7 +90,21 @@ function calsToCode(calsJSON) {
93
90
  * 生成全局代码
94
91
  */
95
92
  genCode(calsJSON.resources);
93
+ /**
94
+ * 生成 package.json 文件
95
+ */
96
+ addCodeItem('package.json', JSON.stringify({
97
+ name: calsJSON.name,
98
+ description: calsJSON.description,
99
+ version: calsJSON.version,
100
+ }, null, 2), '');
96
101
  return codeList;
102
+ function addCodeItem(path, code, parentDir = 'src') {
103
+ codeList.push({
104
+ path: parentDir ? `${parentDir}/${path}` : path,
105
+ code,
106
+ });
107
+ }
97
108
  function genConfig(itemJSON, configFields, configPath, otherConfigFields) {
98
109
  const config = (0, lodash_1.pick)(itemJSON, configFields);
99
110
  if (otherConfigFields) {
@@ -108,7 +119,7 @@ function calsToCode(calsJSON) {
108
119
  Object.keys(config)
109
120
  .sort()
110
121
  .forEach((key) => (newConfig[key] = config[key]));
111
- codeList.push({ path: configPath, code: JSON.stringify(config, null, 2) });
122
+ addCodeItem(configPath, JSON.stringify(config, null, 2));
112
123
  }
113
124
  function genCode(resources, basePath = '') {
114
125
  const codeResources = (resources || []).filter((item) => item.type === 'CODE' && item.name !== '____index____');
@@ -140,10 +151,7 @@ function calsToCode(calsJSON) {
140
151
  break;
141
152
  }
142
153
  if (codePath) {
143
- codeList.push({
144
- path: codePath,
145
- code: codeItem.code,
146
- });
154
+ addCodeItem(codePath, codeItem.code);
147
155
  }
148
156
  });
149
157
  }
@@ -162,7 +170,7 @@ function codeToCals(codeList) {
162
170
  resources: [],
163
171
  };
164
172
  codeList.forEach((codeItem) => {
165
- if (codeItem.path === 'app-config.json') {
173
+ if (codeItem.path === 'src/app-config.json') {
166
174
  /**
167
175
  * app-config.json
168
176
  */
@@ -170,11 +178,11 @@ function codeToCals(codeList) {
170
178
  Object.assign(calsJSON, (0, lodash_1.omit)(config, ['_ignoreResources']));
171
179
  calsJSON.resources = (0, lodash_1.concat)(calsJSON.resources, config._ignoreResources);
172
180
  }
173
- else if (codeItem.path.indexOf('pages/') === 0) {
181
+ else if (codeItem.path.indexOf('src/pages/') === 0) {
174
182
  /**
175
183
  * page
176
184
  */
177
- const [, pageId] = codeItem.path.match(/pages\/(.*?)\/.*/);
185
+ const [, pageId] = codeItem.path.match(/src\/pages\/(.*?)\/.*/);
178
186
  let pageItem = calsJSON.items.find((item) => item.id === pageId);
179
187
  if (!pageItem) {
180
188
  pageItem = {
@@ -184,7 +192,7 @@ function codeToCals(codeList) {
184
192
  };
185
193
  calsJSON.items.push(pageItem);
186
194
  }
187
- if (/pages\/.*?\/page-config.json/.test(codeItem.path)) {
195
+ if (/src\/pages\/.*?\/page-config.json/.test(codeItem.path)) {
188
196
  /**
189
197
  * page-config.json
190
198
  */
@@ -193,7 +201,7 @@ function codeToCals(codeList) {
193
201
  Object.assign(pageItem, propsConfig);
194
202
  pageItem.resources = (0, lodash_1.concat)(pageItem.resources, config._ignoreResources);
195
203
  }
196
- else if (/pages\/.*?\/page.json/.test(codeItem.path)) {
204
+ else if (/src\/pages\/.*?\/page.json/.test(codeItem.path)) {
197
205
  /**
198
206
  * page.json
199
207
  */
@@ -206,7 +214,7 @@ function codeToCals(codeList) {
206
214
  handleNormalCodes(codeItem, pageId, pageItem.resources);
207
215
  }
208
216
  }
209
- else {
217
+ else if (codeItem.path.indexOf('src/') === 0) {
210
218
  /**
211
219
  * global normal codes
212
220
  */
@@ -215,7 +223,9 @@ function codeToCals(codeList) {
215
223
  });
216
224
  return calsJSON;
217
225
  function handleNormalCodes(codeItem, pageId, resources) {
218
- const relativePath = !pageId ? codeItem.path : codeItem.path.replace(`pages/${pageId}/`, '');
226
+ const relativePath = !pageId
227
+ ? codeItem.path.replace('src/', '')
228
+ : codeItem.path.replace(`src/pages/${pageId}/`, '');
219
229
  const _pageId = !pageId ? 'global' : pageId;
220
230
  const commonVal = {
221
231
  code: codeItem.code,
@@ -223,7 +233,7 @@ function codeToCals(codeList) {
223
233
  system: true,
224
234
  };
225
235
  /**
226
- * 只处理 path 为 theme.less, style.less, lifecycle.js, common/xxx.js, handler/xxx.js
236
+ * 只处理 path 为 src/theme.less, src/style.less, src/lifecycle.js, src/common/xxx.js, src/pages/xxx/handler/xxx.js
227
237
  * 其它视为无效文件忽略
228
238
  */
229
239
  switch (relativePath) {
@@ -244,7 +254,7 @@ function codeToCals(codeList) {
244
254
  resources.push(Object.assign(Object.assign({ name, path: `${_pageId}/handler/${name}`, codeType: 'handler-fn' }, commonVal), { system: false }));
245
255
  }
246
256
  // globa common
247
- const commonMatches = codeItem.path.match(/^common\/([^/]*?).js$/);
257
+ const commonMatches = relativePath.match(/^common\/([^/]*?).js$/);
248
258
  if (commonMatches) {
249
259
  const [, name] = commonMatches;
250
260
  calsJSON.resources.push(Object.assign({ name, path: `${_pageId}/common/${name}`, codeType: 'normal-module' }, commonVal));
@@ -257,7 +267,7 @@ exports.codeToCals = codeToCals;
257
267
  /**
258
268
  * 指定目录下的文件转代码
259
269
  */
260
- function fileToCode(dirPath) {
270
+ function fileToCode(dirPath, onlyPath = false) {
261
271
  return __awaiter(this, void 0, void 0, function* () {
262
272
  const result = yield new Promise((resolve, reject) => {
263
273
  // 只包含 js, json, less 文件,其它忽略(因为不属于 weda 的文件)
@@ -268,7 +278,7 @@ function fileToCode(dirPath) {
268
278
  else {
269
279
  const codeList = yield Promise.all(files.map((filePath) => __awaiter(this, void 0, void 0, function* () {
270
280
  const codePath = path_1.default.relative(dirPath, filePath);
271
- const codeContent = yield fs_extra_1.default.readFile(filePath, 'utf8');
281
+ const codeContent = onlyPath ? '' : yield fs_extra_1.default.readFile(filePath, 'utf8');
272
282
  return {
273
283
  path: codePath,
274
284
  code: codeContent,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudbase/cals",
3
- "version": "0.3.33-alpha.0",
3
+ "version": "0.3.33-alpha.1",
4
4
  "description": "Common application specifications",
5
5
  "main": "lib/utils/index.js",
6
6
  "typedocMain": "types/index.ts",