@cedarjs/cli 5.0.0-canary.2340 → 5.0.0-canary.2343
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.
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { Listr } from "listr2";
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
addApiPackages,
|
|
6
|
+
addWebPackages,
|
|
7
|
+
colors as c
|
|
8
|
+
} from "@cedarjs/cli-helpers";
|
|
5
9
|
import {
|
|
6
10
|
getConfigPath,
|
|
7
11
|
getMigrationsPath,
|
|
@@ -14,6 +18,10 @@ function getApiPackageJson() {
|
|
|
14
18
|
const apiPackageJsonPath = path.join(getPaths().api.base, "package.json");
|
|
15
19
|
return JSON.parse(fs.readFileSync(apiPackageJsonPath, "utf-8"));
|
|
16
20
|
}
|
|
21
|
+
function getWebPackageJson() {
|
|
22
|
+
const webPackageJsonPath = path.join(getPaths().web.base, "package.json");
|
|
23
|
+
return JSON.parse(fs.readFileSync(webPackageJsonPath, "utf-8"));
|
|
24
|
+
}
|
|
17
25
|
function hasPackage(packageJson, packageName) {
|
|
18
26
|
return Boolean(
|
|
19
27
|
packageJson.dependencies?.[packageName] || packageJson.devDependencies?.[packageName]
|
|
@@ -147,12 +155,88 @@ function addLiveQueryListenerToGraphqlHandler({ force }) {
|
|
|
147
155
|
skipped: false
|
|
148
156
|
};
|
|
149
157
|
}
|
|
158
|
+
function addConfigureGqlormToApp({ force }) {
|
|
159
|
+
const appPath = getPaths().web.app;
|
|
160
|
+
if (!fs.existsSync(appPath)) {
|
|
161
|
+
return {
|
|
162
|
+
skipped: true,
|
|
163
|
+
reason: `${path.basename(appPath)} not found`
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
const content = fs.readFileSync(appPath, "utf-8");
|
|
167
|
+
const contentLines = content.split("\n");
|
|
168
|
+
const hasGqlormImport = contentLines.some(
|
|
169
|
+
(line) => line.includes("from '@cedarjs/gqlorm/setup'")
|
|
170
|
+
);
|
|
171
|
+
const hasSchemaImport = contentLines.some(
|
|
172
|
+
(line) => line.includes("from '../../.cedar/gqlorm-schema.json'")
|
|
173
|
+
);
|
|
174
|
+
const hasConfigureCall = contentLines.some(
|
|
175
|
+
(line) => line.includes("configureGqlorm({ schema })")
|
|
176
|
+
);
|
|
177
|
+
if (hasGqlormImport && hasSchemaImport && hasConfigureCall && !force) {
|
|
178
|
+
return {
|
|
179
|
+
skipped: true,
|
|
180
|
+
reason: "configureGqlorm is already wired into App"
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
if (!hasGqlormImport) {
|
|
184
|
+
const redwoodWebImportIndex = contentLines.findIndex(
|
|
185
|
+
(line) => line.includes("from '@cedarjs/web'")
|
|
186
|
+
);
|
|
187
|
+
if (redwoodWebImportIndex === -1) {
|
|
188
|
+
return {
|
|
189
|
+
skipped: true,
|
|
190
|
+
reason: "Unexpected syntax. Could not find @cedarjs/web import to insert gqlorm import"
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
contentLines.splice(
|
|
194
|
+
redwoodWebImportIndex,
|
|
195
|
+
0,
|
|
196
|
+
"import { configureGqlorm } from '@cedarjs/gqlorm/setup'"
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
if (!hasSchemaImport) {
|
|
200
|
+
const fatalErrorPageIndex = contentLines.findIndex(
|
|
201
|
+
(line) => line.includes("import FatalErrorPage from 'src/pages/FatalErrorPage'")
|
|
202
|
+
);
|
|
203
|
+
if (fatalErrorPageIndex === -1) {
|
|
204
|
+
return {
|
|
205
|
+
skipped: true,
|
|
206
|
+
reason: "Unexpected syntax. Could not find FatalErrorPage import to insert schema import"
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
contentLines.splice(
|
|
210
|
+
fatalErrorPageIndex + 1,
|
|
211
|
+
0,
|
|
212
|
+
"import schema from '../../.cedar/gqlorm-schema.json' with { type: 'json' }"
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
if (!hasConfigureCall) {
|
|
216
|
+
const appComponentIndex = contentLines.findIndex(
|
|
217
|
+
(line) => /^const App\s*=/.test(line)
|
|
218
|
+
);
|
|
219
|
+
if (appComponentIndex === -1) {
|
|
220
|
+
return {
|
|
221
|
+
skipped: true,
|
|
222
|
+
reason: "Unexpected syntax. Could not find `const App =` to insert configureGqlorm call"
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
contentLines.splice(appComponentIndex, 0, "configureGqlorm({ schema })", "");
|
|
226
|
+
}
|
|
227
|
+
fs.writeFileSync(appPath, contentLines.join("\n"));
|
|
228
|
+
return {
|
|
229
|
+
skipped: false
|
|
230
|
+
};
|
|
231
|
+
}
|
|
150
232
|
async function handler({ force, verbose }) {
|
|
151
233
|
const projectIsTypescript = isTypeScriptProject();
|
|
152
234
|
const apiPackageJson = getApiPackageJson();
|
|
153
235
|
const migrationsPath = await getMigrationsPath(getPaths().api.prismaConfig);
|
|
154
236
|
const hasRealtimeDependency = hasPackage(apiPackageJson, "@cedarjs/realtime");
|
|
155
237
|
const hasPgDependency = hasPackage(apiPackageJson, "pg");
|
|
238
|
+
const webPackageJson = getWebPackageJson();
|
|
239
|
+
const hasGqlormDependency = hasPackage(webPackageJson, "@cedarjs/gqlorm");
|
|
156
240
|
const ext = projectIsTypescript ? "ts" : "js";
|
|
157
241
|
const migrationTemplatePath = path.resolve(
|
|
158
242
|
import.meta.dirname,
|
|
@@ -244,7 +328,7 @@ async function handler({ force, verbose }) {
|
|
|
244
328
|
},
|
|
245
329
|
{
|
|
246
330
|
...addApiPackages(["pg@^8.18.0"]),
|
|
247
|
-
title: "Adding pg dependency to your api
|
|
331
|
+
title: "Adding pg dependency to your api workspace...",
|
|
248
332
|
skip: () => {
|
|
249
333
|
if (hasPgDependency) {
|
|
250
334
|
return "pg is already installed";
|
|
@@ -297,6 +381,25 @@ async function handler({ force, verbose }) {
|
|
|
297
381
|
}
|
|
298
382
|
}
|
|
299
383
|
},
|
|
384
|
+
{
|
|
385
|
+
...addWebPackages(["@cedarjs/gqlorm"]),
|
|
386
|
+
title: "Adding @cedarjs/gqlorm to your web workspace...",
|
|
387
|
+
skip: () => {
|
|
388
|
+
if (hasGqlormDependency) {
|
|
389
|
+
return "@cedarjs/gqlorm is already installed";
|
|
390
|
+
}
|
|
391
|
+
return false;
|
|
392
|
+
}
|
|
393
|
+
},
|
|
394
|
+
{
|
|
395
|
+
title: "Wiring configureGqlorm into App.tsx...",
|
|
396
|
+
task: (_ctx, task) => {
|
|
397
|
+
const result = addConfigureGqlormToApp({ force });
|
|
398
|
+
if (result.skipped) {
|
|
399
|
+
task.skip(result.reason);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
},
|
|
300
403
|
{
|
|
301
404
|
title: "One more thing...",
|
|
302
405
|
task: (_ctx, task) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cedarjs/cli",
|
|
3
|
-
"version": "5.0.0-canary.
|
|
3
|
+
"version": "5.0.0-canary.2343",
|
|
4
4
|
"description": "The CedarJS Command Line",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -33,17 +33,17 @@
|
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@babel/parser": "7.29.3",
|
|
35
35
|
"@babel/preset-typescript": "7.28.5",
|
|
36
|
-
"@cedarjs/api-server": "5.0.0-canary.
|
|
37
|
-
"@cedarjs/cli-helpers": "5.0.0-canary.
|
|
38
|
-
"@cedarjs/fastify-web": "5.0.0-canary.
|
|
39
|
-
"@cedarjs/internal": "5.0.0-canary.
|
|
40
|
-
"@cedarjs/prerender": "5.0.0-canary.
|
|
41
|
-
"@cedarjs/project-config": "5.0.0-canary.
|
|
42
|
-
"@cedarjs/structure": "5.0.0-canary.
|
|
43
|
-
"@cedarjs/telemetry": "5.0.0-canary.
|
|
44
|
-
"@cedarjs/utils": "5.0.0-canary.
|
|
45
|
-
"@cedarjs/vite": "5.0.0-canary.
|
|
46
|
-
"@cedarjs/web-server": "5.0.0-canary.
|
|
36
|
+
"@cedarjs/api-server": "5.0.0-canary.2343",
|
|
37
|
+
"@cedarjs/cli-helpers": "5.0.0-canary.2343",
|
|
38
|
+
"@cedarjs/fastify-web": "5.0.0-canary.2343",
|
|
39
|
+
"@cedarjs/internal": "5.0.0-canary.2343",
|
|
40
|
+
"@cedarjs/prerender": "5.0.0-canary.2343",
|
|
41
|
+
"@cedarjs/project-config": "5.0.0-canary.2343",
|
|
42
|
+
"@cedarjs/structure": "5.0.0-canary.2343",
|
|
43
|
+
"@cedarjs/telemetry": "5.0.0-canary.2343",
|
|
44
|
+
"@cedarjs/utils": "5.0.0-canary.2343",
|
|
45
|
+
"@cedarjs/vite": "5.0.0-canary.2343",
|
|
46
|
+
"@cedarjs/web-server": "5.0.0-canary.2343",
|
|
47
47
|
"@listr2/prompt-adapter-enquirer": "4.2.1",
|
|
48
48
|
"@opentelemetry/api": "1.9.0",
|
|
49
49
|
"@opentelemetry/core": "1.30.1",
|