@tryghost/mg-chorus 0.1.4 → 0.1.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/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 readChorusZip = ({content, entries, options, skippedFileCount}) => {
7
- fsUtils.zip.read(entries, (entryName, zipEntry) => {
8
- // Catch all JSON files
9
- if (/^Entry:.*\.json$/.test(entryName)) {
10
- content.posts.push({
11
- name: entryName,
12
- source: JSON.parse(zipEntry.getData().toString('utf8'))
13
- });
14
-
15
- // Skip if not matched above, and report skipped files if `--verbose`
16
- } else {
17
- if (options.verbose) {
18
- debug(`Skipped: ${entryName}`);
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
- skippedFileCount += 1;
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 zipContent = readChorusZip({content, entries: file, options, skippedFileCount});
47
- content = zipContent.content;
48
- skippedFileCount = zipContent.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 zipContent = readChorusZip({content, entries: entries[0], options, skippedFileCount});
52
- content = zipContent.content;
53
- skippedFileCount = zipContent.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.4",
3
+ "version": "0.1.6",
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.36.0",
23
+ "eslint": "8.39.0",
24
24
  "jest": "29.5.0",
25
25
  "jest-extended": "3.2.4"
26
26
  },
27
27
  "dependencies": {
28
- "@tryghost/debug": "0.1.23",
29
- "@tryghost/errors": "1.2.22",
30
- "@tryghost/string": "0.2.4"
28
+ "@tryghost/debug": "0.1.24",
29
+ "@tryghost/errors": "1.2.24",
30
+ "@tryghost/string": "0.2.5"
31
31
  },
32
- "gitHead": "4579dbfc60607e9721a3b0330de628ac41fd32d5"
32
+ "gitHead": "d65f2805bbe5aa743af77e5c33b1909f467a1725"
33
33
  }