@tryghost/mg-chorus 0.1.3 → 0.1.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/processor.js +14 -0
- package/lib/read-zip.js +50 -22
- package/package.json +6 -6
package/lib/processor.js
CHANGED
|
@@ -34,6 +34,20 @@ const processPost = (data, options) => {
|
|
|
34
34
|
}
|
|
35
35
|
};
|
|
36
36
|
|
|
37
|
+
if (data?.source?.author?.fullOrUserName) {
|
|
38
|
+
let authorSlug = slugify(data.source.author.fullOrUserName);
|
|
39
|
+
let authorObject = {
|
|
40
|
+
url: `/author/${authorSlug}`,
|
|
41
|
+
data: {
|
|
42
|
+
email: `${authorSlug}@example.com`,
|
|
43
|
+
slug: authorSlug,
|
|
44
|
+
name: data.source.author.fullOrUserName
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
post.data.authors.push(authorObject);
|
|
48
|
+
debug(`Adding author to ${data.slug} post object`, authorObject);
|
|
49
|
+
}
|
|
50
|
+
|
|
37
51
|
if (data?.source?.authorProfile?.name) {
|
|
38
52
|
let authorSlug = slugify(data.source.authorProfile.name);
|
|
39
53
|
let authorObject = {
|
package/lib/read-zip.js
CHANGED
|
@@ -1,25 +1,53 @@
|
|
|
1
1
|
import fsUtils from '@tryghost/mg-fs-utils';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
2
4
|
import {_base as debugFactory} from '@tryghost/debug';
|
|
3
5
|
|
|
4
6
|
const debug = debugFactory('migrate:chorus:lib:read-zip');
|
|
5
7
|
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
8
|
+
const readChorusFile = ({content, entries, options, skippedFileCount}) => {
|
|
9
|
+
if (entries.includes('.zip')) {
|
|
10
|
+
fsUtils.zip.read(entries, (entryName, zipEntry) => {
|
|
11
|
+
// Catch all JSON files
|
|
12
|
+
if (/^Entry:.*\.json$/.test(entryName)) {
|
|
13
|
+
try {
|
|
14
|
+
content.posts.push({
|
|
15
|
+
name: entryName,
|
|
16
|
+
source: JSON.parse(zipEntry.getData().toString('utf8'))
|
|
17
|
+
});
|
|
18
|
+
} catch (error) {
|
|
19
|
+
console.log(entries, entryName, error); // eslint-disable-line no-console
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Skip if not matched above, and report skipped files if `--verbose`
|
|
23
|
+
} else {
|
|
24
|
+
if (options.verbose) {
|
|
25
|
+
debug(`Skipped: ${entryName}`);
|
|
26
|
+
}
|
|
27
|
+
skippedFileCount += 1;
|
|
19
28
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
29
|
+
});
|
|
30
|
+
} else {
|
|
31
|
+
fs.readdirSync(entries).forEach((entryName) => {
|
|
32
|
+
if (/^Entry:.*\.json$/.test(entryName)) {
|
|
33
|
+
try {
|
|
34
|
+
content.posts.push({
|
|
35
|
+
name: entryName,
|
|
36
|
+
source: JSON.parse(fs.readFileSync(path.join(entries, entryName), 'utf8'))
|
|
37
|
+
});
|
|
38
|
+
} catch (error) {
|
|
39
|
+
console.log(entries, entryName, error); // eslint-disable-line no-console
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Skip if not matched above, and report skipped files if `--verbose`
|
|
43
|
+
} else {
|
|
44
|
+
if (options.verbose) {
|
|
45
|
+
debug(`Skipped: ${entryName}`);
|
|
46
|
+
}
|
|
47
|
+
skippedFileCount += 1;
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
23
51
|
|
|
24
52
|
return {
|
|
25
53
|
content,
|
|
@@ -43,14 +71,14 @@ export default (entries, options) => {
|
|
|
43
71
|
|
|
44
72
|
if (ifIsArray && entries.length > 1) {
|
|
45
73
|
entries.forEach((file) => {
|
|
46
|
-
const
|
|
47
|
-
content =
|
|
48
|
-
skippedFileCount =
|
|
74
|
+
const fileContent = readChorusFile({content, entries: file, options, skippedFileCount});
|
|
75
|
+
content = fileContent.content;
|
|
76
|
+
skippedFileCount = fileContent.skippedFileCount;
|
|
49
77
|
});
|
|
50
78
|
} else {
|
|
51
|
-
const
|
|
52
|
-
content =
|
|
53
|
-
skippedFileCount =
|
|
79
|
+
const fileContent = readChorusFile({content, entries: entries[0], options, skippedFileCount});
|
|
80
|
+
content = fileContent.content;
|
|
81
|
+
skippedFileCount = fileContent.skippedFileCount;
|
|
54
82
|
}
|
|
55
83
|
|
|
56
84
|
debug(`Skipped files: ${skippedFileCount}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryghost/mg-chorus",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"repository": "https://github.com/TryGhost/migrate/tree/main/packages/mg-chorus",
|
|
5
5
|
"author": "Ghost Foundation",
|
|
6
6
|
"license": "MIT",
|
|
@@ -20,14 +20,14 @@
|
|
|
20
20
|
"access": "public"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"eslint": "8.
|
|
23
|
+
"eslint": "8.38.0",
|
|
24
24
|
"jest": "29.5.0",
|
|
25
25
|
"jest-extended": "3.2.4"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@tryghost/debug": "0.1.
|
|
29
|
-
"@tryghost/errors": "1.2.
|
|
30
|
-
"@tryghost/string": "
|
|
28
|
+
"@tryghost/debug": "0.1.24",
|
|
29
|
+
"@tryghost/errors": "1.2.24",
|
|
30
|
+
"@tryghost/string": "0.2.5"
|
|
31
31
|
},
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "7103ed9a8c922e1bc21c930ba1ad1f924a5c419d"
|
|
33
33
|
}
|