@galacean/cli 0.0.2 → 0.0.4
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.
- package/README.md +1 -30
- package/lib/cli.js +10 -1
- package/lib/diff.js +83 -6
- package/package.json +2 -2
- package/types/cli.d.ts +7 -1
- package/types/diff.d.ts +7 -0
package/README.md
CHANGED
|
@@ -8,33 +8,4 @@ $ npm i -g @galacean/cli
|
|
|
8
8
|
galacean diff <project1-url> <project2-url>
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
执行命令后会在命令文件夹下生成『项目 diff.md』文件,可以打开查看 diff 数据。
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
## 测试 case
|
|
16
|
-
|
|
17
|
-
project: https://local.alipay.net:4000/#/project/24400002
|
|
18
|
-
|
|
19
|
-
- 资产
|
|
20
|
-
|
|
21
|
-
- [ ] 资产新增
|
|
22
|
-
- https://mmtcdp.stable.alipay.net/oasis_be/afts/file/A*3htQQZ8Fa0sAAAAAAAAAAAAADnN-AQ/project.json https://mmtcdp.stable.alipay.net/oasis_be/afts/file/A*smcAQqM3oy0AAAAAAAAAAAAADnN-AQ/project.json
|
|
23
|
-
- [ ] 资产移除
|
|
24
|
-
- https://mmtcdp.stable.alipay.net/oasis_be/afts/file/A*smcAQqM3oy0AAAAAAAAAAAAADnN-AQ/project.json https://mmtcdp.stable.alipay.net/oasis_be/afts/file/A*3htQQZ8Fa0sAAAAAAAAAAAAADnN-AQ/project.json
|
|
25
|
-
|
|
26
|
-
- 场景
|
|
27
|
-
|
|
28
|
-
- Entity
|
|
29
|
-
- [x] Entity 新增
|
|
30
|
-
- https://mmtcdp.stable.alipay.net/oasis_be/afts/file/A*vuobSqCRjRcAAAAAAAAAAAAADnN-AQ/project.json https://mmtcdp.stable.alipay.net/oasis_be/afts/file/A*px25TbJo7CYAAAAAAAAAAAAADnN-AQ/project.json
|
|
31
|
-
- [x] Entity 移除
|
|
32
|
-
- https://mmtcdp.stable.alipay.net/oasis_be/afts/file/A*px25TbJo7CYAAAAAAAAAAAAADnN-AQ/project.json https://mmtcdp.stable.alipay.net/oasis_be/afts/file/A*vuobSqCRjRcAAAAAAAAAAAAADnN-AQ/project.json
|
|
33
|
-
- 组件
|
|
34
|
-
- [ ] 组件新增
|
|
35
|
-
- https://mdn.alipayobjects.com/oasis_be/afts/file/A*R9kHQZQhOtUAAAAAAAAAAAAADkp5AQ/project.json https://mdn.alipayobjects.com/oasis_be/afts/file/A*yB3uQKIU6HUAAAAAAAAAAAAADkp5AQ/project.json
|
|
36
|
-
- [ ] 组件移除
|
|
37
|
-
- https://mdn.alipayobjects.com/oasis_be/afts/file/A*yB3uQKIU6HUAAAAAAAAAAAAADkp5AQ/project.json https://mdn.alipayobjects.com/oasis_be/afts/file/A*R9kHQZQhOtUAAAAAAAAAAAAADkp5AQ/project.json
|
|
38
|
-
|
|
39
|
-
- 复合 case
|
|
40
|
-
- https://mmtcdp.stable.alipay.net/oasis_be/afts/file/A*Y9y2R784BXUAAAAAAAAAAAAADnN-AQ/project.json https://mmtcdp.stable.alipay.net/oasis_be/afts/file/A*OsYURKUVT9YAAAAAAAAAAAAADnN-AQ/project.json
|
|
11
|
+
执行命令后会在命令文件夹下生成『项目 diff.md』文件,可以打开查看 diff 数据。
|
package/lib/cli.js
CHANGED
|
@@ -2,7 +2,7 @@ import { cac } from "cac";
|
|
|
2
2
|
import path from "path";
|
|
3
3
|
import fs from "fs-extra";
|
|
4
4
|
import * as url from "url";
|
|
5
|
-
import { diffProjects } from "./diff.js";
|
|
5
|
+
import { _diffProjects, diffProjects } from "./diff.js";
|
|
6
6
|
import { getFileBufferFromUrl } from "./utils.js";
|
|
7
7
|
import { markdown } from "./Markdown.js";
|
|
8
8
|
const __dirname = url.fileURLToPath(new URL(".", import.meta.url));
|
|
@@ -22,6 +22,15 @@ cli.command("diff [...files]", "diff files").action((files) => {
|
|
|
22
22
|
markdown.generate();
|
|
23
23
|
});
|
|
24
24
|
});
|
|
25
|
+
export function diffProject(before, after) {
|
|
26
|
+
return Promise.all([
|
|
27
|
+
getFileBufferFromUrl(before),
|
|
28
|
+
getFileBufferFromUrl(after),
|
|
29
|
+
]).then((res) => {
|
|
30
|
+
const result = res.map((item) => JSON.parse(item.toString()));
|
|
31
|
+
return _diffProjects(result[0], result[1]);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
25
34
|
const pkg = fs.readJSONSync(path.join(__dirname, "../package.json"));
|
|
26
35
|
cli.help();
|
|
27
36
|
cli.version(pkg.version);
|
package/lib/diff.js
CHANGED
|
@@ -2,6 +2,39 @@ import { Operation, diff, flattenChangeset } from "json-diff-ts";
|
|
|
2
2
|
import { groupBy, cloneDeep } from "lodash-es";
|
|
3
3
|
import { getFileBufferFromUrl } from "./utils.js";
|
|
4
4
|
import { markdown } from "./Markdown.js";
|
|
5
|
+
export async function _diffProjects(project1, project2) {
|
|
6
|
+
const result = diff(project1, project2, { files: "id" });
|
|
7
|
+
const changes = flattenChangeset(result);
|
|
8
|
+
const assets1 = {};
|
|
9
|
+
const assets2 = {};
|
|
10
|
+
project1.files.forEach((item) => {
|
|
11
|
+
assets1[item.id] = item;
|
|
12
|
+
});
|
|
13
|
+
project2.files.forEach((item) => {
|
|
14
|
+
assets2[item.id] = item;
|
|
15
|
+
});
|
|
16
|
+
const diffs = groupBy(changes, "type");
|
|
17
|
+
const sceneChanges = [];
|
|
18
|
+
const assetsChangeInfo = { add: [], remove: [] };
|
|
19
|
+
const scenesChangeInfo = {};
|
|
20
|
+
diffs[Operation.ADD]?.forEach((item) => {
|
|
21
|
+
assetsChangeInfo.add.push(item.value.virtualPath);
|
|
22
|
+
});
|
|
23
|
+
diffs[Operation.REMOVE]?.forEach((item) => {
|
|
24
|
+
assetsChangeInfo.remove.push(item.value.virtualPath);
|
|
25
|
+
});
|
|
26
|
+
diffs[Operation.UPDATE]?.forEach((item) => {
|
|
27
|
+
const id = getIdFromPath(item.path);
|
|
28
|
+
const asset = assets1[id];
|
|
29
|
+
if (asset.type === "Scene") {
|
|
30
|
+
sceneChanges.push(asset);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
await Promise.all(sceneChanges.map(async (asset) => {
|
|
34
|
+
scenesChangeInfo[assets2[asset.id].virtualPath] = await _diffScene(asset.path, assets2[asset.id].path);
|
|
35
|
+
}));
|
|
36
|
+
return { assetsChangeInfo, scenesChangeInfo };
|
|
37
|
+
}
|
|
5
38
|
export async function diffProjects(project1, project2) {
|
|
6
39
|
const result = diff(project1, project2, { files: "id" });
|
|
7
40
|
const changes = flattenChangeset(result);
|
|
@@ -54,12 +87,6 @@ async function diffScene(url1, url2) {
|
|
|
54
87
|
const { diffObj: diffObj1, entities } = getEntities(scene1);
|
|
55
88
|
const { diffObj: diffObj2, entities: newEntities } = getEntities(scene2);
|
|
56
89
|
const changes = flattenChangeset(diff(diffObj1, diffObj2));
|
|
57
|
-
// const changesGroup = groupBy(changes, "type");
|
|
58
|
-
// markdown.addLine(``);
|
|
59
|
-
// markdown.addLine(`- Entity 移除`);
|
|
60
|
-
// changesGroup[Operation.REMOVE]?.forEach((item) => {
|
|
61
|
-
// markdown.addLine(`- ${entities[item.key].name}`, 1);
|
|
62
|
-
// });
|
|
63
90
|
const groups = groupBy(changes, (item) => {
|
|
64
91
|
if (item.path.includes(".components")) {
|
|
65
92
|
return "components";
|
|
@@ -102,6 +129,56 @@ async function diffScene(url1, url2) {
|
|
|
102
129
|
});
|
|
103
130
|
}
|
|
104
131
|
}
|
|
132
|
+
async function _diffScene(url1, url2) {
|
|
133
|
+
const [scene1, scene2] = await Promise.all([
|
|
134
|
+
getFileBufferFromUrl(url1),
|
|
135
|
+
getFileBufferFromUrl(url2),
|
|
136
|
+
]).then((res) => res.map((item) => JSON.parse(item.toString())));
|
|
137
|
+
const { diffObj: diffObj1, entities } = getEntities(scene1);
|
|
138
|
+
const { diffObj: diffObj2, entities: newEntities } = getEntities(scene2);
|
|
139
|
+
const changes = flattenChangeset(diff(diffObj1, diffObj2));
|
|
140
|
+
const sceneChangeInfo = {
|
|
141
|
+
entities: { add: [], remove: [] },
|
|
142
|
+
components: { add: [], remove: [] },
|
|
143
|
+
error: null,
|
|
144
|
+
};
|
|
145
|
+
if (Object.values(newEntities).length <= 0) {
|
|
146
|
+
sceneChangeInfo.error = "Entities is empty";
|
|
147
|
+
}
|
|
148
|
+
const groups = groupBy(changes, (item) => {
|
|
149
|
+
if (item.path.includes(".components")) {
|
|
150
|
+
return "components";
|
|
151
|
+
}
|
|
152
|
+
return "entities";
|
|
153
|
+
});
|
|
154
|
+
if (groups["entities"]) {
|
|
155
|
+
const changesGroup = groupBy(groups["entities"], "type");
|
|
156
|
+
changesGroup[Operation.ADD]?.forEach((item) => {
|
|
157
|
+
const entityPath = getEntityPath(item.key, newEntities);
|
|
158
|
+
sceneChangeInfo.entities.add.push(entityPath);
|
|
159
|
+
});
|
|
160
|
+
changesGroup[Operation.REMOVE]?.forEach((item) => {
|
|
161
|
+
const entityPath = getEntityPath(item.key, entities);
|
|
162
|
+
sceneChangeInfo.entities.remove.push(entityPath);
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
if (groups["components"]) {
|
|
166
|
+
const changesGroup = groupBy(groups["components"], "type");
|
|
167
|
+
changesGroup[Operation.ADD]?.forEach((item) => {
|
|
168
|
+
const entityId = getComponentEntityId(item.path);
|
|
169
|
+
const entityPath = getEntityPath(entityId, entities);
|
|
170
|
+
const comp = item.value;
|
|
171
|
+
sceneChangeInfo.components.add.push(`- ${entityPath} [${comp["class"]}]`);
|
|
172
|
+
});
|
|
173
|
+
changesGroup[Operation.REMOVE]?.forEach((item) => {
|
|
174
|
+
const entityId = getComponentEntityId(item.path);
|
|
175
|
+
const entityPath = getEntityPath(entityId, entities);
|
|
176
|
+
const comp = item.value;
|
|
177
|
+
sceneChangeInfo.components.remove.push(`- ${entityPath} [${comp["class"]}]`);
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
return sceneChangeInfo;
|
|
181
|
+
}
|
|
105
182
|
function getComponentEntityId(str) {
|
|
106
183
|
let regex = /\.([^.]*?)\.components/;
|
|
107
184
|
let matches = str.match(regex);
|
package/package.json
CHANGED
package/types/cli.d.ts
CHANGED
package/types/diff.d.ts
CHANGED