eddev 0.1.51 → 0.2.0-beta.11
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/build/build-favicon.d.ts +1 -0
- package/build/build-favicon.js +71 -0
- package/build/create-serverless-dev-worker.d.ts +3 -0
- package/build/create-serverless-dev-worker.js +99 -0
- package/build/get-webpack-config.js +58 -148
- package/build/manifests/manifest-blocks.d.ts +12 -0
- package/build/manifests/manifest-blocks.js +61 -0
- package/build/manifests/manifest-fields.d.ts +12 -0
- package/build/manifests/manifest-fields.js +42 -0
- package/build/manifests/manifest-views.d.ts +12 -0
- package/build/manifests/manifest-views.js +49 -0
- package/build/manifests/manifest.d.ts +11 -0
- package/build/manifests/manifest.js +96 -0
- package/build/reporter.js +0 -109
- package/build/serverless/create-next-app.d.ts +9 -0
- package/build/serverless/create-next-app.js +434 -0
- package/build/state/serverless-state.d.ts +26 -0
- package/build/state/serverless-state.js +2 -0
- package/build/workers/serverless-worker-dev-script.d.ts +1 -0
- package/build/workers/serverless-worker-dev-script.js +21 -0
- package/build/workers/serverless-worker-script.d.ts +0 -0
- package/build/workers/serverless-worker-script.js +1 -0
- package/cli/build.dev.js +30 -7
- package/cli/build.prod.js +5 -0
- package/cli/cli.js +32 -3
- package/cli/display/components/DevCLIDisplay.d.ts +3 -0
- package/cli/display/components/DevCLIDisplay.js +20 -1
- package/cli/display/components/ServerlessDisplay.d.ts +9 -0
- package/cli/display/components/ServerlessDisplay.js +68 -0
- package/components/NextRouter.d.ts +9 -0
- package/components/NextRouter.js +36 -0
- package/components/ServerlessRouter.d.ts +0 -0
- package/components/ServerlessRouter.js +1 -0
- package/config/config-schema.d.ts +65 -0
- package/config/config-schema.js +23 -0
- package/config/create-schema-file.d.ts +1 -0
- package/config/create-schema-file.js +20 -0
- package/config/get-config.d.ts +45 -0
- package/config/get-config.js +32 -0
- package/config/index.d.ts +2 -0
- package/config/index.js +14 -0
- package/config/parse-config.d.ts +29 -0
- package/config/parse-config.js +8 -0
- package/config/print-zod-errors.d.ts +2 -0
- package/config/print-zod-errors.js +14 -0
- package/gravityforms/useGravityForm.js +1 -1
- package/hooks/queryUtils.js +2 -2
- package/hooks/useAppData.js +15 -4
- package/package.json +11 -6
- package/routing/routing.js +5 -0
- package/serverless/create-rpc-client.d.ts +33 -0
- package/serverless/create-rpc-client.js +20 -0
- package/serverless/define-api.d.ts +2 -0
- package/serverless/define-api.js +66 -0
- package/serverless/define-rpc-router.d.ts +2 -0
- package/serverless/define-rpc-router.js +27 -0
- package/serverless/error-codes.d.ts +2 -0
- package/serverless/error-codes.js +14 -0
- package/serverless/index.d.ts +4 -0
- package/serverless/index.js +16 -0
- package/serverless/rpc-provider.d.ts +1 -0
- package/serverless/rpc-provider.js +5 -0
- package/serverless-template/README.md +34 -0
- package/serverless-template/_utils/ed-config.ts +5 -0
- package/serverless-template/_utils/fetch-wordpress-props.ts +39 -0
- package/serverless-template/global.d.ts +9 -0
- package/serverless-template/next-env.d.ts +3 -0
- package/serverless-template/next.config.js +69 -0
- package/serverless-template/null.ts +1 -0
- package/serverless-template/package.json +19 -0
- package/serverless-template/pages/[...slug].tsx +20 -0
- package/serverless-template/pages/_app.tsx +34 -0
- package/serverless-template/pages/_document.tsx +19 -0
- package/serverless-template/pages/api/hello.ts +10 -0
- package/serverless-template/pages/api/rest/[...method].ts +38 -0
- package/serverless-template/pages/index.tsx +12 -0
- package/serverless-template/tsconfig.json +37 -0
- package/utils/getRepoName.d.ts +2 -2
- package/utils/getRepoName.js +14 -52
- package/utils/serverlessAppContext.d.ts +3 -0
- package/utils/serverlessAppContext.js +6 -0
- package/fields/ImageWell.d.ts +0 -8
- package/fields/ImageWell.js +0 -64
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defineAPI = void 0;
|
|
4
|
+
// import { ZodSchema, z, AnyZodObject, ZodError } from "zod"
|
|
5
|
+
// import { RESTErrorCodes } from "./error-codes"
|
|
6
|
+
function defineAPI(handler) {
|
|
7
|
+
return handler;
|
|
8
|
+
}
|
|
9
|
+
exports.defineAPI = defineAPI;
|
|
10
|
+
// type RESTAPIRequest<
|
|
11
|
+
// TQuery extends ZodSchema<any> | undefined,
|
|
12
|
+
// TBody extends ZodSchema<any> | undefined
|
|
13
|
+
// > = NextApiRequest & {
|
|
14
|
+
// query: TQuery extends AnyZodObject ? z.infer<TQuery> : NextApiRequest["query"]
|
|
15
|
+
// body: TBody extends AnyZodObject ? z.infer<TBody> : NextApiRequest["body"]
|
|
16
|
+
// }
|
|
17
|
+
// type RESTAPIResponse = NextApiResponse & {
|
|
18
|
+
// error(type: keyof typeof RESTErrorCodes, message: string, data: any): void
|
|
19
|
+
// }
|
|
20
|
+
// type AnyRESTAPIRequest = RESTAPIRequest<any, any>
|
|
21
|
+
// const CacheKeyGenerators = {
|
|
22
|
+
// url: (req: AnyRESTAPIRequest) => req.url,
|
|
23
|
+
// query: (req: AnyRESTAPIRequest) => req.url + "." + JSON.stringify(req.query),
|
|
24
|
+
// }
|
|
25
|
+
// type RESTOptions<TResult, TQuery extends ZodSchema<any> | undefined, TBody extends ZodSchema<any> | undefined> = {
|
|
26
|
+
// method: "get" | "post" | "put" | "delete" | "patch"
|
|
27
|
+
// cacheKey?: keyof typeof CacheKeyGenerators
|
|
28
|
+
// cacheTime?: number
|
|
29
|
+
// querystring?: TQuery
|
|
30
|
+
// handle(req: RESTAPIRequest<TQuery, TBody>, res: RESTAPIResponse): void
|
|
31
|
+
// }
|
|
32
|
+
// function stringifyZodError(err: ZodError) {
|
|
33
|
+
// return err.toString()
|
|
34
|
+
// }
|
|
35
|
+
// export function defineRESTAPI<
|
|
36
|
+
// TResult,
|
|
37
|
+
// TQuery extends ZodSchema<any> | undefined,
|
|
38
|
+
// TBody extends ZodSchema<any> | undefined
|
|
39
|
+
// >(opts: RESTOptions<TResult, TQuery, TBody>) {
|
|
40
|
+
// return (_req: NextApiRequest, _res: NextApiResponse) => {
|
|
41
|
+
// // Standard function for error codes/messages
|
|
42
|
+
// const sendError = (type: keyof typeof RESTErrorCodes, message: string, details?: any) => {
|
|
43
|
+
// _res.status(RESTErrorCodes[type] || 500)
|
|
44
|
+
// _res.json({
|
|
45
|
+
// error: true,
|
|
46
|
+
// message,
|
|
47
|
+
// details,
|
|
48
|
+
// })
|
|
49
|
+
// }
|
|
50
|
+
// // Ensure the correct method
|
|
51
|
+
// if (_req.method?.toLowerCase() !== opts.method) {
|
|
52
|
+
// return sendError("invalidverb", `Invalid verb: ${_req.method}`)
|
|
53
|
+
// }
|
|
54
|
+
// // Validate the querystring
|
|
55
|
+
// try {
|
|
56
|
+
// _req.query = opts.querystring ? (opts.querystring.safeParse(_req.query) as any) : _req.query
|
|
57
|
+
// } catch (err) {
|
|
58
|
+
// if (err instanceof ZodError) {
|
|
59
|
+
// return sendError("querystring", stringifyZodError(err), _req.query)
|
|
60
|
+
// } else {
|
|
61
|
+
// return sendError("querystring", err instanceof Error ? err.message : String(err))
|
|
62
|
+
// }
|
|
63
|
+
// }
|
|
64
|
+
// opts.handle(req, res)
|
|
65
|
+
// }
|
|
66
|
+
// }
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.defineRPC = void 0;
|
|
23
|
+
var trpc = __importStar(require("@trpc/server"));
|
|
24
|
+
function defineRPC() {
|
|
25
|
+
return trpc.router();
|
|
26
|
+
}
|
|
27
|
+
exports.defineRPC = defineRPC;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// export const RESTErrorCodes = {
|
|
3
|
+
// notfound: 404,
|
|
4
|
+
// badrequest: 400,
|
|
5
|
+
// unauthorized: 401,
|
|
6
|
+
// forbidden: 403,
|
|
7
|
+
// invalidverb: 400,
|
|
8
|
+
// querystring: 400,
|
|
9
|
+
// body: 400,
|
|
10
|
+
// params: 400,
|
|
11
|
+
// internal: 500,
|
|
12
|
+
// }
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.default = {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./define-api"), exports);
|
|
14
|
+
__exportStar(require("./define-rpc-router"), exports);
|
|
15
|
+
__exportStar(require("./create-rpc-client"), exports);
|
|
16
|
+
__exportStar(require("./error-codes"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function RPCProvider(): void;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).
|
|
2
|
+
|
|
3
|
+
## Getting Started
|
|
4
|
+
|
|
5
|
+
First, run the development server:
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm run dev
|
|
9
|
+
# or
|
|
10
|
+
yarn dev
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
|
|
14
|
+
|
|
15
|
+
You can start editing the page by modifying `pages/index.js`. The page auto-updates as you edit the file.
|
|
16
|
+
|
|
17
|
+
[API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on [http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in `pages/api/hello.js`.
|
|
18
|
+
|
|
19
|
+
The `pages/api` directory is mapped to `/api/*`. Files in this directory are treated as [API routes](https://nextjs.org/docs/api-routes/introduction) instead of React pages.
|
|
20
|
+
|
|
21
|
+
## Learn More
|
|
22
|
+
|
|
23
|
+
To learn more about Next.js, take a look at the following resources:
|
|
24
|
+
|
|
25
|
+
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
|
|
26
|
+
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
|
|
27
|
+
|
|
28
|
+
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!
|
|
29
|
+
|
|
30
|
+
## Deploy on Vercel
|
|
31
|
+
|
|
32
|
+
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
|
|
33
|
+
|
|
34
|
+
Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import config from "./ed-config"
|
|
2
|
+
|
|
3
|
+
const settings = config.serverless
|
|
4
|
+
|
|
5
|
+
export async function fetchWordpressProps(pathname: string) {
|
|
6
|
+
const origin = (process.env.SITE_URL as string).replace(/\/$/, "")
|
|
7
|
+
pathname = pathname.replace(/(^\/|\/$)/g, "")
|
|
8
|
+
const propsURL = origin + ("/" + pathname + "/?_props=all").replace(/\/+/, "/")
|
|
9
|
+
console.log("Fetching", propsURL)
|
|
10
|
+
let response = await fetch(propsURL)
|
|
11
|
+
let text = await response.text()
|
|
12
|
+
|
|
13
|
+
// Convert absolute site URL details to relative paths
|
|
14
|
+
text = text.replace(new RegExp(origin.replace(/(http|https)/, `https?`) + "([a-z0-9-_./]+)", "g"), (url) => {
|
|
15
|
+
const path = url.replace(/https?:\/\/[a-z0-9\-\_\.]+/, "")
|
|
16
|
+
if (path.startsWith("/wp-content/uploads/")) {
|
|
17
|
+
if (settings?.uploads === "proxy") {
|
|
18
|
+
return path
|
|
19
|
+
} else if (settings?.uploads === "remote") {
|
|
20
|
+
return url
|
|
21
|
+
}
|
|
22
|
+
} else if (path.startsWith("/wp-content/themes/")) {
|
|
23
|
+
if (settings?.uploads === "proxy") {
|
|
24
|
+
return path
|
|
25
|
+
} else if (settings?.uploads === "remote") {
|
|
26
|
+
return url
|
|
27
|
+
}
|
|
28
|
+
} else if (path.startsWith("/wp-content/plugins/")) {
|
|
29
|
+
if (settings?.uploads === "proxy") {
|
|
30
|
+
return path
|
|
31
|
+
} else if (settings?.uploads === "remote") {
|
|
32
|
+
return url
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return url
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
return JSON.parse(text)
|
|
39
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
const withTM = require("next-transpile-modules")
|
|
2
|
+
const { resolve } = require("path")
|
|
3
|
+
const { DefinePlugin } = require("webpack")
|
|
4
|
+
const settings = require("./ed.config.json")
|
|
5
|
+
const { getRepoName } = require("eddev/utils/getRepoName")
|
|
6
|
+
|
|
7
|
+
module.exports = (() => {
|
|
8
|
+
const cwd = process.cwd()
|
|
9
|
+
const REPO_NAME = getRepoName(cwd.replace(/\/\.serverless/, "")).repoName
|
|
10
|
+
|
|
11
|
+
return withTM(["eddev"])({
|
|
12
|
+
rewrites() {
|
|
13
|
+
return {
|
|
14
|
+
afterFiles: [
|
|
15
|
+
settings.serverless.uploads === "proxy" && {
|
|
16
|
+
source: "/wp-content/uploads/:path*",
|
|
17
|
+
destination: process.env.SITE_URL + "/wp-content/uploads/:path*",
|
|
18
|
+
},
|
|
19
|
+
settings.serverless.plugin === "proxy" && {
|
|
20
|
+
source: "/wp-content/plugins/:path*",
|
|
21
|
+
destination: process.env.SITE_URL + "/wp-content/plugins/:path*",
|
|
22
|
+
},
|
|
23
|
+
settings.serverless.theme === "proxy" && {
|
|
24
|
+
source: "/wp-content/themes/:path*",
|
|
25
|
+
destination: process.env.SITE_URL + "/wp-content/themes/:path*",
|
|
26
|
+
},
|
|
27
|
+
].filter(Boolean),
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
typescript: {
|
|
31
|
+
ignoreBuildErrors: true,
|
|
32
|
+
},
|
|
33
|
+
webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => {
|
|
34
|
+
config.resolve.alias = {
|
|
35
|
+
...config.resolve.alias,
|
|
36
|
+
"@manifest/views": resolve(cwd, "manifest_views.ts"),
|
|
37
|
+
"@manifest/blocks": resolve(cwd, "manifest_blocks.ts"),
|
|
38
|
+
"@theme": resolve(cwd, "theme.css.tsx"),
|
|
39
|
+
"@wordpress/components": resolve(cwd, "null.ts"),
|
|
40
|
+
"@wordpress/element": resolve(cwd, "null.ts"),
|
|
41
|
+
"@wordpress/blocks": resolve(cwd, "null.ts"),
|
|
42
|
+
"@wordpress/utils": resolve(cwd, "null.ts"),
|
|
43
|
+
"@wordpress/data": resolve(cwd, "null.ts"),
|
|
44
|
+
"@wordpress/hooks": resolve(cwd, "null.ts"),
|
|
45
|
+
"@wordpress/block-editor": resolve(cwd, "null.ts"),
|
|
46
|
+
}
|
|
47
|
+
// config.defines["process.dev"] = isDev ? "true" : "false"
|
|
48
|
+
const define = config.plugins.find((plugin) => plugin instanceof DefinePlugin)
|
|
49
|
+
define.definitions["process.serverless"] = "true"
|
|
50
|
+
define.definitions["process.admin"] = "false"
|
|
51
|
+
define.definitions["process.dev"] = process.env.NODE_ENV === "development"
|
|
52
|
+
|
|
53
|
+
const themePath =
|
|
54
|
+
(settings.serverless.theme === "remote" ? process.env.SITE_URL : "") + "/wp-content/themes/" + REPO_NAME
|
|
55
|
+
|
|
56
|
+
define.definitions["process.env.themePath"] = JSON.stringify(themePath)
|
|
57
|
+
define.definitions["process.themePath"] = JSON.stringify(themePath)
|
|
58
|
+
// config.plugins.push(
|
|
59
|
+
// new DefinePlugin({
|
|
60
|
+
// "process.serverless": "true",
|
|
61
|
+
// "process.admin": "false",
|
|
62
|
+
// // "process.env.themePath": JSON.stringify(`/wp-content/themes/${opts.themeName}`),
|
|
63
|
+
// // "process.themePath": JSON.stringify(`/wp-content/themes/${opts.themeName}`),
|
|
64
|
+
// })
|
|
65
|
+
// )
|
|
66
|
+
return config
|
|
67
|
+
},
|
|
68
|
+
})
|
|
69
|
+
})()
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default {}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "serverless-template",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"scripts": {
|
|
6
|
+
"dev": "next dev",
|
|
7
|
+
"build": "next build",
|
|
8
|
+
"start": "next start"
|
|
9
|
+
},
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"next": "12.0.10",
|
|
12
|
+
"react": "17.0.2",
|
|
13
|
+
"react-dom": "17.0.2"
|
|
14
|
+
},
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"@types/react": "17.0.39",
|
|
17
|
+
"typescript": "4.5.5"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { GetStaticPathsResult, GetStaticPropsContext, GetStaticPropsResult } from "next"
|
|
2
|
+
import { fetchWordpressProps } from "../_utils/fetch-wordpress-props"
|
|
3
|
+
|
|
4
|
+
export default function Home(props: any) {
|
|
5
|
+
return <div>{JSON.stringify(props)}</div>
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export async function getStaticPaths(): Promise<GetStaticPathsResult> {
|
|
9
|
+
return {
|
|
10
|
+
paths: [],
|
|
11
|
+
fallback: true,
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export async function getStaticProps({ params }: GetStaticPropsContext): Promise<GetStaticPropsResult<any>> {
|
|
16
|
+
const result = await fetchWordpressProps((params?.slug as string[]).join("/"))
|
|
17
|
+
return {
|
|
18
|
+
props: result,
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { AppProps } from "next/app"
|
|
2
|
+
import { App } from "@manifest/views"
|
|
3
|
+
import manifest from "@manifest/views"
|
|
4
|
+
import { NextRouter } from "eddev/components/NextRouter"
|
|
5
|
+
import { ServerlessAppDataProvider } from "eddev/utils/serverlessAppContext"
|
|
6
|
+
import { useMemo } from "react"
|
|
7
|
+
import { useRouter } from "next/router"
|
|
8
|
+
|
|
9
|
+
function MyApp({ Component, pageProps }: AppProps) {
|
|
10
|
+
if (!pageProps.appData) return <div />
|
|
11
|
+
|
|
12
|
+
const appData = useMemo(() => {
|
|
13
|
+
return pageProps.appData.data
|
|
14
|
+
}, [])
|
|
15
|
+
|
|
16
|
+
const route = useRouter()
|
|
17
|
+
|
|
18
|
+
const viewProps = pageProps?.viewData?.data
|
|
19
|
+
|
|
20
|
+
const View = manifest[pageProps.view]
|
|
21
|
+
|
|
22
|
+
console.log("ROUTE", pageProps, route.pathname)
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<ServerlessAppDataProvider value={appData}>
|
|
26
|
+
<NextRouter data={pageProps} path={route.pathname}>
|
|
27
|
+
<App>
|
|
28
|
+
<View {...viewProps} />
|
|
29
|
+
</App>
|
|
30
|
+
</NextRouter>
|
|
31
|
+
</ServerlessAppDataProvider>
|
|
32
|
+
)
|
|
33
|
+
}
|
|
34
|
+
export default MyApp
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React from "react"
|
|
2
|
+
import NextDocument, { Html, Head, Main, NextScript } from "next/document"
|
|
3
|
+
import { getCssText } from "@theme"
|
|
4
|
+
|
|
5
|
+
export default class Document extends NextDocument {
|
|
6
|
+
render() {
|
|
7
|
+
return (
|
|
8
|
+
<Html lang="en">
|
|
9
|
+
<Head>
|
|
10
|
+
<style id="stitches" dangerouslySetInnerHTML={{ __html: getCssText() }} />
|
|
11
|
+
</Head>
|
|
12
|
+
<body>
|
|
13
|
+
<Main />
|
|
14
|
+
<NextScript />
|
|
15
|
+
</body>
|
|
16
|
+
</Html>
|
|
17
|
+
)
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
|
|
2
|
+
import type { NextApiRequest, NextApiResponse } from 'next'
|
|
3
|
+
|
|
4
|
+
type Data = {
|
|
5
|
+
name: string
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export default (req: NextApiRequest, res: NextApiResponse<Data>) => {
|
|
9
|
+
res.status(200).json({ name: 'John Doe' })
|
|
10
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
const validProxyPaths = {
|
|
2
|
+
"form-submit": {
|
|
3
|
+
path: "/wp-json/ed/v1/gf/submit",
|
|
4
|
+
method: "GET",
|
|
5
|
+
},
|
|
6
|
+
query: {
|
|
7
|
+
path: "/wp-json/ed/v1/query/*",
|
|
8
|
+
method: "GET",
|
|
9
|
+
},
|
|
10
|
+
mutation: {
|
|
11
|
+
path: "/wp-json/ed/v1/mutation/*",
|
|
12
|
+
method: "POST",
|
|
13
|
+
},
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export default async function (req: any, res: any) {
|
|
17
|
+
// Ensure that the request is for a proxy path
|
|
18
|
+
const proxyPath = validProxyPaths[req.query.method[0] as keyof typeof validProxyPaths]!
|
|
19
|
+
|
|
20
|
+
if (!proxyPath) {
|
|
21
|
+
return res.status(404).json({
|
|
22
|
+
error: "Not found",
|
|
23
|
+
})
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const finalPath = proxyPath.path.replace("*", req.query.method.slice(1).join("/"))
|
|
27
|
+
|
|
28
|
+
const response = await fetch(process.env.SITE_URL + finalPath, {
|
|
29
|
+
method: proxyPath.method,
|
|
30
|
+
headers: {
|
|
31
|
+
"Content-Type": "application/json",
|
|
32
|
+
},
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
const payload = await response.json()
|
|
36
|
+
|
|
37
|
+
res.status(200).json(payload)
|
|
38
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { fetchWordpressProps } from "../_utils/fetch-wordpress-props"
|
|
2
|
+
|
|
3
|
+
export default function Home() {
|
|
4
|
+
return <div>Test</div>
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export async function getStaticProps({ params }: any) {
|
|
8
|
+
const result = await fetchWordpressProps("/")
|
|
9
|
+
return {
|
|
10
|
+
props: result,
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es5",
|
|
4
|
+
"lib": ["dom", "dom.iterable", "esnext"],
|
|
5
|
+
"allowJs": true,
|
|
6
|
+
"skipLibCheck": true,
|
|
7
|
+
"strict": true,
|
|
8
|
+
"forceConsistentCasingInFileNames": true,
|
|
9
|
+
"noEmit": true,
|
|
10
|
+
"esModuleInterop": true,
|
|
11
|
+
"module": "esnext",
|
|
12
|
+
"moduleResolution": "node",
|
|
13
|
+
"resolveJsonModule": true,
|
|
14
|
+
"isolatedModules": true,
|
|
15
|
+
"jsx": "preserve",
|
|
16
|
+
"incremental": true,
|
|
17
|
+
"baseUrl": ".",
|
|
18
|
+
"paths": {
|
|
19
|
+
"@manifest/views": ["manifest_views.ts"],
|
|
20
|
+
"@manifest/blocks": ["manifest_blocks.ts"],
|
|
21
|
+
"@components/*": ["components/*"],
|
|
22
|
+
"@views/*": ["views/*"],
|
|
23
|
+
"@hooks/*": ["hooks/*"],
|
|
24
|
+
"@queries/*": ["hooks/queries/*"],
|
|
25
|
+
"@theme": ["theme.css.tsx"],
|
|
26
|
+
"@wordpress/components": ["null.ts"],
|
|
27
|
+
"@wordpress/element": ["null.ts"],
|
|
28
|
+
"@wordpress/blocks": ["null.ts"],
|
|
29
|
+
"@wordpress/utils": ["null.ts"],
|
|
30
|
+
"@wordpress/data": ["null.ts"],
|
|
31
|
+
"@wordpress/hooks": ["null.ts"],
|
|
32
|
+
"@wordpress/block-editor": ["null.ts"]
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"include": ["next-env.d.ts", "global.d.ts", "**/*.ts", "**/*.tsx"],
|
|
36
|
+
"exclude": ["node_modules"]
|
|
37
|
+
}
|
package/utils/getRepoName.d.ts
CHANGED
package/utils/getRepoName.js
CHANGED
|
@@ -1,62 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
18
|
-
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;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
4
|
};
|
|
41
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
6
|
exports.getRepoName = void 0;
|
|
43
|
-
var
|
|
7
|
+
var git_repo_name_1 = __importDefault(require("git-repo-name"));
|
|
44
8
|
var path_1 = __importDefault(require("path"));
|
|
45
9
|
function getRepoName(dir) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
});
|
|
60
|
-
});
|
|
10
|
+
if (process.env.VERCEL) {
|
|
11
|
+
return {
|
|
12
|
+
repoName: process.env.VERCEL_GIT_REPO_SLUG,
|
|
13
|
+
themeName: process.env.VERCEL_GIT_REPO_SLUG,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
var info = git_repo_name_1.default.sync(dir);
|
|
18
|
+
return {
|
|
19
|
+
repoName: info || "",
|
|
20
|
+
themeName: path_1.default.basename(dir),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
61
23
|
}
|
|
62
24
|
exports.getRepoName = getRepoName;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ServerlessAppDataProvider = exports.ServerlessAppDataContext = void 0;
|
|
4
|
+
var react_1 = require("react");
|
|
5
|
+
exports.ServerlessAppDataContext = (0, react_1.createContext)(undefined);
|
|
6
|
+
exports.ServerlessAppDataProvider = exports.ServerlessAppDataContext.Provider;
|