eddev 0.2.0-beta.5 → 0.2.0-beta.9

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.
@@ -247,16 +247,21 @@ function getWebpackConfig(opts) {
247
247
  manifestLoaders = [];
248
248
  // Views
249
249
  ALIAS["@manifest/views"] = path_1.default.resolve(opts.baseDirectory, "_view_manifest.js");
250
- manifestLoaders.push((0, manifest_views_1.createViewManifestGenerator)({
251
- baseDirectory: opts.baseDirectory,
252
- isAdmin: true,
253
- isDev: isDev,
254
- isServerless: isServerless,
255
- watch: isDev,
256
- onGenerate: function (manifest) {
257
- writeVirtualModule(ALIAS["@manifest/views"], manifest);
258
- },
259
- }));
250
+ if (opts.isAdmin) {
251
+ writeVirtualModule(ALIAS["@manifest/views"], "export default {}");
252
+ }
253
+ else {
254
+ manifestLoaders.push((0, manifest_views_1.createViewManifestGenerator)({
255
+ baseDirectory: opts.baseDirectory,
256
+ isAdmin: false,
257
+ isDev: isDev,
258
+ isServerless: isServerless,
259
+ watch: isDev,
260
+ onGenerate: function (manifest) {
261
+ writeVirtualModule(ALIAS["@manifest/views"], manifest);
262
+ },
263
+ }));
264
+ }
260
265
  // Field manifest
261
266
  ALIAS["@manifest/fields"] = path_1.default.resolve(opts.baseDirectory, "_fields_manifest.js");
262
267
  if (opts.isAdmin) {
@@ -10,6 +10,25 @@ var __assign = (this && this.__assign) || function () {
10
10
  };
11
11
  return __assign.apply(this, arguments);
12
12
  };
13
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
16
+ }) : (function(o, m, k, k2) {
17
+ if (k2 === undefined) k2 = k;
18
+ o[k2] = m[k];
19
+ }));
20
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
21
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
22
+ }) : function(o, v) {
23
+ o["default"] = v;
24
+ });
25
+ var __importStar = (this && this.__importStar) || function (mod) {
26
+ if (mod && mod.__esModule) return mod;
27
+ var result = {};
28
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
29
+ __setModuleDefault(result, mod);
30
+ return result;
31
+ };
13
32
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
33
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
34
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -46,6 +65,15 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
46
65
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
66
  }
48
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
+ };
49
77
  var __importDefault = (this && this.__importDefault) || function (mod) {
50
78
  return (mod && mod.__esModule) ? mod : { "default": mod };
51
79
  };
@@ -59,65 +87,86 @@ var fs_1 = require("fs");
59
87
  var manifest_blocks_1 = require("../manifests/manifest-blocks");
60
88
  var promises_1 = require("fs/promises");
61
89
  var manifest_views_1 = require("../manifests/manifest-views");
90
+ function requireConfig(dir) {
91
+ var configPath = (0, path_1.resolve)(dir, "ed.config.json");
92
+ return require(configPath);
93
+ }
62
94
  function createNextApp(opts) {
95
+ var _a;
63
96
  return __awaiter(this, void 0, void 0, function () {
64
- var serverlessDirectory;
65
- return __generator(this, function (_a) {
66
- switch (_a.label) {
97
+ var isVercel, serverlessDirectory;
98
+ return __generator(this, function (_b) {
99
+ switch (_b.label) {
67
100
  case 0:
68
- serverlessDirectory = (0, path_1.resolve)(opts.baseDirectory, ".serverless");
69
- // Clean first
70
- return [4 /*yield*/, clean(serverlessDirectory)
71
- // Copy the template folder
72
- ];
101
+ isVercel = process.env.VERCEL;
102
+ serverlessDirectory = isVercel ? opts.baseDirectory : (0, path_1.resolve)(opts.baseDirectory, ".serverless");
103
+ if (!!isVercel) return [3 /*break*/, 2];
104
+ return [4 /*yield*/, clean(serverlessDirectory)];
73
105
  case 1:
74
- // Clean first
75
- _a.sent();
76
- // Copy the template folder
77
- return [4 /*yield*/, copyTemplate(serverlessDirectory)
78
- // Update package.json
79
- ];
80
- case 2:
81
- // Copy the template folder
82
- _a.sent();
106
+ _b.sent();
107
+ _b.label = 2;
108
+ case 2:
109
+ // Copy the template folder
110
+ return [4 /*yield*/, copyTemplate(serverlessDirectory)
83
111
  // Update package.json
84
- return [4 /*yield*/, updatePackagesFile(opts.baseDirectory, serverlessDirectory)
85
- // Update packages
86
- // TODO: On vercel, can we maybe just symlink or copy node_modules?
87
- ];
112
+ ];
88
113
  case 3:
89
- // Update package.json
90
- _a.sent();
91
- // Update packages
92
- // TODO: On vercel, can we maybe just symlink or copy node_modules?
93
- return [4 /*yield*/, updatePackages(serverlessDirectory)
94
- // Symlink important files and directories
95
- ];
114
+ // Copy the template folder
115
+ _b.sent();
116
+ if (!!isVercel) return [3 /*break*/, 5];
117
+ return [4 /*yield*/, updatePackagesFile(opts.baseDirectory, serverlessDirectory)];
96
118
  case 4:
97
- // Update packages
98
- // TODO: On vercel, can we maybe just symlink or copy node_modules?
99
- _a.sent();
100
- // Symlink important files and directories
101
- return [4 /*yield*/, syncFiles(opts.baseDirectory, serverlessDirectory)
102
- // Create manifests
103
- ];
119
+ _b.sent();
120
+ _b.label = 5;
104
121
  case 5:
105
- // Symlink important files and directories
106
- _a.sent();
122
+ if (!!isVercel) return [3 /*break*/, 7];
123
+ return [4 /*yield*/, updatePackages(serverlessDirectory)];
124
+ case 6:
125
+ _b.sent();
126
+ _b.label = 7;
127
+ case 7:
128
+ if (!!isVercel) return [3 /*break*/, 10];
129
+ // Sync important files during development, as they change
130
+ return [4 /*yield*/, syncFiles(opts.baseDirectory, serverlessDirectory, __spreadArray([
131
+ "blocks/**/*",
132
+ "components/**/*",
133
+ "hooks/**/*",
134
+ "queries/**/*",
135
+ ".env",
136
+ "views/**/*",
137
+ "theme.css.tsx",
138
+ "types.graphql.ts",
139
+ "types.views.ts",
140
+ "types.blocks.ts",
141
+ "utils/**/*",
142
+ "ed.config.json"
143
+ ], (((_a = requireConfig(opts.baseDirectory).serverless) === null || _a === void 0 ? void 0 : _a.devAssets) || []), true))
144
+ // Also sync APIs into the APIs folder
145
+ ];
146
+ case 8:
147
+ // Sync important files during development, as they change
148
+ _b.sent();
149
+ // Also sync APIs into the APIs folder
150
+ return [4 /*yield*/, syncFiles(opts.baseDirectory, (0, path_1.join)(serverlessDirectory, "pages/"), ["api/**/*"])];
151
+ case 9:
152
+ // Also sync APIs into the APIs folder
153
+ _b.sent();
154
+ _b.label = 10;
155
+ case 10:
107
156
  // Create manifests
108
157
  initManifests(serverlessDirectory, opts.dev);
109
- if (!opts.dev) return [3 /*break*/, 7];
158
+ if (!opts.dev) return [3 /*break*/, 12];
110
159
  return [4 /*yield*/, runScript(serverlessDirectory, "dev")];
111
- case 6:
112
- _a.sent();
113
- return [3 /*break*/, 9];
114
- case 7:
115
- if (!opts.build) return [3 /*break*/, 9];
160
+ case 11:
161
+ _b.sent();
162
+ return [3 /*break*/, 14];
163
+ case 12:
164
+ if (!opts.build) return [3 /*break*/, 14];
116
165
  return [4 /*yield*/, runScript(serverlessDirectory, "build")];
117
- case 8:
118
- _a.sent();
119
- _a.label = 9;
120
- case 9: return [2 /*return*/];
166
+ case 13:
167
+ _b.sent();
168
+ _b.label = 14;
169
+ case 14: return [2 /*return*/];
121
170
  }
122
171
  });
123
172
  });
@@ -152,7 +201,6 @@ function copyTemplate(targetFolder) {
152
201
  switch (_a.label) {
153
202
  case 0:
154
203
  sourceFolder = (0, path_1.resolve)(__dirname, "../../serverless-template");
155
- console.log("Copying from", sourceFolder, "to", targetFolder);
156
204
  (0, fs_extra_1.mkdirp)(targetFolder);
157
205
  return [4 /*yield*/, (0, glob_promise_1.default)((0, path_1.resolve)(sourceFolder, "**/*.*"))];
158
206
  case 1:
@@ -160,9 +208,6 @@ function copyTemplate(targetFolder) {
160
208
  return [4 /*yield*/, Promise.all(files.map(function (src) {
161
209
  var dest = src.replace(sourceFolder, targetFolder);
162
210
  return (0, fs_extra_1.copy)(src, dest);
163
- // return new Promise((resolve) => {
164
- // console.log("Copy", src, "to", dest)
165
- // })
166
211
  }))];
167
212
  case 2:
168
213
  _a.sent();
@@ -205,36 +250,35 @@ function updatePackagesFile(sourceFolder, targetFolder) {
205
250
  });
206
251
  });
207
252
  }
208
- function syncFiles(sourceFolder, targetFolder) {
253
+ function syncFiles(sourceFolder, targetFolder, patterns) {
209
254
  return __awaiter(this, void 0, void 0, function () {
210
- var links;
255
+ var _this = this;
211
256
  return __generator(this, function (_a) {
212
- switch (_a.label) {
213
- case 0:
214
- links = [
215
- "blocks",
216
- "components",
217
- "hooks",
218
- "queries",
219
- ".env",
220
- "views",
221
- "theme.css.tsx",
222
- "types.graphql.ts",
223
- "types.views.ts",
224
- "types.blocks.ts",
225
- "utils",
226
- ];
227
- return [4 /*yield*/, Promise.all(links.map(function (file) {
228
- var src = (0, path_1.resolve)(sourceFolder, file);
229
- var dest = (0, path_1.resolve)(targetFolder, file);
230
- if ((0, fs_1.existsSync)(src)) {
231
- return (0, fs_extra_1.copy)(src, dest);
232
- }
233
- }))];
234
- case 1:
235
- _a.sent();
236
- return [2 /*return*/];
237
- }
257
+ return [2 /*return*/, new Promise(function (ready) { return __awaiter(_this, void 0, void 0, function () {
258
+ var chokidar;
259
+ return __generator(this, function (_a) {
260
+ switch (_a.label) {
261
+ case 0: return [4 /*yield*/, Promise.resolve().then(function () { return __importStar(require("chokidar")); })];
262
+ case 1:
263
+ chokidar = (_a.sent()).default;
264
+ chokidar
265
+ .watch(patterns)
266
+ .on("add", function (path) {
267
+ (0, fs_extra_1.copy)(path, (0, path_1.join)(targetFolder, path));
268
+ })
269
+ .on("unlink", function (path) {
270
+ (0, fs_extra_1.remove)((0, path_1.join)(targetFolder, path));
271
+ })
272
+ .on("change", function (path) {
273
+ (0, fs_extra_1.copy)(path, (0, path_1.join)(targetFolder, path));
274
+ })
275
+ .on("ready", function () {
276
+ ready(undefined);
277
+ });
278
+ return [2 /*return*/];
279
+ }
280
+ });
281
+ }); })];
238
282
  });
239
283
  });
240
284
  }
package/cli/build.dev.js CHANGED
@@ -48,12 +48,15 @@ var ink_1 = require("ink");
48
48
  var DevCLIDisplay_1 = require("./display/components/DevCLIDisplay");
49
49
  var create_webpack_worker_1 = require("../build/create-webpack-worker");
50
50
  var create_codegen_worker_1 = require("../build/create-codegen-worker");
51
+ var create_schema_file_1 = require("../config/create-schema-file");
51
52
  function devCommand(opts) {
52
53
  return __awaiter(this, void 0, void 0, function () {
53
54
  var themeName, enableFrontend, enableAdmin, enableCodegen, frontendObservable, adminObservable, codegenObservable;
54
55
  return __generator(this, function (_a) {
55
56
  switch (_a.label) {
56
- case 0: return [4 /*yield*/, (0, promptIfRepoNameIncorrect_1.promptIfRepoThemeMismatch)()];
57
+ case 0:
58
+ (0, create_schema_file_1.createConfigSchemaFile)(path_1.default.resolve(process.cwd(), ".ed.config.schema.json"));
59
+ return [4 /*yield*/, (0, promptIfRepoNameIncorrect_1.promptIfRepoThemeMismatch)()];
57
60
  case 1:
58
61
  _a.sent();
59
62
  themeName = path_1.default.basename(process.cwd());
@@ -0,0 +1,47 @@
1
+ import { z } from "zod";
2
+ export declare const EDConfigSchema: z.ZodObject<{
3
+ $schema: z.ZodOptional<z.ZodString>;
4
+ serverless: z.ZodOptional<z.ZodObject<{
5
+ enabled: z.ZodBoolean;
6
+ uploads: z.ZodEnum<["proxy", "remote"]>;
7
+ plugins: z.ZodEnum<["proxy", "remote"]>;
8
+ theme: z.ZodEnum<["proxy", "copy", "remote"]>;
9
+ devAssets: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
10
+ apiOnly: z.ZodOptional<z.ZodBoolean>;
11
+ }, "strip", z.ZodTypeAny, {
12
+ devAssets?: string[] | undefined;
13
+ apiOnly?: boolean | undefined;
14
+ plugins: "proxy" | "remote";
15
+ enabled: boolean;
16
+ uploads: "proxy" | "remote";
17
+ theme: "copy" | "proxy" | "remote";
18
+ }, {
19
+ devAssets?: string[] | undefined;
20
+ apiOnly?: boolean | undefined;
21
+ plugins: "proxy" | "remote";
22
+ enabled: boolean;
23
+ uploads: "proxy" | "remote";
24
+ theme: "copy" | "proxy" | "remote";
25
+ }>>;
26
+ }, "strip", z.ZodTypeAny, {
27
+ $schema?: string | undefined;
28
+ serverless?: {
29
+ devAssets?: string[] | undefined;
30
+ apiOnly?: boolean | undefined;
31
+ plugins: "proxy" | "remote";
32
+ enabled: boolean;
33
+ uploads: "proxy" | "remote";
34
+ theme: "copy" | "proxy" | "remote";
35
+ } | undefined;
36
+ }, {
37
+ $schema?: string | undefined;
38
+ serverless?: {
39
+ devAssets?: string[] | undefined;
40
+ apiOnly?: boolean | undefined;
41
+ plugins: "proxy" | "remote";
42
+ enabled: boolean;
43
+ uploads: "proxy" | "remote";
44
+ theme: "copy" | "proxy" | "remote";
45
+ } | undefined;
46
+ }>;
47
+ export declare type EDConfig = z.infer<typeof EDConfigSchema>;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EDConfigSchema = void 0;
4
+ var zod_1 = require("zod");
5
+ exports.EDConfigSchema = zod_1.z.object({
6
+ $schema: zod_1.z.string().optional(),
7
+ serverless: zod_1.z
8
+ .object({
9
+ enabled: zod_1.z.boolean(),
10
+ uploads: zod_1.z.enum(["proxy", "remote"]),
11
+ plugins: zod_1.z.enum(["proxy", "remote"]),
12
+ theme: zod_1.z.enum(["proxy", "copy", "remote"]),
13
+ devAssets: zod_1.z.array(zod_1.z.string()).optional(),
14
+ apiOnly: zod_1.z.boolean().optional(),
15
+ })
16
+ .optional(),
17
+ });
@@ -0,0 +1 @@
1
+ export declare function createConfigSchemaFile(location: string): void;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.createConfigSchemaFile = void 0;
7
+ var fs_1 = require("fs");
8
+ var zod_to_json_schema_1 = __importDefault(require("zod-to-json-schema"));
9
+ var config_schema_1 = require("./config-schema");
10
+ function createConfigSchemaFile(location) {
11
+ var schema = (0, zod_to_json_schema_1.default)(config_schema_1.EDConfigSchema);
12
+ var content = JSON.stringify(schema, null, 2);
13
+ if ((0, fs_1.existsSync)(location)) {
14
+ var existingContent = (0, fs_1.readFileSync)(location).toString();
15
+ if (existingContent === content)
16
+ return;
17
+ }
18
+ (0, fs_1.writeFileSync)(location, content);
19
+ }
20
+ exports.createConfigSchemaFile = createConfigSchemaFile;
@@ -0,0 +1,2 @@
1
+ export * from "./config-schema";
2
+ export * from "./parse-config";
@@ -0,0 +1,14 @@
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("./config-schema"), exports);
14
+ __exportStar(require("./parse-config"), exports);
@@ -0,0 +1,21 @@
1
+ export declare function parseConfig(config: any): import("zod").SafeParseReturnType<{
2
+ $schema?: string | undefined;
3
+ serverless?: {
4
+ devAssets?: string[] | undefined;
5
+ apiOnly?: boolean | undefined;
6
+ plugins: "proxy" | "remote";
7
+ enabled: boolean;
8
+ uploads: "proxy" | "remote";
9
+ theme: "copy" | "proxy" | "remote";
10
+ } | undefined;
11
+ }, {
12
+ $schema?: string | undefined;
13
+ serverless?: {
14
+ devAssets?: string[] | undefined;
15
+ apiOnly?: boolean | undefined;
16
+ plugins: "proxy" | "remote";
17
+ enabled: boolean;
18
+ uploads: "proxy" | "remote";
19
+ theme: "copy" | "proxy" | "remote";
20
+ } | undefined;
21
+ }>;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseConfig = void 0;
4
+ var config_schema_1 = require("./config-schema");
5
+ function parseConfig(config) {
6
+ return config_schema_1.EDConfigSchema.safeParse(config);
7
+ }
8
+ exports.parseConfig = parseConfig;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -18,7 +18,6 @@ function useAppData(selector) {
18
18
  // @ts-ignore
19
19
  if (process.serverless) {
20
20
  var value = (0, react_1.useContext)(serverlessAppContext_1.ServerlessAppDataContext);
21
- console.log("VALUE IS", value);
22
21
  if (selector)
23
22
  return selector(value);
24
23
  return value;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eddev",
3
- "version": "0.2.0-beta.5",
3
+ "version": "0.2.0-beta.9",
4
4
  "main": "./index.js",
5
5
  "license": "MIT",
6
6
  "bin": {
@@ -16,6 +16,7 @@
16
16
  "@types/babel__traverse": "^7.14.2",
17
17
  "@types/chokidar": "^2.1.3",
18
18
  "@types/fs-extra": "^9.0.13",
19
+ "@types/git-repo-name": "^1.0.1",
19
20
  "@types/inquirer": "^8.1.1",
20
21
  "@types/loadable__component": "^5.13.4",
21
22
  "@types/node": "^16.7.10",
@@ -64,7 +65,7 @@
64
65
  "execa": "^6.0.0",
65
66
  "friendly-errors-webpack-plugin": "^1.7.0",
66
67
  "fs-extra": "^10.0.0",
67
- "git-remote-origin-url": "^3.1.0",
68
+ "git-repo-name": "^1.0.1",
68
69
  "glob": "^7.1.7",
69
70
  "glob-promise": "^4.2.0",
70
71
  "graphql": "^15.5.3",
@@ -89,6 +90,8 @@
89
90
  "webpack-dev-server": "^3.11.2",
90
91
  "webpack-hot-middleware": "^2.25.0",
91
92
  "webpack-virtual-modules": "^0.4.3",
93
+ "zod": "^3.11.6",
94
+ "zod-to-json-schema": "^3.11.3",
92
95
  "zustand": "^3.5.10"
93
96
  },
94
97
  "peerDependencies": {
@@ -0,0 +1,32 @@
1
+ export declare function createRPCClient(): {
2
+ Provider: ({ client, queryClient, children, isPrepass, ssrContext, }: {
3
+ queryClient: QueryClient;
4
+ client: import("@trpc/react").TRPCClient<import("@trpc/server").AnyRouter<any>>;
5
+ children: import("react").ReactNode;
6
+ isPrepass?: boolean | undefined;
7
+ ssrContext?: unknown;
8
+ }) => JSX.Element;
9
+ createClient: (opts: import("@trpc/react").CreateTRPCClientOptions<import("@trpc/server").AnyRouter<any>>) => import("@trpc/react").TRPCClient<import("@trpc/server").AnyRouter<any>>;
10
+ useContext: () => import("@trpc/react/dist/declarations/src/internals/context").TRPCContextState<import("@trpc/server").AnyRouter<any>, unknown>;
11
+ useQuery: <TPath extends string>(pathAndInput: [TPath, (null | undefined)?], opts?: import("@trpc/react").UseTRPCQueryOptions<TPath, unknown, any, import("@trpc/react").TRPCClientErrorLike<import("@trpc/server").AnyRouter<any>>> | undefined) => UseQueryResult<{ [TPath_1 in keyof TRouter["_def"]["queries"]]: {
12
+ input: import("@trpc/server").inferProcedureInput<TRouter["_def"]["queries"][TPath_1]>;
13
+ output: import("@trpc/server").ThenArg<ReturnType<TRouter["_def"]["queries"][TPath_1]["call"]>>;
14
+ }; }[TPath_2]["output"], import("@trpc/react").TRPCClientErrorLike<TRouter>>;
15
+ useMutation: <TPath_1 extends string>(path: TPath_1 | [TPath_1], opts?: import("@trpc/react").UseTRPCMutationOptions<unknown, import("@trpc/react").TRPCClientErrorLike<import("@trpc/server").AnyRouter<any>>, any> | undefined) => UseMutationResult<{ [TPath_3 in keyof TRouter["_def"]["mutations"]]: {
16
+ input: import("@trpc/server").inferProcedureInput<TRouter["_def"]["mutations"][TPath_3]>;
17
+ output: import("@trpc/server").ThenArg<ReturnType<TRouter["_def"]["mutations"][TPath_3]["call"]>>;
18
+ }; }[TPath_1_1]["output"], import("@trpc/react").TRPCClientErrorLike<TRouter>, { [TPath_3 in keyof TRouter["_def"]["mutations"]]: {
19
+ input: import("@trpc/server").inferProcedureInput<TRouter["_def"]["mutations"][TPath_3]>;
20
+ output: import("@trpc/server").ThenArg<ReturnType<TRouter["_def"]["mutations"][TPath_3]["call"]>>;
21
+ }; }[TPath_1_1]["input"], unknown>;
22
+ useSubscription: <TPath_2 extends string, TOutput extends any>(pathAndInput: [TPath_2, (null | undefined)?], opts: {
23
+ enabled?: boolean | undefined;
24
+ onError?: ((err: import("@trpc/react").TRPCClientErrorLike<import("@trpc/server").AnyRouter<any>>) => void) | undefined;
25
+ onNext: (data: TOutput) => void;
26
+ }) => void;
27
+ useDehydratedState: (client: import("@trpc/react").TRPCClient<import("@trpc/server").AnyRouter<any>>, trpcState: any) => any;
28
+ useInfiniteQuery: <TPath_3 extends never>(pathAndInput: [path: TPath_3, input: Omit<unknown, "cursor">], opts?: import("@trpc/react").UseTRPCInfiniteQueryOptions<TPath_3, Omit<unknown, "cursor">, any, import("@trpc/react").TRPCClientErrorLike<import("@trpc/server").AnyRouter<any>>> | undefined) => UseInfiniteQueryResult<{ [TPath_1 in keyof TRouter["_def"]["queries"]]: {
29
+ input: import("@trpc/server").inferProcedureInput<TRouter["_def"]["queries"][TPath_1]>;
30
+ output: import("@trpc/server").ThenArg<ReturnType<TRouter["_def"]["queries"][TPath_1]["call"]>>;
31
+ }; }[TPath_3_1]["output"], import("@trpc/react").TRPCClientErrorLike<TRouter>>;
32
+ };
@@ -0,0 +1,20 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.createRPCClient = void 0;
15
+ var react_1 = require("@trpc/react");
16
+ function createRPCClient() {
17
+ var trpc = (0, react_1.createReactQueryHooks)();
18
+ return __assign({}, trpc);
19
+ }
20
+ exports.createRPCClient = createRPCClient;
@@ -0,0 +1,2 @@
1
+ import { NextApiHandler } from "next/types";
2
+ export declare function defineAPI(handler: NextApiHandler): NextApiHandler<any>;
@@ -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,2 @@
1
+ import * as trpc from "@trpc/server";
2
+ export declare function defineRPC<TContext>(): import("@trpc/server/dist/declarations/src/router").Router<TContext, TContext, {}, {}, {}, trpc.DefaultErrorShape>;
@@ -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,2 @@
1
+ declare const _default: {};
2
+ export default _default;
@@ -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,4 @@
1
+ export * from "./define-api";
2
+ export * from "./define-rpc-router";
3
+ export * from "./create-rpc-client";
4
+ export * from "./error-codes";
@@ -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,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RPCProvider = void 0;
4
+ function RPCProvider() { }
5
+ exports.RPCProvider = RPCProvider;
@@ -0,0 +1,5 @@
1
+ // @ts-ignore
2
+ const settings = require("../ed.config.json")
3
+ import { EDConfig } from "eddev/config"
4
+
5
+ export default settings as EDConfig
@@ -1,17 +1,38 @@
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
8
  const propsURL = origin + ("/" + pathname + "/?_props=all").replace(/\/+/, "/")
6
9
  let response = await fetch(propsURL)
7
10
  let text = await response.text()
8
11
 
9
12
  // Convert absolute site URL details to relative paths
10
- // console.log("WAS", text)
11
- console.log("REPLACING", origin, propsURL, response.status, response.statusText, text)
12
- console.log("RESPONSE", response)
13
- text = text.replaceAll(origin, "")
14
- console.log("NOW", text)
13
+ text = text.replace(new RegExp(origin.replace(/(http|https)/, `https?`) + "([a-z0-9-_./]+)", "g"), (url) => {
14
+ const path = url.replace(/https?:\/\/[a-z0-9\-\_\.]+/, "")
15
+ if (path.startsWith("/wp-content/uploads/")) {
16
+ if (settings?.uploads === "proxy") {
17
+ return path
18
+ } else if (settings?.uploads === "remote") {
19
+ return url
20
+ }
21
+ } else if (path.startsWith("/wp-content/themes/")) {
22
+ if (settings?.uploads === "proxy") {
23
+ return path
24
+ } else if (settings?.uploads === "remote") {
25
+ return url
26
+ }
27
+ } else if (path.startsWith("/wp-content/plugins/")) {
28
+ if (settings?.uploads === "proxy") {
29
+ return path
30
+ } else if (settings?.uploads === "remote") {
31
+ return url
32
+ }
33
+ }
34
+ return url
35
+ })
15
36
 
16
37
  return JSON.parse(text)
17
38
  }
@@ -1,58 +1,71 @@
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
+ console.log(resolve(cwd, "manifest_blocks.ts"))
35
+ config.resolve.alias = {
36
+ ...config.resolve.alias,
37
+ "@manifest/views": resolve(cwd, "manifest_views.ts"),
38
+ "@manifest/blocks": resolve(cwd, "manifest_blocks.ts"),
39
+ "@theme": resolve(cwd, "theme.css.tsx"),
40
+ "@wordpress/components": resolve(cwd, "null.ts"),
41
+ "@wordpress/element": resolve(cwd, "null.ts"),
42
+ "@wordpress/blocks": resolve(cwd, "null.ts"),
43
+ "@wordpress/utils": resolve(cwd, "null.ts"),
44
+ "@wordpress/data": resolve(cwd, "null.ts"),
45
+ "@wordpress/hooks": resolve(cwd, "null.ts"),
46
+ "@wordpress/block-editor": resolve(cwd, "null.ts"),
47
+ }
48
+ // config.defines["process.dev"] = isDev ? "true" : "false"
49
+ const define = config.plugins.find((plugin) => plugin instanceof DefinePlugin)
50
+ define.definitions["process.serverless"] = "true"
51
+ define.definitions["process.admin"] = "false"
52
+ define.definitions["process.dev"] = process.env.NODE_ENV === "development"
8
53
 
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
- })
54
+ const themePath =
55
+ (settings.serverless.theme === "remote" ? process.env.SITE_URL : "") + "/wp-content/themes/" + REPO_NAME
56
+
57
+ console.log("Theme path", themePath)
58
+ define.definitions["process.env.themePath"] = JSON.stringify(themePath)
59
+ define.definitions["process.themePath"] = JSON.stringify(themePath)
60
+ // config.plugins.push(
61
+ // new DefinePlugin({
62
+ // "process.serverless": "true",
63
+ // "process.admin": "false",
64
+ // // "process.env.themePath": JSON.stringify(`/wp-content/themes/${opts.themeName}`),
65
+ // // "process.themePath": JSON.stringify(`/wp-content/themes/${opts.themeName}`),
66
+ // })
67
+ // )
68
+ return config
69
+ },
70
+ })
71
+ })()
@@ -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;