@plasmicapp/loader-gatsby 1.0.254 → 1.0.256
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/gatsby-node.d.ts +6 -14
- package/dist/gatsby-node.js +297 -274
- package/dist/gatsby-node.js.map +7 -1
- package/dist/gatsby-ssr.js +71 -51
- package/dist/gatsby-ssr.js.map +7 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +373 -26
- package/dist/index.js.map +7 -1
- package/package.json +35 -17
- package/dist/loader.js +0 -15
- package/dist/loader.js.map +0 -1
- package/dist/server-require.js +0 -18
- package/dist/server-require.js.map +0 -1
package/dist/gatsby-node.d.ts
CHANGED
|
@@ -1,19 +1,11 @@
|
|
|
1
1
|
import { InitOptions } from "@plasmicapp/loader-react";
|
|
2
|
-
import {
|
|
3
|
-
export declare const onPreInit:
|
|
4
|
-
|
|
5
|
-
}) => any;
|
|
6
|
-
export type GatsbyPluginOptions = InitOptions & {
|
|
2
|
+
import { GatsbyNode, PluginOptions } from "gatsby";
|
|
3
|
+
export declare const onPreInit: GatsbyNode["onPreInit"];
|
|
4
|
+
export type GatsbyPluginOptions = PluginOptions & InitOptions & {
|
|
7
5
|
defaultPlasmicPage?: string;
|
|
8
6
|
ignorePaths?: string[];
|
|
9
7
|
};
|
|
10
|
-
export declare const sourceNodes:
|
|
8
|
+
export declare const sourceNodes: GatsbyNode["sourceNodes"];
|
|
11
9
|
export declare const createResolvers: GatsbyNode["createResolvers"];
|
|
12
|
-
export declare const createSchemaCustomization:
|
|
13
|
-
|
|
14
|
-
}) => void;
|
|
15
|
-
interface LoaderGatsbyPluginOptions extends GatsbyPluginOptions {
|
|
16
|
-
defaultPlasmicPage: string;
|
|
17
|
-
}
|
|
18
|
-
export declare const createPages: ({ graphql, actions, reporter }: CreatePagesArgs, opts: LoaderGatsbyPluginOptions) => Promise<void>;
|
|
19
|
-
export {};
|
|
10
|
+
export declare const createSchemaCustomization: GatsbyNode["createSchemaCustomization"];
|
|
11
|
+
export declare const createPages: GatsbyNode["createPages"];
|
package/dist/gatsby-node.js
CHANGED
|
@@ -1,285 +1,308 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty
|
|
3
|
-
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
10
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
11
|
+
var __spreadValues = (a, b) => {
|
|
12
|
+
for (var prop in b || (b = {}))
|
|
13
|
+
if (__hasOwnProp.call(b, prop))
|
|
14
|
+
__defNormalProp(a, prop, b[prop]);
|
|
15
|
+
if (__getOwnPropSymbols)
|
|
16
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
17
|
+
if (__propIsEnum.call(b, prop))
|
|
18
|
+
__defNormalProp(a, prop, b[prop]);
|
|
19
|
+
}
|
|
20
|
+
return a;
|
|
10
21
|
};
|
|
11
|
-
|
|
22
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
23
|
+
var __export = (target, all) => {
|
|
24
|
+
for (var name in all)
|
|
25
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
26
|
+
};
|
|
27
|
+
var __copyProps = (to, from, except, desc) => {
|
|
28
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
29
|
+
for (let key of __getOwnPropNames(from))
|
|
30
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
31
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
32
|
+
}
|
|
33
|
+
return to;
|
|
34
|
+
};
|
|
35
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
36
|
+
var __async = (__this, __arguments, generator) => {
|
|
37
|
+
return new Promise((resolve, reject) => {
|
|
38
|
+
var fulfilled = (value) => {
|
|
39
|
+
try {
|
|
40
|
+
step(generator.next(value));
|
|
41
|
+
} catch (e) {
|
|
42
|
+
reject(e);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
var rejected = (value) => {
|
|
46
|
+
try {
|
|
47
|
+
step(generator.throw(value));
|
|
48
|
+
} catch (e) {
|
|
49
|
+
reject(e);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
53
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
// src/gatsby-node.ts
|
|
58
|
+
var gatsby_node_exports = {};
|
|
59
|
+
__export(gatsby_node_exports, {
|
|
60
|
+
createPages: () => createPages,
|
|
61
|
+
createResolvers: () => createResolvers,
|
|
62
|
+
createSchemaCustomization: () => createSchemaCustomization,
|
|
63
|
+
onPreInit: () => onPreInit,
|
|
64
|
+
sourceNodes: () => sourceNodes
|
|
65
|
+
});
|
|
66
|
+
module.exports = __toCommonJS(gatsby_node_exports);
|
|
67
|
+
var import_loader_react = require("@plasmicapp/loader-react");
|
|
68
|
+
|
|
69
|
+
// src/server-require.ts
|
|
70
|
+
var secretRequire;
|
|
71
|
+
try {
|
|
72
|
+
secretRequire = eval("require");
|
|
73
|
+
} catch (err) {
|
|
74
|
+
secretRequire = void 0;
|
|
75
|
+
}
|
|
76
|
+
function serverRequire(module2) {
|
|
77
|
+
if (!secretRequire) {
|
|
78
|
+
throw new Error(
|
|
79
|
+
`Unexpected serverRequire() -- can only do this from a Node server!`
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
return secretRequire(module2);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// src/gatsby-node.ts
|
|
86
|
+
var onPreInit = ({ reporter }) => reporter.success("Loaded @plasmicapp/loader-gatsby");
|
|
12
87
|
var PLASMIC_NODE_NAME = "plasmicData";
|
|
13
|
-
var PLASMIC_DATA_TYPE =
|
|
14
|
-
|
|
15
|
-
|
|
88
|
+
var PLASMIC_DATA_TYPE = `
|
|
89
|
+
type ${PLASMIC_NODE_NAME} implements Node {
|
|
90
|
+
name: String!
|
|
91
|
+
displayName: String!
|
|
92
|
+
projectId: String!
|
|
93
|
+
path: String
|
|
94
|
+
isPage: Boolean!
|
|
95
|
+
renderData: JSON!
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
type Query {
|
|
99
|
+
plasmicComponents(componentNames: [String]!): JSON
|
|
100
|
+
plasmicOptions: JSON
|
|
101
|
+
}
|
|
102
|
+
`;
|
|
103
|
+
var SOURCE_WAIT_TIME = 3e3;
|
|
104
|
+
var SOURCE_MAX_WAIT_TIME = 1e4;
|
|
16
105
|
var allPaths = [];
|
|
17
|
-
var sourceNodes = function (
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
var PLASMIC, components, _loop_1, _i, allComponents_1, component, _a, components_1, component, renderData, curComponent, componentMeta, componentNode;
|
|
28
|
-
return tslib_1.__generator(this, function (_b) {
|
|
29
|
-
switch (_b.label) {
|
|
30
|
-
case 0:
|
|
31
|
-
reporter.info("[Plasmic Loader] - Creating nodes");
|
|
32
|
-
PLASMIC = (0, loader_react_1.initPlasmicLoader)({
|
|
33
|
-
projects: opts.projects,
|
|
34
|
-
preview: opts.preview,
|
|
35
|
-
host: opts.host,
|
|
36
|
-
platform: "gatsby",
|
|
37
|
-
});
|
|
38
|
-
return [4 /*yield*/, PLASMIC.fetchComponents()];
|
|
39
|
-
case 1:
|
|
40
|
-
components = _b.sent();
|
|
41
|
-
_loop_1 = function (component) {
|
|
42
|
-
var hasComponent = components.some(function (c) { return c.name === component.name; });
|
|
43
|
-
/**
|
|
44
|
-
* We shouldn't delete nodes that will be updated, if we delete all nodes
|
|
45
|
-
* and then create it again, this could case the graphql layer to have no
|
|
46
|
-
* plasmic data for some time, but this can be enough time to a re render
|
|
47
|
-
* causing components that call a graphql query to plasmic data to crash
|
|
48
|
-
* */
|
|
49
|
-
if (!hasComponent) {
|
|
50
|
-
deleteNode(component);
|
|
51
|
-
reporter.verbose("[Plasmic Loader] - Deleted node ".concat(component.name));
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
for (_i = 0, allComponents_1 = allComponents; _i < allComponents_1.length; _i++) {
|
|
55
|
-
component = allComponents_1[_i];
|
|
56
|
-
_loop_1(component);
|
|
57
|
-
}
|
|
58
|
-
allComponents = [];
|
|
59
|
-
_a = 0, components_1 = components;
|
|
60
|
-
_b.label = 2;
|
|
61
|
-
case 2:
|
|
62
|
-
if (!(_a < components_1.length)) return [3 /*break*/, 5];
|
|
63
|
-
component = components_1[_a];
|
|
64
|
-
return [4 /*yield*/, PLASMIC.fetchComponentData({
|
|
65
|
-
name: component.name,
|
|
66
|
-
projectId: component.projectId,
|
|
67
|
-
})];
|
|
68
|
-
case 3:
|
|
69
|
-
renderData = _b.sent();
|
|
70
|
-
curComponent = tslib_1.__assign(tslib_1.__assign({}, component), { renderData: renderData });
|
|
71
|
-
componentMeta = {
|
|
72
|
-
// We use the same id as curComponent.id since loader-react might
|
|
73
|
-
// expect the id to match plasmic component uuid.
|
|
74
|
-
// id: getNodeId(component.projectId, component.name),
|
|
75
|
-
parent: null,
|
|
76
|
-
children: [],
|
|
77
|
-
internal: {
|
|
78
|
-
type: PLASMIC_NODE_NAME,
|
|
79
|
-
contentDigest: createContentDigest(curComponent),
|
|
80
|
-
},
|
|
81
|
-
};
|
|
82
|
-
componentNode = Object.assign({}, curComponent, componentMeta);
|
|
83
|
-
createNode(componentNode);
|
|
84
|
-
reporter.verbose("[Plasmic Loader] - Created component node ".concat(component.name));
|
|
85
|
-
allComponents.push(componentNode);
|
|
86
|
-
_b.label = 4;
|
|
87
|
-
case 4:
|
|
88
|
-
_a++;
|
|
89
|
-
return [3 /*break*/, 2];
|
|
90
|
-
case 5: return [2 /*return*/];
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
}); };
|
|
94
|
-
if (process.env.NODE_ENV !== "production") {
|
|
95
|
-
debounce = (0, server_require_1.default)("lodash/debounce");
|
|
96
|
-
triggerSourcing_1 = debounce(refreshData, SOURCE_WAIT_TIME, {
|
|
97
|
-
maxWait: SOURCE_MAX_WAIT_TIME,
|
|
98
|
-
});
|
|
99
|
-
PlasmicRemoteChangeWatcher = (0, server_require_1.default)("@plasmicapp/watcher")
|
|
100
|
-
.PlasmicRemoteChangeWatcher;
|
|
101
|
-
watcher = new PlasmicRemoteChangeWatcher({
|
|
102
|
-
projects: opts.projects,
|
|
103
|
-
host: opts.host,
|
|
104
|
-
});
|
|
105
|
-
watcher.subscribe({
|
|
106
|
-
onUpdate: function () {
|
|
107
|
-
if (opts.preview) {
|
|
108
|
-
triggerSourcing_1();
|
|
109
|
-
}
|
|
110
|
-
},
|
|
111
|
-
onPublish: function () {
|
|
112
|
-
if (!opts.preview) {
|
|
113
|
-
triggerSourcing_1();
|
|
114
|
-
}
|
|
115
|
-
},
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
return [4 /*yield*/, refreshData()];
|
|
119
|
-
case 1:
|
|
120
|
-
_b.sent();
|
|
121
|
-
return [2 /*return*/];
|
|
122
|
-
}
|
|
123
|
-
});
|
|
106
|
+
var sourceNodes = (_0, _1) => __async(void 0, [_0, _1], function* ({ actions, createContentDigest, reporter }, opts) {
|
|
107
|
+
const { createNode, deleteNode } = actions;
|
|
108
|
+
let allComponents = [];
|
|
109
|
+
const refreshData = () => __async(void 0, null, function* () {
|
|
110
|
+
reporter.info(`[Plasmic Loader] - Creating nodes`);
|
|
111
|
+
const PLASMIC = (0, import_loader_react.initPlasmicLoader)({
|
|
112
|
+
projects: opts.projects,
|
|
113
|
+
preview: opts.preview,
|
|
114
|
+
host: opts.host,
|
|
115
|
+
platform: "gatsby"
|
|
124
116
|
});
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
117
|
+
const components = yield PLASMIC.fetchComponents();
|
|
118
|
+
for (const component of allComponents) {
|
|
119
|
+
const hasComponent = components.some((c) => c.name === component.name);
|
|
120
|
+
if (!hasComponent) {
|
|
121
|
+
deleteNode(component);
|
|
122
|
+
reporter.verbose(`[Plasmic Loader] - Deleted node ${component.name}`);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
allComponents = [];
|
|
126
|
+
for (const component of components) {
|
|
127
|
+
const renderData = yield PLASMIC.fetchComponentData({
|
|
128
|
+
name: component.name,
|
|
129
|
+
projectId: component.projectId
|
|
130
|
+
});
|
|
131
|
+
const curComponent = __spreadProps(__spreadValues({}, component), {
|
|
132
|
+
renderData
|
|
133
|
+
});
|
|
134
|
+
const componentMeta = {
|
|
135
|
+
// We use the same id as curComponent.id since loader-react might
|
|
136
|
+
// expect the id to match plasmic component uuid.
|
|
137
|
+
// id: getNodeId(component.projectId, component.name),
|
|
138
|
+
parent: null,
|
|
139
|
+
children: [],
|
|
140
|
+
internal: {
|
|
141
|
+
type: PLASMIC_NODE_NAME,
|
|
142
|
+
contentDigest: createContentDigest(curComponent)
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
const componentNode = Object.assign({}, curComponent, componentMeta);
|
|
146
|
+
createNode(componentNode);
|
|
147
|
+
reporter.verbose(
|
|
148
|
+
`[Plasmic Loader] - Created component node ${component.name}`
|
|
149
|
+
);
|
|
150
|
+
allComponents.push(componentNode);
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
if (process.env.NODE_ENV !== "production") {
|
|
154
|
+
const debounce = serverRequire("lodash/debounce");
|
|
155
|
+
const triggerSourcing = debounce(refreshData, SOURCE_WAIT_TIME, {
|
|
156
|
+
maxWait: SOURCE_MAX_WAIT_TIME
|
|
146
157
|
});
|
|
158
|
+
try {
|
|
159
|
+
const PlasmicRemoteChangeWatcher = serverRequire("@plasmicapp/watcher").PlasmicRemoteChangeWatcher;
|
|
160
|
+
const watcher = new PlasmicRemoteChangeWatcher({
|
|
161
|
+
projects: opts.projects,
|
|
162
|
+
host: opts.host
|
|
163
|
+
});
|
|
164
|
+
watcher.subscribe({
|
|
165
|
+
onUpdate: () => {
|
|
166
|
+
if (opts.preview) {
|
|
167
|
+
triggerSourcing();
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
onPublish: () => {
|
|
171
|
+
if (!opts.preview) {
|
|
172
|
+
triggerSourcing();
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
} catch (e) {
|
|
177
|
+
console.warn("Couldn't subscribe to Plasmic changes", e);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
yield refreshData();
|
|
181
|
+
});
|
|
182
|
+
function getAllNodes(nodeModel, type) {
|
|
183
|
+
return __async(this, null, function* () {
|
|
184
|
+
try {
|
|
185
|
+
const { entries } = yield nodeModel.findAll({ type });
|
|
186
|
+
return Array.from(entries);
|
|
187
|
+
} catch (_) {
|
|
188
|
+
return nodeModel.getAllNodes({ type });
|
|
189
|
+
}
|
|
190
|
+
});
|
|
147
191
|
}
|
|
148
|
-
var createResolvers =
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
componentNames: "[String]!",
|
|
156
|
-
},
|
|
157
|
-
resolve: function (_source, args, context, _info) {
|
|
158
|
-
var _a;
|
|
159
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
160
|
-
var componentNames, components, bundles, compMetas, _loop_2, _i, components_2, component, renderData;
|
|
161
|
-
return tslib_1.__generator(this, function (_b) {
|
|
162
|
-
switch (_b.label) {
|
|
163
|
-
case 0:
|
|
164
|
-
componentNames = args.componentNames;
|
|
165
|
-
return [4 /*yield*/, getAllNodes(context.nodeModel, PLASMIC_NODE_NAME)];
|
|
166
|
-
case 1:
|
|
167
|
-
components = _b.sent();
|
|
168
|
-
bundles = [];
|
|
169
|
-
compMetas = [];
|
|
170
|
-
_loop_2 = function (component) {
|
|
171
|
-
if (componentNames.includes(component.name) ||
|
|
172
|
-
componentNames.includes(component.displayName) ||
|
|
173
|
-
!!(component.path &&
|
|
174
|
-
componentNames.some(function (lookup) {
|
|
175
|
-
return (0, loader_react_1.matchesPagePath)(component.path, lookup);
|
|
176
|
-
}))) {
|
|
177
|
-
var bundle = (_a = component.renderData) === null || _a === void 0 ? void 0 : _a.bundle;
|
|
178
|
-
if (bundle) {
|
|
179
|
-
bundles.push(bundle);
|
|
180
|
-
var meta = component;
|
|
181
|
-
// If component is a page, try to parse dynamic params.
|
|
182
|
-
if (component.path) {
|
|
183
|
-
for (var _c = 0, componentNames_1 = componentNames; _c < componentNames_1.length; _c++) {
|
|
184
|
-
var lookup = componentNames_1[_c];
|
|
185
|
-
var match = (0, loader_react_1.matchesPagePath)(component.path, lookup);
|
|
186
|
-
if (match) {
|
|
187
|
-
meta = tslib_1.__assign(tslib_1.__assign({}, meta), { params: match.params });
|
|
188
|
-
break;
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
compMetas.push(meta);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
};
|
|
196
|
-
for (_i = 0, components_2 = components; _i < components_2.length; _i++) {
|
|
197
|
-
component = components_2[_i];
|
|
198
|
-
_loop_2(component);
|
|
199
|
-
}
|
|
200
|
-
renderData = (0, loader_react_1.convertBundlesToComponentRenderData)(bundles, compMetas);
|
|
201
|
-
renderData === null || renderData === void 0 ? void 0 : renderData.entryCompMetas.sort(function (meta1, meta2) {
|
|
202
|
-
// We sort the matched component metas by the number of path params, so
|
|
203
|
-
// if there are two pages `/products/foo` and `/products/[slug]`,
|
|
204
|
-
// the first one will have higher precedence.
|
|
205
|
-
return Array.from(Object.keys(meta1.params || {})).length -
|
|
206
|
-
Array.from(Object.keys(meta2.params || {})).length;
|
|
207
|
-
});
|
|
208
|
-
return [2 /*return*/, renderData];
|
|
209
|
-
}
|
|
210
|
-
});
|
|
211
|
-
});
|
|
212
|
-
},
|
|
213
|
-
},
|
|
214
|
-
plasmicOptions: {
|
|
215
|
-
type: "JSON",
|
|
216
|
-
resolve: function () {
|
|
217
|
-
return {
|
|
218
|
-
projects: opts.projects,
|
|
219
|
-
preview: opts.preview,
|
|
220
|
-
host: opts.host,
|
|
221
|
-
};
|
|
222
|
-
},
|
|
223
|
-
},
|
|
192
|
+
var createResolvers = ({ createResolvers: createResolvers2 }, opts) => {
|
|
193
|
+
createResolvers2({
|
|
194
|
+
Query: {
|
|
195
|
+
plasmicComponents: {
|
|
196
|
+
type: "JSON",
|
|
197
|
+
args: {
|
|
198
|
+
componentNames: `[String]!`
|
|
224
199
|
},
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
pages = (_c = result.data) === null || _c === void 0 ? void 0 : _c.allPlasmicData.nodes;
|
|
251
|
-
if (!pages) {
|
|
252
|
-
reporter.error("[Plasmic Loader] - GraphQL did not return pages");
|
|
253
|
-
return [2 /*return*/];
|
|
200
|
+
resolve(_source, args, context, _info) {
|
|
201
|
+
return __async(this, null, function* () {
|
|
202
|
+
var _a2;
|
|
203
|
+
const { componentNames } = args;
|
|
204
|
+
const components = yield getAllNodes(
|
|
205
|
+
context.nodeModel,
|
|
206
|
+
PLASMIC_NODE_NAME
|
|
207
|
+
);
|
|
208
|
+
const bundles = [];
|
|
209
|
+
const compMetas = [];
|
|
210
|
+
for (const component of components) {
|
|
211
|
+
if (componentNames.includes(component.name) || componentNames.includes(component.displayName) || !!(component.path && componentNames.some(
|
|
212
|
+
(lookup) => (0, import_loader_react.matchesPagePath)(component.path, lookup)
|
|
213
|
+
))) {
|
|
214
|
+
const bundle = (_a2 = component.renderData) == null ? void 0 : _a2.bundle;
|
|
215
|
+
if (bundle) {
|
|
216
|
+
bundles.push(bundle);
|
|
217
|
+
let meta = component;
|
|
218
|
+
if (component.path) {
|
|
219
|
+
for (const lookup of componentNames) {
|
|
220
|
+
const match = (0, import_loader_react.matchesPagePath)(component.path, lookup);
|
|
221
|
+
if (match) {
|
|
222
|
+
meta = __spreadProps(__spreadValues({}, meta), { params: match.params });
|
|
223
|
+
break;
|
|
224
|
+
}
|
|
254
225
|
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
component: defaultPlasmicPage,
|
|
260
|
-
});
|
|
261
|
-
reporter.verbose("[Plasmic Loader] - Deleted page ".concat(path));
|
|
262
|
-
}
|
|
263
|
-
allPaths = [];
|
|
264
|
-
for (_b = 0, pages_1 = pages; _b < pages_1.length; _b++) {
|
|
265
|
-
page = pages_1[_b];
|
|
266
|
-
path = page.path;
|
|
267
|
-
if (ignorePaths.includes(path) || ignorePaths.includes(path + "/")) {
|
|
268
|
-
continue;
|
|
269
|
-
}
|
|
270
|
-
allPaths.push(page.path);
|
|
271
|
-
createPage({
|
|
272
|
-
path: page.path,
|
|
273
|
-
component: defaultPlasmicPage,
|
|
274
|
-
context: {},
|
|
275
|
-
});
|
|
276
|
-
reporter.verbose("[Plasmic Loader] - Created page ".concat(page.path));
|
|
277
|
-
}
|
|
278
|
-
_d.label = 2;
|
|
279
|
-
case 2: return [2 /*return*/];
|
|
226
|
+
}
|
|
227
|
+
compMetas.push(meta);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
280
230
|
}
|
|
281
|
-
|
|
282
|
-
|
|
231
|
+
const renderData = (0, import_loader_react.convertBundlesToComponentRenderData)(
|
|
232
|
+
bundles,
|
|
233
|
+
compMetas
|
|
234
|
+
);
|
|
235
|
+
renderData == null ? void 0 : renderData.entryCompMetas.sort(
|
|
236
|
+
(meta1, meta2) => (
|
|
237
|
+
// We sort the matched component metas by the number of path params, so
|
|
238
|
+
// if there are two pages `/products/foo` and `/products/[slug]`,
|
|
239
|
+
// the first one will have higher precedence.
|
|
240
|
+
Array.from(Object.keys(meta1.params || {})).length - Array.from(Object.keys(meta2.params || {})).length
|
|
241
|
+
)
|
|
242
|
+
);
|
|
243
|
+
return renderData;
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
},
|
|
247
|
+
plasmicOptions: {
|
|
248
|
+
type: "JSON",
|
|
249
|
+
resolve() {
|
|
250
|
+
return {
|
|
251
|
+
projects: opts.projects,
|
|
252
|
+
preview: opts.preview,
|
|
253
|
+
host: opts.host
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
};
|
|
260
|
+
var createSchemaCustomization = ({ actions }) => {
|
|
261
|
+
const { createTypes } = actions;
|
|
262
|
+
createTypes(PLASMIC_DATA_TYPE);
|
|
283
263
|
};
|
|
284
|
-
|
|
285
|
-
|
|
264
|
+
var createPages = (_0, _1) => __async(void 0, [_0, _1], function* ({ graphql, actions, reporter }, opts) {
|
|
265
|
+
var _a;
|
|
266
|
+
const { defaultPlasmicPage } = opts;
|
|
267
|
+
const ignorePaths = opts.ignorePaths || [];
|
|
268
|
+
if (defaultPlasmicPage) {
|
|
269
|
+
reporter.info(`[Plasmic Loader] - Creating pages`);
|
|
270
|
+
const { createPage, deletePage } = actions;
|
|
271
|
+
const result = yield graphql(`
|
|
272
|
+
query {
|
|
273
|
+
allPlasmicData(filter: { isPage: { eq: true } }) {
|
|
274
|
+
nodes {
|
|
275
|
+
path
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
`);
|
|
280
|
+
const pages = (_a = result.data) == null ? void 0 : _a.allPlasmicData.nodes;
|
|
281
|
+
if (!pages) {
|
|
282
|
+
reporter.error(`[Plasmic Loader] - GraphQL did not return pages`);
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
for (const path of allPaths) {
|
|
286
|
+
deletePage({
|
|
287
|
+
path,
|
|
288
|
+
component: defaultPlasmicPage
|
|
289
|
+
});
|
|
290
|
+
reporter.verbose(`[Plasmic Loader] - Deleted page ${path}`);
|
|
291
|
+
}
|
|
292
|
+
allPaths = [];
|
|
293
|
+
for (const page of pages) {
|
|
294
|
+
const path = page.path;
|
|
295
|
+
if (ignorePaths.includes(path) || ignorePaths.includes(path + "/")) {
|
|
296
|
+
continue;
|
|
297
|
+
}
|
|
298
|
+
allPaths.push(page.path);
|
|
299
|
+
createPage({
|
|
300
|
+
path: page.path,
|
|
301
|
+
component: defaultPlasmicPage,
|
|
302
|
+
context: {}
|
|
303
|
+
});
|
|
304
|
+
reporter.verbose(`[Plasmic Loader] - Created page ${page.path}`);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
});
|
|
308
|
+
//# sourceMappingURL=gatsby-node.js.map
|