@confect/cli 9.0.0-next.1 → 9.0.0-next.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.
- package/CHANGELOG.md +337 -1
- package/dist/BuildError.mjs +9 -2
- package/dist/BuildError.mjs.map +1 -1
- package/dist/Bundler.mjs +67 -57
- package/dist/Bundler.mjs.map +1 -1
- package/dist/CodeBlockWriter.mjs +1 -1
- package/dist/CodeBlockWriter.mjs.map +1 -1
- package/dist/CodegenError.mjs +29 -21
- package/dist/CodegenError.mjs.map +1 -1
- package/dist/ConfectDirectory.mjs +5 -2
- package/dist/ConfectDirectory.mjs.map +1 -1
- package/dist/ConvexDirectory.mjs +6 -2
- package/dist/ConvexDirectory.mjs.map +1 -1
- package/dist/FunctionPath.mjs +1 -1
- package/dist/FunctionPath.mjs.map +1 -1
- package/dist/FunctionPaths.mjs +5 -1
- package/dist/FunctionPaths.mjs.map +1 -1
- package/dist/GroupPath.mjs +9 -2
- package/dist/GroupPath.mjs.map +1 -1
- package/dist/GroupPaths.mjs +1 -1
- package/dist/GroupPaths.mjs.map +1 -1
- package/dist/LeafModule.mjs +19 -26
- package/dist/LeafModule.mjs.map +1 -1
- package/dist/ProjectRoot.mjs +8 -3
- package/dist/ProjectRoot.mjs.map +1 -1
- package/dist/SpecAssemblyNode.mjs +9 -11
- package/dist/SpecAssemblyNode.mjs.map +1 -1
- package/dist/TableModule.mjs +94 -0
- package/dist/TableModule.mjs.map +1 -0
- package/dist/cliApp.mjs +1 -1
- package/dist/cliApp.mjs.map +1 -1
- package/dist/confect/codegen.mjs +203 -142
- package/dist/confect/codegen.mjs.map +1 -1
- package/dist/confect/dev.mjs +36 -17
- package/dist/confect/dev.mjs.map +1 -1
- package/dist/confect.mjs +2 -2
- package/dist/confect.mjs.map +1 -1
- package/dist/index.mjs +3 -2
- package/dist/index.mjs.map +1 -1
- package/dist/log.mjs +9 -4
- package/dist/log.mjs.map +1 -1
- package/dist/package.mjs +1 -1
- package/dist/templates.mjs +132 -45
- package/dist/templates.mjs.map +1 -1
- package/dist/utils.mjs +42 -22
- package/dist/utils.mjs.map +1 -1
- package/package.json +33 -50
- package/dist/index.d.mts +0 -1
- package/src/BuildError.ts +0 -210
- package/src/Bundler.ts +0 -144
- package/src/CodeBlockWriter.ts +0 -65
- package/src/CodegenError.ts +0 -376
- package/src/ConfectDirectory.ts +0 -42
- package/src/ConvexDirectory.ts +0 -68
- package/src/FunctionPath.ts +0 -27
- package/src/FunctionPaths.ts +0 -103
- package/src/GroupPath.ts +0 -118
- package/src/GroupPaths.ts +0 -7
- package/src/LeafModule.ts +0 -317
- package/src/ProjectRoot.ts +0 -50
- package/src/SpecAssemblyNode.ts +0 -82
- package/src/cliApp.ts +0 -8
- package/src/confect/codegen.ts +0 -710
- package/src/confect/dev.ts +0 -749
- package/src/confect.ts +0 -19
- package/src/index.ts +0 -22
- package/src/log.ts +0 -104
- package/src/templates.ts +0 -482
- package/src/utils.ts +0 -429
package/src/utils.ts
DELETED
|
@@ -1,429 +0,0 @@
|
|
|
1
|
-
import type { FunctionSpec, Spec } from "@confect/core";
|
|
2
|
-
import { FileSystem, Path } from "@effect/platform";
|
|
3
|
-
import type { PlatformError } from "@effect/platform/Error";
|
|
4
|
-
import {
|
|
5
|
-
Array,
|
|
6
|
-
Context,
|
|
7
|
-
Effect,
|
|
8
|
-
HashSet,
|
|
9
|
-
Option,
|
|
10
|
-
Order,
|
|
11
|
-
pipe,
|
|
12
|
-
Record,
|
|
13
|
-
Ref,
|
|
14
|
-
String,
|
|
15
|
-
} from "effect";
|
|
16
|
-
import * as FunctionPaths from "./FunctionPaths";
|
|
17
|
-
import * as GroupPath from "./GroupPath";
|
|
18
|
-
import * as GroupPaths from "./GroupPaths";
|
|
19
|
-
import { logFileAdded, logFileModified, logFileRemoved } from "./log";
|
|
20
|
-
import { ConfectDirectory } from "./ConfectDirectory";
|
|
21
|
-
import { ConvexDirectory } from "./ConvexDirectory";
|
|
22
|
-
import * as templates from "./templates";
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Tracks whether the current codegen run wrote anything to disk. Set to
|
|
26
|
-
* `true` by every helper that actually overwrites a file (skipping the
|
|
27
|
-
* content-unchanged case). `codegenHandler` provides a fresh `Ref` per
|
|
28
|
-
* run and reads it back to report `anyWritesHappened`; callers outside a
|
|
29
|
-
* codegen pass hit the cached default `Ref` and need not interact with
|
|
30
|
-
* the tracker.
|
|
31
|
-
*/
|
|
32
|
-
export class WriteTracker extends Context.Reference<WriteTracker>()(
|
|
33
|
-
"@confect/cli/WriteTracker",
|
|
34
|
-
{ defaultValue: () => Ref.unsafeMake(false) },
|
|
35
|
-
) {}
|
|
36
|
-
|
|
37
|
-
const markWritten = Effect.gen(function* () {
|
|
38
|
-
const tracker = yield* WriteTracker;
|
|
39
|
-
yield* Ref.set(tracker, true);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
export const removePathExtension = (pathStr: string) =>
|
|
43
|
-
Effect.gen(function* () {
|
|
44
|
-
const path = yield* Path.Path;
|
|
45
|
-
|
|
46
|
-
return String.slice(0, -path.extname(pathStr).length)(pathStr);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
/** Ensures a relative path is a valid ESM/TS module specifier (e.g. `spec` → `./spec`). */
|
|
50
|
-
export const toModuleImportPath = (relativePath: string) =>
|
|
51
|
-
Effect.gen(function* () {
|
|
52
|
-
const withoutExt = yield* removePathExtension(relativePath);
|
|
53
|
-
return withoutExt.startsWith(".") ? withoutExt : `./${withoutExt}`;
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
export const writeFileStringAndLog = (filePath: string, contents: string) =>
|
|
57
|
-
Effect.gen(function* () {
|
|
58
|
-
const fs = yield* FileSystem.FileSystem;
|
|
59
|
-
if (!(yield* fs.exists(filePath))) {
|
|
60
|
-
yield* fs.writeFileString(filePath, contents);
|
|
61
|
-
yield* markWritten;
|
|
62
|
-
yield* logFileAdded(filePath);
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
const existing = yield* fs.readFileString(filePath);
|
|
66
|
-
if (existing !== contents) {
|
|
67
|
-
yield* fs.writeFileString(filePath, contents);
|
|
68
|
-
yield* markWritten;
|
|
69
|
-
yield* logFileModified(filePath);
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
export const findProjectRoot = Effect.gen(function* () {
|
|
74
|
-
const fs = yield* FileSystem.FileSystem;
|
|
75
|
-
const path = yield* Path.Path;
|
|
76
|
-
|
|
77
|
-
const startDir = path.resolve(".");
|
|
78
|
-
const root = path.parse(startDir).root;
|
|
79
|
-
|
|
80
|
-
const directories = Array.unfold(startDir, (dir) =>
|
|
81
|
-
dir === root
|
|
82
|
-
? Option.none()
|
|
83
|
-
: Option.some([dir, path.dirname(dir)] as const),
|
|
84
|
-
);
|
|
85
|
-
|
|
86
|
-
const projectRoot = yield* Effect.findFirst(directories, (dir) =>
|
|
87
|
-
fs.exists(path.join(dir, "package.json")),
|
|
88
|
-
);
|
|
89
|
-
|
|
90
|
-
return Option.getOrElse(projectRoot, () => startDir);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
export type WriteChange = "Added" | "Modified" | "Unchanged";
|
|
94
|
-
|
|
95
|
-
export const writeFileString = (
|
|
96
|
-
filePath: string,
|
|
97
|
-
contents: string,
|
|
98
|
-
): Effect.Effect<WriteChange, PlatformError, FileSystem.FileSystem> =>
|
|
99
|
-
Effect.gen(function* () {
|
|
100
|
-
const fs = yield* FileSystem.FileSystem;
|
|
101
|
-
|
|
102
|
-
if (!(yield* fs.exists(filePath))) {
|
|
103
|
-
yield* fs.writeFileString(filePath, contents);
|
|
104
|
-
yield* markWritten;
|
|
105
|
-
return "Added";
|
|
106
|
-
}
|
|
107
|
-
const existing = yield* fs.readFileString(filePath);
|
|
108
|
-
if (existing !== contents) {
|
|
109
|
-
yield* fs.writeFileString(filePath, contents);
|
|
110
|
-
yield* markWritten;
|
|
111
|
-
return "Modified";
|
|
112
|
-
}
|
|
113
|
-
return "Unchanged";
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
export const removePathIfExists = (
|
|
117
|
-
filePath: string,
|
|
118
|
-
): Effect.Effect<void, PlatformError, FileSystem.FileSystem> =>
|
|
119
|
-
Effect.gen(function* () {
|
|
120
|
-
const fs = yield* FileSystem.FileSystem;
|
|
121
|
-
|
|
122
|
-
if (!(yield* fs.exists(filePath))) {
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
yield* fs
|
|
127
|
-
.remove(filePath)
|
|
128
|
-
.pipe(
|
|
129
|
-
Effect.catchTag("SystemError", (error) =>
|
|
130
|
-
error.reason === "NotFound" ? Effect.void : Effect.fail(error),
|
|
131
|
-
),
|
|
132
|
-
);
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* Bump the mtime of `convex/schema.ts` so the Convex CLI's chokidar watcher
|
|
137
|
-
* emits a `change` event after every successful Confect codegen run. Without
|
|
138
|
-
* this, a codegen that doesn't change any file content (for example,
|
|
139
|
-
* recovering from a transient broken state in `confect/`) leaves Convex
|
|
140
|
-
* stuck on its previous error because nothing it observes has changed.
|
|
141
|
-
*/
|
|
142
|
-
export const touchConvexSchema = Effect.gen(function* () {
|
|
143
|
-
const fs = yield* FileSystem.FileSystem;
|
|
144
|
-
const path = yield* Path.Path;
|
|
145
|
-
const convexDirectory = yield* ConvexDirectory.get;
|
|
146
|
-
const schemaPath = path.join(convexDirectory, "schema.ts");
|
|
147
|
-
|
|
148
|
-
if (!(yield* fs.exists(schemaPath))) {
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
const now = new Date();
|
|
153
|
-
yield* fs.utimes(schemaPath, now, now);
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
export const generateGroupModule = ({
|
|
157
|
-
groupPath,
|
|
158
|
-
functionNames,
|
|
159
|
-
registeredFunctionsImportPath,
|
|
160
|
-
useNode = false,
|
|
161
|
-
}: {
|
|
162
|
-
groupPath: GroupPath.GroupPath;
|
|
163
|
-
functionNames: string[];
|
|
164
|
-
registeredFunctionsImportPath: string;
|
|
165
|
-
useNode?: boolean;
|
|
166
|
-
}) =>
|
|
167
|
-
Effect.gen(function* () {
|
|
168
|
-
const fs = yield* FileSystem.FileSystem;
|
|
169
|
-
const path = yield* Path.Path;
|
|
170
|
-
const convexDirectory = yield* ConvexDirectory.get;
|
|
171
|
-
|
|
172
|
-
const relativeModulePath = yield* GroupPath.modulePath(groupPath);
|
|
173
|
-
const modulePath = path.join(convexDirectory, relativeModulePath);
|
|
174
|
-
|
|
175
|
-
const directoryPath = path.dirname(modulePath);
|
|
176
|
-
if (!(yield* fs.exists(directoryPath))) {
|
|
177
|
-
yield* fs.makeDirectory(directoryPath, { recursive: true });
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
const functionsContentsString = yield* templates.functions({
|
|
181
|
-
functionNames,
|
|
182
|
-
registeredFunctionsImportPath,
|
|
183
|
-
useNode,
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
if (!(yield* fs.exists(modulePath))) {
|
|
187
|
-
yield* fs.writeFileString(modulePath, functionsContentsString);
|
|
188
|
-
yield* markWritten;
|
|
189
|
-
return "Added" as const;
|
|
190
|
-
}
|
|
191
|
-
const existing = yield* fs.readFileString(modulePath);
|
|
192
|
-
if (existing !== functionsContentsString) {
|
|
193
|
-
yield* fs.writeFileString(modulePath, functionsContentsString);
|
|
194
|
-
yield* markWritten;
|
|
195
|
-
return "Modified" as const;
|
|
196
|
-
}
|
|
197
|
-
return "Unchanged" as const;
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
const logGroupPaths = <R>(
|
|
201
|
-
groupPaths: GroupPaths.GroupPaths,
|
|
202
|
-
logFn: (fullPath: string) => Effect.Effect<void, never, R>,
|
|
203
|
-
) =>
|
|
204
|
-
Effect.gen(function* () {
|
|
205
|
-
const path = yield* Path.Path;
|
|
206
|
-
const convexDirectory = yield* ConvexDirectory.get;
|
|
207
|
-
|
|
208
|
-
yield* Effect.forEach(groupPaths, (gp) =>
|
|
209
|
-
Effect.gen(function* () {
|
|
210
|
-
const relativeModulePath = yield* GroupPath.modulePath(gp);
|
|
211
|
-
yield* logFn(path.join(convexDirectory, relativeModulePath));
|
|
212
|
-
}),
|
|
213
|
-
);
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
export const generateFunctions = (spec: Spec.AnyWithProps) =>
|
|
217
|
-
Effect.gen(function* () {
|
|
218
|
-
const path = yield* Path.Path;
|
|
219
|
-
const convexDirectory = yield* ConvexDirectory.get;
|
|
220
|
-
const confectDirectory = yield* ConfectDirectory.get;
|
|
221
|
-
|
|
222
|
-
const groupPathsFromFs = yield* getGroupPathsFromFs;
|
|
223
|
-
const functionPaths = FunctionPaths.make(spec);
|
|
224
|
-
const groupPathsFromSpec = FunctionPaths.groupPaths(functionPaths);
|
|
225
|
-
|
|
226
|
-
const overlappingGroupPaths = GroupPaths.GroupPaths.make(
|
|
227
|
-
HashSet.intersection(groupPathsFromFs, groupPathsFromSpec),
|
|
228
|
-
);
|
|
229
|
-
yield* Effect.forEach(overlappingGroupPaths, (groupPath) =>
|
|
230
|
-
Effect.gen(function* () {
|
|
231
|
-
const group = yield* GroupPath.getGroupSpec(spec, groupPath);
|
|
232
|
-
const functionNames = pipe(
|
|
233
|
-
group.functions,
|
|
234
|
-
Record.values,
|
|
235
|
-
Array.sortBy(
|
|
236
|
-
Order.mapInput(
|
|
237
|
-
Order.string,
|
|
238
|
-
(fn: FunctionSpec.AnyWithProps) => fn.name,
|
|
239
|
-
),
|
|
240
|
-
),
|
|
241
|
-
Array.map((fn) => fn.name),
|
|
242
|
-
);
|
|
243
|
-
const relativeModulePath = yield* GroupPath.modulePath(groupPath);
|
|
244
|
-
const modulePath = path.join(convexDirectory, relativeModulePath);
|
|
245
|
-
const registrySegments =
|
|
246
|
-
groupPath.pathSegments[0] === "node"
|
|
247
|
-
? groupPath.pathSegments.slice(1)
|
|
248
|
-
: groupPath.pathSegments;
|
|
249
|
-
const registeredFunctionsPath =
|
|
250
|
-
path.join(
|
|
251
|
-
confectDirectory,
|
|
252
|
-
"_generated",
|
|
253
|
-
"registeredFunctions",
|
|
254
|
-
...registrySegments,
|
|
255
|
-
) + ".ts";
|
|
256
|
-
const registeredFunctionsImportPath = yield* toModuleImportPath(
|
|
257
|
-
path.relative(path.dirname(modulePath), registeredFunctionsPath),
|
|
258
|
-
);
|
|
259
|
-
const result = yield* generateGroupModule({
|
|
260
|
-
groupPath,
|
|
261
|
-
functionNames,
|
|
262
|
-
registeredFunctionsImportPath,
|
|
263
|
-
useNode: groupPath.pathSegments[0] === "node",
|
|
264
|
-
});
|
|
265
|
-
if (result === "Modified") {
|
|
266
|
-
yield* logFileModified(modulePath);
|
|
267
|
-
}
|
|
268
|
-
}),
|
|
269
|
-
);
|
|
270
|
-
|
|
271
|
-
const extinctGroupPaths = GroupPaths.GroupPaths.make(
|
|
272
|
-
HashSet.difference(groupPathsFromFs, groupPathsFromSpec),
|
|
273
|
-
);
|
|
274
|
-
yield* removeGroups(extinctGroupPaths);
|
|
275
|
-
yield* logGroupPaths(extinctGroupPaths, logFileRemoved);
|
|
276
|
-
|
|
277
|
-
const newGroupPaths = GroupPaths.GroupPaths.make(
|
|
278
|
-
HashSet.difference(groupPathsFromSpec, groupPathsFromFs),
|
|
279
|
-
);
|
|
280
|
-
yield* writeGroups(spec, newGroupPaths);
|
|
281
|
-
yield* logGroupPaths(newGroupPaths, logFileAdded);
|
|
282
|
-
|
|
283
|
-
return functionPaths;
|
|
284
|
-
});
|
|
285
|
-
|
|
286
|
-
const getGroupPathsFromFs = Effect.gen(function* () {
|
|
287
|
-
const fs = yield* FileSystem.FileSystem;
|
|
288
|
-
const path = yield* Path.Path;
|
|
289
|
-
const convexDirectory = yield* ConvexDirectory.get;
|
|
290
|
-
|
|
291
|
-
const RESERVED_CONVEX_TS_FILE_NAMES = new Set([
|
|
292
|
-
"schema.ts",
|
|
293
|
-
"http.ts",
|
|
294
|
-
"crons.ts",
|
|
295
|
-
"auth.config.ts",
|
|
296
|
-
"convex.config.ts",
|
|
297
|
-
]);
|
|
298
|
-
|
|
299
|
-
const allConvexPaths = yield* fs.readDirectory(convexDirectory, {
|
|
300
|
-
recursive: true,
|
|
301
|
-
});
|
|
302
|
-
const groupPathArray = yield* pipe(
|
|
303
|
-
allConvexPaths,
|
|
304
|
-
Array.filter(
|
|
305
|
-
(convexPath) =>
|
|
306
|
-
path.extname(convexPath) === ".ts" &&
|
|
307
|
-
!RESERVED_CONVEX_TS_FILE_NAMES.has(path.basename(convexPath)) &&
|
|
308
|
-
path.basename(path.dirname(convexPath)) !== "_generated",
|
|
309
|
-
),
|
|
310
|
-
Effect.forEach((groupModulePath) =>
|
|
311
|
-
GroupPath.fromGroupModulePath(groupModulePath),
|
|
312
|
-
),
|
|
313
|
-
);
|
|
314
|
-
return pipe(groupPathArray, HashSet.fromIterable, GroupPaths.GroupPaths.make);
|
|
315
|
-
});
|
|
316
|
-
|
|
317
|
-
export const removeGroups = (groupPaths: GroupPaths.GroupPaths) =>
|
|
318
|
-
Effect.gen(function* () {
|
|
319
|
-
const path = yield* Path.Path;
|
|
320
|
-
const convexDirectory = yield* ConvexDirectory.get;
|
|
321
|
-
|
|
322
|
-
yield* Effect.all(
|
|
323
|
-
HashSet.map(groupPaths, (groupPath) =>
|
|
324
|
-
Effect.gen(function* () {
|
|
325
|
-
const relativeModulePath = yield* GroupPath.modulePath(groupPath);
|
|
326
|
-
const modulePath = path.join(convexDirectory, relativeModulePath);
|
|
327
|
-
|
|
328
|
-
yield* Effect.logDebug(`Removing group '${relativeModulePath}'...`);
|
|
329
|
-
|
|
330
|
-
yield* removePathIfExists(modulePath);
|
|
331
|
-
yield* Effect.logDebug(`Group '${relativeModulePath}' removed`);
|
|
332
|
-
}),
|
|
333
|
-
),
|
|
334
|
-
{ concurrency: "unbounded" },
|
|
335
|
-
);
|
|
336
|
-
});
|
|
337
|
-
|
|
338
|
-
export const writeGroups = (
|
|
339
|
-
spec: Spec.AnyWithProps,
|
|
340
|
-
groupPaths: GroupPaths.GroupPaths,
|
|
341
|
-
) =>
|
|
342
|
-
Effect.forEach(groupPaths, (groupPath) =>
|
|
343
|
-
Effect.gen(function* () {
|
|
344
|
-
const path = yield* Path.Path;
|
|
345
|
-
const convexDirectory = yield* ConvexDirectory.get;
|
|
346
|
-
const confectDirectory = yield* ConfectDirectory.get;
|
|
347
|
-
const group = yield* GroupPath.getGroupSpec(spec, groupPath);
|
|
348
|
-
|
|
349
|
-
const functionNames = pipe(
|
|
350
|
-
group.functions,
|
|
351
|
-
Record.values,
|
|
352
|
-
Array.sortBy(
|
|
353
|
-
Order.mapInput(
|
|
354
|
-
Order.string,
|
|
355
|
-
(fn: FunctionSpec.AnyWithProps) => fn.name,
|
|
356
|
-
),
|
|
357
|
-
),
|
|
358
|
-
Array.map((fn) => fn.name),
|
|
359
|
-
);
|
|
360
|
-
|
|
361
|
-
const relativeModulePath = yield* GroupPath.modulePath(groupPath);
|
|
362
|
-
const modulePath = path.join(convexDirectory, relativeModulePath);
|
|
363
|
-
const registeredFunctionsPath =
|
|
364
|
-
path.join(
|
|
365
|
-
confectDirectory,
|
|
366
|
-
"_generated",
|
|
367
|
-
"registeredFunctions",
|
|
368
|
-
...groupPath.pathSegments,
|
|
369
|
-
) + ".ts";
|
|
370
|
-
const registeredFunctionsImportPath = yield* toModuleImportPath(
|
|
371
|
-
path.relative(path.dirname(modulePath), registeredFunctionsPath),
|
|
372
|
-
);
|
|
373
|
-
|
|
374
|
-
yield* Effect.logDebug(`Generating group ${groupPath}...`);
|
|
375
|
-
yield* generateGroupModule({
|
|
376
|
-
groupPath,
|
|
377
|
-
functionNames,
|
|
378
|
-
registeredFunctionsImportPath,
|
|
379
|
-
useNode: groupPath.pathSegments[0] === "node",
|
|
380
|
-
});
|
|
381
|
-
yield* Effect.logDebug(`Group ${groupPath} generated`);
|
|
382
|
-
}),
|
|
383
|
-
);
|
|
384
|
-
|
|
385
|
-
const generateOptionalFile = (
|
|
386
|
-
confectFile: string,
|
|
387
|
-
convexFile: string,
|
|
388
|
-
generateContents: (importPath: string) => Effect.Effect<string>,
|
|
389
|
-
) =>
|
|
390
|
-
Effect.gen(function* () {
|
|
391
|
-
const fs = yield* FileSystem.FileSystem;
|
|
392
|
-
const path = yield* Path.Path;
|
|
393
|
-
const confectDirectory = yield* ConfectDirectory.get;
|
|
394
|
-
const convexDirectory = yield* ConvexDirectory.get;
|
|
395
|
-
|
|
396
|
-
const confectFilePath = path.join(confectDirectory, confectFile);
|
|
397
|
-
|
|
398
|
-
if (!(yield* fs.exists(confectFilePath))) {
|
|
399
|
-
return Option.none();
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
const convexFilePath = path.join(convexDirectory, convexFile);
|
|
403
|
-
const relativeImportPath = path.relative(
|
|
404
|
-
path.dirname(convexFilePath),
|
|
405
|
-
confectFilePath,
|
|
406
|
-
);
|
|
407
|
-
const importPathWithoutExt = yield* removePathExtension(relativeImportPath);
|
|
408
|
-
const contents = yield* generateContents(importPathWithoutExt);
|
|
409
|
-
const change = yield* writeFileString(convexFilePath, contents);
|
|
410
|
-
return Option.some({ change, convexFilePath });
|
|
411
|
-
});
|
|
412
|
-
|
|
413
|
-
export const generateHttp = generateOptionalFile(
|
|
414
|
-
"http.ts",
|
|
415
|
-
"http.ts",
|
|
416
|
-
(importPath) => templates.http({ httpImportPath: importPath }),
|
|
417
|
-
);
|
|
418
|
-
|
|
419
|
-
export const generateCrons = generateOptionalFile(
|
|
420
|
-
"crons.ts",
|
|
421
|
-
"crons.ts",
|
|
422
|
-
(importPath) => templates.crons({ cronsImportPath: importPath }),
|
|
423
|
-
);
|
|
424
|
-
|
|
425
|
-
export const generateAuthConfig = generateOptionalFile(
|
|
426
|
-
"auth.ts",
|
|
427
|
-
"auth.config.ts",
|
|
428
|
-
(importPath) => templates.authConfig({ authImportPath: importPath }),
|
|
429
|
-
);
|