@tryghost/mg-ghost-api 0.3.6 → 0.4.0
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 +9 -3
- package/index.js +2 -0
- package/lib/fetch.js +29 -6
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -25,11 +25,17 @@ or
|
|
|
25
25
|
To run a Ghost API migration, the required command is:
|
|
26
26
|
|
|
27
27
|
```sh
|
|
28
|
-
migrate ghost
|
|
28
|
+
migrate ghost --url https://example.com --apikey 1234abcd
|
|
29
29
|
```
|
|
30
30
|
|
|
31
31
|
It's possible to pass more options, in order to achieve a better migration file for Ghost:
|
|
32
32
|
|
|
33
|
+
- **`--url`** (required)
|
|
34
|
+
- Ghost API URL
|
|
35
|
+
- string - default: `null`
|
|
36
|
+
- **`--apikey`** (required)
|
|
37
|
+
- Ghost API key
|
|
38
|
+
- string - default: `null`
|
|
33
39
|
- **`-V` `--verbose`**
|
|
34
40
|
- bool - default: `false`
|
|
35
41
|
- Show verbose output
|
|
@@ -71,7 +77,7 @@ It's possible to pass more options, in order to achieve a better migration file
|
|
|
71
77
|
A more complex migration command could look like this:
|
|
72
78
|
|
|
73
79
|
```sh
|
|
74
|
-
migrate ghost
|
|
80
|
+
migrate ghost --url https://example.com --apikey 1234abcd --batch 5 --limit 10 --postFilter 'tag:[news, press]' --pages false --verbose
|
|
75
81
|
```
|
|
76
82
|
|
|
77
83
|
This will get the first 50 posts with the tag `news` or `press`, in 5 batches of 10 posts, exclude pages, and show all available output in the console.
|
|
@@ -93,7 +99,7 @@ Follow the instructions for the top-level repo.
|
|
|
93
99
|
To run a local development copy, `cd` into this directory, and replace `migrate` with `yarn dev`, like so:
|
|
94
100
|
|
|
95
101
|
```sh
|
|
96
|
-
yarn dev ghost
|
|
102
|
+
yarn dev ghost --url https://example.com --apikey 1234abcd
|
|
97
103
|
```
|
|
98
104
|
|
|
99
105
|
|
package/index.js
CHANGED
package/lib/fetch.js
CHANGED
|
@@ -1,9 +1,30 @@
|
|
|
1
1
|
import ghostAPI from '@tryghost/admin-api';
|
|
2
2
|
|
|
3
|
+
const contentStats = async (options) => {
|
|
4
|
+
const requestOptions = {
|
|
5
|
+
url: options.url,
|
|
6
|
+
version: 'v2.0',
|
|
7
|
+
key: options.apikey
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const site = new ghostAPI(requestOptions);
|
|
11
|
+
|
|
12
|
+
// Request the smallest amount of data possible
|
|
13
|
+
const posts = await site.posts.browse({limit: 1, fields: 'title'});
|
|
14
|
+
const pages = await site.pages.browse({limit: 1, fields: 'title'});
|
|
15
|
+
const users = await site.users.browse({limit: 1, fields: 'name'});
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
posts: posts.meta.pagination.total,
|
|
19
|
+
pages: pages.meta.pagination.total,
|
|
20
|
+
users: users.meta.pagination.total
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
|
|
3
24
|
const discover = async (options) => {
|
|
4
25
|
const requestOptions = {
|
|
5
26
|
url: options.url,
|
|
6
|
-
version: 'v2',
|
|
27
|
+
version: 'v2.0',
|
|
7
28
|
key: options.apikey
|
|
8
29
|
};
|
|
9
30
|
|
|
@@ -73,7 +94,7 @@ const cachedFetch = async (fileCache, api, type, options, page) => {
|
|
|
73
94
|
return response;
|
|
74
95
|
};
|
|
75
96
|
|
|
76
|
-
const buildTasks = (fileCache, tasks, api, type, options) => {
|
|
97
|
+
const buildTasks = (fileCache, tasks, api, type, options, logger) => {
|
|
77
98
|
for (let page = 1; page <= api.batches[type]; page++) {
|
|
78
99
|
tasks.push({
|
|
79
100
|
title: `Fetching ${type}, page ${page} of ${api.batches[type]}`,
|
|
@@ -86,7 +107,7 @@ const buildTasks = (fileCache, tasks, api, type, options) => {
|
|
|
86
107
|
|
|
87
108
|
ctx.result[type] = ctx.result[type].concat(response);
|
|
88
109
|
} catch (error) {
|
|
89
|
-
|
|
110
|
+
logger.error({message: `Failed to fetch ${type}, page ${page} of ${api.batches[type]}`, error});
|
|
90
111
|
throw error;
|
|
91
112
|
}
|
|
92
113
|
}
|
|
@@ -96,6 +117,7 @@ const buildTasks = (fileCache, tasks, api, type, options) => {
|
|
|
96
117
|
|
|
97
118
|
const tasks = async (options, ctx) => {
|
|
98
119
|
const {limit} = ctx.options;
|
|
120
|
+
const {logger} = ctx;
|
|
99
121
|
|
|
100
122
|
const api = await discover(options, {limit});
|
|
101
123
|
|
|
@@ -106,14 +128,15 @@ const tasks = async (options, ctx) => {
|
|
|
106
128
|
users: []
|
|
107
129
|
};
|
|
108
130
|
|
|
109
|
-
buildTasks(ctx.fileCache, tasks, api, 'posts', options);
|
|
110
|
-
buildTasks(ctx.fileCache, tasks, api, 'pages', options);
|
|
111
|
-
buildTasks(ctx.fileCache, tasks, api, 'users', options);
|
|
131
|
+
buildTasks(ctx.fileCache, tasks, api, 'posts', options, logger);
|
|
132
|
+
buildTasks(ctx.fileCache, tasks, api, 'pages', options, logger);
|
|
133
|
+
buildTasks(ctx.fileCache, tasks, api, 'users', options, logger);
|
|
112
134
|
|
|
113
135
|
return tasks;
|
|
114
136
|
};
|
|
115
137
|
|
|
116
138
|
export default {
|
|
139
|
+
contentStats,
|
|
117
140
|
discover,
|
|
118
141
|
tasks
|
|
119
142
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryghost/mg-ghost-api",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"repository": "https://github.com/TryGhost/migrate/tree/main/packages/mg-ghost-api",
|
|
5
5
|
"author": "Ghost Foundation",
|
|
6
6
|
"license": "MIT",
|
|
@@ -20,12 +20,12 @@
|
|
|
20
20
|
"access": "public"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"eslint": "8.
|
|
24
|
-
"jest": "29.3
|
|
25
|
-
"jest-extended": "3.2.
|
|
23
|
+
"eslint": "8.34.0",
|
|
24
|
+
"jest": "29.4.3",
|
|
25
|
+
"jest-extended": "3.2.3"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@tryghost/admin-api": "1.13.2"
|
|
29
29
|
},
|
|
30
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "c4270f6229caa350155a03a0646b3c0c21eaff5e"
|
|
31
31
|
}
|