@jungvonmatt/contentful-ssg 1.0.5 → 1.4.8
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/dist/cli.js +2 -2
- package/dist/lib/config.js +8 -1
- package/dist/lib/file-manager.js +10 -2
- package/dist/types.d.ts +3 -0
- package/package.json +15 -3
- package/src/cli.ts +2 -2
- package/src/lib/config.ts +15 -1
- package/src/lib/file-manager.ts +14 -2
- package/src/types.ts +4 -0
package/dist/cli.js
CHANGED
|
@@ -16,8 +16,8 @@ const env = dotenv.config();
|
|
|
16
16
|
dotenvExpand(env);
|
|
17
17
|
const parseArgs = (cmd) => ({
|
|
18
18
|
environment: cmd.env,
|
|
19
|
-
preview:
|
|
20
|
-
verbose:
|
|
19
|
+
preview: cmd.preview,
|
|
20
|
+
verbose: cmd.verbose,
|
|
21
21
|
});
|
|
22
22
|
const errorHandler = (error, silence) => {
|
|
23
23
|
if (!silence) {
|
package/dist/lib/config.js
CHANGED
|
@@ -4,6 +4,7 @@ import { cosmiconfig } from 'cosmiconfig';
|
|
|
4
4
|
import mergeOptionsModule from 'merge-options';
|
|
5
5
|
import { dirname, isAbsolute, resolve } from 'path';
|
|
6
6
|
import slash from 'slash';
|
|
7
|
+
import { reduceAsync } from './array.js';
|
|
7
8
|
import { createRequire } from './create-require.js';
|
|
8
9
|
import { isObject, removeEmpty } from './object.js';
|
|
9
10
|
const typescriptLoader = async (filePath) => {
|
|
@@ -84,6 +85,7 @@ export const getConfig = async (args) => {
|
|
|
84
85
|
environmentId: 'master',
|
|
85
86
|
host: 'api.contentful.com',
|
|
86
87
|
directory: resolve(process.cwd(), 'content'),
|
|
88
|
+
managedDirectories: [],
|
|
87
89
|
plugins: [],
|
|
88
90
|
resolvedPlugins: [],
|
|
89
91
|
};
|
|
@@ -140,5 +142,10 @@ export const getConfig = async (args) => {
|
|
|
140
142
|
...result.resolvedPlugins,
|
|
141
143
|
...(await Promise.all((result.plugins || []).map(async (plugin) => resolvePlugin(plugin, result)))),
|
|
142
144
|
];
|
|
143
|
-
|
|
145
|
+
result.managedDirectories = [...result.managedDirectories, result.directory];
|
|
146
|
+
const hookedConfig = await reduceAsync(resolvedPlugins.filter((plugin) => typeof plugin.config === 'function'), async (prev, hooks) => {
|
|
147
|
+
const hook = hooks.config;
|
|
148
|
+
return hook(prev);
|
|
149
|
+
}, result);
|
|
150
|
+
return { ...hookedConfig, ...result, resolvedPlugins };
|
|
144
151
|
};
|
package/dist/lib/file-manager.js
CHANGED
|
@@ -2,6 +2,7 @@ import { dirname, resolve, relative, join } from 'path';
|
|
|
2
2
|
import ignore from 'ignore';
|
|
3
3
|
import { readFile, readdir, lstat } from 'fs/promises';
|
|
4
4
|
import { remove, outputFile } from 'fs-extra';
|
|
5
|
+
import { existsSync } from 'fs';
|
|
5
6
|
export class FileManager {
|
|
6
7
|
ignoreBase = process.cwd();
|
|
7
8
|
ignore;
|
|
@@ -25,7 +26,11 @@ export class FileManager {
|
|
|
25
26
|
const ignorePatterns = await readFile(gitignore);
|
|
26
27
|
this.ignore = ignore().add(ignorePatterns.toString('utf8'));
|
|
27
28
|
}
|
|
28
|
-
const
|
|
29
|
+
const directories = [
|
|
30
|
+
...new Set([...(this.config.managedDirectories || []), this.config.directory]),
|
|
31
|
+
];
|
|
32
|
+
const globPattern = directories.map((directory) => resolve(this.config.rootDir || '', directory, '**/*.*'));
|
|
33
|
+
const existing = await globby(globPattern);
|
|
29
34
|
this.files = new Set(existing.map((file) => resolve(file)));
|
|
30
35
|
}
|
|
31
36
|
async writeFile(file, data, options) {
|
|
@@ -51,7 +56,7 @@ export class FileManager {
|
|
|
51
56
|
await Promise.all(recursiveRemovalPromises);
|
|
52
57
|
fileNames = await readdir(directory);
|
|
53
58
|
}
|
|
54
|
-
if (fileNames.length === 0 &&
|
|
59
|
+
if (fileNames.length === 0 && ![this.config.directory, 'data'].includes(directory)) {
|
|
55
60
|
await remove(directory);
|
|
56
61
|
}
|
|
57
62
|
}
|
|
@@ -59,6 +64,9 @@ export class FileManager {
|
|
|
59
64
|
const promises = [...this.ignoredFiles].map(async (file) => this.deleteFile(file));
|
|
60
65
|
await Promise.allSettled(promises);
|
|
61
66
|
await this.removeEmptyDirectories(this.config.directory);
|
|
67
|
+
if (existsSync('data')) {
|
|
68
|
+
await this.removeEmptyDirectories('data');
|
|
69
|
+
}
|
|
62
70
|
return true;
|
|
63
71
|
}
|
|
64
72
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -30,10 +30,12 @@ export interface ContentfulRcConfig {
|
|
|
30
30
|
activeEnvironmentId: string;
|
|
31
31
|
host: string;
|
|
32
32
|
}
|
|
33
|
+
export declare type ConfigHook = (config: Config) => Config | Promise<Config>;
|
|
33
34
|
export declare type RuntimeHook = (runtimeContext: RuntimeContext) => Promise<Partial<RuntimeContext>> | Partial<RuntimeContext> | void;
|
|
34
35
|
export declare type TransformHook<T> = (transformContext: TransformContext, runtimeContext?: RuntimeContext, prev?: T) => Promise<T> | T;
|
|
35
36
|
export declare type ValidateHook = (transformContext: TransformContext, runtimeContext?: RuntimeContext) => Promise<boolean> | boolean;
|
|
36
37
|
export interface Hooks {
|
|
38
|
+
config?: ConfigHook;
|
|
37
39
|
before?: RuntimeHook;
|
|
38
40
|
after?: RuntimeHook;
|
|
39
41
|
transform?: TransformHook<KeyValueMap>;
|
|
@@ -46,6 +48,7 @@ export interface Hooks {
|
|
|
46
48
|
export declare type Config = Partial<ContentfulConfig> & Hooks & {
|
|
47
49
|
rootDir?: string;
|
|
48
50
|
directory: string;
|
|
51
|
+
managedDirectories?: string[];
|
|
49
52
|
verbose?: boolean;
|
|
50
53
|
plugins?: Array<[string, KeyValueMap] | PluginInfo | string>;
|
|
51
54
|
resolvedPlugins?: Hooks[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jungvonmatt/contentful-ssg",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.8",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -8,11 +8,14 @@
|
|
|
8
8
|
"exports": {
|
|
9
9
|
".": "./dist/index.js",
|
|
10
10
|
"./lib/object": "./dist/lib/object.js",
|
|
11
|
+
"./lib/config": "./dist/lib/config.js",
|
|
11
12
|
"./lib/array": "./dist/lib/array.js",
|
|
12
13
|
"./lib/utils": "./dist/lib/utils.js",
|
|
14
|
+
"./lib/ui": "./dist/lib/ui.js",
|
|
13
15
|
"./lib/contentful": "./dist/lib/contentful.js",
|
|
14
16
|
"./lib/hook-manager": "./dist/lib/hook-manager.js",
|
|
15
17
|
"./lib/file-manager": "./dist/lib/file-manager.js",
|
|
18
|
+
"./converter": "./dist/converter/index.js",
|
|
16
19
|
"./converter/json": "./dist/converter/json.js",
|
|
17
20
|
"./converter/yaml": "./dist/converter/yaml.js",
|
|
18
21
|
"./converter/toml": "./dist/converter/toml.js",
|
|
@@ -27,6 +30,12 @@
|
|
|
27
30
|
"lib/utils": [
|
|
28
31
|
"./dist/lib/utils.d.ts"
|
|
29
32
|
],
|
|
33
|
+
"lib/ui": [
|
|
34
|
+
"./dist/lib/ui.d.ts"
|
|
35
|
+
],
|
|
36
|
+
"lib/config": [
|
|
37
|
+
"./dist/lib/config.d.ts"
|
|
38
|
+
],
|
|
30
39
|
"lib/object": [
|
|
31
40
|
"./dist/lib/object.d.ts"
|
|
32
41
|
],
|
|
@@ -42,6 +51,9 @@
|
|
|
42
51
|
"lib/file-manager": [
|
|
43
52
|
"./dist/lib/file-manager.d.ts"
|
|
44
53
|
],
|
|
54
|
+
"converter": [
|
|
55
|
+
"./dist/converter/index.d.ts"
|
|
56
|
+
],
|
|
45
57
|
"converter/json": [
|
|
46
58
|
"./dist/converter/json.d.ts"
|
|
47
59
|
],
|
|
@@ -79,7 +91,7 @@
|
|
|
79
91
|
"dist"
|
|
80
92
|
],
|
|
81
93
|
"author": "Jung von Matt TECH GmbH",
|
|
82
|
-
"license": "
|
|
94
|
+
"license": "MIT",
|
|
83
95
|
"dependencies": {
|
|
84
96
|
"@contentful/rich-text-html-renderer": "^15.6.2",
|
|
85
97
|
"@contentful/rich-text-types": "^15.6.2",
|
|
@@ -143,5 +155,5 @@
|
|
|
143
155
|
"module": "es2020"
|
|
144
156
|
}
|
|
145
157
|
},
|
|
146
|
-
"gitHead": "
|
|
158
|
+
"gitHead": "28da6d98d1ba37a9bbaf6f1b22157c226be6d477"
|
|
147
159
|
}
|
package/src/cli.ts
CHANGED
|
@@ -22,8 +22,8 @@ dotenvExpand(env);
|
|
|
22
22
|
|
|
23
23
|
const parseArgs = (cmd) => ({
|
|
24
24
|
environment: cmd.env as string,
|
|
25
|
-
preview:
|
|
26
|
-
verbose:
|
|
25
|
+
preview: cmd.preview as boolean,
|
|
26
|
+
verbose: cmd.verbose as boolean,
|
|
27
27
|
});
|
|
28
28
|
|
|
29
29
|
type CommandError = Error & {
|
package/src/lib/config.ts
CHANGED
|
@@ -14,6 +14,7 @@ import type {
|
|
|
14
14
|
PluginInfo,
|
|
15
15
|
PluginModule,
|
|
16
16
|
} from '../types.js';
|
|
17
|
+
import { reduceAsync } from './array.js';
|
|
17
18
|
import { createRequire } from './create-require.js';
|
|
18
19
|
import { isObject, removeEmpty } from './object.js';
|
|
19
20
|
|
|
@@ -126,6 +127,7 @@ export const getConfig = async (args?: Partial<Config>): Promise<Config> => {
|
|
|
126
127
|
environmentId: 'master',
|
|
127
128
|
host: 'api.contentful.com',
|
|
128
129
|
directory: resolve(process.cwd(), 'content'),
|
|
130
|
+
managedDirectories: [],
|
|
129
131
|
plugins: [],
|
|
130
132
|
resolvedPlugins: [],
|
|
131
133
|
};
|
|
@@ -197,5 +199,17 @@ export const getConfig = async (args?: Partial<Config>): Promise<Config> => {
|
|
|
197
199
|
(result.plugins || []).map(async (plugin) => resolvePlugin(plugin, result))
|
|
198
200
|
)),
|
|
199
201
|
];
|
|
200
|
-
|
|
202
|
+
|
|
203
|
+
result.managedDirectories = [...result.managedDirectories, result.directory];
|
|
204
|
+
|
|
205
|
+
const hookedConfig = await reduceAsync(
|
|
206
|
+
resolvedPlugins.filter((plugin) => typeof plugin.config === 'function'),
|
|
207
|
+
async (prev: Config, hooks) => {
|
|
208
|
+
const hook = hooks.config;
|
|
209
|
+
return hook(prev);
|
|
210
|
+
},
|
|
211
|
+
result
|
|
212
|
+
);
|
|
213
|
+
|
|
214
|
+
return { ...hookedConfig, ...result, resolvedPlugins };
|
|
201
215
|
};
|
package/src/lib/file-manager.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { dirname, resolve, relative, join } from 'path';
|
|
|
4
4
|
import ignore from 'ignore';
|
|
5
5
|
import { readFile, readdir, lstat } from 'fs/promises';
|
|
6
6
|
import { remove, outputFile } from 'fs-extra';
|
|
7
|
+
import { existsSync } from 'fs';
|
|
7
8
|
|
|
8
9
|
export class FileManager {
|
|
9
10
|
ignoreBase: string = process.cwd();
|
|
@@ -38,8 +39,15 @@ export class FileManager {
|
|
|
38
39
|
this.ignore = ignore().add(ignorePatterns.toString('utf8'));
|
|
39
40
|
}
|
|
40
41
|
|
|
42
|
+
const directories = [
|
|
43
|
+
...new Set([...(this.config.managedDirectories || []), this.config.directory]),
|
|
44
|
+
];
|
|
45
|
+
|
|
46
|
+
const globPattern = directories.map((directory) =>
|
|
47
|
+
resolve(this.config.rootDir || '', directory, '**/*.*')
|
|
48
|
+
);
|
|
41
49
|
// Create set of existing files
|
|
42
|
-
const existing = await globby(
|
|
50
|
+
const existing = await globby(globPattern);
|
|
43
51
|
|
|
44
52
|
this.files = new Set(existing.map((file) => resolve(file)));
|
|
45
53
|
}
|
|
@@ -91,7 +99,7 @@ export class FileManager {
|
|
|
91
99
|
fileNames = await readdir(directory);
|
|
92
100
|
}
|
|
93
101
|
|
|
94
|
-
if (fileNames.length === 0 &&
|
|
102
|
+
if (fileNames.length === 0 && ![this.config.directory, 'data'].includes(directory)) {
|
|
95
103
|
await remove(directory);
|
|
96
104
|
}
|
|
97
105
|
}
|
|
@@ -101,6 +109,10 @@ export class FileManager {
|
|
|
101
109
|
|
|
102
110
|
await Promise.allSettled(promises);
|
|
103
111
|
await this.removeEmptyDirectories(this.config.directory);
|
|
112
|
+
if (existsSync('data')) {
|
|
113
|
+
await this.removeEmptyDirectories('data');
|
|
114
|
+
}
|
|
115
|
+
|
|
104
116
|
return true;
|
|
105
117
|
}
|
|
106
118
|
}
|
package/src/types.ts
CHANGED
|
@@ -52,6 +52,8 @@ export interface ContentfulRcConfig {
|
|
|
52
52
|
host: string;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
export type ConfigHook = (config: Config) => Config | Promise<Config>;
|
|
56
|
+
|
|
55
57
|
export type RuntimeHook = (
|
|
56
58
|
runtimeContext: RuntimeContext
|
|
57
59
|
) => Promise<Partial<RuntimeContext>> | Partial<RuntimeContext> | void;
|
|
@@ -66,6 +68,7 @@ export type ValidateHook = (
|
|
|
66
68
|
) => Promise<boolean> | boolean;
|
|
67
69
|
|
|
68
70
|
export interface Hooks {
|
|
71
|
+
config?: ConfigHook;
|
|
69
72
|
before?: RuntimeHook;
|
|
70
73
|
after?: RuntimeHook;
|
|
71
74
|
transform?: TransformHook<KeyValueMap>;
|
|
@@ -80,6 +83,7 @@ export type Config = Partial<ContentfulConfig> &
|
|
|
80
83
|
Hooks & {
|
|
81
84
|
rootDir?: string;
|
|
82
85
|
directory: string;
|
|
86
|
+
managedDirectories?: string[];
|
|
83
87
|
verbose?: boolean;
|
|
84
88
|
plugins?: Array<[string, KeyValueMap] | PluginInfo | string>;
|
|
85
89
|
resolvedPlugins?: Hooks[];
|