@cloudbase/framework-plugin-low-code 0.6.35 → 0.6.36

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.
@@ -1 +1 @@
1
- {"version":3,"file":"materials.d.ts","sourceRoot":"","sources":["../../../src/builder/mp/materials.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,aAAa,EACb,oBAAoB,EACpB,uBAAuB,EAIxB,MAAM,mBAAmB,CAAC;AAa3B,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAU/C,OAAO,WAAW,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAM7C,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,UAAU,EACrB,MAAM,EAAE,UAAU,EAAE,EACpB,GAAG,EAAE,aAAa,iBA8NnB;AAGD,wBAAgB,2BAA2B,CACzC,KAAK,EAAE,UAAU,EACjB,YAAY,EAAE,oBAAoB,EAAE,EACpC,cAAc,EAAE,aAAa,EAAE,EAC/B,WAAW,CAAC,EAAE,UAAU,cAsCzB;AA6ID,wBAAgB,UAAU,CACxB,GAAG,EAAE,QAAQ,CAAC,uBAAuB,CAAC,CAAC,YAAY,CAAC,EACpD,GAAG,EAAE,aAAa,EAClB,WAAW,CAAC,EAAE,WAAW;;;;;;EA8D1B"}
1
+ {"version":3,"file":"materials.d.ts","sourceRoot":"","sources":["../../../src/builder/mp/materials.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,aAAa,EACb,oBAAoB,EACpB,uBAAuB,EAIxB,MAAM,mBAAmB,CAAC;AAa3B,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAU/C,OAAO,WAAW,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAM7C,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,UAAU,EACrB,MAAM,EAAE,UAAU,EAAE,EACpB,GAAG,EAAE,aAAa,iBAuMnB;AAGD,wBAAgB,2BAA2B,CACzC,KAAK,EAAE,UAAU,EACjB,YAAY,EAAE,oBAAoB,EAAE,EACpC,cAAc,EAAE,aAAa,EAAE,EAC/B,WAAW,CAAC,EAAE,UAAU,cAsCzB;AA6ID,wBAAgB,UAAU,CACxB,GAAG,EAAE,QAAQ,CAAC,uBAAuB,CAAC,CAAC,YAAY,CAAC,EACpD,GAAG,EAAE,aAAa,EAClB,WAAW,CAAC,EAAE,WAAW;;;;;;EA8D1B"}
@@ -86,26 +86,16 @@ function installMaterials(projDir, usedComps, weapps, ctx) {
86
86
  usingMaterialMap[targetDir] = true;
87
87
  }
88
88
  const materialsSrcDirPath = path.join(materialsSrcDir, 'src');
89
- let compGroupIndexJson = '';
90
- let componentsJson = {};
91
- const dirsToDelete = [];
92
- try {
93
- compGroupIndexJson = yield fs.readJSON(path.join(materialsSrcDirPath, 'index.json'));
94
- const componentsPathMap = compGroupIndexJson.components;
95
- componentsJson = Object.keys(componentsPathMap).reduce((acc, compName) => {
96
- if (usedComps[name].has(compName)) {
97
- acc[compName] = componentsPathMap[compName];
98
- }
99
- else {
100
- if (typeof componentsPathMap[compName] === 'string') {
101
- dirsToDelete.push(path.join(targetDir, path.dirname(componentsPathMap[compName])));
102
- }
103
- }
104
- return acc;
105
- }, {});
106
- }
107
- catch (e) {
108
- console.error('streamline error:', e);
89
+ const materialIndexJsonPath = path.join(materialsSrcDirPath, 'index.json');
90
+ const isCompGroupIndexJsonExist = fs.existsSync(materialIndexJsonPath);
91
+ let dirsToDelete = [];
92
+ let compGroupIndexJson = {};
93
+ let componentsJsonUsed = {};
94
+ if (isCompGroupIndexJsonExist) {
95
+ compGroupIndexJson = yield fs.readJSON(materialIndexJsonPath);
96
+ const result = yield getNotUsedMpComponentDirs(compGroupIndexJson.components, materialsSrcDirPath, targetDir, usedComps[name]);
97
+ dirsToDelete = result.dirsToDelete;
98
+ componentsJsonUsed = result.componentsJson;
109
99
  }
110
100
  if (libUpdated(targetDir, version)) {
111
101
  if (fs.existsSync(materialsSrcDirPath)) {
@@ -129,8 +119,8 @@ function installMaterials(projDir, usedComps, weapps, ctx) {
129
119
  });
130
120
  }
131
121
  }
132
- if (compGroupIndexJson) {
133
- yield fs.writeJSON(path.join(targetDir, 'index.json'), Object.assign(Object.assign({}, compGroupIndexJson), { components: componentsJson }), { spaces: 2 });
122
+ if (isCompGroupIndexJsonExist) {
123
+ yield fs.writeJSON(path.join(targetDir, 'index.json'), Object.assign(Object.assign({}, compGroupIndexJson), { components: componentsJsonUsed }), { spaces: 2 });
134
124
  yield Promise.all(dirsToDelete.map((dir) => __awaiter(this, void 0, void 0, function* () {
135
125
  fs.remove(dir);
136
126
  })));
@@ -360,3 +350,69 @@ function getWxmlTag(cmp, ctx, nameMangler) {
360
350
  };
361
351
  }
362
352
  exports.getWxmlTag = getWxmlTag;
353
+ function getNotUsedMpComponentDirs(componentsPathMap, materialsSrcDirPath, targetDir, unsedCompsInGroup) {
354
+ return __awaiter(this, void 0, void 0, function* () {
355
+ const dirsToDelete = [];
356
+ const interalReferences = [];
357
+ const componentsJson = Object.keys(componentsPathMap).reduce((acc, compName) => {
358
+ const referencePath = componentsPathMap[compName];
359
+ if (unsedCompsInGroup.has(compName)) {
360
+ acc[compName] = referencePath;
361
+ }
362
+ else {
363
+ if (typeof referencePath === 'string') {
364
+ dirsToDelete.push(path.join(targetDir, path.dirname(referencePath)));
365
+ }
366
+ }
367
+ return acc;
368
+ }, {});
369
+ function guessDirFromPath(absReferencePath) {
370
+ if (fs.existsSync(path.join(absReferencePath, 'index.json'))) {
371
+ return absReferencePath;
372
+ }
373
+ if ((absReferencePath.endsWith('index') &&
374
+ fs.existsSync(absReferencePath + '.json')) ||
375
+ (absReferencePath.endsWith('index.json') &&
376
+ fs.existsSync(absReferencePath))) {
377
+ return path.dirname(absReferencePath);
378
+ }
379
+ return null;
380
+ }
381
+ const queue = [];
382
+ unsedCompsInGroup.forEach((compName) => {
383
+ const referencePath = componentsPathMap[compName];
384
+ if (typeof referencePath === 'string') {
385
+ const absCompDirPath = path.join(materialsSrcDirPath, path.dirname(referencePath));
386
+ queue.push(absCompDirPath);
387
+ }
388
+ });
389
+ const visited = new Set();
390
+ while (queue.length > 0) {
391
+ const absCompDirPath = queue.shift();
392
+ if (visited.has(absCompDirPath)) {
393
+ continue;
394
+ }
395
+ visited.add(absCompDirPath);
396
+ const jsonPath = path.join(absCompDirPath, 'index.json');
397
+ const compIndexJson = yield fs.readJSON(jsonPath);
398
+ const usingComponents = compIndexJson.usingComponents;
399
+ if (typeof usingComponents === 'object' && Object.keys(usingComponents).length > 0) {
400
+ Object.values(usingComponents).forEach((referencePath) => {
401
+ if (referencePath.startsWith('.') || referencePath.startsWith('/')) {
402
+ const absReferencePath = path.join(absCompDirPath, referencePath);
403
+ const absInteralRefDirPath = guessDirFromPath(absReferencePath);
404
+ if (absInteralRefDirPath) {
405
+ interalReferences.push(absInteralRefDirPath.replace(materialsSrcDirPath, targetDir));
406
+ queue.push(absInteralRefDirPath);
407
+ }
408
+ }
409
+ });
410
+ }
411
+ }
412
+ const result = {
413
+ componentsJson,
414
+ dirsToDelete: dirsToDelete.filter((i) => !interalReferences.includes(i)),
415
+ };
416
+ return result;
417
+ });
418
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudbase/framework-plugin-low-code",
3
- "version": "0.6.35",
3
+ "version": "0.6.36",
4
4
  "description": "云开发 Tencent CloudBase Framework Low Code Plugin,将低码配置生成完整项目并一键部署云开发资源。",
5
5
  "author": "yhsunshining@gmail.com",
6
6
  "homepage": "https://github.com/TencentCloudBase/cloudbase-framework#readme",