eddev 0.2.0-beta.1 → 0.2.0-beta.10

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.
Files changed (55) hide show
  1. package/build/build-favicon.d.ts +1 -0
  2. package/build/build-favicon.js +71 -0
  3. package/build/create-serverless-dev-worker.d.ts +3 -0
  4. package/build/create-serverless-dev-worker.js +99 -0
  5. package/build/get-webpack-config.js +15 -10
  6. package/build/reporter.js +0 -109
  7. package/build/serverless/create-next-app.d.ts +2 -0
  8. package/build/serverless/create-next-app.js +212 -76
  9. package/build/state/serverless-state.d.ts +26 -0
  10. package/build/state/serverless-state.js +2 -0
  11. package/build/workers/serverless-worker-dev-script.d.ts +1 -0
  12. package/build/workers/serverless-worker-dev-script.js +21 -0
  13. package/{cli/prepare-next.d.ts → build/workers/serverless-worker-script.d.ts} +0 -0
  14. package/{cli/prepare-next.js → build/workers/serverless-worker-script.js} +0 -0
  15. package/cli/build.dev.js +30 -7
  16. package/cli/build.prod.js +5 -0
  17. package/cli/cli.js +22 -14
  18. package/cli/display/components/DevCLIDisplay.d.ts +3 -0
  19. package/cli/display/components/DevCLIDisplay.js +20 -1
  20. package/cli/display/components/ServerlessDisplay.d.ts +9 -0
  21. package/cli/display/components/ServerlessDisplay.js +68 -0
  22. package/config/config-schema.d.ts +65 -0
  23. package/config/config-schema.js +23 -0
  24. package/config/create-schema-file.d.ts +1 -0
  25. package/config/create-schema-file.js +20 -0
  26. package/config/get-config.d.ts +45 -0
  27. package/config/get-config.js +32 -0
  28. package/config/index.d.ts +2 -0
  29. package/config/index.js +14 -0
  30. package/config/parse-config.d.ts +29 -0
  31. package/config/parse-config.js +8 -0
  32. package/config/print-zod-errors.d.ts +2 -0
  33. package/config/print-zod-errors.js +14 -0
  34. package/hooks/useAppData.js +0 -1
  35. package/package.json +7 -7
  36. package/serverless/create-rpc-client.d.ts +33 -0
  37. package/serverless/create-rpc-client.js +20 -0
  38. package/serverless/define-api.d.ts +2 -0
  39. package/serverless/define-api.js +66 -0
  40. package/serverless/define-rpc-router.d.ts +2 -0
  41. package/serverless/define-rpc-router.js +27 -0
  42. package/serverless/error-codes.d.ts +2 -0
  43. package/serverless/error-codes.js +14 -0
  44. package/serverless/index.d.ts +4 -0
  45. package/serverless/index.js +16 -0
  46. package/serverless/rpc-provider.d.ts +1 -0
  47. package/serverless/rpc-provider.js +5 -0
  48. package/serverless-template/_utils/ed-config.ts +5 -0
  49. package/serverless-template/_utils/fetch-wordpress-props.ts +30 -6
  50. package/serverless-template/next.config.js +63 -52
  51. package/serverless-template/pages/_document.tsx +19 -0
  52. package/utils/getRepoName.d.ts +2 -2
  53. package/utils/getRepoName.js +6 -52
  54. package/fields/ImageWell.d.ts +0 -8
  55. package/fields/ImageWell.js +0 -64
@@ -1,15 +1,39 @@
1
+ import config from "./ed-config"
2
+
3
+ const settings = config.serverless
4
+
1
5
  export async function fetchWordpressProps(pathname: string) {
2
6
  const origin = (process.env.SITE_URL as string).replace(/\/$/, "")
3
7
  pathname = pathname.replace(/(^\/|\/$)/g, "")
4
-
5
- let response = await fetch(origin + "/" + pathname + "/?_props=all")
8
+ const propsURL = origin + ("/" + pathname + "/?_props=all").replace(/\/+/, "/")
9
+ console.log("Fetching", propsURL)
10
+ let response = await fetch(propsURL)
6
11
  let text = await response.text()
7
12
 
8
13
  // Convert absolute site URL details to relative paths
9
- // console.log("WAS", text)
10
- console.log("REPLACING", origin)
11
- text = text.replaceAll(origin, "")
12
- console.log("NOW", text)
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
+ })
13
37
 
14
38
  return JSON.parse(text)
15
39
  }
@@ -1,58 +1,69 @@
1
1
  const withTM = require("next-transpile-modules")
2
2
  const { resolve } = require("path")
3
3
  const { DefinePlugin } = require("webpack")
4
+ const settings = require("./ed.config.json")
5
+ const { getRepoName } = require("eddev/utils/getRepoName")
4
6
 
5
- // console.log("PATH", process.cwd().replace(/\.serverless/, ""))
7
+ module.exports = (() => {
8
+ const cwd = process.cwd()
9
+ const REPO_NAME = getRepoName(cwd.replace(/\/\.serverless/, "")).repoName
6
10
 
7
- module.exports = {}
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"
8
52
 
9
- module.exports = withTM(["eddev"])({
10
- async rewrites() {
11
- return {
12
- afterFiles: [
13
- {
14
- source: "/wp-content/uploads/:path*",
15
- destination: process.env.SITE_URL + "/wp-content/uploads/:path*",
16
- },
17
- ],
18
- }
19
- },
20
- typescript: {
21
- ignoreBuildErrors: true,
22
- },
23
- webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => {
24
- const cwd = process.cwd()
25
- console.log(resolve(cwd, "manifest_blocks.ts"))
26
- config.resolve.alias = {
27
- ...config.resolve.alias,
28
- "@manifest/views": resolve(cwd, "manifest_views.ts"),
29
- "@manifest/blocks": resolve(cwd, "manifest_blocks.ts"),
30
- // "@components/*": resolve(cwd, "components/*"),
31
- // "@views/*": resolve(cwd, "views/*"),
32
- // "@hooks/*": resolve(cwd, "hooks/*"),
33
- // "@queries/*": resolve(cwd, "hooks/queries/*"),
34
- "@theme": resolve(cwd, "theme.css.tsx"),
35
- "@wordpress/components": resolve(cwd, "null.ts"),
36
- "@wordpress/element": resolve(cwd, "null.ts"),
37
- "@wordpress/blocks": resolve(cwd, "null.ts"),
38
- "@wordpress/utils": resolve(cwd, "null.ts"),
39
- "@wordpress/data": resolve(cwd, "null.ts"),
40
- "@wordpress/hooks": resolve(cwd, "null.ts"),
41
- "@wordpress/block-editor": resolve(cwd, "null.ts"),
42
- }
43
- // config.defines["process.dev"] = isDev ? "true" : "false"
44
- const define = config.plugins.find((plugin) => plugin instanceof DefinePlugin)
45
- define.definitions["process.serverless"] = "true"
46
- define.definitions["process.admin"] = "false"
47
- define.definitions["process.dev"] = process.env.NODE_ENV === "development"
48
- // config.plugins.push(
49
- // new DefinePlugin({
50
- // "process.serverless": "true",
51
- // "process.admin": "false",
52
- // // "process.env.themePath": JSON.stringify(`/wp-content/themes/${opts.themeName}`),
53
- // // "process.themePath": JSON.stringify(`/wp-content/themes/${opts.themeName}`),
54
- // })
55
- // )
56
- return config
57
- },
58
- })
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,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
+ }
@@ -1,4 +1,4 @@
1
- export declare function getRepoName(dir: string): Promise<{
1
+ export declare function getRepoName(dir: string): {
2
2
  repoName: string | undefined;
3
3
  themeName: string;
4
- }>;
4
+ };
@@ -1,62 +1,16 @@
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 git_remote_origin_url_1 = __importDefault(require("git-remote-origin-url"));
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
- var _a;
47
- return __awaiter(this, void 0, void 0, function () {
48
- var info;
49
- return __generator(this, function (_b) {
50
- switch (_b.label) {
51
- case 0: return [4 /*yield*/, (0, git_remote_origin_url_1.default)(dir)];
52
- case 1:
53
- info = _b.sent();
54
- return [2 /*return*/, {
55
- repoName: (_a = info.match(/([^\/]+).git$/)) === null || _a === void 0 ? void 0 : _a[1],
56
- themeName: path_1.default.basename(dir),
57
- }];
58
- }
59
- });
60
- });
10
+ var info = git_repo_name_1.default.sync(dir);
11
+ return {
12
+ repoName: info || "",
13
+ themeName: path_1.default.basename(dir),
14
+ };
61
15
  }
62
16
  exports.getRepoName = getRepoName;
@@ -1,8 +0,0 @@
1
- /// <reference types="react" />
2
- declare type Props = {
3
- previewSize: string;
4
- value: number;
5
- onChange: (value: number | null) => void;
6
- };
7
- export declare function ImageWell(props: Props): JSX.Element;
8
- export {};
@@ -1,64 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ImageWell = void 0;
4
- var jsx_runtime_1 = require("react/jsx-runtime");
5
- var react_1 = require("@stitches/react");
6
- var react_2 = require("react");
7
- function ImageWell(props) {
8
- var _a = (0, react_2.useState)(null), selectedImage = _a[0], setSelectedImage = _a[1];
9
- var _b = (0, react_2.useState)(false), imageIsLoading = _b[0], setImageIsLoading = _b[1];
10
- (0, react_2.useEffect)(function () {
11
- if (props.value) {
12
- var cancelled = false;
13
- setImageIsLoading(true);
14
- fetch("/wp-json/ed/v1/media/" + Number(props.value))
15
- .then(function (response) { return response.json(); })
16
- .then(function (image) {
17
- setImageIsLoading(false);
18
- setSelectedImage(image);
19
- });
20
- }
21
- }, [props.value]);
22
- return ((0, jsx_runtime_1.jsxs)(Wrapper, { children: [imageIsLoading ? ((0, jsx_runtime_1.jsx)(Loading, { children: (0, jsx_runtime_1.jsx)(Spinner, {}, void 0) }, void 0)) : selectedImage ? ((0, jsx_runtime_1.jsx)(ImageContainer, { children: (0, jsx_runtime_1.jsx)("img", { src: selectedImage.sizes[props.previewSize] || selectedImage.sizes["thumbnail"] }, void 0) }, void 0)) : null, (0, jsx_runtime_1.jsx)(Toolbar, { children: selectedImage || imageIsLoading ? ((0, jsx_runtime_1.jsxs)(react_2.Fragment, { children: [(0, jsx_runtime_1.jsx)(Button, { children: "Remove" }, void 0), (0, jsx_runtime_1.jsx)(Button, { children: "Edit" }, void 0), (0, jsx_runtime_1.jsx)(Button, { children: "View" }, void 0)] }, void 0)) : null }, void 0)] }, void 0));
23
- }
24
- exports.ImageWell = ImageWell;
25
- var Wrapper = (0, react_1.styled)("div", {
26
- position: "relative",
27
- display: "block",
28
- width: "100%",
29
- border: "1px solid #aaaaaa",
30
- });
31
- var ImageContainer = (0, react_1.styled)("div", {
32
- padding: "4px",
33
- img: {
34
- maxWidth: "100%",
35
- },
36
- });
37
- var spin = (0, react_1.keyframes)({
38
- from: {
39
- transform: "rotate(0deg)",
40
- },
41
- to: {
42
- transform: "rotate(360deg)",
43
- },
44
- });
45
- var Spinner = (0, react_1.styled)("div", {
46
- display: "block",
47
- width: "32px",
48
- height: "32px",
49
- border: "4px solid transparent",
50
- borderTop: "currentColor",
51
- animation: "".concat(spin, " 1s linear infinite"),
52
- });
53
- var Loading = (0, react_1.styled)("div", {
54
- display: "flex",
55
- justifyContent: "center",
56
- alignItems: "center",
57
- padding: "8px",
58
- });
59
- var Toolbar = (0, react_1.styled)("div", {
60
- position: "absolute",
61
- top: 0,
62
- right: 0,
63
- padding: "4px",
64
- });