@cedarjs/cli 4.2.1-next.0 → 4.2.1-next.269
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/dist/cfw.js +8 -6
- package/dist/commands/build/buildHandler.js +43 -42
- package/dist/commands/build/buildPackagesTask.js +6 -6
- package/dist/commands/build.js +7 -1
- package/dist/commands/deploy/baremetal/SshExecutor.js +13 -4
- package/dist/commands/deploy/baremetal/baremetalHandler.js +117 -65
- package/dist/commands/deploy/baremetal.js +24 -3
- package/dist/commands/deploy/flightcontrolHandler.js +16 -14
- package/dist/commands/deploy/helpers/deployHandler.js +10 -5
- package/dist/commands/deploy/packing/nft.js +1 -2
- package/dist/commands/deploy/render.js +1 -1
- package/dist/commands/deploy/renderHandler.js +22 -12
- package/dist/commands/deploy/serverlessHandler.js +67 -25
- package/dist/commands/destroy/component/component.js +2 -3
- package/dist/commands/destroy/directive/directive.js +1 -3
- package/dist/commands/destroy/directive/directiveHandler.js +2 -4
- package/dist/commands/destroy/function/function.js +1 -3
- package/dist/commands/destroy/handlerHelpers.js +16 -16
- package/dist/commands/destroy/helpers.js +8 -2
- package/dist/commands/destroy/layout/layout.js +1 -2
- package/dist/commands/destroy/page/pageHandler.js +1 -1
- package/dist/commands/destroy/scaffold/scaffoldHandler.js +28 -9
- package/dist/commands/destroy/sdl/sdlHandler.js +1 -1
- package/dist/commands/dev/devHandler.js +25 -25
- package/dist/commands/dev.js +3 -0
- package/dist/commands/experimental/live-queries/liveQueriesHandler.js +110 -4
- package/dist/commands/experimental/setupInngest.js +1 -1
- package/dist/commands/experimental/setupInngestHandler.js +12 -11
- package/dist/commands/experimental/setupOpentelemetry.js +1 -1
- package/dist/commands/experimental/setupOpentelemetryHandler.js +11 -7
- package/dist/commands/experimental/setupReactCompiler.js +1 -1
- package/dist/commands/experimental/setupReactCompilerHandler.js +45 -30
- package/dist/commands/experimental/setupRscHandler.js +14 -11
- package/dist/commands/experimental/setupStreamingSsr.js +1 -1
- package/dist/commands/experimental/setupStreamingSsrHandler.js +46 -31
- package/dist/commands/experimental/templates/rsc/Document.tsx.template +1 -1
- package/dist/commands/experimental/templates/rsc/entry.client.tsx.template +8 -8
- package/dist/commands/experimental/templates/streamingSsr/Document.tsx.template +1 -1
- package/dist/commands/experimental/templates/streamingSsr/entry.client.tsx.template +6 -6
- package/dist/commands/experimental/util.js +3 -2
- package/dist/commands/generate/cell/cellHandler.js +22 -21
- package/dist/commands/generate/component/componentHandler.js +14 -16
- package/dist/commands/generate/dataMigration/dataMigration.js +24 -13
- package/dist/commands/generate/dbAuth/dbAuth.js +1 -0
- package/dist/commands/generate/dbAuth/dbAuthHandler.js +40 -30
- package/dist/commands/generate/directive/directiveHandler.js +12 -14
- package/dist/commands/generate/function/function.js +1 -0
- package/dist/commands/generate/function/functionHandler.js +12 -17
- package/dist/commands/generate/helpers.js +17 -17
- package/dist/commands/generate/job/job.js +1 -0
- package/dist/commands/generate/job/jobHandler.js +15 -17
- package/dist/commands/generate/layout/layoutHandler.js +13 -16
- package/dist/commands/generate/model/model.js +1 -0
- package/dist/commands/generate/model/modelHandler.js +9 -3
- package/dist/commands/generate/ogImage/ogImage.js +1 -0
- package/dist/commands/generate/ogImage/ogImageHandler.js +16 -9
- package/dist/commands/generate/package/packageHandler.js +32 -49
- package/dist/commands/generate/page/pageHandler.js +25 -22
- package/dist/commands/generate/realtime/realtime.js +1 -1
- package/dist/commands/generate/realtime/realtimeHandler.js +46 -20
- package/dist/commands/generate/scaffold/scaffold.js +1 -0
- package/dist/commands/generate/scaffold/scaffoldHandler.js +35 -27
- package/dist/commands/generate/script/script.js +1 -0
- package/dist/commands/generate/script/templates/tsconfig.json.template +14 -0
- package/dist/commands/generate/sdl/sdl.js +4 -3
- package/dist/commands/generate/sdl/sdlHandler.js +38 -18
- package/dist/commands/generate/secret/secret.js +19 -19
- package/dist/commands/generate/service/service.js +5 -5
- package/dist/commands/generate/service/serviceHandler.js +59 -22
- package/dist/commands/generate/yargsCommandHelpers.js +6 -1
- package/dist/commands/generate/yargsHandlerHelpers.js +18 -10
- package/dist/commands/generate.js +3 -10
- package/dist/commands/jobsHandler.js +3 -2
- package/dist/commands/prismaHandler.js +10 -9
- package/dist/commands/serve.js +84 -137
- package/dist/commands/serveApiHandler.js +5 -5
- package/dist/commands/serveBothHandler.js +10 -7
- package/dist/commands/serveWebHandler.js +2 -2
- package/dist/commands/setup/auth/auth.js +12 -6
- package/dist/commands/setup/cache/cacheHandler.js +11 -6
- package/dist/commands/setup/deploy/deploy.js +4 -3
- package/dist/commands/setup/deploy/helpers/helpers.js +5 -1
- package/dist/commands/setup/deploy/helpers/index.js +157 -5
- package/dist/commands/setup/deploy/providers/baremetalHandler.js +26 -4
- package/dist/commands/setup/deploy/providers/coherenceHandler.js +53 -25
- package/dist/commands/setup/deploy/providers/flightcontrolHandler.js +33 -23
- package/dist/commands/setup/deploy/providers/netlify.js +6 -0
- package/dist/commands/setup/deploy/providers/netlifyHandler.js +112 -11
- package/dist/commands/setup/deploy/providers/renderHandler.js +10 -5
- package/dist/commands/setup/deploy/providers/serverlessHandler.js +5 -3
- package/dist/commands/setup/deploy/providers/universal-deploy.js +11 -0
- package/dist/commands/setup/deploy/providers/universalDeployHandler.js +188 -0
- package/dist/commands/setup/deploy/providers/vercel.js +6 -0
- package/dist/commands/setup/deploy/providers/vercelHandler.js +113 -12
- package/dist/commands/setup/deploy/templates/baremetal.js +3 -2
- package/dist/commands/setup/deploy/templates/flightcontrol.js +60 -49
- package/dist/commands/setup/deploy/templates/netlify.js +2 -1
- package/dist/commands/setup/deploy/templates/netlifyUD.js +31 -0
- package/dist/commands/setup/docker/docker.js +1 -1
- package/dist/commands/setup/docker/dockerHandler.js +72 -37
- package/dist/commands/setup/docker/templates/Dockerfile.npm +119 -0
- package/dist/commands/setup/docker/templates/Dockerfile.pnpm +112 -0
- package/dist/commands/setup/docker/templates/{Dockerfile → Dockerfile.yarn} +1 -1
- package/dist/commands/setup/docker/templates/docker-compose.dev.yml +2 -2
- package/dist/commands/setup/generator/generatorHandler.js +4 -3
- package/dist/commands/setup/graphql/features/fragments/fragmentsHandler.js +2 -2
- package/dist/commands/setup/graphql/features/trustedDocuments/trustedDocumentsHandler.js +2 -2
- package/dist/commands/setup/i18n/i18nHandler.js +18 -15
- package/dist/commands/setup/jobs/jobsHandler.js +10 -5
- package/dist/commands/setup/mailer/mailerHandler.js +11 -9
- package/dist/commands/setup/package/packageHandler.js +14 -10
- package/dist/commands/setup/realtime/realtimeHandler.js +22 -20
- package/dist/commands/setup/server-file/serverFileHandler.js +16 -8
- package/dist/commands/setup/tsconfig/tsconfigHandler.js +5 -3
- package/dist/commands/setup/ui/helpers/helpers.js +5 -1
- package/dist/commands/setup/ui/libraries/chakra-uiHandler.js +11 -5
- package/dist/commands/setup/ui/libraries/mantineHandler.js +21 -13
- package/dist/commands/setup/ui/libraries/tailwindcssHandler.js +38 -26
- package/dist/commands/setup/uploads/uploadsHandler.js +7 -4
- package/dist/commands/setup.js +1 -2
- package/dist/commands/test/testHandler.js +2 -1
- package/dist/commands/test/testHandlerEsm.js +2 -2
- package/dist/commands/type-checkHandler.js +4 -6
- package/dist/commands/upgrade/upgradeHandler.js +2 -4
- package/dist/index.js +10 -4
- package/dist/lib/configureStorybook.js +2 -2
- package/dist/lib/exec.js +36 -24
- package/dist/lib/exit.js +19 -4
- package/dist/lib/extendFile.js +22 -12
- package/dist/lib/index.js +119 -85
- package/dist/lib/merge/algorithms.js +4 -1
- package/dist/lib/merge/index.js +76 -41
- package/dist/lib/merge/semanticIdentity.js +18 -6
- package/dist/lib/merge/strategy.js +86 -36
- package/dist/lib/packages.js +23 -13
- package/dist/lib/plugin.js +12 -5
- package/dist/lib/pluralHelpers.js +1 -1
- package/dist/lib/project.js +3 -1
- package/dist/lib/rollback.js +7 -7
- package/dist/lib/schemaHelpers.js +12 -12
- package/dist/lib/test.js +4 -0
- package/dist/lib/updateCheck.js +6 -4
- package/dist/middleware/checkNodeVersion.js +5 -0
- package/dist/plugin.js +18 -12
- package/dist/telemetry/exporter.js +12 -5
- package/dist/telemetry/index.js +4 -3
- package/dist/telemetry/resource.js +9 -5
- package/dist/telemetry/send.js +14 -10
- package/package.json +15 -13
- package/dist/commands/setup/vite/templates/vite.config.ts.template +0 -19
- package/dist/commands/setup/vite/vite.js +0 -38
- package/dist/commands/setup/vite/viteHandler.js +0 -82
- /package/dist/{index.d.js → global.d.js} +0 -0
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
|
+
import * as parser from "@babel/parser";
|
|
4
|
+
import * as t from "@babel/types";
|
|
3
5
|
import execa from "execa";
|
|
4
6
|
import { Listr } from "listr2";
|
|
7
|
+
import * as recast from "recast";
|
|
5
8
|
import { getConfigPath, getConfig } from "@cedarjs/project-config";
|
|
6
9
|
import { getPaths, writeFilesTask } from "../../../../lib/index.js";
|
|
7
10
|
const updateApiURLTask = (apiUrl) => {
|
|
@@ -38,9 +41,10 @@ const preRequisiteCheckTask = (preRequisites) => {
|
|
|
38
41
|
task: async () => {
|
|
39
42
|
try {
|
|
40
43
|
await execa(...preReq.command);
|
|
41
|
-
} catch (
|
|
42
|
-
|
|
43
|
-
|
|
44
|
+
} catch (e) {
|
|
45
|
+
const baseMsg = e instanceof Error ? e.message : String(e);
|
|
46
|
+
const err = new Error(baseMsg + "\n" + preReq.errorMessage);
|
|
47
|
+
throw err;
|
|
44
48
|
}
|
|
45
49
|
}
|
|
46
50
|
};
|
|
@@ -56,7 +60,7 @@ const addFilesTask = ({
|
|
|
56
60
|
return {
|
|
57
61
|
title: `${title}...`,
|
|
58
62
|
task: () => {
|
|
59
|
-
|
|
63
|
+
const fileNameToContentMap = {};
|
|
60
64
|
files.forEach((fileData) => {
|
|
61
65
|
fileNameToContentMap[fileData.path] = fileData.content;
|
|
62
66
|
});
|
|
@@ -64,6 +68,150 @@ const addFilesTask = ({
|
|
|
64
68
|
}
|
|
65
69
|
};
|
|
66
70
|
};
|
|
71
|
+
const verifyUDSetupTask = () => {
|
|
72
|
+
return {
|
|
73
|
+
title: "Checking if Universal Deploy is set up...",
|
|
74
|
+
task: () => {
|
|
75
|
+
const paths = getPaths();
|
|
76
|
+
const viteConfigTs = path.join(paths.web.base, "vite.config.ts");
|
|
77
|
+
const viteConfigJs = path.join(paths.web.base, "vite.config.js");
|
|
78
|
+
const viteConfigPath = fs.existsSync(viteConfigTs) ? viteConfigTs : viteConfigJs;
|
|
79
|
+
if (!fs.existsSync(viteConfigPath)) {
|
|
80
|
+
throw new Error("Vite config file not found");
|
|
81
|
+
}
|
|
82
|
+
const content = fs.readFileSync(viteConfigPath, "utf-8");
|
|
83
|
+
if (!content.includes("cedarUniversalDeployPlugin")) {
|
|
84
|
+
throw new Error(
|
|
85
|
+
"Universal Deploy is not set up. Please run `yarn cedar setup deploy universal-deploy` first."
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
function posToIndex(str, line, column) {
|
|
92
|
+
const lines = str.split("\n");
|
|
93
|
+
let index = 0;
|
|
94
|
+
for (let i = 0; i < line - 1; i++) {
|
|
95
|
+
index += lines[i].length + 1;
|
|
96
|
+
}
|
|
97
|
+
return index + column;
|
|
98
|
+
}
|
|
99
|
+
function resolveConfigObject(arg) {
|
|
100
|
+
if (t.isObjectExpression(arg)) {
|
|
101
|
+
return arg;
|
|
102
|
+
}
|
|
103
|
+
if (t.isArrowFunctionExpression(arg)) {
|
|
104
|
+
if (t.isObjectExpression(arg.body)) {
|
|
105
|
+
return arg.body;
|
|
106
|
+
}
|
|
107
|
+
if (t.isBlockStatement(arg.body)) {
|
|
108
|
+
const returnStmt = arg.body.body.find((s) => t.isReturnStatement(s));
|
|
109
|
+
if (t.isObjectExpression(returnStmt?.argument)) {
|
|
110
|
+
return returnStmt.argument;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
if (t.isFunctionExpression(arg)) {
|
|
116
|
+
if (t.isBlockStatement(arg.body)) {
|
|
117
|
+
const returnStmt = arg.body.body.find(t.isReturnStatement);
|
|
118
|
+
if (t.isObjectExpression(returnStmt?.argument)) {
|
|
119
|
+
return returnStmt.argument;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
function insertPluginsBeforeCedar({
|
|
127
|
+
content,
|
|
128
|
+
pluginCodes
|
|
129
|
+
}) {
|
|
130
|
+
const ast = recast.parse(content, {
|
|
131
|
+
parser: {
|
|
132
|
+
parse(source) {
|
|
133
|
+
return parser.parse(source, {
|
|
134
|
+
sourceType: "module",
|
|
135
|
+
plugins: ["typescript", "jsx"]
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
const defaultExport = ast.program.body.find(t.isExportDefaultDeclaration);
|
|
141
|
+
if (!defaultExport) {
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
const declaration = defaultExport.declaration;
|
|
145
|
+
const configArg = resolveConfigObject(declaration.arguments[0]);
|
|
146
|
+
if (!configArg) {
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
const pluginsProp = configArg.properties.find(t.isObjectProperty);
|
|
150
|
+
if (!t.isArrayExpression(pluginsProp?.value)) {
|
|
151
|
+
return null;
|
|
152
|
+
}
|
|
153
|
+
const arrayExpr = pluginsProp.value;
|
|
154
|
+
const elements = arrayExpr.elements;
|
|
155
|
+
const cedarIndex = elements.findIndex(
|
|
156
|
+
(el) => t.isCallExpression(el) && t.isIdentifier(el.callee) && el.callee.name === "cedar"
|
|
157
|
+
);
|
|
158
|
+
if (cedarIndex === -1) {
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
const cedarElement = elements[cedarIndex];
|
|
162
|
+
if (!cedarElement || !t.isCallExpression(cedarElement)) {
|
|
163
|
+
return null;
|
|
164
|
+
}
|
|
165
|
+
const cedarNode = cedarElement;
|
|
166
|
+
if (!cedarNode.loc || !arrayExpr.loc || !pluginsProp.loc) {
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
const isInline = cedarNode.loc.start.line === arrayExpr.loc.start.line;
|
|
170
|
+
if (isInline) {
|
|
171
|
+
const startPos = posToIndex(
|
|
172
|
+
content,
|
|
173
|
+
arrayExpr.loc.start.line,
|
|
174
|
+
arrayExpr.loc.start.column
|
|
175
|
+
);
|
|
176
|
+
const endPos = posToIndex(
|
|
177
|
+
content,
|
|
178
|
+
arrayExpr.loc.end.line,
|
|
179
|
+
arrayExpr.loc.end.column
|
|
180
|
+
);
|
|
181
|
+
const precedingText = content.slice(0, startPos);
|
|
182
|
+
const followingText = content.slice(endPos);
|
|
183
|
+
const existingCodes = elements.flatMap((el) => {
|
|
184
|
+
if (!el?.loc) {
|
|
185
|
+
return [];
|
|
186
|
+
}
|
|
187
|
+
return [
|
|
188
|
+
content.slice(
|
|
189
|
+
posToIndex(content, el.loc.start.line, el.loc.start.column),
|
|
190
|
+
posToIndex(content, el.loc.end.line, el.loc.end.column)
|
|
191
|
+
)
|
|
192
|
+
];
|
|
193
|
+
});
|
|
194
|
+
const lines2 = content.split("\n");
|
|
195
|
+
const pluginsLine = pluginsProp.loc.start.line;
|
|
196
|
+
const pluginsIndent = (lines2[pluginsLine - 1].match(/^\s*/) ?? [""])[0];
|
|
197
|
+
const elemIndent = pluginsIndent + " ";
|
|
198
|
+
const allCodes = [...existingCodes];
|
|
199
|
+
allCodes.splice(cedarIndex, 0, ...pluginCodes);
|
|
200
|
+
const multiline = [
|
|
201
|
+
"[",
|
|
202
|
+
...allCodes.map((code) => `${elemIndent}${code},`),
|
|
203
|
+
`${pluginsIndent}]`
|
|
204
|
+
].join("\n");
|
|
205
|
+
return precedingText + multiline + followingText;
|
|
206
|
+
}
|
|
207
|
+
const cedarLine = cedarNode.loc.start.line;
|
|
208
|
+
const insertPos = posToIndex(content, cedarLine, 0);
|
|
209
|
+
const lines = content.split("\n");
|
|
210
|
+
const indent = (lines[cedarLine - 1].match(/^\s*/) ?? [""])[0];
|
|
211
|
+
const insertion = pluginCodes.map((code) => `${indent}${code},
|
|
212
|
+
`).join("");
|
|
213
|
+
return content.slice(0, insertPos) + insertion + content.slice(insertPos);
|
|
214
|
+
}
|
|
67
215
|
const addToGitIgnoreTask = ({ paths }) => {
|
|
68
216
|
return {
|
|
69
217
|
title: "Updating .gitignore...",
|
|
@@ -71,6 +219,7 @@ const addToGitIgnoreTask = ({ paths }) => {
|
|
|
71
219
|
if (!fs.existsSync(path.resolve(getPaths().base, ".gitignore"))) {
|
|
72
220
|
return "No gitignore present, skipping.";
|
|
73
221
|
}
|
|
222
|
+
return void 0;
|
|
74
223
|
},
|
|
75
224
|
task: async (_ctx, task) => {
|
|
76
225
|
const gitIgnore = path.resolve(getPaths().base, ".gitignore");
|
|
@@ -89,6 +238,7 @@ const addToDotEnvTask = ({ lines }) => {
|
|
|
89
238
|
if (!fs.existsSync(path.resolve(getPaths().base, ".env"))) {
|
|
90
239
|
return "No .env present, skipping.";
|
|
91
240
|
}
|
|
241
|
+
return void 0;
|
|
92
242
|
},
|
|
93
243
|
task: async (_ctx, task) => {
|
|
94
244
|
const env = path.resolve(getPaths().base, ".env");
|
|
@@ -105,6 +255,8 @@ export {
|
|
|
105
255
|
addToDotEnvTask,
|
|
106
256
|
addToGitIgnoreTask,
|
|
107
257
|
getUserApiUrl,
|
|
258
|
+
insertPluginsBeforeCedar,
|
|
108
259
|
preRequisiteCheckTask,
|
|
109
|
-
updateApiURLTask
|
|
260
|
+
updateApiURLTask,
|
|
261
|
+
verifyUDSetupTask
|
|
110
262
|
};
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
2
3
|
import { Listr } from "listr2";
|
|
4
|
+
import prompts from "prompts";
|
|
3
5
|
import { recordTelemetryAttributes, colors as c } from "@cedarjs/cli-helpers";
|
|
4
6
|
import { errorTelemetry } from "@cedarjs/telemetry";
|
|
5
7
|
import {
|
|
@@ -35,6 +37,24 @@ const handler = async ({ force }) => {
|
|
|
35
37
|
command: "setup deploy baremetal",
|
|
36
38
|
force
|
|
37
39
|
});
|
|
40
|
+
if (fs.existsSync(path.join(getPaths().base, ".pnp.cjs"))) {
|
|
41
|
+
console.warn(
|
|
42
|
+
c.warning(
|
|
43
|
+
"Your project uses Yarn PnP (Plug'n'Play), which is not officially supported for Baremetal deployments. The generated ecosystem.config.js file uses node_modules/.bin/cedar as the PM2 script path, which will most likely not work under PnP.\n\nYou will need to manually configure the server. See also the packageManagerCommand field in deploy.toml."
|
|
44
|
+
)
|
|
45
|
+
);
|
|
46
|
+
console.log();
|
|
47
|
+
const { confirmed } = await prompts({
|
|
48
|
+
type: "confirm",
|
|
49
|
+
name: "confirmed",
|
|
50
|
+
message: "Generate the default config anyway? (You can edit it later)"
|
|
51
|
+
});
|
|
52
|
+
if (!confirmed) {
|
|
53
|
+
console.log("Aborting baremetal setup.");
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
console.log();
|
|
57
|
+
}
|
|
38
58
|
const tasks = new Listr(
|
|
39
59
|
[
|
|
40
60
|
await addPackagesTask({
|
|
@@ -52,9 +72,11 @@ const handler = async ({ force }) => {
|
|
|
52
72
|
try {
|
|
53
73
|
await tasks.run();
|
|
54
74
|
} catch (e) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
75
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
76
|
+
errorTelemetry(process.argv, message);
|
|
77
|
+
console.error(c.error(message));
|
|
78
|
+
const exitCode = e instanceof Error && "exitCode" in e && typeof e.exitCode === "number" ? e.exitCode : 1;
|
|
79
|
+
process.exit(exitCode);
|
|
58
80
|
}
|
|
59
81
|
};
|
|
60
82
|
export {
|
|
@@ -8,6 +8,10 @@ import {
|
|
|
8
8
|
isTypeScriptProject,
|
|
9
9
|
getConfigPath
|
|
10
10
|
} from "@cedarjs/cli-helpers";
|
|
11
|
+
import {
|
|
12
|
+
formatCedarCommand,
|
|
13
|
+
formatRunBinCommand
|
|
14
|
+
} from "@cedarjs/cli-helpers/packageManager/display";
|
|
11
15
|
import { getPaths, getPrismaSchemas } from "@cedarjs/project-config";
|
|
12
16
|
import { errorTelemetry } from "@cedarjs/telemetry";
|
|
13
17
|
import { printSetupNotes } from "../../../../lib/index.js";
|
|
@@ -34,9 +38,11 @@ async function handler({ force }) {
|
|
|
34
38
|
);
|
|
35
39
|
await tasks.run();
|
|
36
40
|
} catch (e) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
41
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
42
|
+
errorTelemetry(process.argv, message);
|
|
43
|
+
console.error(c.error(message));
|
|
44
|
+
const exitCode = e instanceof Error && "exitCode" in e && typeof e.exitCode === "number" ? e.exitCode : 1;
|
|
45
|
+
process.exit(exitCode);
|
|
40
46
|
}
|
|
41
47
|
}
|
|
42
48
|
async function getAddCoherenceFilesTask(force) {
|
|
@@ -46,11 +52,11 @@ async function getAddCoherenceFilesTask(force) {
|
|
|
46
52
|
content: coherenceFiles.healthCheck
|
|
47
53
|
}
|
|
48
54
|
];
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
55
|
+
const coherenceConfigContent = await getCoherenceConfigFileContent();
|
|
56
|
+
files.push({
|
|
57
|
+
path: path.join(cedarPaths.base, "coherence.yml"),
|
|
58
|
+
content: coherenceConfigContent
|
|
59
|
+
});
|
|
54
60
|
return addFilesTask({
|
|
55
61
|
title: `Adding coherence.yml and health.${EXTENSION}`,
|
|
56
62
|
files,
|
|
@@ -74,20 +80,34 @@ async function getCoherenceConfigFileContent() {
|
|
|
74
80
|
if (db === "postgresql") {
|
|
75
81
|
db = "postgres";
|
|
76
82
|
}
|
|
77
|
-
const
|
|
83
|
+
const apiProdCommandSegments = [formatCedarCommand(["build", "api"]), "&&"];
|
|
78
84
|
if (serverFileExists()) {
|
|
79
|
-
|
|
80
|
-
"
|
|
81
|
-
"node",
|
|
82
|
-
"api/dist/server.js",
|
|
83
|
-
"--apiRootPath=/api"
|
|
85
|
+
apiProdCommandSegments.push(
|
|
86
|
+
formatRunBinCommand("node", ["api/dist/server.js", "--apiRootPath=/api"])
|
|
84
87
|
);
|
|
85
88
|
} else {
|
|
86
|
-
|
|
89
|
+
apiProdCommandSegments.push(
|
|
90
|
+
formatCedarCommand(["serve", "api", "--apiRootPath=/api"])
|
|
91
|
+
);
|
|
87
92
|
}
|
|
93
|
+
const apiDevCommandSegments = [
|
|
94
|
+
formatCedarCommand(["build", "api"]),
|
|
95
|
+
"&&",
|
|
96
|
+
formatCedarCommand(["dev", "api", "--apiRootPath=/api"])
|
|
97
|
+
];
|
|
98
|
+
const migrationCommandSegments = [
|
|
99
|
+
formatCedarCommand(["prisma", "migrate", "deploy"]),
|
|
100
|
+
"&&",
|
|
101
|
+
formatCedarCommand(["data-migrate", "up"])
|
|
102
|
+
];
|
|
88
103
|
return coherenceFiles.yamlTemplate({
|
|
89
104
|
db,
|
|
90
|
-
apiProdCommand: `[${
|
|
105
|
+
apiProdCommand: `[${apiProdCommandSegments.map((cmd) => `"${cmd}"`).join(", ")}]`,
|
|
106
|
+
apiDevCommand: `[${apiDevCommandSegments.map((cmd) => `"${cmd}"`).join(", ")}]`,
|
|
107
|
+
migrationCommand: `[${migrationCommandSegments.map((cmd) => `"${cmd}"`).join(", ")}]`,
|
|
108
|
+
webProdCommand: `["${formatCedarCommand(["serve", "web"])}"]`,
|
|
109
|
+
webDevCommand: `["${formatCedarCommand(["dev", "web", '--fwd=\\"--allowed-hosts all\\"'])}"]`,
|
|
110
|
+
webBuildCommand: `["${formatCedarCommand(["build", "web", "--no-prerender"])}"]`
|
|
91
111
|
});
|
|
92
112
|
}
|
|
93
113
|
const SUPPORTED_DATABASES = ["mysql", "postgresql"];
|
|
@@ -117,13 +137,13 @@ function updateConfigTomlTask() {
|
|
|
117
137
|
}
|
|
118
138
|
configContent = configContent.replaceAll(
|
|
119
139
|
HOST_REGEXP,
|
|
120
|
-
(
|
|
140
|
+
(_match, spaceBeforeAssign, spaceAfterAssign) => ["host", spaceBeforeAssign, "=", spaceAfterAssign, '"0.0.0.0"'].join(
|
|
121
141
|
""
|
|
122
142
|
)
|
|
123
143
|
);
|
|
124
144
|
configContent = configContent.replace(
|
|
125
145
|
API_URL_REGEXP,
|
|
126
|
-
(
|
|
146
|
+
(_match, spaceBeforeAssign, spaceAfterAssign) => ["apiUrl", spaceBeforeAssign, "=", spaceAfterAssign, '"/api"'].join(
|
|
127
147
|
""
|
|
128
148
|
)
|
|
129
149
|
);
|
|
@@ -145,14 +165,22 @@ const HOST_REGEXP = /host(\s*)=(\s*)\".+\"/g;
|
|
|
145
165
|
const API_URL_REGEXP = /apiUrl(\s*)=(\s*)\".+\"/;
|
|
146
166
|
const PORT_REGEXP = /port(\s*)=(\s*)(?<port>\d{4})/g;
|
|
147
167
|
const coherenceFiles = {
|
|
148
|
-
yamlTemplate({
|
|
168
|
+
yamlTemplate({
|
|
169
|
+
db,
|
|
170
|
+
apiProdCommand,
|
|
171
|
+
apiDevCommand,
|
|
172
|
+
migrationCommand,
|
|
173
|
+
webProdCommand,
|
|
174
|
+
webDevCommand,
|
|
175
|
+
webBuildCommand
|
|
176
|
+
}) {
|
|
149
177
|
return `api:
|
|
150
178
|
type: backend
|
|
151
179
|
url_path: "/api"
|
|
152
180
|
prod:
|
|
153
181
|
command: ${apiProdCommand}
|
|
154
182
|
dev:
|
|
155
|
-
command:
|
|
183
|
+
command: ${apiDevCommand}
|
|
156
184
|
local_packages: ["node_modules"]
|
|
157
185
|
|
|
158
186
|
system:
|
|
@@ -168,20 +196,20 @@ const coherenceFiles = {
|
|
|
168
196
|
${db === "postgres" ? "adapter: postgresql" : ""}
|
|
169
197
|
|
|
170
198
|
# If you use data migrations, use the following instead:
|
|
171
|
-
# migration: ["
|
|
172
|
-
migration:
|
|
199
|
+
# migration: ["${formatCedarCommand(["prisma", "migrate", "deploy"])}", "&&", "${formatCedarCommand(["data-migrate", "up"])}"]
|
|
200
|
+
migration: ${migrationCommand}
|
|
173
201
|
|
|
174
202
|
web:
|
|
175
203
|
type: frontend
|
|
176
204
|
assets_path: "web/dist"
|
|
177
205
|
prod:
|
|
178
|
-
command:
|
|
206
|
+
command: ${webProdCommand}
|
|
179
207
|
dev:
|
|
180
|
-
command:
|
|
208
|
+
command: ${webDevCommand}
|
|
181
209
|
|
|
182
210
|
# Heads up: Redwood's prerender doesn't work with Coherence yet.
|
|
183
211
|
# For current status and updates, see https://github.com/redwoodjs/redwood/issues/8333.
|
|
184
|
-
build:
|
|
212
|
+
build: ${webBuildCommand}
|
|
185
213
|
local_packages: ["node_modules"]
|
|
186
214
|
|
|
187
215
|
system:
|
|
@@ -4,18 +4,20 @@ import path from "path";
|
|
|
4
4
|
import prismaInternals from "@prisma/internals";
|
|
5
5
|
import { Listr } from "listr2";
|
|
6
6
|
import { recordTelemetryAttributes, colors as c } from "@cedarjs/cli-helpers";
|
|
7
|
+
import { formatCedarCommand } from "@cedarjs/cli-helpers/packageManager/display";
|
|
7
8
|
import { getPaths, getPrismaSchemas } from "@cedarjs/project-config";
|
|
8
9
|
import { errorTelemetry } from "@cedarjs/telemetry";
|
|
9
10
|
import { writeFilesTask, printSetupNotes } from "../../../../lib/index.js";
|
|
10
11
|
import { getUserApiUrl, updateApiURLTask } from "../helpers/index.js";
|
|
11
12
|
import {
|
|
12
|
-
|
|
13
|
+
getFlightcontrolConfig,
|
|
13
14
|
databaseEnvVariables,
|
|
14
15
|
postgresDatabaseService,
|
|
15
16
|
mysqlDatabaseService
|
|
16
17
|
} from "../templates/flightcontrol.js";
|
|
17
18
|
const { getConfig } = prismaInternals;
|
|
18
19
|
const getFlightcontrolJson = async (database) => {
|
|
20
|
+
const flightcontrolConfig = getFlightcontrolConfig();
|
|
19
21
|
if (database === "none") {
|
|
20
22
|
return {
|
|
21
23
|
path: path.join(getPaths().base, "flightcontrol.json"),
|
|
@@ -46,18 +48,20 @@ const getFlightcontrolJson = async (database) => {
|
|
|
46
48
|
{
|
|
47
49
|
...flightcontrolConfig.environments[0],
|
|
48
50
|
services: [
|
|
49
|
-
...flightcontrolConfig.environments[0].services.map(
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
51
|
+
...flightcontrolConfig.environments[0].services.map(
|
|
52
|
+
(service) => {
|
|
53
|
+
if (service.id === "cedar-api") {
|
|
54
|
+
return {
|
|
55
|
+
...service,
|
|
56
|
+
envVariables: {
|
|
57
|
+
...service.envVariables,
|
|
58
|
+
...databaseEnvVariables
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
return service;
|
|
58
63
|
}
|
|
59
|
-
|
|
60
|
-
}),
|
|
64
|
+
),
|
|
61
65
|
dbService
|
|
62
66
|
]
|
|
63
67
|
}
|
|
@@ -69,15 +73,15 @@ const getFlightcontrolJson = async (database) => {
|
|
|
69
73
|
Prisma datasource provider is detected to be ${detectedDatabase}.
|
|
70
74
|
|
|
71
75
|
Update your schema.prisma provider to be postgresql or mysql, then run
|
|
72
|
-
|
|
73
|
-
|
|
76
|
+
${formatCedarCommand(["prisma", "migrate", "dev"])}
|
|
77
|
+
${formatCedarCommand(["setup", "deploy", "flightcontrol"])}
|
|
74
78
|
`);
|
|
75
79
|
}
|
|
76
80
|
};
|
|
77
81
|
const updateGraphQLFunction = () => {
|
|
78
82
|
return {
|
|
79
83
|
title: "Adding CORS config to createGraphQLHandler...",
|
|
80
|
-
task: (
|
|
84
|
+
task: () => {
|
|
81
85
|
const graphqlTsPath = path.join(
|
|
82
86
|
getPaths().base,
|
|
83
87
|
"api/src/functions/graphql.ts"
|
|
@@ -125,7 +129,7 @@ const updateGraphQLFunction = () => {
|
|
|
125
129
|
const updateDbAuth = () => {
|
|
126
130
|
return {
|
|
127
131
|
title: "Updating dbAuth cookie config (if used)...",
|
|
128
|
-
task: (
|
|
132
|
+
task: () => {
|
|
129
133
|
const authTsPath = path.join(getPaths().base, "api/src/functions/auth.ts");
|
|
130
134
|
const authJsPath = path.join(getPaths().base, "api/src/functions/auth.js");
|
|
131
135
|
let authFnPath;
|
|
@@ -174,7 +178,7 @@ const updateDbAuth = () => {
|
|
|
174
178
|
const updateApp = () => {
|
|
175
179
|
return {
|
|
176
180
|
title: "Updating App.jsx fetch config...",
|
|
177
|
-
task: (
|
|
181
|
+
task: () => {
|
|
178
182
|
const appTsPath = path.join(getPaths().base, "web/src/App.tsx");
|
|
179
183
|
const appJsPath = path.join(getPaths().base, "web/src/App.jsx");
|
|
180
184
|
let appPath;
|
|
@@ -232,8 +236,9 @@ const addToDotEnvDefaultTask = () => {
|
|
|
232
236
|
CEDAR_API_URL=${getUserApiUrl()}
|
|
233
237
|
`;
|
|
234
238
|
}
|
|
239
|
+
return void 0;
|
|
235
240
|
},
|
|
236
|
-
task: async (
|
|
241
|
+
task: async () => {
|
|
237
242
|
const env = path.resolve(getPaths().base, ".env.defaults");
|
|
238
243
|
const apiUrl = getUserApiUrl();
|
|
239
244
|
const line = `
|
|
@@ -250,7 +255,10 @@ const notes = [
|
|
|
250
255
|
"Check out the deployment docs at https://app.flightcontrol.dev/docs for detailed instructions\n",
|
|
251
256
|
"NOTE: If you are using yarn v1, remove the installCommand's from flightcontrol.json"
|
|
252
257
|
];
|
|
253
|
-
const handler = async ({
|
|
258
|
+
const handler = async ({
|
|
259
|
+
force,
|
|
260
|
+
database
|
|
261
|
+
}) => {
|
|
254
262
|
recordTelemetryAttributes({
|
|
255
263
|
command: "setup deploy flightcontrol",
|
|
256
264
|
force,
|
|
@@ -262,7 +270,7 @@ const handler = async ({ force, database }) => {
|
|
|
262
270
|
title: "Adding flightcontrol.json",
|
|
263
271
|
task: async () => {
|
|
264
272
|
const fileData = await getFlightcontrolJson(database);
|
|
265
|
-
|
|
273
|
+
const files = {};
|
|
266
274
|
files[fileData.path] = JSON.stringify(fileData.content, null, 2);
|
|
267
275
|
return writeFilesTask(files, { overwriteExisting: force });
|
|
268
276
|
}
|
|
@@ -279,9 +287,11 @@ const handler = async ({ force, database }) => {
|
|
|
279
287
|
try {
|
|
280
288
|
await tasks.run();
|
|
281
289
|
} catch (e) {
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
290
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
291
|
+
errorTelemetry(process.argv, message);
|
|
292
|
+
console.error(c.error(message));
|
|
293
|
+
const exitCode = e instanceof Error && "exitCode" in e && typeof e.exitCode === "number" ? e.exitCode : 1;
|
|
294
|
+
process.exit(exitCode);
|
|
285
295
|
}
|
|
286
296
|
};
|
|
287
297
|
export {
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import { createHandler } from "../helpers/helpers.js";
|
|
2
2
|
const command = "netlify";
|
|
3
3
|
const description = "Setup Netlify deploy";
|
|
4
|
+
const builder = (yargs) => yargs.option("ud", {
|
|
5
|
+
description: "Setup for use with Universal Deploy",
|
|
6
|
+
type: "boolean",
|
|
7
|
+
default: false
|
|
8
|
+
});
|
|
4
9
|
const handler = createHandler("netlify");
|
|
5
10
|
export {
|
|
11
|
+
builder,
|
|
6
12
|
command,
|
|
7
13
|
description,
|
|
8
14
|
handler
|