@confect/cli 1.0.0-next.3 → 1.0.0
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 +15 -0
- package/dist/confect/codegen.mjs +83 -11
- package/dist/confect/codegen.mjs.map +1 -1
- package/dist/confect/dev.mjs +156 -131
- package/dist/confect/dev.mjs.map +1 -1
- package/dist/log.mjs +5 -4
- package/dist/log.mjs.map +1 -1
- package/dist/package.mjs +1 -1
- package/dist/templates.mjs +34 -8
- package/dist/templates.mjs.map +1 -1
- package/dist/utils.mjs +17 -11
- package/dist/utils.mjs.map +1 -1
- package/package.json +3 -3
- package/src/confect/codegen.ts +146 -21
- package/src/confect/dev.ts +310 -283
- package/src/log.ts +14 -37
- package/src/templates.ts +78 -6
- package/src/utils.ts +15 -1
package/src/log.ts
CHANGED
|
@@ -66,41 +66,18 @@ export const logFunctionRemoved = logFunction("-", Ansi.red);
|
|
|
66
66
|
|
|
67
67
|
// --- Process status logs ---
|
|
68
68
|
|
|
69
|
-
const logStatus =
|
|
70
|
-
(
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
pipe(
|
|
83
|
-
AnsiDoc.char(" "),
|
|
84
|
-
AnsiDoc.cat(AnsiDoc.text(messageText)),
|
|
85
|
-
AnsiDoc.cat(AnsiDoc.char(" ")),
|
|
86
|
-
AnsiDoc.annotate(messageColor),
|
|
87
|
-
),
|
|
88
|
-
),
|
|
89
|
-
AnsiDoc.catWithSpace(AnsiDoc.text(message)),
|
|
90
|
-
AnsiDoc.render({ style: "pretty" }),
|
|
91
|
-
),
|
|
92
|
-
);
|
|
69
|
+
const logStatus = (char: string, charColor: Ansi.Ansi) => (message: string) =>
|
|
70
|
+
Console.log(
|
|
71
|
+
pipe(
|
|
72
|
+
AnsiDoc.char(char),
|
|
73
|
+
AnsiDoc.annotate(charColor),
|
|
74
|
+
AnsiDoc.catWithSpace(AnsiDoc.text(message)),
|
|
75
|
+
AnsiDoc.render({ style: "pretty" }),
|
|
76
|
+
),
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
export const logSuccess = logStatus("✔︎", Ansi.green);
|
|
80
|
+
|
|
81
|
+
export const logFailure = logStatus("✘", Ansi.red);
|
|
93
82
|
|
|
94
|
-
export const
|
|
95
|
-
"✔︎",
|
|
96
|
-
Ansi.green,
|
|
97
|
-
"SUCCESS",
|
|
98
|
-
Ansi.combine(Ansi.green, Ansi.bgGreenBright),
|
|
99
|
-
);
|
|
100
|
-
|
|
101
|
-
export const logFailed = logStatus(
|
|
102
|
-
"✘",
|
|
103
|
-
Ansi.red,
|
|
104
|
-
"FAILURE",
|
|
105
|
-
Ansi.combine(Ansi.red, Ansi.bgRedBright),
|
|
106
|
-
);
|
|
83
|
+
export const logPending = logStatus("⭘", Ansi.yellow);
|
package/src/templates.ts
CHANGED
|
@@ -7,21 +7,34 @@ export const functions = ({
|
|
|
7
7
|
groupPath,
|
|
8
8
|
functionNames,
|
|
9
9
|
registeredFunctionsImportPath,
|
|
10
|
+
registeredFunctionsVariableName = "registeredFunctions",
|
|
11
|
+
registeredFunctionsLookupPath,
|
|
12
|
+
useNode = false,
|
|
10
13
|
}: {
|
|
11
14
|
groupPath: GroupPath.GroupPath;
|
|
12
15
|
functionNames: string[];
|
|
13
16
|
registeredFunctionsImportPath: string;
|
|
17
|
+
registeredFunctionsVariableName?: string;
|
|
18
|
+
registeredFunctionsLookupPath?: readonly string[];
|
|
19
|
+
useNode?: boolean;
|
|
14
20
|
}) =>
|
|
15
21
|
Effect.gen(function* () {
|
|
16
22
|
const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });
|
|
17
23
|
|
|
24
|
+
const lookupPath = registeredFunctionsLookupPath ?? groupPath.pathSegments;
|
|
25
|
+
|
|
26
|
+
if (useNode) {
|
|
27
|
+
yield* cbw.writeLine(`"use node";`);
|
|
28
|
+
yield* cbw.blankLine();
|
|
29
|
+
}
|
|
30
|
+
|
|
18
31
|
yield* cbw.writeLine(
|
|
19
|
-
`import
|
|
32
|
+
`import ${registeredFunctionsVariableName} from "${registeredFunctionsImportPath}";`,
|
|
20
33
|
);
|
|
21
34
|
yield* cbw.newLine();
|
|
22
35
|
for (const functionName of functionNames) {
|
|
23
36
|
yield* cbw.writeLine(
|
|
24
|
-
`export const ${functionName} =
|
|
37
|
+
`export const ${functionName} = ${registeredFunctionsVariableName}.${Array.join([...lookupPath, functionName], ".")};`,
|
|
25
38
|
);
|
|
26
39
|
}
|
|
27
40
|
|
|
@@ -85,14 +98,27 @@ export const authConfig = ({ authImportPath }: { authImportPath: string }) =>
|
|
|
85
98
|
return yield* cbw.toString();
|
|
86
99
|
});
|
|
87
100
|
|
|
88
|
-
export const refs = ({
|
|
101
|
+
export const refs = ({
|
|
102
|
+
specImportPath,
|
|
103
|
+
nodeSpecImportPath,
|
|
104
|
+
}: {
|
|
105
|
+
specImportPath: string;
|
|
106
|
+
nodeSpecImportPath?: string;
|
|
107
|
+
}) =>
|
|
89
108
|
Effect.gen(function* () {
|
|
90
109
|
const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });
|
|
91
110
|
|
|
92
111
|
yield* cbw.writeLine(`import { Refs } from "@confect/core";`);
|
|
93
112
|
yield* cbw.writeLine(`import spec from "${specImportPath}";`);
|
|
113
|
+
if (nodeSpecImportPath !== undefined) {
|
|
114
|
+
yield* cbw.writeLine(`import nodeSpec from "${nodeSpecImportPath}";`);
|
|
115
|
+
}
|
|
94
116
|
yield* cbw.blankLine();
|
|
95
|
-
yield* cbw.writeLine(
|
|
117
|
+
yield* cbw.writeLine(
|
|
118
|
+
nodeSpecImportPath !== undefined
|
|
119
|
+
? `export default Refs.make(spec, nodeSpec);`
|
|
120
|
+
: `export default Refs.make(spec);`,
|
|
121
|
+
);
|
|
96
122
|
|
|
97
123
|
return yield* cbw.toString();
|
|
98
124
|
});
|
|
@@ -116,6 +142,26 @@ export const api = ({
|
|
|
116
142
|
return yield* cbw.toString();
|
|
117
143
|
});
|
|
118
144
|
|
|
145
|
+
export const nodeApi = ({
|
|
146
|
+
schemaImportPath,
|
|
147
|
+
nodeSpecImportPath,
|
|
148
|
+
}: {
|
|
149
|
+
schemaImportPath: string;
|
|
150
|
+
nodeSpecImportPath: string;
|
|
151
|
+
}) =>
|
|
152
|
+
Effect.gen(function* () {
|
|
153
|
+
const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });
|
|
154
|
+
|
|
155
|
+
yield* cbw.writeLine(`import { Api } from "@confect/server";`);
|
|
156
|
+
yield* cbw.blankLine();
|
|
157
|
+
yield* cbw.writeLine(`import schema from "${schemaImportPath}";`);
|
|
158
|
+
yield* cbw.writeLine(`import nodeSpec from "${nodeSpecImportPath}";`);
|
|
159
|
+
yield* cbw.blankLine();
|
|
160
|
+
yield* cbw.writeLine(`export default Api.make(schema, nodeSpec);`);
|
|
161
|
+
|
|
162
|
+
return yield* cbw.toString();
|
|
163
|
+
});
|
|
164
|
+
|
|
119
165
|
export const registeredFunctions = ({
|
|
120
166
|
implImportPath,
|
|
121
167
|
}: {
|
|
@@ -125,11 +171,37 @@ export const registeredFunctions = ({
|
|
|
125
171
|
const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });
|
|
126
172
|
|
|
127
173
|
yield* cbw.writeLine(
|
|
128
|
-
`import { RegisteredFunctions } from "@confect/server";`,
|
|
174
|
+
`import { RegisteredConvexFunction, RegisteredFunctions } from "@confect/server";`,
|
|
129
175
|
);
|
|
130
176
|
yield* cbw.writeLine(`import impl from "${implImportPath}";`);
|
|
131
177
|
yield* cbw.blankLine();
|
|
132
|
-
yield* cbw.writeLine(
|
|
178
|
+
yield* cbw.writeLine(
|
|
179
|
+
`export default RegisteredFunctions.make(impl, RegisteredConvexFunction.make);`,
|
|
180
|
+
);
|
|
181
|
+
|
|
182
|
+
return yield* cbw.toString();
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
export const nodeRegisteredFunctions = ({
|
|
186
|
+
nodeImplImportPath,
|
|
187
|
+
}: {
|
|
188
|
+
nodeImplImportPath: string;
|
|
189
|
+
}) =>
|
|
190
|
+
Effect.gen(function* () {
|
|
191
|
+
const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });
|
|
192
|
+
|
|
193
|
+
yield* cbw.writeLine(
|
|
194
|
+
`import { RegisteredFunctions } from "@confect/server";`,
|
|
195
|
+
);
|
|
196
|
+
yield* cbw.writeLine(
|
|
197
|
+
`import { RegisteredNodeFunction } from "@confect/server/node";`,
|
|
198
|
+
);
|
|
199
|
+
yield* cbw.blankLine();
|
|
200
|
+
yield* cbw.writeLine(`import nodeImpl from "${nodeImplImportPath}";`);
|
|
201
|
+
yield* cbw.blankLine();
|
|
202
|
+
yield* cbw.writeLine(
|
|
203
|
+
`export default RegisteredFunctions.make(nodeImpl, RegisteredNodeFunction.make);`,
|
|
204
|
+
);
|
|
133
205
|
|
|
134
206
|
return yield* cbw.toString();
|
|
135
207
|
});
|
package/src/utils.ts
CHANGED
|
@@ -103,19 +103,33 @@ export const generateGroupModule = ({
|
|
|
103
103
|
yield* fs.makeDirectory(directoryPath, { recursive: true });
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
+
const isNodeGroup = groupPath.pathSegments[0] === "node";
|
|
107
|
+
const registeredFunctionsFileName = isNodeGroup
|
|
108
|
+
? "nodeRegisteredFunctions.ts"
|
|
109
|
+
: "registeredFunctions.ts";
|
|
106
110
|
const registeredFunctionsPath = path.join(
|
|
107
111
|
confectDirectory,
|
|
108
112
|
"_generated",
|
|
109
|
-
|
|
113
|
+
registeredFunctionsFileName,
|
|
110
114
|
);
|
|
111
115
|
const registeredFunctionsImportPath = yield* removePathExtension(
|
|
112
116
|
path.relative(path.dirname(modulePath), registeredFunctionsPath),
|
|
113
117
|
);
|
|
118
|
+
const registeredFunctionsVariableName = isNodeGroup
|
|
119
|
+
? "nodeRegisteredFunctions"
|
|
120
|
+
: "registeredFunctions";
|
|
114
121
|
|
|
115
122
|
const functionsContentsString = yield* templates.functions({
|
|
116
123
|
groupPath,
|
|
117
124
|
functionNames,
|
|
118
125
|
registeredFunctionsImportPath,
|
|
126
|
+
registeredFunctionsVariableName,
|
|
127
|
+
useNode: isNodeGroup,
|
|
128
|
+
...(isNodeGroup
|
|
129
|
+
? {
|
|
130
|
+
registeredFunctionsLookupPath: groupPath.pathSegments.slice(1),
|
|
131
|
+
}
|
|
132
|
+
: {}),
|
|
119
133
|
});
|
|
120
134
|
|
|
121
135
|
if (!(yield* fs.exists(modulePath))) {
|