1 | "use strict";
|
2 |
|
3 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4 | exports.__esModule = true;
|
5 | exports.nodeManifestReducer = void 0;
|
6 | var _reporter = _interopRequireDefault(require("gatsby-cli/lib/reporter"));
|
7 | const ONE_DAY = 1000 * 60 * 60 * 24;
|
8 | const DEFAULT_MAX_DAYS_OLD = 30;
|
9 | const nodeManifestReducer = (state = [], action) => {
|
10 | switch (action.type) {
|
11 | case `CREATE_NODE_MANIFEST`:
|
12 | {
|
13 | const {
|
14 | manifestId,
|
15 | pluginName,
|
16 | node,
|
17 | updatedAtUTC
|
18 | } = action.payload;
|
19 | const maxDaysOld = Number(process.env.NODE_MANIFEST_MAX_DAYS_OLD) || DEFAULT_MAX_DAYS_OLD;
|
20 | if (updatedAtUTC) {
|
21 | const nodeLastUpdatedAtUTC = new Date(updatedAtUTC).getTime();
|
22 | if (nodeLastUpdatedAtUTC instanceof Date && !isNaN(nodeLastUpdatedAtUTC)) {
|
23 | _reporter.default.warn(`Plugin ${pluginName} called unstable_createNodeManifest with an updatedAtUTC that isn't a proper value to instantiate a Date.`);
|
24 | return state;
|
25 | }
|
26 | const shouldCreateNodeManifest = Date.now() - nodeLastUpdatedAtUTC <= maxDaysOld * ONE_DAY;
|
27 | if (!shouldCreateNodeManifest) {
|
28 | return state;
|
29 | }
|
30 | }
|
31 | if (typeof manifestId !== `string`) {
|
32 | _reporter.default.warn(`Plugin ${pluginName} called unstable_createNodeManifest with a manifestId that isn't a string.`);
|
33 | return state;
|
34 | }
|
35 | if (!(node !== null && node !== void 0 && node.id)) {
|
36 | _reporter.default.warn(`Plugin ${pluginName} called unstable_createNodeManifest but didn't provide a node.`);
|
37 | return state;
|
38 | }
|
39 | state.push({
|
40 | manifestId,
|
41 | pluginName,
|
42 | node: {
|
43 | id: node.id
|
44 | }
|
45 | });
|
46 | return state;
|
47 | }
|
48 | case `DELETE_NODE_MANIFESTS`:
|
49 | {
|
50 | state = [];
|
51 | return state;
|
52 | }
|
53 | default:
|
54 | return state;
|
55 | }
|
56 | };
|
57 | exports.nodeManifestReducer = nodeManifestReducer;
|
58 |
|
\ | No newline at end of file |