@jungvonmatt/contentful-ssg 1.0.6 → 1.1.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.
@@ -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
- return { ...result, resolvedPlugins };
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
  };
@@ -26,7 +26,11 @@ export class FileManager {
26
26
  const ignorePatterns = await readFile(gitignore);
27
27
  this.ignore = ignore().add(ignorePatterns.toString('utf8'));
28
28
  }
29
- const existing = await globby([`${this.config.directory}/**/*.*`, `data/**/*.*`]);
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);
30
34
  this.files = new Set(existing.map((file) => resolve(file)));
31
35
  }
32
36
  async writeFile(file, data, options) {
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.0.6",
3
+ "version": "1.1.0",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "type": "module",
@@ -143,5 +143,5 @@
143
143
  "module": "es2020"
144
144
  }
145
145
  },
146
- "gitHead": "72fea365aa247c8942d01c499becf8548874b09d"
146
+ "gitHead": "95f58f6323beda2a6ba1b3cb6fecd07ff6d6cc7f"
147
147
  }
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
- return { ...result, resolvedPlugins };
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
  };
@@ -39,8 +39,15 @@ export class FileManager {
39
39
  this.ignore = ignore().add(ignorePatterns.toString('utf8'));
40
40
  }
41
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
+ );
42
49
  // Create set of existing files
43
- const existing = await globby([`${this.config.directory}/**/*.*`, `data/**/*.*`]);
50
+ const existing = await globby(globPattern);
44
51
 
45
52
  this.files = new Set(existing.map((file) => resolve(file)));
46
53
  }
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[];