@galacean/cli 0.0.4 → 0.0.6

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/lib/Markdown.js CHANGED
@@ -1,18 +1,17 @@
1
1
  import fs from "fs-extra";
2
2
  import path from "path";
3
- export class Markdown {
4
- _txt = "";
3
+ export const markdown = {
4
+ _txt: "",
5
5
  get txt() {
6
6
  return this._txt;
7
- }
7
+ },
8
8
  addLine(line, tab = 0) {
9
9
  for (let i = 0; i < tab; i++) {
10
10
  line = "\t" + line;
11
11
  }
12
12
  this._txt += line + "\n";
13
- }
13
+ },
14
14
  generate() {
15
15
  fs.writeFileSync(path.join(process.cwd(), "项目 Diff.md"), this._txt);
16
- }
17
- }
18
- export const markdown = new Markdown();
16
+ },
17
+ };
package/lib/cli.js CHANGED
@@ -1,3 +1,12 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
1
10
  import { cac } from "cac";
2
11
  import path from "path";
3
12
  import fs from "fs-extra";
@@ -5,6 +14,8 @@ import * as url from "url";
5
14
  import { _diffProjects, diffProjects } from "./diff.js";
6
15
  import { getFileBufferFromUrl } from "./utils.js";
7
16
  import { markdown } from "./Markdown.js";
17
+ import { mergeProject } from "./mergeProject.js";
18
+ import * as ncp from "copy-paste";
8
19
  const __dirname = url.fileURLToPath(new URL(".", import.meta.url));
9
20
  const cli = cac();
10
21
  cli.command("diff [...files]", "diff files").action((files) => {
@@ -16,12 +27,32 @@ cli.command("diff [...files]", "diff files").action((files) => {
16
27
  Promise.all([
17
28
  getFileBufferFromUrl(files[0]),
18
29
  getFileBufferFromUrl(files[1]),
19
- ]).then(async (res) => {
30
+ ]).then((res) => __awaiter(void 0, void 0, void 0, function* () {
20
31
  const result = res.map((item) => JSON.parse(item.toString()));
21
- await diffProjects(result[0], result[1]);
32
+ yield diffProjects(result[0], result[1]);
22
33
  markdown.generate();
23
- });
34
+ }));
24
35
  });
36
+ cli
37
+ .command("merge [...files]", "merge project.json by md5")
38
+ .action((files) => __awaiter(void 0, void 0, void 0, function* () {
39
+ const before = files[0];
40
+ const after = files[1];
41
+ yield Promise.all([
42
+ getFileBufferFromUrl(before),
43
+ getFileBufferFromUrl(after),
44
+ ]).then((res) => {
45
+ const result = res.map((item) => JSON.parse(item.toString()));
46
+ const resProject = mergeProject(result[0], result[1]);
47
+ const output = JSON.stringify(resProject, null, 2);
48
+ // console.log(output);
49
+ return new Promise((resolve) => {
50
+ ncp.copy(output, () => {
51
+ resolve();
52
+ });
53
+ });
54
+ });
55
+ }));
25
56
  export function diffProject(before, after) {
26
57
  return Promise.all([
27
58
  getFileBufferFromUrl(before),
package/lib/diff.js CHANGED
@@ -1,183 +1,204 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
1
10
  import { Operation, diff, flattenChangeset } from "json-diff-ts";
2
11
  import { groupBy, cloneDeep } from "lodash-es";
3
12
  import { getFileBufferFromUrl } from "./utils.js";
4
13
  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
- }
38
- export async function diffProjects(project1, project2) {
39
- const result = diff(project1, project2, { files: "id" });
40
- const changes = flattenChangeset(result);
41
- const assets1 = {};
42
- const assets2 = {};
43
- project1.files.forEach((item) => {
44
- assets1[item.id] = item;
45
- });
46
- project2.files.forEach((item) => {
47
- assets2[item.id] = item;
48
- });
49
- const diffs = groupBy(changes, "type");
50
- const sceneChanges = [];
51
- markdown.addLine("## 资产");
52
- markdown.addLine(``);
53
- markdown.addLine(`- 资产新增`);
54
- diffs[Operation.ADD]?.forEach((item) => {
55
- markdown.addLine(`- ${item.value.virtualPath}`, 1);
56
- });
57
- markdown.addLine(``);
58
- markdown.addLine(`- 资产移除`);
59
- diffs[Operation.REMOVE]?.forEach((item) => {
60
- markdown.addLine(`- ${item.value.virtualPath}`, 1);
61
- });
62
- // markdown.addLine(``);
63
- // markdown.addLine(`- 资产修改`);
64
- // markdown.addLine(``);
65
- diffs[Operation.UPDATE]?.forEach((item) => {
66
- const id = getIdFromPath(item.path);
67
- const asset = assets1[id];
68
- if (asset.type === "Scene") {
69
- sceneChanges.push(asset);
70
- }
71
- // markdown.addLine(`- ${asset.virtualPath}`, 1);
14
+ export function _diffProjects(project1, project2) {
15
+ var _a, _b, _c;
16
+ return __awaiter(this, void 0, void 0, function* () {
17
+ const result = diff(project1, project2, { files: "id" });
18
+ const changes = flattenChangeset(result);
19
+ const assets1 = {};
20
+ const assets2 = {};
21
+ project1.files.forEach((item) => {
22
+ assets1[item.id] = item;
23
+ });
24
+ project2.files.forEach((item) => {
25
+ assets2[item.id] = item;
26
+ });
27
+ const diffs = groupBy(changes, "type");
28
+ const sceneChanges = [];
29
+ const assetsChangeInfo = { add: [], remove: [] };
30
+ const scenesChangeInfo = {};
31
+ (_a = diffs[Operation.ADD]) === null || _a === void 0 ? void 0 : _a.forEach((item) => {
32
+ assetsChangeInfo.add.push(item.value.virtualPath);
33
+ });
34
+ (_b = diffs[Operation.REMOVE]) === null || _b === void 0 ? void 0 : _b.forEach((item) => {
35
+ assetsChangeInfo.remove.push(item.value.virtualPath);
36
+ });
37
+ (_c = diffs[Operation.UPDATE]) === null || _c === void 0 ? void 0 : _c.forEach((item) => {
38
+ const id = getIdFromPath(item.path);
39
+ const asset = assets1[id];
40
+ if (asset.type === "Scene") {
41
+ sceneChanges.push(asset);
42
+ }
43
+ });
44
+ yield Promise.all(sceneChanges.map((asset) => __awaiter(this, void 0, void 0, function* () {
45
+ scenesChangeInfo[assets2[asset.id].virtualPath] = yield _diffScene(asset.path, assets2[asset.id].path);
46
+ })));
47
+ return { assetsChangeInfo, scenesChangeInfo };
72
48
  });
73
- markdown.addLine(``);
74
- markdown.addLine("## 场景");
75
- markdown.addLine(``);
76
- await Promise.all(sceneChanges.map((asset) => {
77
- markdown.addLine(`### ${assets2[asset.id].virtualPath}`);
78
- markdown.addLine(``);
79
- return diffScene(asset.path, assets2[asset.id].path);
80
- }));
81
49
  }
82
- async function diffScene(url1, url2) {
83
- const [scene1, scene2] = await Promise.all([
84
- getFileBufferFromUrl(url1),
85
- getFileBufferFromUrl(url2),
86
- ]).then((res) => res.map((item) => JSON.parse(item.toString())));
87
- const { diffObj: diffObj1, entities } = getEntities(scene1);
88
- const { diffObj: diffObj2, entities: newEntities } = getEntities(scene2);
89
- const changes = flattenChangeset(diff(diffObj1, diffObj2));
90
- const groups = groupBy(changes, (item) => {
91
- if (item.path.includes(".components")) {
92
- return "components";
93
- }
94
- return "entities";
95
- });
96
- if (groups["entities"]) {
97
- markdown.addLine(`#### Entities`);
98
- markdown.addLine("");
99
- const changesGroup = groupBy(groups["entities"], "type");
100
- markdown.addLine(`- 新增`);
101
- changesGroup[Operation.ADD]?.forEach((item) => {
102
- const entityPath = getEntityPath(item.key, newEntities);
103
- markdown.addLine(`- ${entityPath}`, 1);
50
+ export function diffProjects(project1, project2) {
51
+ var _a, _b, _c;
52
+ return __awaiter(this, void 0, void 0, function* () {
53
+ const result = diff(project1, project2, { files: "id" });
54
+ const changes = flattenChangeset(result);
55
+ const assets1 = {};
56
+ const assets2 = {};
57
+ project1.files.forEach((item) => {
58
+ assets1[item.id] = item;
104
59
  });
105
- markdown.addLine(`- 移除`);
106
- changesGroup[Operation.REMOVE]?.forEach((item) => {
107
- const entityPath = getEntityPath(item.key, entities);
108
- markdown.addLine(`- ${entityPath}`, 1);
60
+ project2.files.forEach((item) => {
61
+ assets2[item.id] = item;
109
62
  });
110
- }
111
- if (groups["components"]) {
63
+ const diffs = groupBy(changes, "type");
64
+ const sceneChanges = [];
65
+ markdown.addLine("## 资产");
112
66
  markdown.addLine(``);
113
- markdown.addLine(`#### 组件`);
114
- markdown.addLine("");
115
- const changesGroup = groupBy(groups["components"], "type");
116
- markdown.addLine(`- 新增`);
117
- changesGroup[Operation.ADD]?.forEach((item) => {
118
- const entityId = getComponentEntityId(item.path);
119
- const entityPath = getEntityPath(entityId, entities);
120
- const comp = item.value;
121
- markdown.addLine(`- ${entityPath} [${comp["class"]}]`, 1);
67
+ markdown.addLine(`- 资产新增`);
68
+ (_a = diffs[Operation.ADD]) === null || _a === void 0 ? void 0 : _a.forEach((item) => {
69
+ markdown.addLine(`- ${item.value.virtualPath}`, 1);
122
70
  });
123
- markdown.addLine(`- 移除`);
124
- changesGroup[Operation.REMOVE]?.forEach((item) => {
125
- const entityId = getComponentEntityId(item.path);
126
- const entityPath = getEntityPath(entityId, entities);
127
- const comp = item.value;
128
- markdown.addLine(`- ${entityPath} [${comp["class"]}]`, 1);
71
+ markdown.addLine(``);
72
+ markdown.addLine(`- 资产移除`);
73
+ (_b = diffs[Operation.REMOVE]) === null || _b === void 0 ? void 0 : _b.forEach((item) => {
74
+ markdown.addLine(`- ${item.value.virtualPath}`, 1);
129
75
  });
130
- }
76
+ // markdown.addLine(``);
77
+ // markdown.addLine(`- 资产修改`);
78
+ // markdown.addLine(``);
79
+ (_c = diffs[Operation.UPDATE]) === null || _c === void 0 ? void 0 : _c.forEach((item) => {
80
+ const id = getIdFromPath(item.path);
81
+ const asset = assets1[id];
82
+ if (asset.type === "Scene") {
83
+ sceneChanges.push(asset);
84
+ }
85
+ // markdown.addLine(`- ${asset.virtualPath}`, 1);
86
+ });
87
+ markdown.addLine(``);
88
+ markdown.addLine("## 场景");
89
+ markdown.addLine(``);
90
+ yield Promise.all(sceneChanges.map((asset) => {
91
+ markdown.addLine(`### ${assets2[asset.id].virtualPath}`);
92
+ markdown.addLine(``);
93
+ return diffScene(asset.path, assets2[asset.id].path);
94
+ }));
95
+ });
131
96
  }
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";
97
+ function diffScene(url1, url2) {
98
+ var _a, _b, _c, _d;
99
+ return __awaiter(this, void 0, void 0, function* () {
100
+ const [scene1, scene2] = yield Promise.all([
101
+ getFileBufferFromUrl(url1),
102
+ getFileBufferFromUrl(url2),
103
+ ]).then((res) => res.map((item) => JSON.parse(item.toString())));
104
+ const { diffObj: diffObj1, entities } = getEntities(scene1);
105
+ const { diffObj: diffObj2, entities: newEntities } = getEntities(scene2);
106
+ const changes = flattenChangeset(diff(diffObj1, diffObj2));
107
+ const groups = groupBy(changes, (item) => {
108
+ if (item.path.includes(".components")) {
109
+ return "components";
110
+ }
111
+ return "entities";
112
+ });
113
+ if (groups["entities"]) {
114
+ markdown.addLine(`#### Entities`);
115
+ markdown.addLine("");
116
+ const changesGroup = groupBy(groups["entities"], "type");
117
+ markdown.addLine(`- 新增`);
118
+ (_a = changesGroup[Operation.ADD]) === null || _a === void 0 ? void 0 : _a.forEach((item) => {
119
+ const entityPath = getEntityPath(item.key, newEntities);
120
+ markdown.addLine(`- ${entityPath}`, 1);
121
+ });
122
+ markdown.addLine(`- 移除`);
123
+ (_b = changesGroup[Operation.REMOVE]) === null || _b === void 0 ? void 0 : _b.forEach((item) => {
124
+ const entityPath = getEntityPath(item.key, entities);
125
+ markdown.addLine(`- ${entityPath}`, 1);
126
+ });
127
+ }
128
+ if (groups["components"]) {
129
+ markdown.addLine(``);
130
+ markdown.addLine(`#### 组件`);
131
+ markdown.addLine("");
132
+ const changesGroup = groupBy(groups["components"], "type");
133
+ markdown.addLine(`- 新增`);
134
+ (_c = changesGroup[Operation.ADD]) === null || _c === void 0 ? void 0 : _c.forEach((item) => {
135
+ const entityId = getComponentEntityId(item.path);
136
+ const entityPath = getEntityPath(entityId, entities);
137
+ const comp = item.value;
138
+ markdown.addLine(`- ${entityPath} [${comp["class"]}]`, 1);
139
+ });
140
+ markdown.addLine(`- 移除`);
141
+ (_d = changesGroup[Operation.REMOVE]) === null || _d === void 0 ? void 0 : _d.forEach((item) => {
142
+ const entityId = getComponentEntityId(item.path);
143
+ const entityPath = getEntityPath(entityId, entities);
144
+ const comp = item.value;
145
+ markdown.addLine(`- ${entityPath} [${comp["class"]}]`, 1);
146
+ });
151
147
  }
152
- return "entities";
153
148
  });
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"]}]`);
149
+ }
150
+ function _diffScene(url1, url2) {
151
+ var _a, _b, _c, _d;
152
+ return __awaiter(this, void 0, void 0, function* () {
153
+ const [scene1, scene2] = yield Promise.all([
154
+ getFileBufferFromUrl(url1),
155
+ getFileBufferFromUrl(url2),
156
+ ]).then((res) => res.map((item) => JSON.parse(item.toString())));
157
+ const { diffObj: diffObj1, entities } = getEntities(scene1);
158
+ const { diffObj: diffObj2, entities: newEntities } = getEntities(scene2);
159
+ const changes = flattenChangeset(diff(diffObj1, diffObj2));
160
+ const sceneChangeInfo = {
161
+ entities: { add: [], remove: [] },
162
+ components: { add: [], remove: [] },
163
+ error: null,
164
+ };
165
+ if (Object.values(newEntities).length <= 0) {
166
+ sceneChangeInfo.error = "Entities is empty";
167
+ }
168
+ const groups = groupBy(changes, (item) => {
169
+ if (item.path.includes(".components")) {
170
+ return "components";
171
+ }
172
+ return "entities";
178
173
  });
179
- }
180
- return sceneChangeInfo;
174
+ if (groups["entities"]) {
175
+ const changesGroup = groupBy(groups["entities"], "type");
176
+ (_a = changesGroup[Operation.ADD]) === null || _a === void 0 ? void 0 : _a.forEach((item) => {
177
+ const entityPath = getEntityPath(item.key, newEntities);
178
+ sceneChangeInfo.entities.add.push(entityPath);
179
+ });
180
+ (_b = changesGroup[Operation.REMOVE]) === null || _b === void 0 ? void 0 : _b.forEach((item) => {
181
+ const entityPath = getEntityPath(item.key, entities);
182
+ sceneChangeInfo.entities.remove.push(entityPath);
183
+ });
184
+ }
185
+ if (groups["components"]) {
186
+ const changesGroup = groupBy(groups["components"], "type");
187
+ (_c = changesGroup[Operation.ADD]) === null || _c === void 0 ? void 0 : _c.forEach((item) => {
188
+ const entityId = getComponentEntityId(item.path);
189
+ const entityPath = getEntityPath(entityId, entities);
190
+ const comp = item.value;
191
+ sceneChangeInfo.components.add.push(`- ${entityPath} [${comp["class"]}]`);
192
+ });
193
+ (_d = changesGroup[Operation.REMOVE]) === null || _d === void 0 ? void 0 : _d.forEach((item) => {
194
+ const entityId = getComponentEntityId(item.path);
195
+ const entityPath = getEntityPath(entityId, entities);
196
+ const comp = item.value;
197
+ sceneChangeInfo.components.remove.push(`- ${entityPath} [${comp["class"]}]`);
198
+ });
199
+ }
200
+ return sceneChangeInfo;
201
+ });
181
202
  }
182
203
  function getComponentEntityId(str) {
183
204
  let regex = /\.([^.]*?)\.components/;
@@ -0,0 +1,21 @@
1
+ export function mergeProject(before, after) {
2
+ const originFiles = {};
3
+ before.files.forEach((file) => {
4
+ originFiles[file.id] = file;
5
+ });
6
+ const afterFiles = {};
7
+ after.files.forEach((file) => {
8
+ afterFiles[file.id] = file;
9
+ });
10
+ const resultFiles = Object.assign({}, afterFiles);
11
+ Object.keys(afterFiles).forEach((id) => {
12
+ const originItem = originFiles[id];
13
+ const afterItem = afterFiles[id];
14
+ if (originItem && originItem.md5 && originItem.md5 === afterItem.md5) {
15
+ // 资产修改
16
+ afterItem.path = originItem.path;
17
+ }
18
+ });
19
+ after.files = Object.values(resultFiles).filter((item) => item != undefined);
20
+ return after;
21
+ }
package/lib/utils.js CHANGED
@@ -1,3 +1,12 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
1
10
  import https from "https";
2
11
  import http from "http";
3
12
  import fs from "fs-extra";
@@ -71,29 +80,31 @@ export function sum(array) {
71
80
  }
72
81
  return sum;
73
82
  }
74
- export async function getBufferAndNameFromUri(uri) {
75
- let buffer;
76
- let name;
77
- const isUrl = /^(http|https):\/\/[^\s/$.?#].[^\s]*$/.test(uri);
78
- if (isUrl) {
79
- buffer = await urlToBuffer(uri);
80
- const urlRegex = /\/([^/]+\.[^/.]+)$/;
81
- const matches = uri.match(urlRegex);
82
- if (matches) {
83
- name = matches[1];
83
+ export function getBufferAndNameFromUri(uri) {
84
+ return __awaiter(this, void 0, void 0, function* () {
85
+ let buffer;
86
+ let name;
87
+ const isUrl = /^(http|https):\/\/[^\s/$.?#].[^\s]*$/.test(uri);
88
+ if (isUrl) {
89
+ buffer = yield urlToBuffer(uri);
90
+ const urlRegex = /\/([^/]+\.[^/.]+)$/;
91
+ const matches = uri.match(urlRegex);
92
+ if (matches) {
93
+ name = matches[1];
94
+ }
95
+ else {
96
+ name = "noname";
97
+ }
84
98
  }
85
99
  else {
86
- name = "noname";
100
+ uri = uri !== null && uri !== void 0 ? uri : ".";
101
+ const filepath = path.isAbsolute(uri) ? uri : path.join(process.cwd(), uri);
102
+ const stream = yield fs.createReadStream(filepath);
103
+ buffer = yield streamToBuffer(stream);
104
+ name = path.basename(filepath);
87
105
  }
88
- }
89
- else {
90
- uri = uri ?? ".";
91
- const filepath = path.isAbsolute(uri) ? uri : path.join(process.cwd(), uri);
92
- const stream = await fs.createReadStream(filepath);
93
- buffer = await streamToBuffer(stream);
94
- name = path.basename(filepath);
95
- }
96
- return { buffer, name };
106
+ return { buffer, name };
107
+ });
97
108
  }
98
109
  export function stringIsAValidUrl(s) {
99
110
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@galacean/cli",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "main": "lib/index.js",
5
5
  "type": "module",
6
6
  "author": {
@@ -33,6 +33,7 @@
33
33
  "@types/lodash-es": "^4.17.12",
34
34
  "cac": "^6.7.3",
35
35
  "chalk": "^5.3.0",
36
+ "copy-paste": "^1.5.3",
36
37
  "fs-extra": "^10.0.0",
37
38
  "inquirer": "^8.1.2",
38
39
  "json-diff-ts": "^2.2.1",
@@ -1,7 +1,6 @@
1
- export declare class Markdown {
2
- private _txt;
3
- get txt(): string;
1
+ export declare const markdown: {
2
+ _txt: string;
3
+ readonly txt: any;
4
4
  addLine(line: string, tab?: number): void;
5
5
  generate(): void;
6
- }
7
- export declare const markdown: Markdown;
6
+ };
@@ -0,0 +1,10 @@
1
+ interface IProject {
2
+ files: Array<IFile>;
3
+ }
4
+ interface IFile {
5
+ path: string;
6
+ md5: string;
7
+ id: string;
8
+ }
9
+ export declare function mergeProject(before: IProject, after: IProject): IProject;
10
+ export {};