@galacean/cli 0.0.4 → 0.0.5
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 +6 -7
- package/lib/cli.js +12 -3
- package/lib/diff.js +186 -165
- package/lib/utils.js +31 -20
- package/package.json +1 -1
- package/types/Markdown.d.ts +4 -5
package/lib/Markdown.js
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
import fs from "fs-extra";
|
|
2
2
|
import path from "path";
|
|
3
|
-
export
|
|
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";
|
|
@@ -16,11 +25,11 @@ cli.command("diff [...files]", "diff files").action((files) => {
|
|
|
16
25
|
Promise.all([
|
|
17
26
|
getFileBufferFromUrl(files[0]),
|
|
18
27
|
getFileBufferFromUrl(files[1]),
|
|
19
|
-
]).then(
|
|
28
|
+
]).then((res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
29
|
const result = res.map((item) => JSON.parse(item.toString()));
|
|
21
|
-
|
|
30
|
+
yield diffProjects(result[0], result[1]);
|
|
22
31
|
markdown.generate();
|
|
23
|
-
});
|
|
32
|
+
}));
|
|
24
33
|
});
|
|
25
34
|
export function diffProject(before, after) {
|
|
26
35
|
return Promise.all([
|
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
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
|
|
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
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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
|
-
|
|
106
|
-
|
|
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
|
-
|
|
63
|
+
const diffs = groupBy(changes, "type");
|
|
64
|
+
const sceneChanges = [];
|
|
65
|
+
markdown.addLine("## 资产");
|
|
112
66
|
markdown.addLine(``);
|
|
113
|
-
markdown.addLine(
|
|
114
|
-
|
|
115
|
-
|
|
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
|
-
|
|
125
|
-
|
|
126
|
-
|
|
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
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
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
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
sceneChangeInfo.
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
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
|
-
|
|
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/;
|
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
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
package/types/Markdown.d.ts
CHANGED