@cedarjs/cli 5.0.0-canary.2456 → 5.0.0-canary.2458
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/commands/deploy/baremetal/baremetalHandler.js +44 -1
- package/dist/commands/deploy/baremetal.js +7 -1
- package/dist/commands/generate/ogImage/ogImageHandler.js +16 -9
- package/dist/commands/generate/secret/secret.js +2 -2
- package/dist/commands/generate/yargsHandlerHelpers.js +18 -10
- package/dist/lib/rollback.js +2 -2
- package/dist/middleware/checkNodeVersion.js +3 -0
- package/package.json +12 -12
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import boxen from "boxen";
|
|
4
|
+
import execa from "execa";
|
|
4
5
|
import { Listr } from "listr2";
|
|
5
6
|
import * as toml from "smol-toml";
|
|
6
7
|
import { env as envInterpolation } from "string-env-interpolation";
|
|
@@ -490,6 +491,44 @@ const commands = (yargs, ssh) => {
|
|
|
490
491
|
}
|
|
491
492
|
return servers;
|
|
492
493
|
};
|
|
494
|
+
const warnIfUnpushedCommits = async () => {
|
|
495
|
+
try {
|
|
496
|
+
const { stdout } = await execa("git", ["log", "@{u}..", "--oneline"], {
|
|
497
|
+
cwd: getPaths().base
|
|
498
|
+
});
|
|
499
|
+
const unpushedCommits = stdout.trim();
|
|
500
|
+
if (!unpushedCommits) {
|
|
501
|
+
return;
|
|
502
|
+
}
|
|
503
|
+
console.warn(
|
|
504
|
+
c.warning("\nWarning: You have local commits that have not been pushed:")
|
|
505
|
+
);
|
|
506
|
+
console.warn(
|
|
507
|
+
unpushedCommits.split("\n").map((line) => ` ${line}`).join("\n")
|
|
508
|
+
);
|
|
509
|
+
console.warn(
|
|
510
|
+
c.warning(
|
|
511
|
+
"The server will pull from the remote, so these commits will not be deployed.\n"
|
|
512
|
+
)
|
|
513
|
+
);
|
|
514
|
+
const { default: prompts } = await import("prompts");
|
|
515
|
+
const { confirmed } = await prompts({
|
|
516
|
+
type: "confirm",
|
|
517
|
+
name: "confirmed",
|
|
518
|
+
message: "Deploy anyway?",
|
|
519
|
+
initial: false
|
|
520
|
+
});
|
|
521
|
+
if (!confirmed) {
|
|
522
|
+
console.log("Aborting deploy. Push your commits and try again.");
|
|
523
|
+
process.exit(1);
|
|
524
|
+
}
|
|
525
|
+
} catch (e) {
|
|
526
|
+
console.error(
|
|
527
|
+
c.error("\nCould not check for unpushed commits before deploying.")
|
|
528
|
+
);
|
|
529
|
+
throw e;
|
|
530
|
+
}
|
|
531
|
+
};
|
|
493
532
|
const handler = async (yargs) => {
|
|
494
533
|
const { SshExecutor } = await import("./SshExecutor.js");
|
|
495
534
|
const tomlPath = path.join(getPaths().base, "deploy.toml");
|
|
@@ -500,6 +539,9 @@ const handler = async (yargs) => {
|
|
|
500
539
|
);
|
|
501
540
|
process.exit(1);
|
|
502
541
|
}
|
|
542
|
+
if (yargs.gitCheck) {
|
|
543
|
+
await warnIfUnpushedCommits();
|
|
544
|
+
}
|
|
503
545
|
const ssh = new SshExecutor(yargs.verbose);
|
|
504
546
|
try {
|
|
505
547
|
const tasks = new Listr(commands(yargs, ssh), {
|
|
@@ -533,5 +575,6 @@ export {
|
|
|
533
575
|
serverConfigWithDefaults,
|
|
534
576
|
throwMissingConfig,
|
|
535
577
|
verifyConfig,
|
|
536
|
-
verifyServerConfig
|
|
578
|
+
verifyServerConfig,
|
|
579
|
+
warnIfUnpushedCommits
|
|
537
580
|
};
|
|
@@ -71,6 +71,11 @@ const builder = (yargs) => {
|
|
|
71
71
|
default: false,
|
|
72
72
|
type: "boolean"
|
|
73
73
|
});
|
|
74
|
+
yargs.option("git-check", {
|
|
75
|
+
describe: "Check for unpushed commits before deploying",
|
|
76
|
+
default: true,
|
|
77
|
+
type: "boolean"
|
|
78
|
+
});
|
|
74
79
|
yargs.epilogue(
|
|
75
80
|
`Also see the ${terminalLink(
|
|
76
81
|
"Redwood Baremetal Deploy Reference",
|
|
@@ -92,7 +97,8 @@ async function handler(yargs) {
|
|
|
92
97
|
cleanup: yargs.cleanup,
|
|
93
98
|
maintenance: yargs.maintenance,
|
|
94
99
|
rollback: yargs.rollback,
|
|
95
|
-
verbose: yargs.verbose
|
|
100
|
+
verbose: yargs.verbose,
|
|
101
|
+
gitCheck: yargs.gitCheck
|
|
96
102
|
});
|
|
97
103
|
const { handler: baremetalHandler } = await import("./baremetal/baremetalHandler.js");
|
|
98
104
|
return baremetalHandler(yargs);
|
|
@@ -13,7 +13,10 @@ import {
|
|
|
13
13
|
} from "../../../lib/index.js";
|
|
14
14
|
import { prepareForRollback } from "../../../lib/rollback.js";
|
|
15
15
|
import { customOrDefaultTemplatePath } from "../yargsHandlerHelpers.js";
|
|
16
|
-
const files = async ({
|
|
16
|
+
const files = async ({
|
|
17
|
+
pagePath,
|
|
18
|
+
typescript = false
|
|
19
|
+
}) => {
|
|
17
20
|
const extension = typescript ? ".tsx" : ".jsx";
|
|
18
21
|
const componentOutputPath = path.join(
|
|
19
22
|
getPaths().web.pages,
|
|
@@ -73,6 +76,10 @@ const handler = async (options) => {
|
|
|
73
76
|
const extension = options.typescript ? "tsx" : "jsx";
|
|
74
77
|
try {
|
|
75
78
|
await validatePath(normalizedPagePath, extension);
|
|
79
|
+
const listrOptions = {
|
|
80
|
+
exitOnError: true,
|
|
81
|
+
...options.verbose ? { renderer: "verbose" } : { rendererOptions: { collapseSubtasks: false } }
|
|
82
|
+
};
|
|
76
83
|
const tasks = new Listr(
|
|
77
84
|
[
|
|
78
85
|
{
|
|
@@ -86,22 +93,22 @@ const handler = async (options) => {
|
|
|
86
93
|
}
|
|
87
94
|
}
|
|
88
95
|
],
|
|
89
|
-
|
|
90
|
-
rendererOptions: { collapseSubtasks: false },
|
|
91
|
-
exitOnError: true,
|
|
92
|
-
renderer: options.verbose && "verbose"
|
|
93
|
-
}
|
|
96
|
+
listrOptions
|
|
94
97
|
);
|
|
95
98
|
if (options.rollback && !options.force) {
|
|
96
99
|
prepareForRollback(tasks);
|
|
97
100
|
}
|
|
98
101
|
await tasks.run();
|
|
99
102
|
} catch (e) {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
104
|
+
errorTelemetry(process.argv, message);
|
|
105
|
+
console.error(c.error(message));
|
|
106
|
+
process.exit(errorExitCode(e));
|
|
103
107
|
}
|
|
104
108
|
};
|
|
109
|
+
function errorExitCode(e) {
|
|
110
|
+
return typeof e === "object" && e !== null && "exitCode" in e && typeof e.exitCode === "number" ? e.exitCode : 1;
|
|
111
|
+
}
|
|
105
112
|
export {
|
|
106
113
|
files,
|
|
107
114
|
handler,
|
|
@@ -3,13 +3,13 @@ import { terminalLink } from "termi-link";
|
|
|
3
3
|
import { recordTelemetryAttributes } from "@cedarjs/cli-helpers";
|
|
4
4
|
const DEFAULT_LENGTH = 32;
|
|
5
5
|
const generateSecret = (length = DEFAULT_LENGTH) => {
|
|
6
|
-
return crypto.randomBytes(length).toString("base64");
|
|
6
|
+
return crypto.randomBytes(Math.trunc(length)).toString("base64");
|
|
7
7
|
};
|
|
8
8
|
const command = "secret";
|
|
9
9
|
const description = "Generates a secret key using a cryptographically-secure source of entropy";
|
|
10
10
|
const builder = (yargs) => yargs.option("length", {
|
|
11
11
|
description: "Length of the generated secret",
|
|
12
|
-
type: "
|
|
12
|
+
type: "number",
|
|
13
13
|
required: false,
|
|
14
14
|
default: DEFAULT_LENGTH
|
|
15
15
|
}).option("raw", {
|
|
@@ -51,7 +51,11 @@ const templateForFile = async ({
|
|
|
51
51
|
templatePath,
|
|
52
52
|
templateVars
|
|
53
53
|
}) => {
|
|
54
|
-
const
|
|
54
|
+
const sideBase = getPaths()[side];
|
|
55
|
+
const basePath = sidePathSection ? sideBase[sidePathSection] : sideBase;
|
|
56
|
+
if (typeof basePath !== "string") {
|
|
57
|
+
throw new Error(`Invalid path section: "${sidePathSection}"`);
|
|
58
|
+
}
|
|
55
59
|
const fullOutputPath = path.join(basePath, outputPath);
|
|
56
60
|
const fullTemplatePath = customOrDefaultTemplatePath({
|
|
57
61
|
generator,
|
|
@@ -126,6 +130,10 @@ function createHandler({
|
|
|
126
130
|
validateName(argv.name);
|
|
127
131
|
try {
|
|
128
132
|
argv = await preTasksFn(argv);
|
|
133
|
+
const listrOptions = {
|
|
134
|
+
exitOnError: true,
|
|
135
|
+
...argv.verbose ? { renderer: "verbose" } : { rendererOptions: { collapseSubtasks: false } }
|
|
136
|
+
};
|
|
129
137
|
const tasks = new Listr(
|
|
130
138
|
[
|
|
131
139
|
{
|
|
@@ -137,28 +145,28 @@ function createHandler({
|
|
|
137
145
|
},
|
|
138
146
|
...includeAdditionalTasks(argv)
|
|
139
147
|
],
|
|
140
|
-
|
|
141
|
-
rendererOptions: { collapseSubtasks: false },
|
|
142
|
-
exitOnError: true,
|
|
143
|
-
renderer: argv.verbose && "verbose"
|
|
144
|
-
}
|
|
148
|
+
listrOptions
|
|
145
149
|
);
|
|
146
150
|
if (argv.rollback && !argv.force) {
|
|
147
151
|
prepareForRollback(tasks);
|
|
148
152
|
}
|
|
149
153
|
await tasks.run();
|
|
150
154
|
} catch (e) {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
155
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
156
|
+
errorTelemetry(process.argv, message);
|
|
157
|
+
console.error(c.error(message));
|
|
158
|
+
process.exit(errorExitCode(e));
|
|
154
159
|
}
|
|
155
160
|
};
|
|
156
161
|
}
|
|
162
|
+
function errorExitCode(e) {
|
|
163
|
+
return typeof e === "object" && e !== null && "exitCode" in e && typeof e.exitCode === "number" ? e.exitCode : 1;
|
|
164
|
+
}
|
|
157
165
|
const createYargsForComponentGeneration = ({
|
|
158
166
|
componentName,
|
|
159
167
|
preTasksFn = (options) => options,
|
|
160
168
|
/** filesFn is not used if generator implements its own `handler` */
|
|
161
|
-
filesFn = () => ({}),
|
|
169
|
+
filesFn = async () => ({}),
|
|
162
170
|
optionsObj,
|
|
163
171
|
positionalsObj = {},
|
|
164
172
|
/** function that takes the options object and returns an array of listr tasks */
|
package/dist/lib/rollback.js
CHANGED
|
@@ -21,7 +21,7 @@ function addFileToRollback(filePath, atEnd = false) {
|
|
|
21
21
|
rollback.push(step);
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
-
|
|
24
|
+
const executeRollback = async (_, task) => {
|
|
25
25
|
if (task) {
|
|
26
26
|
task.title = "Reverting generator actions...";
|
|
27
27
|
}
|
|
@@ -53,7 +53,7 @@ async function executeRollback(_ = null, task = null) {
|
|
|
53
53
|
if (task) {
|
|
54
54
|
task.title = `Reverted because: ${task.task.message?.error ?? "unknown error"}`;
|
|
55
55
|
}
|
|
56
|
-
}
|
|
56
|
+
};
|
|
57
57
|
function resetRollback() {
|
|
58
58
|
rollback.length = 0;
|
|
59
59
|
}
|
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.2458",
|
|
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.2458",
|
|
37
|
+
"@cedarjs/cli-helpers": "5.0.0-canary.2458",
|
|
38
|
+
"@cedarjs/fastify-web": "5.0.0-canary.2458",
|
|
39
|
+
"@cedarjs/internal": "5.0.0-canary.2458",
|
|
40
|
+
"@cedarjs/prerender": "5.0.0-canary.2458",
|
|
41
|
+
"@cedarjs/project-config": "5.0.0-canary.2458",
|
|
42
|
+
"@cedarjs/structure": "5.0.0-canary.2458",
|
|
43
|
+
"@cedarjs/telemetry": "5.0.0-canary.2458",
|
|
44
|
+
"@cedarjs/utils": "5.0.0-canary.2458",
|
|
45
|
+
"@cedarjs/vite": "5.0.0-canary.2458",
|
|
46
|
+
"@cedarjs/web-server": "5.0.0-canary.2458",
|
|
47
47
|
"@listr2/prompt-adapter-enquirer": "4.2.1",
|
|
48
48
|
"@opentelemetry/api": "1.9.1",
|
|
49
49
|
"@opentelemetry/core": "1.30.1",
|