eddev 0.2.66 → 0.2.67-beta1
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/admin/components/ImageWell.d.ts +2 -3
- package/admin/components/ImageWell.js +39 -51
- package/admin/defineField.d.ts +2 -2
- package/admin/defineWidget.d.ts +1 -1
- package/admin/defineWidget.js +2 -2
- package/admin/index.js +5 -1
- package/admin/installFieldTypes.js +26 -26
- package/admin/runWidgets.js +17 -28
- package/admin/selectMedia.d.ts +2 -2
- package/admin/selectMedia.js +1 -1
- package/blocks/ContentBlocks.d.ts +6 -6
- package/blocks/ContentBlocks.js +58 -66
- package/blocks/ErrorBoundaryEditor.d.ts +1 -1
- package/blocks/ErrorBoundaryEditor.js +16 -45
- package/blocks/ErrorBoundaryFrontend.d.ts +1 -1
- package/blocks/ErrorBoundaryFrontend.js +16 -45
- package/blocks/InspectorControls.d.ts +1 -1
- package/blocks/InspectorControls.js +3 -3
- package/blocks/blockAttributes.d.ts +2 -2
- package/blocks/blockAttributes.js +24 -44
- package/blocks/index.js +5 -1
- package/blocks/inlineEditing.d.ts +7 -7
- package/blocks/inlineEditing.js +36 -55
- package/blocks/installGutenbergHooks.js +48 -68
- package/build/babel/plugin-name-defined-components.js +15 -16
- package/build/build-favicon.js +11 -62
- package/build/clean.js +5 -52
- package/build/create-codegen-worker.js +78 -33
- package/build/create-serverless-dev-worker.js +61 -39
- package/build/create-webpack-worker.js +65 -33
- package/build/file-tree.d.ts +2 -2
- package/build/file-tree.js +12 -12
- package/build/get-webpack-config.js +341 -395
- package/build/graphql-codegen/graphql-codegen-files.js +31 -25
- package/build/graphql-codegen/graphql-codegen-no-duplicates.js +4 -4
- package/build/graphql-codegen/graphql-codegen-queries.js +102 -99
- package/build/manifests/manifest-blocks.d.ts +1 -1
- package/build/manifests/manifest-blocks.js +37 -29
- package/build/manifests/manifest-fields.d.ts +1 -1
- package/build/manifests/manifest-fields.js +23 -21
- package/build/manifests/manifest-views.d.ts +1 -1
- package/build/manifests/manifest-views.js +32 -25
- package/build/manifests/manifest-widgets.d.ts +1 -1
- package/build/manifests/manifest-widgets.js +22 -20
- package/build/manifests/manifest.d.ts +2 -2
- package/build/manifests/manifest.js +30 -90
- package/build/reporter.d.ts +1 -1
- package/build/reporter.js +29 -32
- package/build/serverless/create-next-app.d.ts +1 -1
- package/build/serverless/create-next-app.js +245 -467
- package/build/state/codegen-state.d.ts +4 -4
- package/build/state/compiler-state.d.ts +5 -5
- package/build/state/serverless-state.d.ts +3 -3
- package/build/workers/codegen-worker-script.js +392 -507
- package/build/workers/serverless-worker-dev-script.js +4 -4
- package/build/workers/webpack-worker-script.js +89 -150
- package/cli/build.dev.d.ts +1 -1
- package/cli/build.dev.js +79 -126
- package/cli/build.prod.d.ts +1 -1
- package/cli/build.prod.js +42 -98
- package/cli/cli.js +16 -55
- package/cli/display/components/BundleDisplay.d.ts +1 -2
- package/cli/display/components/BundleDisplay.js +13 -24
- package/cli/display/components/CodegenDisplay.d.ts +1 -2
- package/cli/display/components/CodegenDisplay.js +14 -25
- package/cli/display/components/DevCLIDisplay.d.ts +2 -3
- package/cli/display/components/DevCLIDisplay.js +14 -25
- package/cli/display/components/Fullscreen.js +9 -20
- package/cli/display/components/ServerlessDisplay.d.ts +2 -3
- package/cli/display/components/ServerlessDisplay.js +15 -26
- package/cli/display/components/StatusIcon.d.ts +2 -3
- package/cli/display/components/StatusIcon.js +3 -3
- package/cli/preinstall.js +4 -5
- package/cli/setup.js +25 -73
- package/components/AdminBar.d.ts +1 -2
- package/components/AdminBar.js +37 -3
- package/components/BrowserRouter.d.ts +2 -2
- package/components/BrowserRouter.js +41 -54
- package/components/InlinePage.d.ts +2 -2
- package/components/InlinePage.js +17 -29
- package/components/NextRouter.d.ts +2 -2
- package/components/NextRouter.js +20 -29
- package/components/index.js +5 -1
- package/config/config-schema.d.ts +1 -1
- package/config/config-schema.js +1 -1
- package/config/create-schema-file.js +6 -6
- package/config/get-config.js +10 -13
- package/config/index.js +5 -1
- package/config/parse-config.js +1 -1
- package/config/print-zod-errors.js +3 -3
- package/dev-ui/components/BreakpointColumnHeader.d.ts +2 -3
- package/dev-ui/components/BreakpointColumnHeader.js +7 -18
- package/dev-ui/components/BreakpointIndicator.d.ts +1 -2
- package/dev-ui/components/BreakpointIndicator.js +25 -32
- package/dev-ui/components/DevUI.d.ts +1 -2
- package/dev-ui/components/DevUI.js +13 -13
- package/dev-ui/components/Launcher.d.ts +2 -2
- package/dev-ui/components/Launcher.js +13 -25
- package/dev-ui/components/PanelWrapper.d.ts +2 -2
- package/dev-ui/components/PanelWrapper.js +8 -8
- package/dev-ui/components/ResponsiveLerpControl.d.ts +2 -3
- package/dev-ui/components/ResponsiveLerpControl.js +27 -38
- package/dev-ui/components/ResponsiveScaleEditor.d.ts +4 -5
- package/dev-ui/components/ResponsiveScaleEditor.js +64 -78
- package/dev-ui/components/atoms/Button.js +1 -1
- package/dev-ui/components/atoms/Dropdown.d.ts +3 -3
- package/dev-ui/components/atoms/Dropdown.js +8 -9
- package/dev-ui/components/atoms/NumberField.d.ts +2 -3
- package/dev-ui/components/atoms/NumberField.js +29 -42
- package/dev-ui/components/atoms/Spacer.js +1 -1
- package/dev-ui/components/atoms/Text.js +1 -1
- package/dev-ui/components/atoms/ToggleButton.d.ts +2 -2
- package/dev-ui/components/atoms/ToggleButton.js +5 -16
- package/dev-ui/components/atoms/Tooltip.d.ts +2 -2
- package/dev-ui/components/atoms/Tooltip.js +8 -20
- package/dev-ui/components/panels/AppDataDebugger.d.ts +1 -2
- package/dev-ui/components/panels/AppDataDebugger.js +8 -19
- package/dev-ui/components/panels/ColorEditor.d.ts +1 -2
- package/dev-ui/components/panels/ColorEditor.js +35 -42
- package/dev-ui/components/panels/PageDataDebugger.d.ts +1 -2
- package/dev-ui/components/panels/PageDataDebugger.js +8 -20
- package/dev-ui/components/panels/QueryDebugger.d.ts +1 -2
- package/dev-ui/components/panels/QueryDebugger.js +12 -24
- package/dev-ui/components/panels/SpacingEditor.d.ts +1 -2
- package/dev-ui/components/panels/SpacingEditor.js +34 -48
- package/dev-ui/components/panels/TypographyEditor.d.ts +1 -2
- package/dev-ui/components/panels/TypographyEditor.js +38 -46
- package/dev-ui/hooks/useBreakpoint.d.ts +1 -1
- package/dev-ui/hooks/useBreakpoint.js +13 -13
- package/dev-ui/hooks/usePersistState.js +6 -7
- package/dev-ui/hooks/useStylesheet.js +6 -6
- package/dev-ui/icons.d.ts +15 -16
- package/dev-ui/icons.js +16 -27
- package/dev-ui/index.js +5 -1
- package/dev-ui/loader.d.ts +1 -2
- package/dev-ui/loader.js +13 -9
- package/dev-ui/panels.d.ts +2 -2
- package/dev-ui/panels.js +7 -7
- package/dev-ui/theme.d.ts +96 -70
- package/dev-ui/theme.js +3 -3
- package/dynamic/dynamic-component.d.ts +1 -10
- package/dynamic/dynamic-component.js +1 -1
- package/dynamic/index.js +5 -1
- package/entry/Root.d.ts +2 -3
- package/entry/Root.js +16 -26
- package/entry/entry.admin.dev.js +4 -4
- package/entry/entry.admin.prod.js +4 -4
- package/entry/entry.monolith.dev.js +5 -5
- package/entry/entry.monolith.prod.js +5 -5
- package/gravityforms/gravity-forms.d.ts +2 -2
- package/gravityforms/index.js +5 -1
- package/gravityforms/useGravityForm.d.ts +2 -2
- package/gravityforms/useGravityForm.js +126 -130
- package/hooks/index.js +5 -1
- package/hooks/queryUtils.d.ts +14 -14
- package/hooks/queryUtils.js +101 -192
- package/hooks/useAppData.d.ts +2 -2
- package/hooks/useAppData.js +9 -9
- package/hooks/usePageLoad.js +4 -4
- package/hooks/useQueryDebug.d.ts +1 -1
- package/hooks/useQueryDebug.js +7 -7
- package/hooks/useRPC.d.ts +4 -4
- package/hooks/useRPC.js +3 -3
- package/package.json +7 -7
- package/routing/index.js +5 -1
- package/routing/remoteProps.d.ts +1 -1
- package/routing/remoteProps.js +31 -72
- package/routing/routing.d.ts +15 -15
- package/routing/routing.js +108 -170
- package/routing/updateEditLink.js +1 -1
- package/serverless/define-api.d.ts +1 -1
- package/serverless/define-rpc-router.js +8 -4
- package/serverless/index.js +6 -2
- package/style/createStitches.d.ts +375 -783
- package/style/createStitches.js +164 -142
- package/style/index.js +5 -1
- package/tsconfig.json +1 -1
- package/utils/Observable.d.ts +2 -2
- package/utils/Observable.js +12 -15
- package/utils/getRepoName.js +3 -3
- package/utils/promptIfRepoNameIncorrect.js +18 -64
- package/utils/refreshOverlayInterop.js +1 -1
- package/utils/reportErrorStack.d.ts +1 -1
- package/utils/reportErrorStack.js +1 -1
- package/utils/serverlessAppContext.js +1 -1
- package/utils/updateEnvFile.js +19 -69
- package/utils/useObservable.js +3 -3
- package/views/index.js +5 -1
|
@@ -1,18 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
3
|
if (k2 === undefined) k2 = k;
|
|
15
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
16
9
|
}) : (function(o, m, k, k2) {
|
|
17
10
|
if (k2 === undefined) k2 = k;
|
|
18
11
|
o[k2] = m[k];
|
|
@@ -29,514 +22,424 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
29
22
|
__setModuleDefault(result, mod);
|
|
30
23
|
return result;
|
|
31
24
|
};
|
|
32
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
33
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
34
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
35
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
36
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
37
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
38
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
39
|
-
});
|
|
40
|
-
};
|
|
41
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
42
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
43
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
44
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
45
|
-
function step(op) {
|
|
46
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
47
|
-
while (_) try {
|
|
48
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
49
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
50
|
-
switch (op[0]) {
|
|
51
|
-
case 0: case 1: t = op; break;
|
|
52
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
53
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
54
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
55
|
-
default:
|
|
56
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
57
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
58
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
59
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
60
|
-
if (t[2]) _.ops.pop();
|
|
61
|
-
_.trys.pop(); continue;
|
|
62
|
-
}
|
|
63
|
-
op = body.call(thisArg, _);
|
|
64
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
65
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
69
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
70
|
-
if (ar || !(i in from)) {
|
|
71
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
72
|
-
ar[i] = from[i];
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
76
|
-
};
|
|
77
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
78
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
79
27
|
};
|
|
80
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
81
29
|
exports.beginWork = void 0;
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
30
|
+
const worker_threads_1 = require("worker_threads");
|
|
31
|
+
const chokidar_1 = require("chokidar");
|
|
32
|
+
const Path = __importStar(require("path"));
|
|
33
|
+
const fs_1 = require("fs");
|
|
34
|
+
const graphql_1 = require("graphql");
|
|
35
|
+
const load_1 = require("@graphql-tools/load");
|
|
36
|
+
const url_loader_1 = require("@graphql-tools/url-loader");
|
|
89
37
|
// import { generate } from "@graphql-codegen/cli"
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
38
|
+
const core_1 = require("@graphql-codegen/core");
|
|
39
|
+
const glob_promise_1 = __importDefault(require("glob-promise"));
|
|
40
|
+
const promises_1 = require("fs/promises");
|
|
41
|
+
const cross_fetch_1 = __importDefault(require("cross-fetch"));
|
|
94
42
|
// Plugins
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
43
|
+
const typescriptPlugin = __importStar(require("@graphql-codegen/typescript"));
|
|
44
|
+
const typescriptOperationsPlugin = __importStar(require("@graphql-codegen/typescript-operations"));
|
|
45
|
+
const CodegenNoDuplicates = __importStar(require("../graphql-codegen/graphql-codegen-no-duplicates"));
|
|
46
|
+
const CodegenFiles = __importStar(require("../graphql-codegen/graphql-codegen-files"));
|
|
47
|
+
const CodegenQueries = __importStar(require("../graphql-codegen/graphql-codegen-queries"));
|
|
48
|
+
const https_1 = require("https");
|
|
49
|
+
const sendSignal = (sig) => {
|
|
102
50
|
if (worker_threads_1.parentPort) {
|
|
103
51
|
worker_threads_1.parentPort.postMessage(sig);
|
|
104
52
|
}
|
|
105
53
|
};
|
|
106
|
-
|
|
54
|
+
const graphqlPatterns = {
|
|
107
55
|
blocks: "./blocks/**/*.graphql",
|
|
108
56
|
views: "./views/**/*.graphql",
|
|
109
57
|
queries: "./queries/**/*.graphql",
|
|
110
58
|
fragments: "./queries/fragments/**/*.graphql",
|
|
111
59
|
};
|
|
112
|
-
|
|
60
|
+
const tsxPatterns = {
|
|
113
61
|
blocks: "./blocks/**/*.tsx",
|
|
114
62
|
views: "./views/**/*.tsx",
|
|
115
63
|
};
|
|
116
|
-
function beginWork(opts) {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
64
|
+
async function beginWork(opts) {
|
|
65
|
+
sendSignal({
|
|
66
|
+
code: "ready",
|
|
67
|
+
});
|
|
68
|
+
// Hold onto the endpoint
|
|
69
|
+
let envFile = Path.resolve(opts.baseDirectory, "./.env");
|
|
70
|
+
let endpoint = process.env.DEBUG_GRAPHQL_URL;
|
|
71
|
+
const schemaFile = Path.resolve(opts.baseDirectory, "schema.json"); //relative(process.cwd(), Path.join(opts.baseDirectory, "schema.json"))
|
|
72
|
+
let schema = null;
|
|
73
|
+
let rawSchema = null;
|
|
74
|
+
let lastSchemaHash = "";
|
|
75
|
+
let regenerating = false;
|
|
76
|
+
// Track what needs regenerating
|
|
77
|
+
let needsSchemaFetch = true;
|
|
78
|
+
// console.log (await response.text())
|
|
79
|
+
// Loads the schema from WP, and returns whether or not it's changed
|
|
80
|
+
const loadSchemaFromWordPress = async () => {
|
|
81
|
+
rawSchema = await (0, load_1.loadSchema)(endpoint, {
|
|
82
|
+
loaders: [new url_loader_1.UrlLoader()],
|
|
83
|
+
customFetch: (url, opts) => {
|
|
84
|
+
const httpsAgent = new https_1.Agent({
|
|
85
|
+
rejectUnauthorized: false,
|
|
86
|
+
});
|
|
87
|
+
return (0, cross_fetch_1.default)(url, {
|
|
88
|
+
...opts,
|
|
89
|
+
agent: url.includes("https") ? httpsAgent : undefined,
|
|
90
|
+
});
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
schema = (0, graphql_1.introspectionFromSchema)(rawSchema, {
|
|
94
|
+
descriptions: true,
|
|
95
|
+
schemaDescription: false,
|
|
96
|
+
specifiedByUrl: true,
|
|
97
|
+
});
|
|
98
|
+
processSchema(schema);
|
|
99
|
+
const hash = JSON.stringify(schema);
|
|
100
|
+
if (hash !== lastSchemaHash) {
|
|
101
|
+
lastSchemaHash = hash;
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
// Create RPC/API types
|
|
109
|
+
(0, promises_1.writeFile)(Path.join(opts.baseDirectory, "types.api.ts"), `
|
|
110
|
+
import type { router, createContext } from "./apis/_rpc"
|
|
111
|
+
import { createReactQueryHooks } from "@trpc/react"
|
|
112
|
+
export {}
|
|
113
|
+
|
|
114
|
+
const createQueryHooks = () => createReactQueryHooks<typeof router>()
|
|
115
|
+
|
|
116
|
+
declare global {
|
|
117
|
+
type RPCUse = ReturnType<typeof createQueryHooks>
|
|
118
|
+
type RPCRouter = typeof router
|
|
119
|
+
type RPCContextType = Awaited<ReturnType<typeof createContext>>
|
|
120
|
+
type RPCClient = ReturnType<RPCUse["createClient"]>
|
|
121
|
+
type RPCUseQuery = RPCUse["useQuery"]
|
|
122
|
+
type RPCUseMutation = RPCUse["useMutation"]
|
|
123
|
+
type RPCUseInfiniteQuery = RPCUse["useInfiniteQuery"]
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
declare global {
|
|
127
|
+
namespace NodeJS {
|
|
128
|
+
interface Process {
|
|
129
|
+
// @ts-ignore
|
|
130
|
+
browser: boolean
|
|
131
|
+
dev: boolean
|
|
132
|
+
admin: boolean
|
|
133
|
+
serverless: boolean
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
`);
|
|
139
|
+
// Function which runs the full process
|
|
140
|
+
const regenerate = debounce(100, async () => {
|
|
141
|
+
regenerating = true;
|
|
142
|
+
const startTime = Date.now();
|
|
143
|
+
// Only refetch the schema when necessary
|
|
144
|
+
if (needsSchemaFetch) {
|
|
121
145
|
sendSignal({
|
|
122
|
-
code: "
|
|
146
|
+
code: "fetching",
|
|
123
147
|
});
|
|
124
|
-
|
|
125
|
-
endpoint
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
regenerating = false;
|
|
132
|
-
needsSchemaFetch = true;
|
|
133
|
-
loadSchemaFromWordPress = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
134
|
-
var hash;
|
|
135
|
-
return __generator(this, function (_a) {
|
|
136
|
-
switch (_a.label) {
|
|
137
|
-
case 0: return [4 /*yield*/, (0, load_1.loadSchema)(endpoint, {
|
|
138
|
-
loaders: [new url_loader_1.UrlLoader()],
|
|
139
|
-
customFetch: function (url, opts) {
|
|
140
|
-
var httpsAgent = new https_1.Agent({
|
|
141
|
-
rejectUnauthorized: false,
|
|
142
|
-
});
|
|
143
|
-
return (0, cross_fetch_1.default)(url, __assign(__assign({}, opts), { agent: url.includes("https") ? httpsAgent : undefined }));
|
|
144
|
-
},
|
|
145
|
-
})];
|
|
146
|
-
case 1:
|
|
147
|
-
rawSchema = _a.sent();
|
|
148
|
-
schema = (0, graphql_1.introspectionFromSchema)(rawSchema, {
|
|
149
|
-
descriptions: true,
|
|
150
|
-
schemaDescription: false,
|
|
151
|
-
specifiedByUrl: true,
|
|
152
|
-
});
|
|
153
|
-
processSchema(schema);
|
|
154
|
-
hash = JSON.stringify(schema);
|
|
155
|
-
if (hash !== lastSchemaHash) {
|
|
156
|
-
lastSchemaHash = hash;
|
|
157
|
-
return [2 /*return*/, true];
|
|
158
|
-
}
|
|
159
|
-
else {
|
|
160
|
-
return [2 /*return*/, false];
|
|
161
|
-
}
|
|
162
|
-
return [2 /*return*/];
|
|
163
|
-
}
|
|
164
|
-
});
|
|
165
|
-
}); };
|
|
166
|
-
// Create RPC/API types
|
|
167
|
-
(0, promises_1.writeFile)(Path.join(opts.baseDirectory, "types.api.ts"), "\n import type { router, createContext } from \"./apis/_rpc\"\n import { createReactQueryHooks } from \"@trpc/react\"\n export {}\n \n const createQueryHooks = () => createReactQueryHooks<typeof router>()\n \n declare global {\n type RPCUse = ReturnType<typeof createQueryHooks>\n type RPCRouter = typeof router\n type RPCContextType = Awaited<ReturnType<typeof createContext>>\n type RPCClient = ReturnType<RPCUse[\"createClient\"]>\n type RPCUseQuery = RPCUse[\"useQuery\"]\n type RPCUseMutation = RPCUse[\"useMutation\"]\n type RPCUseInfiniteQuery = RPCUse[\"useInfiniteQuery\"]\n }\n\n declare global {\n namespace NodeJS {\n interface Process {\n // @ts-ignore\n browser: boolean\n dev: boolean\n admin: boolean\n serverless: boolean\n }\n }\n }\n \n ");
|
|
168
|
-
regenerate = debounce(100, function () { return __awaiter(_this, void 0, void 0, function () {
|
|
169
|
-
var startTime, hasChanged, err_1, documentSets, parseErrors, _loop_1, _a, _b, _i, key, generates, errors, _c, _d, _e, file, base, config, output, err_2;
|
|
170
|
-
var _this = this;
|
|
171
|
-
return __generator(this, function (_f) {
|
|
172
|
-
switch (_f.label) {
|
|
173
|
-
case 0:
|
|
174
|
-
regenerating = true;
|
|
175
|
-
startTime = Date.now();
|
|
176
|
-
if (!needsSchemaFetch) return [3 /*break*/, 5];
|
|
177
|
-
sendSignal({
|
|
178
|
-
code: "fetching",
|
|
179
|
-
});
|
|
180
|
-
// Show an error if no endpoint was found
|
|
181
|
-
if (!endpoint) {
|
|
182
|
-
sendSignal({
|
|
183
|
-
code: "error",
|
|
184
|
-
errors: [
|
|
185
|
-
"Could not find DEBUG_GRAPHQL_URL value in .env. This will be automatically populated once you visit WP Admin first the first time!",
|
|
186
|
-
],
|
|
187
|
-
});
|
|
188
|
-
regenerating = false;
|
|
189
|
-
return [2 /*return*/];
|
|
190
|
-
}
|
|
191
|
-
_f.label = 1;
|
|
192
|
-
case 1:
|
|
193
|
-
_f.trys.push([1, 3, , 4]);
|
|
194
|
-
return [4 /*yield*/, loadSchemaFromWordPress()];
|
|
195
|
-
case 2:
|
|
196
|
-
hasChanged = _f.sent();
|
|
197
|
-
return [3 /*break*/, 4];
|
|
198
|
-
case 3:
|
|
199
|
-
err_1 = _f.sent();
|
|
200
|
-
// Error loading schema
|
|
201
|
-
sendSignal({
|
|
202
|
-
code: "error",
|
|
203
|
-
errors: ["Could not load GraphQL schema from server:\n" + String(err_1)],
|
|
204
|
-
});
|
|
205
|
-
regenerating = false;
|
|
206
|
-
return [2 /*return*/];
|
|
207
|
-
case 4:
|
|
208
|
-
// Store the schema file
|
|
209
|
-
(0, fs_1.writeFileSync)(schemaFile, JSON.stringify(schema), {
|
|
210
|
-
encoding: "utf-8",
|
|
211
|
-
});
|
|
212
|
-
// No need to refetch
|
|
213
|
-
needsSchemaFetch = false;
|
|
214
|
-
_f.label = 5;
|
|
215
|
-
case 5:
|
|
216
|
-
documentSets = {};
|
|
217
|
-
parseErrors = [];
|
|
218
|
-
_loop_1 = function (key) {
|
|
219
|
-
var pattern, files;
|
|
220
|
-
return __generator(this, function (_g) {
|
|
221
|
-
switch (_g.label) {
|
|
222
|
-
case 0:
|
|
223
|
-
pattern = graphqlPatterns[key];
|
|
224
|
-
// Find all the documents by globbing
|
|
225
|
-
documentSets[key] = [];
|
|
226
|
-
return [4 /*yield*/, (0, glob_promise_1.default)(Path.resolve(opts.baseDirectory, pattern))];
|
|
227
|
-
case 1:
|
|
228
|
-
files = _g.sent();
|
|
229
|
-
return [4 /*yield*/, Promise.all(files.map(function (file) { return __awaiter(_this, void 0, void 0, function () {
|
|
230
|
-
var contents, document_1, err_3;
|
|
231
|
-
return __generator(this, function (_a) {
|
|
232
|
-
switch (_a.label) {
|
|
233
|
-
case 0:
|
|
234
|
-
_a.trys.push([0, 2, , 3]);
|
|
235
|
-
return [4 /*yield*/, (0, promises_1.readFile)(file)];
|
|
236
|
-
case 1:
|
|
237
|
-
contents = (_a.sent()).toString();
|
|
238
|
-
document_1 = (0, graphql_1.parse)(contents);
|
|
239
|
-
documentSets[key].push({
|
|
240
|
-
document: document_1,
|
|
241
|
-
rawSDL: contents,
|
|
242
|
-
location: file,
|
|
243
|
-
});
|
|
244
|
-
return [3 /*break*/, 3];
|
|
245
|
-
case 2:
|
|
246
|
-
err_3 = _a.sent();
|
|
247
|
-
parseErrors.push("Error parsing \"".concat(file.replace(opts.baseDirectory, ""), ":\n").concat(err_3));
|
|
248
|
-
return [3 /*break*/, 3];
|
|
249
|
-
case 3: return [2 /*return*/];
|
|
250
|
-
}
|
|
251
|
-
});
|
|
252
|
-
}); }))];
|
|
253
|
-
case 2:
|
|
254
|
-
_g.sent();
|
|
255
|
-
return [2 /*return*/];
|
|
256
|
-
}
|
|
257
|
-
});
|
|
258
|
-
};
|
|
259
|
-
_a = [];
|
|
260
|
-
for (_b in graphqlPatterns)
|
|
261
|
-
_a.push(_b);
|
|
262
|
-
_i = 0;
|
|
263
|
-
_f.label = 6;
|
|
264
|
-
case 6:
|
|
265
|
-
if (!(_i < _a.length)) return [3 /*break*/, 9];
|
|
266
|
-
key = _a[_i];
|
|
267
|
-
return [5 /*yield**/, _loop_1(key)];
|
|
268
|
-
case 7:
|
|
269
|
-
_f.sent();
|
|
270
|
-
_f.label = 8;
|
|
271
|
-
case 8:
|
|
272
|
-
_i++;
|
|
273
|
-
return [3 /*break*/, 6];
|
|
274
|
-
case 9:
|
|
275
|
-
if (parseErrors.length > 0) {
|
|
276
|
-
sendSignal({
|
|
277
|
-
code: "error",
|
|
278
|
-
errors: parseErrors,
|
|
279
|
-
});
|
|
280
|
-
regenerating = false;
|
|
281
|
-
return [2 /*return*/];
|
|
282
|
-
}
|
|
283
|
-
generates = {
|
|
284
|
-
"types.graphql.ts": {
|
|
285
|
-
documents: __spreadArray(__spreadArray(__spreadArray([], documentSets.queries, true), documentSets.views, true), documentSets.blocks, true),
|
|
286
|
-
plugins: [
|
|
287
|
-
{
|
|
288
|
-
typescript: {},
|
|
289
|
-
},
|
|
290
|
-
{
|
|
291
|
-
typescriptOperations: {},
|
|
292
|
-
},
|
|
293
|
-
],
|
|
294
|
-
pluginMap: {
|
|
295
|
-
typescript: typescriptPlugin,
|
|
296
|
-
typescriptOperations: typescriptOperationsPlugin,
|
|
297
|
-
noDuplicates: CodegenNoDuplicates,
|
|
298
|
-
},
|
|
299
|
-
config: {
|
|
300
|
-
// maybeValue: "T",
|
|
301
|
-
avoidOptionals: {
|
|
302
|
-
field: true,
|
|
303
|
-
inputValue: false,
|
|
304
|
-
object: true,
|
|
305
|
-
defaultValue: true,
|
|
306
|
-
},
|
|
307
|
-
// exportFragmentSpreadSubTypes: true,
|
|
308
|
-
inlineFragmentTypes: "combine",
|
|
309
|
-
onlyOperationTypes: true,
|
|
310
|
-
skipTypename: true,
|
|
311
|
-
preResolveTypes: true,
|
|
312
|
-
maybeValue: "T | null",
|
|
313
|
-
},
|
|
314
|
-
},
|
|
315
|
-
"types.views.ts": {
|
|
316
|
-
documents: __spreadArray(__spreadArray([], documentSets.views, true), documentSets.fragments, true),
|
|
317
|
-
plugins: [
|
|
318
|
-
{
|
|
319
|
-
files: {},
|
|
320
|
-
},
|
|
321
|
-
],
|
|
322
|
-
pluginMap: {
|
|
323
|
-
files: CodegenFiles,
|
|
324
|
-
},
|
|
325
|
-
config: {
|
|
326
|
-
rootDir: opts.baseDirectory,
|
|
327
|
-
folderName: "views",
|
|
328
|
-
globalName: "ViewProps",
|
|
329
|
-
additionalTypes: {
|
|
330
|
-
_html: "{ \"template\": string, \"htmlContent\": string }",
|
|
331
|
-
_app: "{ children: any }",
|
|
332
|
-
},
|
|
333
|
-
},
|
|
334
|
-
},
|
|
335
|
-
"types.blocks.ts": {
|
|
336
|
-
documents: __spreadArray(__spreadArray([], documentSets.blocks, true), documentSets.fragments, true),
|
|
337
|
-
plugins: [
|
|
338
|
-
{
|
|
339
|
-
files: {},
|
|
340
|
-
},
|
|
341
|
-
],
|
|
342
|
-
pluginMap: {
|
|
343
|
-
files: CodegenFiles,
|
|
344
|
-
},
|
|
345
|
-
config: {
|
|
346
|
-
rootDir: opts.baseDirectory,
|
|
347
|
-
globalName: "BlockProps",
|
|
348
|
-
folderName: "blocks",
|
|
349
|
-
getType: function (importedName, def) {
|
|
350
|
-
var _a, _b, _c;
|
|
351
|
-
var queryKeyVals = [];
|
|
352
|
-
var blockSelection = "";
|
|
353
|
-
for (var _i = 0, _d = def.selectionSet.selections; _i < _d.length; _i++) {
|
|
354
|
-
var item = _d[_i];
|
|
355
|
-
if (item.name.value === "block") {
|
|
356
|
-
var blockField = (_c = (_b = (_a = item === null || item === void 0 ? void 0 : item.selectionSet) === null || _a === void 0 ? void 0 : _a.selections[0]) === null || _b === void 0 ? void 0 : _b.name) === null || _c === void 0 ? void 0 : _c.value;
|
|
357
|
-
blockSelection = "Exclude<".concat(importedName, "[\"block\"][").concat(JSON.stringify(blockField), "], null | undefined>");
|
|
358
|
-
}
|
|
359
|
-
else {
|
|
360
|
-
queryKeyVals.push([JSON.stringify(item.name.value), "".concat(importedName, "[").concat(JSON.stringify(item.name.value), "]")].join(": "));
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
var type = [];
|
|
364
|
-
if (queryKeyVals.length)
|
|
365
|
-
type.push("{".concat(queryKeyVals.join(",\n"), "}"));
|
|
366
|
-
if (blockSelection)
|
|
367
|
-
type.push(blockSelection);
|
|
368
|
-
if (type.length === 0)
|
|
369
|
-
return {};
|
|
370
|
-
return type.join(" & ");
|
|
371
|
-
},
|
|
372
|
-
},
|
|
373
|
-
},
|
|
374
|
-
"hooks/queries.ts": {
|
|
375
|
-
documents: __spreadArray([], documentSets.queries, true),
|
|
376
|
-
plugins: [
|
|
377
|
-
{
|
|
378
|
-
queries: {},
|
|
379
|
-
},
|
|
380
|
-
],
|
|
381
|
-
pluginMap: {
|
|
382
|
-
queries: CodegenQueries,
|
|
383
|
-
},
|
|
384
|
-
config: {
|
|
385
|
-
rootDir: opts.baseDirectory,
|
|
386
|
-
},
|
|
387
|
-
},
|
|
388
|
-
};
|
|
389
|
-
// Notify of generation start
|
|
390
|
-
sendSignal({
|
|
391
|
-
code: "generating",
|
|
392
|
-
});
|
|
393
|
-
errors = [];
|
|
394
|
-
_c = 0, _d = Object.entries(generates);
|
|
395
|
-
_f.label = 10;
|
|
396
|
-
case 10:
|
|
397
|
-
if (!(_c < _d.length)) return [3 /*break*/, 15];
|
|
398
|
-
_e = _d[_c], file = _e[0], base = _e[1];
|
|
399
|
-
_f.label = 11;
|
|
400
|
-
case 11:
|
|
401
|
-
_f.trys.push([11, 13, , 14]);
|
|
402
|
-
config = __assign(__assign({}, base), { documents: base.documents.sort(function (a, b) { return a.location.localeCompare(b.location); }), filename: Path.join(opts.baseDirectory, file), schema: rawSchema });
|
|
403
|
-
return [4 /*yield*/, (0, core_1.codegen)(config)
|
|
404
|
-
// Write the file
|
|
405
|
-
];
|
|
406
|
-
case 12:
|
|
407
|
-
output = _f.sent();
|
|
408
|
-
// Write the file
|
|
409
|
-
writeFileIfUnchanged(file, output);
|
|
410
|
-
return [3 /*break*/, 14];
|
|
411
|
-
case 13:
|
|
412
|
-
err_2 = _f.sent();
|
|
413
|
-
errors.push(String(err_2));
|
|
414
|
-
return [3 /*break*/, 14];
|
|
415
|
-
case 14:
|
|
416
|
-
_c++;
|
|
417
|
-
return [3 /*break*/, 10];
|
|
418
|
-
case 15:
|
|
419
|
-
// Success/fail
|
|
420
|
-
if (errors.length) {
|
|
421
|
-
sendSignal({
|
|
422
|
-
code: "error",
|
|
423
|
-
errors: errors,
|
|
424
|
-
});
|
|
425
|
-
}
|
|
426
|
-
else {
|
|
427
|
-
sendSignal({
|
|
428
|
-
code: "success",
|
|
429
|
-
duration: Date.now() - startTime,
|
|
430
|
-
});
|
|
431
|
-
}
|
|
432
|
-
regenerating = false;
|
|
433
|
-
return [2 /*return*/];
|
|
434
|
-
}
|
|
148
|
+
// Show an error if no endpoint was found
|
|
149
|
+
if (!endpoint) {
|
|
150
|
+
sendSignal({
|
|
151
|
+
code: "error",
|
|
152
|
+
errors: [
|
|
153
|
+
"Could not find DEBUG_GRAPHQL_URL value in .env. This will be automatically populated once you visit WP Admin first the first time!",
|
|
154
|
+
],
|
|
435
155
|
});
|
|
436
|
-
|
|
437
|
-
|
|
156
|
+
regenerating = false;
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
try {
|
|
160
|
+
// Load the schema
|
|
161
|
+
const hasChanged = await loadSchemaFromWordPress();
|
|
162
|
+
}
|
|
163
|
+
catch (err) {
|
|
164
|
+
// Error loading schema
|
|
438
165
|
sendSignal({
|
|
439
|
-
code: "
|
|
440
|
-
|
|
166
|
+
code: "error",
|
|
167
|
+
errors: ["Could not load GraphQL schema from server:\n" + String(err)],
|
|
441
168
|
});
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
169
|
+
regenerating = false;
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
// Store the schema file
|
|
173
|
+
(0, fs_1.writeFileSync)(schemaFile, JSON.stringify(schema), {
|
|
174
|
+
encoding: "utf-8",
|
|
175
|
+
});
|
|
176
|
+
// No need to refetch
|
|
177
|
+
needsSchemaFetch = false;
|
|
178
|
+
}
|
|
179
|
+
// Load all the GraphQL files
|
|
180
|
+
const documentSets = {};
|
|
181
|
+
let parseErrors = [];
|
|
182
|
+
for (const key in graphqlPatterns) {
|
|
183
|
+
const pattern = graphqlPatterns[key];
|
|
184
|
+
// Find all the documents by globbing
|
|
185
|
+
documentSets[key] = [];
|
|
186
|
+
const files = await (0, glob_promise_1.default)(Path.resolve(opts.baseDirectory, pattern));
|
|
187
|
+
await Promise.all(files.map(async (file) => {
|
|
188
|
+
try {
|
|
189
|
+
const contents = (await (0, promises_1.readFile)(file)).toString();
|
|
190
|
+
const document = (0, graphql_1.parse)(contents);
|
|
191
|
+
documentSets[key].push({
|
|
192
|
+
document,
|
|
193
|
+
rawSDL: contents,
|
|
194
|
+
location: file,
|
|
448
195
|
});
|
|
449
196
|
}
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
regenerateBecauseChanges(path);
|
|
453
|
-
});
|
|
197
|
+
catch (err) {
|
|
198
|
+
parseErrors.push(`Error parsing "${file.replace(opts.baseDirectory, "")}:\n${err}`);
|
|
454
199
|
}
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
200
|
+
}));
|
|
201
|
+
}
|
|
202
|
+
if (parseErrors.length > 0) {
|
|
203
|
+
sendSignal({
|
|
204
|
+
code: "error",
|
|
205
|
+
errors: parseErrors,
|
|
206
|
+
});
|
|
207
|
+
regenerating = false;
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
// Regenerate
|
|
211
|
+
const generates = {
|
|
212
|
+
"types.graphql.ts": {
|
|
213
|
+
documents: [...documentSets.queries, ...documentSets.views, ...documentSets.blocks],
|
|
214
|
+
plugins: [
|
|
215
|
+
{
|
|
216
|
+
typescript: {},
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
typescriptOperations: {},
|
|
220
|
+
},
|
|
221
|
+
],
|
|
222
|
+
pluginMap: {
|
|
223
|
+
typescript: typescriptPlugin,
|
|
224
|
+
typescriptOperations: typescriptOperationsPlugin,
|
|
225
|
+
noDuplicates: CodegenNoDuplicates,
|
|
226
|
+
},
|
|
227
|
+
config: {
|
|
228
|
+
// maybeValue: "T",
|
|
229
|
+
avoidOptionals: {
|
|
230
|
+
field: true,
|
|
231
|
+
inputValue: false,
|
|
232
|
+
object: true,
|
|
233
|
+
defaultValue: true,
|
|
234
|
+
},
|
|
235
|
+
// exportFragmentSpreadSubTypes: true,
|
|
236
|
+
inlineFragmentTypes: "combine",
|
|
237
|
+
onlyOperationTypes: true,
|
|
238
|
+
skipTypename: true,
|
|
239
|
+
preResolveTypes: true,
|
|
240
|
+
maybeValue: "T | null",
|
|
241
|
+
},
|
|
242
|
+
},
|
|
243
|
+
"types.views.ts": {
|
|
244
|
+
documents: [...documentSets.views, ...documentSets.fragments],
|
|
245
|
+
plugins: [
|
|
246
|
+
{
|
|
247
|
+
files: {},
|
|
248
|
+
},
|
|
249
|
+
],
|
|
250
|
+
pluginMap: {
|
|
251
|
+
files: CodegenFiles,
|
|
252
|
+
},
|
|
253
|
+
config: {
|
|
254
|
+
rootDir: opts.baseDirectory,
|
|
255
|
+
folderName: "views",
|
|
256
|
+
globalName: "ViewProps",
|
|
257
|
+
additionalTypes: {
|
|
258
|
+
_html: `{ "template": string, "htmlContent": string }`,
|
|
259
|
+
_app: `{ children: any }`,
|
|
260
|
+
},
|
|
261
|
+
},
|
|
262
|
+
},
|
|
263
|
+
"types.blocks.ts": {
|
|
264
|
+
documents: [...documentSets.blocks, ...documentSets.fragments],
|
|
265
|
+
plugins: [
|
|
266
|
+
{
|
|
267
|
+
files: {},
|
|
268
|
+
},
|
|
269
|
+
],
|
|
270
|
+
pluginMap: {
|
|
271
|
+
files: CodegenFiles,
|
|
272
|
+
},
|
|
273
|
+
config: {
|
|
274
|
+
rootDir: opts.baseDirectory,
|
|
275
|
+
globalName: "BlockProps",
|
|
276
|
+
folderName: "blocks",
|
|
277
|
+
getType: (importedName, def) => {
|
|
278
|
+
const queryKeyVals = [];
|
|
279
|
+
let blockSelection = "";
|
|
280
|
+
for (const item of def.selectionSet.selections) {
|
|
281
|
+
if (item.name.value === "block") {
|
|
282
|
+
const blockField = item?.selectionSet?.selections[0]?.name?.value;
|
|
283
|
+
blockSelection = `Exclude<${importedName}["block"][${JSON.stringify(blockField)}], null | undefined>`;
|
|
284
|
+
}
|
|
285
|
+
else {
|
|
286
|
+
queryKeyVals.push([JSON.stringify(item.name.value), `${importedName}[${JSON.stringify(item.name.value)}]`].join(": "));
|
|
287
|
+
}
|
|
480
288
|
}
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
289
|
+
const type = [];
|
|
290
|
+
if (queryKeyVals.length)
|
|
291
|
+
type.push(`{${queryKeyVals.join(",\n")}}`);
|
|
292
|
+
if (blockSelection)
|
|
293
|
+
type.push(blockSelection);
|
|
294
|
+
if (type.length === 0)
|
|
295
|
+
return {};
|
|
296
|
+
return type.join(" & ");
|
|
297
|
+
},
|
|
298
|
+
},
|
|
299
|
+
},
|
|
300
|
+
"hooks/queries.ts": {
|
|
301
|
+
documents: [...documentSets.queries],
|
|
302
|
+
plugins: [
|
|
303
|
+
{
|
|
304
|
+
queries: {},
|
|
305
|
+
},
|
|
306
|
+
],
|
|
307
|
+
pluginMap: {
|
|
308
|
+
queries: CodegenQueries,
|
|
309
|
+
},
|
|
310
|
+
config: {
|
|
311
|
+
rootDir: opts.baseDirectory,
|
|
312
|
+
},
|
|
313
|
+
},
|
|
314
|
+
};
|
|
315
|
+
// Notify of generation start
|
|
316
|
+
sendSignal({
|
|
317
|
+
code: "generating",
|
|
318
|
+
});
|
|
319
|
+
// Generate each file
|
|
320
|
+
let errors = [];
|
|
321
|
+
for (let [file, base] of Object.entries(generates)) {
|
|
322
|
+
try {
|
|
323
|
+
const config = {
|
|
324
|
+
...base,
|
|
325
|
+
documents: base.documents.sort((a, b) => a.location.localeCompare(b.location)),
|
|
326
|
+
filename: Path.join(opts.baseDirectory, file),
|
|
327
|
+
schema: rawSchema,
|
|
328
|
+
};
|
|
329
|
+
// Actually generate
|
|
330
|
+
const output = await (0, core_1.codegen)(config);
|
|
331
|
+
// Write the file
|
|
332
|
+
writeFileIfUnchanged(file, output);
|
|
333
|
+
}
|
|
334
|
+
catch (err) {
|
|
335
|
+
errors.push(String(err));
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
// Success/fail
|
|
339
|
+
if (errors.length) {
|
|
340
|
+
sendSignal({
|
|
341
|
+
code: "error",
|
|
342
|
+
errors: errors,
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
else {
|
|
346
|
+
sendSignal({
|
|
347
|
+
code: "success",
|
|
348
|
+
duration: Date.now() - startTime,
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
regenerating = false;
|
|
352
|
+
});
|
|
353
|
+
const regenerateBecauseChanges = (reason) => {
|
|
354
|
+
sendSignal({
|
|
355
|
+
code: "invalidated",
|
|
356
|
+
reason: reason.replace(opts.baseDirectory, ""),
|
|
357
|
+
});
|
|
358
|
+
regenerate();
|
|
359
|
+
};
|
|
360
|
+
if (opts.watch) {
|
|
361
|
+
for (let key in graphqlPatterns) {
|
|
362
|
+
watchGlob(Path.resolve(opts.baseDirectory, graphqlPatterns[key]), (path) => {
|
|
363
|
+
regenerateBecauseChanges(path);
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
for (let key in tsxPatterns) {
|
|
367
|
+
watchFilenames(Path.resolve(opts.baseDirectory, tsxPatterns[key]), (path) => {
|
|
368
|
+
regenerateBecauseChanges(path);
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
// Watch PHP files + ACF JSON files for changes
|
|
372
|
+
const maybeRegenerate = async (path) => {
|
|
373
|
+
sendSignal({
|
|
374
|
+
code: "invalidated",
|
|
375
|
+
reason: path.replace(opts.baseDirectory, ""),
|
|
376
|
+
});
|
|
377
|
+
if (!regenerating) {
|
|
378
|
+
const hasChanged = await loadSchemaFromWordPress();
|
|
379
|
+
if (hasChanged) {
|
|
380
|
+
regenerateBecauseChanges(path);
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
sendSignal({
|
|
385
|
+
code: "success",
|
|
386
|
+
reason: "No changes to schema",
|
|
387
|
+
duration: 0,
|
|
388
|
+
});
|
|
389
|
+
};
|
|
390
|
+
watchGlob(Path.resolve(opts.baseDirectory, "./acf-json/*.json"), (path) => {
|
|
391
|
+
needsSchemaFetch = true;
|
|
392
|
+
maybeRegenerate(path);
|
|
393
|
+
});
|
|
394
|
+
watchGlob(Path.resolve(opts.baseDirectory, "./backend/**/*.php"), (path) => {
|
|
395
|
+
needsSchemaFetch = true;
|
|
396
|
+
maybeRegenerate(path);
|
|
397
|
+
});
|
|
398
|
+
watchGlob(envFile, () => {
|
|
399
|
+
// Parse the env file and extract the endpoint
|
|
400
|
+
let nextEndpoint = "";
|
|
401
|
+
try {
|
|
402
|
+
const contents = (0, fs_1.readFileSync)(envFile, "utf8");
|
|
403
|
+
nextEndpoint = contents.match(/DEBUG_GRAPHQL_URL=(.*)/)?.[1];
|
|
404
|
+
}
|
|
405
|
+
catch (err) {
|
|
406
|
+
sendSignal({
|
|
407
|
+
code: "error",
|
|
408
|
+
errors: ["Unable to read .env file"],
|
|
510
409
|
});
|
|
410
|
+
return;
|
|
411
|
+
}
|
|
412
|
+
if (endpoint !== nextEndpoint && nextEndpoint) {
|
|
413
|
+
needsSchemaFetch = true;
|
|
414
|
+
regenerate();
|
|
511
415
|
}
|
|
512
|
-
regenerate();
|
|
513
|
-
return [2 /*return*/];
|
|
514
416
|
});
|
|
515
|
-
}
|
|
417
|
+
}
|
|
418
|
+
regenerate();
|
|
516
419
|
}
|
|
517
420
|
exports.beginWork = beginWork;
|
|
518
421
|
function watchGlob(glob, callback) {
|
|
519
|
-
|
|
422
|
+
const watcher = (0, chokidar_1.watch)(glob, {
|
|
520
423
|
ignoreInitial: true,
|
|
521
424
|
persistent: true,
|
|
522
425
|
});
|
|
523
|
-
watcher.on("ready",
|
|
524
|
-
watcher.on("all",
|
|
426
|
+
watcher.on("ready", () => {
|
|
427
|
+
watcher.on("all", (event, path) => {
|
|
525
428
|
callback(path);
|
|
526
429
|
});
|
|
527
430
|
});
|
|
528
431
|
return watcher;
|
|
529
432
|
}
|
|
530
433
|
function watchFilenames(glob, callback) {
|
|
531
|
-
|
|
434
|
+
const watcher = (0, chokidar_1.watch)(glob, {
|
|
532
435
|
ignoreInitial: true,
|
|
533
436
|
persistent: true,
|
|
534
437
|
});
|
|
535
|
-
watcher.on("ready",
|
|
536
|
-
watcher.on("add",
|
|
438
|
+
watcher.on("ready", () => {
|
|
439
|
+
watcher.on("add", (path) => {
|
|
537
440
|
callback(path);
|
|
538
441
|
});
|
|
539
|
-
watcher.on("unlink",
|
|
442
|
+
watcher.on("unlink", (path) => {
|
|
540
443
|
callback(path);
|
|
541
444
|
});
|
|
542
445
|
});
|
|
@@ -544,48 +447,32 @@ function watchFilenames(glob, callback) {
|
|
|
544
447
|
}
|
|
545
448
|
function writeFileIfUnchanged(file, contents) {
|
|
546
449
|
if ((0, fs_1.existsSync)(file)) {
|
|
547
|
-
|
|
450
|
+
const existing = (0, fs_1.readFileSync)(file).toString();
|
|
548
451
|
if (existing === contents)
|
|
549
452
|
return;
|
|
550
453
|
}
|
|
551
454
|
(0, fs_1.writeFileSync)(file, contents);
|
|
552
455
|
}
|
|
553
456
|
function debounce(wait, fn) {
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
var debounced = function () {
|
|
557
|
-
var args = [];
|
|
558
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
559
|
-
args[_i] = arguments[_i];
|
|
560
|
-
}
|
|
457
|
+
let timeout;
|
|
458
|
+
const debounced = (...args) => {
|
|
561
459
|
clearTimeout(timeout);
|
|
562
|
-
timeout = setTimeout(
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
_a.sent();
|
|
571
|
-
return [3 /*break*/, 3];
|
|
572
|
-
case 2:
|
|
573
|
-
err_4 = _a.sent();
|
|
574
|
-
console.error(err_4);
|
|
575
|
-
return [3 /*break*/, 3];
|
|
576
|
-
case 3: return [2 /*return*/];
|
|
577
|
-
}
|
|
578
|
-
});
|
|
579
|
-
}); }, wait);
|
|
460
|
+
timeout = setTimeout(async () => {
|
|
461
|
+
try {
|
|
462
|
+
await fn(...args);
|
|
463
|
+
}
|
|
464
|
+
catch (err) {
|
|
465
|
+
console.error(err);
|
|
466
|
+
}
|
|
467
|
+
}, wait);
|
|
580
468
|
};
|
|
581
469
|
return debounced;
|
|
582
470
|
}
|
|
583
471
|
function processSchema(schema) {
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
var _a;
|
|
472
|
+
const walkFields = (fields) => { };
|
|
473
|
+
const updateFieldType = (fieldType) => {
|
|
587
474
|
if (fieldType.kind === "LIST") {
|
|
588
|
-
if (
|
|
475
|
+
if (fieldType.ofType?.kind !== "NON_NULL") {
|
|
589
476
|
fieldType.ofType = {
|
|
590
477
|
kind: "NON_NULL",
|
|
591
478
|
name: null,
|
|
@@ -594,19 +481,17 @@ function processSchema(schema) {
|
|
|
594
481
|
}
|
|
595
482
|
}
|
|
596
483
|
};
|
|
597
|
-
|
|
484
|
+
const updateType = (type) => {
|
|
598
485
|
if (typeof type.type === "object" && type.type) {
|
|
599
486
|
updateFieldType(type.type);
|
|
600
487
|
}
|
|
601
488
|
if (type.fields) {
|
|
602
|
-
for (
|
|
603
|
-
var field = _a[_i];
|
|
489
|
+
for (const field of type.fields) {
|
|
604
490
|
updateType(field);
|
|
605
491
|
}
|
|
606
492
|
}
|
|
607
493
|
};
|
|
608
|
-
for (
|
|
609
|
-
var type = _a[_i];
|
|
494
|
+
for (const type of schema.__schema.types) {
|
|
610
495
|
updateType(type);
|
|
611
496
|
}
|
|
612
497
|
}
|