@jungvonmatt/contentful-ssg 1.4.8 → 1.4.9
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 +5 -0
- package/dist/cli.js +5 -4
- package/dist/index.js +5 -8
- package/dist/lib/config.js +1 -1
- package/dist/types.d.ts +1 -0
- package/package.json +2 -2
- package/src/cli.ts +6 -5
- package/src/index.test.ts +58 -0
- package/src/index.ts +6 -9
- package/src/lib/config.ts +1 -1
- package/src/types.ts +1 -0
package/README.md
CHANGED
|
@@ -217,6 +217,11 @@ Fetch all content entries and store them as yaml in the configured directory
|
|
|
217
217
|
npx cssg fetch
|
|
218
218
|
```
|
|
219
219
|
|
|
220
|
+
To see all available command line options call
|
|
221
|
+
```bash
|
|
222
|
+
npx cssg help fetch
|
|
223
|
+
```
|
|
224
|
+
|
|
220
225
|
## Example configuration
|
|
221
226
|
|
|
222
227
|
### Grow
|
package/dist/cli.js
CHANGED
|
@@ -14,10 +14,10 @@ import { getConfig, getEnvironmentConfig } from './lib/config.js';
|
|
|
14
14
|
import { run } from './index.js';
|
|
15
15
|
const env = dotenv.config();
|
|
16
16
|
dotenvExpand(env);
|
|
17
|
-
const
|
|
18
|
-
environment: cmd.env,
|
|
17
|
+
const parseFetchArgs = (cmd) => ({
|
|
19
18
|
preview: cmd.preview,
|
|
20
19
|
verbose: cmd.verbose,
|
|
20
|
+
ignoreErrors: cmd.ignoreErrors,
|
|
21
21
|
});
|
|
22
22
|
const errorHandler = (error, silence) => {
|
|
23
23
|
if (!silence) {
|
|
@@ -37,7 +37,7 @@ program
|
|
|
37
37
|
.option('--typescript', 'Initialize typescript config')
|
|
38
38
|
.action(actionRunner(async (cmd) => {
|
|
39
39
|
const useTypescript = Boolean(cmd?.typescript ?? false);
|
|
40
|
-
const config = await getConfig(
|
|
40
|
+
const config = await getConfig();
|
|
41
41
|
const verified = await askAll(config);
|
|
42
42
|
const environmentConfig = getEnvironmentConfig();
|
|
43
43
|
const filePath = path.join(process.cwd(), `contentful-ssg.config.${useTypescript ? 'ts' : 'js'}`);
|
|
@@ -88,8 +88,9 @@ program
|
|
|
88
88
|
.description('Fetch content objects')
|
|
89
89
|
.option('-p, --preview', 'Fetch with preview mode')
|
|
90
90
|
.option('-v, --verbose', 'Verbose output')
|
|
91
|
+
.option('--ignore-errors', 'No error return code when transform has errors')
|
|
91
92
|
.action(actionRunner(async (cmd) => {
|
|
92
|
-
const config = await getConfig(
|
|
93
|
+
const config = await getConfig(parseFetchArgs(cmd || {}));
|
|
93
94
|
const verified = await askMissing(config);
|
|
94
95
|
return run(verified);
|
|
95
96
|
}));
|
package/dist/index.js
CHANGED
|
@@ -54,10 +54,7 @@ export const run = async (config) => {
|
|
|
54
54
|
{
|
|
55
55
|
title: 'Before Hook',
|
|
56
56
|
skip: (ctx) => !ctx.hooks.has('before'),
|
|
57
|
-
task: async (ctx) =>
|
|
58
|
-
const result = await ctx.hooks.before();
|
|
59
|
-
ctx = { ...ctx, ...(result || {}) };
|
|
60
|
-
},
|
|
57
|
+
task: async (ctx) => ctx.hooks.before(),
|
|
61
58
|
},
|
|
62
59
|
{
|
|
63
60
|
title: 'Writing files',
|
|
@@ -109,10 +106,7 @@ export const run = async (config) => {
|
|
|
109
106
|
{
|
|
110
107
|
title: 'After Hook',
|
|
111
108
|
skip: (ctx) => !ctx.hooks.has('after'),
|
|
112
|
-
task: async (ctx) =>
|
|
113
|
-
const result = await ctx.hooks.after();
|
|
114
|
-
ctx = { ...ctx, ...(result || {}) };
|
|
115
|
-
},
|
|
109
|
+
task: async (ctx) => ctx.hooks.after(),
|
|
116
110
|
},
|
|
117
111
|
{
|
|
118
112
|
title: 'Cleanup',
|
|
@@ -122,4 +116,7 @@ export const run = async (config) => {
|
|
|
122
116
|
const ctx = await tasks.run();
|
|
123
117
|
await ctx.stats.print();
|
|
124
118
|
console.log('\n---------------------------------------------');
|
|
119
|
+
if (ctx.stats.errors?.length && !config.ignoreErrors) {
|
|
120
|
+
process.exit(1);
|
|
121
|
+
}
|
|
125
122
|
};
|
package/dist/lib/config.js
CHANGED
|
@@ -80,7 +80,7 @@ export const getEnvironmentConfig = (strict = true) => removeEmpty({
|
|
|
80
80
|
previewAccessToken: process.env.CONTENTFUL_PREVIEW_TOKEN,
|
|
81
81
|
accessToken: process.env.CONTENTFUL_DELIVERY_TOKEN,
|
|
82
82
|
}, strict);
|
|
83
|
-
export const getConfig = async (args) => {
|
|
83
|
+
export const getConfig = async (args = {}) => {
|
|
84
84
|
const defaultOptions = {
|
|
85
85
|
environmentId: 'master',
|
|
86
86
|
host: 'api.contentful.com',
|
package/dist/types.d.ts
CHANGED
|
@@ -50,6 +50,7 @@ export declare type Config = Partial<ContentfulConfig> & Hooks & {
|
|
|
50
50
|
directory: string;
|
|
51
51
|
managedDirectories?: string[];
|
|
52
52
|
verbose?: boolean;
|
|
53
|
+
ignoreErrors?: boolean;
|
|
53
54
|
plugins?: Array<[string, KeyValueMap] | PluginInfo | string>;
|
|
54
55
|
resolvedPlugins?: Hooks[];
|
|
55
56
|
preset?: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jungvonmatt/contentful-ssg",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.9",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -155,5 +155,5 @@
|
|
|
155
155
|
"module": "es2020"
|
|
156
156
|
}
|
|
157
157
|
},
|
|
158
|
-
"gitHead": "
|
|
158
|
+
"gitHead": "17ccdcf1aedc0eea54740aa71279e5bd1cb77699"
|
|
159
159
|
}
|
package/src/cli.ts
CHANGED
|
@@ -15,15 +15,15 @@ import { omitKeys } from './lib/object.js';
|
|
|
15
15
|
|
|
16
16
|
import { getConfig, getEnvironmentConfig } from './lib/config.js';
|
|
17
17
|
import { run } from './index.js';
|
|
18
|
-
import { ContentfulConfig } from './types.js';
|
|
18
|
+
import { Config, ContentfulConfig } from './types.js';
|
|
19
19
|
|
|
20
20
|
const env = dotenv.config();
|
|
21
21
|
dotenvExpand(env);
|
|
22
22
|
|
|
23
|
-
const
|
|
24
|
-
environment: cmd.env as string,
|
|
23
|
+
const parseFetchArgs = (cmd): Partial<Config> => ({
|
|
25
24
|
preview: cmd.preview as boolean,
|
|
26
25
|
verbose: cmd.verbose as boolean,
|
|
26
|
+
ignoreErrors: cmd.ignoreErrors as boolean,
|
|
27
27
|
});
|
|
28
28
|
|
|
29
29
|
type CommandError = Error & {
|
|
@@ -54,7 +54,7 @@ program
|
|
|
54
54
|
.action(
|
|
55
55
|
actionRunner(async (cmd) => {
|
|
56
56
|
const useTypescript = Boolean(cmd?.typescript ?? false);
|
|
57
|
-
const config = await getConfig(
|
|
57
|
+
const config = await getConfig();
|
|
58
58
|
const verified = await askAll(config);
|
|
59
59
|
|
|
60
60
|
const environmentConfig = getEnvironmentConfig();
|
|
@@ -148,9 +148,10 @@ program
|
|
|
148
148
|
.description('Fetch content objects')
|
|
149
149
|
.option('-p, --preview', 'Fetch with preview mode')
|
|
150
150
|
.option('-v, --verbose', 'Verbose output')
|
|
151
|
+
.option('--ignore-errors', 'No error return code when transform has errors')
|
|
151
152
|
.action(
|
|
152
153
|
actionRunner(async (cmd) => {
|
|
153
|
-
const config = await getConfig(
|
|
154
|
+
const config = await getConfig(parseFetchArgs(cmd || {}));
|
|
154
155
|
const verified = await askMissing(config);
|
|
155
156
|
|
|
156
157
|
return run(verified);
|
package/src/index.test.ts
CHANGED
|
@@ -86,4 +86,62 @@ describe('Run', () => {
|
|
|
86
86
|
expect(output).toMatch(`${chalk.cyan(0)} entries skipped due to validation issues`);
|
|
87
87
|
expect(output).toMatch(`${chalk.red(0)} errors`);
|
|
88
88
|
});
|
|
89
|
+
|
|
90
|
+
test('fails on exception before/after', async () => {
|
|
91
|
+
console.log = jest.fn();
|
|
92
|
+
const mockError = jest.fn().mockImplementation(() => {
|
|
93
|
+
throw new Error();
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
await expect(async () => {
|
|
97
|
+
await run({
|
|
98
|
+
directory: 'test',
|
|
99
|
+
before: mockError,
|
|
100
|
+
});
|
|
101
|
+
}).rejects.toThrowError();
|
|
102
|
+
|
|
103
|
+
await expect(async () => {
|
|
104
|
+
await run({
|
|
105
|
+
directory: 'test',
|
|
106
|
+
after: mockError,
|
|
107
|
+
});
|
|
108
|
+
}).rejects.toThrowError();
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
test('fails on transform exception', async () => {
|
|
112
|
+
console.log = jest.fn();
|
|
113
|
+
const mockExit = jest.spyOn(process, 'exit').mockImplementation((number) => {
|
|
114
|
+
throw new Error('process.exit: ' + number);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
await expect(async () => {
|
|
118
|
+
await run({
|
|
119
|
+
directory: 'test',
|
|
120
|
+
transform: async () => {
|
|
121
|
+
throw new Error();
|
|
122
|
+
},
|
|
123
|
+
});
|
|
124
|
+
}).rejects.toThrowError();
|
|
125
|
+
|
|
126
|
+
expect(mockExit).toHaveBeenCalledWith(1);
|
|
127
|
+
mockExit.mockRestore();
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
test('does not fail on transform exception with ignoreErrors option', async () => {
|
|
131
|
+
console.log = jest.fn();
|
|
132
|
+
const mockExit = jest.spyOn(process, 'exit').mockImplementation((number) => {
|
|
133
|
+
throw new Error('process.exit: ' + number);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
await run({
|
|
137
|
+
directory: 'test',
|
|
138
|
+
ignoreErrors: true,
|
|
139
|
+
transform: async () => {
|
|
140
|
+
throw new Error();
|
|
141
|
+
},
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
expect(mockExit).toBeCalledTimes(0);
|
|
145
|
+
mockExit.mockRestore();
|
|
146
|
+
});
|
|
89
147
|
});
|
package/src/index.ts
CHANGED
|
@@ -73,10 +73,7 @@ export const run = async (config: Config): Promise<void> => {
|
|
|
73
73
|
{
|
|
74
74
|
title: 'Before Hook',
|
|
75
75
|
skip: (ctx) => !ctx.hooks.has('before'),
|
|
76
|
-
task: async (ctx) =>
|
|
77
|
-
const result = await ctx.hooks.before();
|
|
78
|
-
ctx = { ...ctx, ...(result || {}) };
|
|
79
|
-
},
|
|
76
|
+
task: async (ctx) => ctx.hooks.before(),
|
|
80
77
|
},
|
|
81
78
|
{
|
|
82
79
|
title: 'Writing files',
|
|
@@ -135,12 +132,8 @@ export const run = async (config: Config): Promise<void> => {
|
|
|
135
132
|
{
|
|
136
133
|
title: 'After Hook',
|
|
137
134
|
skip: (ctx) => !ctx.hooks.has('after'),
|
|
138
|
-
task: async (ctx) =>
|
|
139
|
-
const result = await ctx.hooks.after();
|
|
140
|
-
ctx = { ...ctx, ...(result || {}) };
|
|
141
|
-
},
|
|
135
|
+
task: async (ctx) => ctx.hooks.after(),
|
|
142
136
|
},
|
|
143
|
-
|
|
144
137
|
{
|
|
145
138
|
title: 'Cleanup',
|
|
146
139
|
task: async (ctx) => ctx.fileManager.cleanup(),
|
|
@@ -152,4 +145,8 @@ export const run = async (config: Config): Promise<void> => {
|
|
|
152
145
|
const ctx = await tasks.run();
|
|
153
146
|
await ctx.stats.print();
|
|
154
147
|
console.log('\n---------------------------------------------');
|
|
148
|
+
|
|
149
|
+
if (ctx.stats.errors?.length && !config.ignoreErrors) {
|
|
150
|
+
process.exit(1);
|
|
151
|
+
}
|
|
155
152
|
};
|
package/src/lib/config.ts
CHANGED
|
@@ -122,7 +122,7 @@ export const getEnvironmentConfig = (strict = true): ContentfulConfig =>
|
|
|
122
122
|
* Get configuration
|
|
123
123
|
* @param {Object} args
|
|
124
124
|
*/
|
|
125
|
-
export const getConfig = async (args
|
|
125
|
+
export const getConfig = async (args: Partial<Config> = {}): Promise<Config> => {
|
|
126
126
|
const defaultOptions: Config = {
|
|
127
127
|
environmentId: 'master',
|
|
128
128
|
host: 'api.contentful.com',
|
package/src/types.ts
CHANGED
|
@@ -85,6 +85,7 @@ export type Config = Partial<ContentfulConfig> &
|
|
|
85
85
|
directory: string;
|
|
86
86
|
managedDirectories?: string[];
|
|
87
87
|
verbose?: boolean;
|
|
88
|
+
ignoreErrors?: boolean;
|
|
88
89
|
plugins?: Array<[string, KeyValueMap] | PluginInfo | string>;
|
|
89
90
|
resolvedPlugins?: Hooks[];
|
|
90
91
|
preset?: string;
|