@cedarjs/cli 5.0.0-canary.2375 → 5.0.0-canary.2376
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.
|
@@ -7,8 +7,9 @@ import * as setupDeployFlightcontrol from "./providers/flightcontrol.js";
|
|
|
7
7
|
import * as setupDeployNetlify from "./providers/netlify.js";
|
|
8
8
|
import * as setupDeployRender from "./providers/render.js";
|
|
9
9
|
import * as setupDeployServerless from "./providers/serverless.js";
|
|
10
|
+
import * as setupDeployUniversalDeploy from "./providers/universal-deploy.js";
|
|
10
11
|
import * as setupDeployVercel from "./providers/vercel.js";
|
|
11
|
-
const builder = (yargs) => yargs.command(setupDeployBaremetal).command(setupDeployCoherence).command(setupDeployFlightcontrol).command(setupDeployNetlify).command(setupDeployRender).command(setupDeployServerless).command(setupDeployVercel).demandCommand().option("force", {
|
|
12
|
+
const builder = (yargs) => yargs.command(setupDeployBaremetal).command(setupDeployCoherence).command(setupDeployFlightcontrol).command(setupDeployNetlify).command(setupDeployRender).command(setupDeployServerless).command(setupDeployUniversalDeploy).command(setupDeployVercel).demandCommand().option("force", {
|
|
12
13
|
alias: "f",
|
|
13
14
|
default: false,
|
|
14
15
|
description: "Overwrite existing configuration",
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const command = "universal-deploy";
|
|
2
|
+
const description = "Setup Universal Deploy";
|
|
3
|
+
async function handler() {
|
|
4
|
+
const { handler: handler2 } = await import("./universalDeployHandler.js");
|
|
5
|
+
return handler2();
|
|
6
|
+
}
|
|
7
|
+
export {
|
|
8
|
+
command,
|
|
9
|
+
description,
|
|
10
|
+
handler
|
|
11
|
+
};
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { Listr } from "listr2";
|
|
4
|
+
import {
|
|
5
|
+
colors as c,
|
|
6
|
+
getPaths,
|
|
7
|
+
isTypeScriptProject,
|
|
8
|
+
recordTelemetryAttributes
|
|
9
|
+
} from "@cedarjs/cli-helpers";
|
|
10
|
+
import { errorTelemetry } from "@cedarjs/telemetry";
|
|
11
|
+
import { printSetupNotes } from "../../../../lib/index.js";
|
|
12
|
+
const notes = [
|
|
13
|
+
"Universal Deploy is set up!",
|
|
14
|
+
"",
|
|
15
|
+
"Next steps:",
|
|
16
|
+
` ${c.highlight("yarn cedar build --ud")} \u2014 build the Universal Deploy server entry`,
|
|
17
|
+
` ${c.highlight("yarn cedar serve --ud")} \u2014 serve it locally`
|
|
18
|
+
];
|
|
19
|
+
async function handler() {
|
|
20
|
+
recordTelemetryAttributes({
|
|
21
|
+
command: "setup deploy universal-deploy"
|
|
22
|
+
});
|
|
23
|
+
const tasks = new Listr(
|
|
24
|
+
[addUniversalDeployPluginToViteConfig(), printSetupNotes(notes)],
|
|
25
|
+
{ rendererOptions: { collapseSubtasks: false } }
|
|
26
|
+
);
|
|
27
|
+
try {
|
|
28
|
+
await tasks.run();
|
|
29
|
+
} catch (e) {
|
|
30
|
+
errorTelemetry(process.argv, e.message);
|
|
31
|
+
console.error(c.error(e.message));
|
|
32
|
+
process.exit(e.exitCode || 1);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function addUniversalDeployPluginToViteConfig() {
|
|
36
|
+
return {
|
|
37
|
+
title: "Adding cedarUniversalDeployPlugin to vite config...",
|
|
38
|
+
task: async (_ctx, task) => {
|
|
39
|
+
const projectIsTS = isTypeScriptProject();
|
|
40
|
+
const viteConfigPath = path.join(
|
|
41
|
+
getPaths().web.base,
|
|
42
|
+
`vite.config.${projectIsTS ? "ts" : "js"}`
|
|
43
|
+
);
|
|
44
|
+
if (!fs.existsSync(viteConfigPath)) {
|
|
45
|
+
task.skip(`${viteConfigPath} not found`);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
let content = fs.readFileSync(viteConfigPath, "utf-8");
|
|
49
|
+
if (content.includes("cedarUniversalDeployPlugin")) {
|
|
50
|
+
task.skip("cedarUniversalDeployPlugin is already configured.");
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
content = mergeImport(content);
|
|
54
|
+
content = addPluginToConfig(content);
|
|
55
|
+
fs.writeFileSync(viteConfigPath, content);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function findCedarViteImportLine(lines) {
|
|
60
|
+
for (let i = 0; i < lines.length; i++) {
|
|
61
|
+
if (/^import\b/.test(lines[i]) && /from\s+['"]@cedarjs\/vite['"]/.test(lines[i])) {
|
|
62
|
+
return i;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
for (let i = 0; i < lines.length; i++) {
|
|
66
|
+
if (/from\s+['"]@cedarjs\/vite['"]/.test(lines[i])) {
|
|
67
|
+
for (let j = i; j >= 0; j--) {
|
|
68
|
+
if (/^import\b/.test(lines[j])) {
|
|
69
|
+
return j;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return i;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return -1;
|
|
76
|
+
}
|
|
77
|
+
function mergeImport(content) {
|
|
78
|
+
const lines = content.split("\n");
|
|
79
|
+
const importIndex = findCedarViteImportLine(lines);
|
|
80
|
+
if (importIndex === -1) {
|
|
81
|
+
throw new Error("No import from @cedarjs/vite found");
|
|
82
|
+
}
|
|
83
|
+
const importLine = lines[importIndex];
|
|
84
|
+
const singleLineNamed = importLine.match(
|
|
85
|
+
/^(import\s*\{\s*)([^}]*?)(\s*\}\s*from\s+['"]@cedarjs\/vite['"];?)$/
|
|
86
|
+
);
|
|
87
|
+
if (singleLineNamed) {
|
|
88
|
+
const specifiers = singleLineNamed[2].trim();
|
|
89
|
+
if (specifiers.includes("cedarUniversalDeployPlugin")) {
|
|
90
|
+
return content;
|
|
91
|
+
}
|
|
92
|
+
lines[importIndex] = specifiers ? `${singleLineNamed[1]}${specifiers}, cedarUniversalDeployPlugin${singleLineNamed[3]}` : `${singleLineNamed[1]}cedarUniversalDeployPlugin${singleLineNamed[3]}`;
|
|
93
|
+
return lines.join("\n");
|
|
94
|
+
}
|
|
95
|
+
let closeIndex = importIndex;
|
|
96
|
+
for (let i = importIndex + 1; i < lines.length; i++) {
|
|
97
|
+
if (/}\s*from\s+['"]@cedarjs\/vite['"]/.test(lines[i])) {
|
|
98
|
+
closeIndex = i;
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (closeIndex > importIndex) {
|
|
103
|
+
const specifiersLines = lines.slice(importIndex + 1, closeIndex);
|
|
104
|
+
const allSpecifiers = specifiersLines.join(" ");
|
|
105
|
+
if (allSpecifiers.includes("cedarUniversalDeployPlugin")) {
|
|
106
|
+
return content;
|
|
107
|
+
}
|
|
108
|
+
const indentMatch = specifiersLines[0]?.match(/^(\s+)/);
|
|
109
|
+
const indent = indentMatch?.[1] || " ";
|
|
110
|
+
lines.splice(closeIndex, 0, `${indent}cedarUniversalDeployPlugin,`);
|
|
111
|
+
return lines.join("\n");
|
|
112
|
+
}
|
|
113
|
+
const defaultMatch = importLine.match(
|
|
114
|
+
/^import\s+(\w+)\s+from\s+['"]@cedarjs\/vite['"];?\s*$/
|
|
115
|
+
);
|
|
116
|
+
if (defaultMatch) {
|
|
117
|
+
lines[importIndex] = importLine.replace(
|
|
118
|
+
/(import\s+\w+)(\s+from\s+['"]@cedarjs\/vite['"];?)/,
|
|
119
|
+
"$1, { cedarUniversalDeployPlugin }$2"
|
|
120
|
+
);
|
|
121
|
+
return lines.join("\n");
|
|
122
|
+
}
|
|
123
|
+
return content;
|
|
124
|
+
}
|
|
125
|
+
function addPluginToConfig(content) {
|
|
126
|
+
const lines = content.split("\n");
|
|
127
|
+
const pluginsLineIndex = lines.findIndex(
|
|
128
|
+
(line) => /plugins\s*:\s*\[/.test(line)
|
|
129
|
+
);
|
|
130
|
+
if (pluginsLineIndex === -1) {
|
|
131
|
+
return content;
|
|
132
|
+
}
|
|
133
|
+
const pluginsLine = lines[pluginsLineIndex];
|
|
134
|
+
const inlineMatch = pluginsLine.trim().match(/^plugins\s*:\s*\[([\s\S]*?)\]\s*,?\s*$/);
|
|
135
|
+
if (inlineMatch) {
|
|
136
|
+
const inner = inlineMatch[1].trimEnd();
|
|
137
|
+
const indentation = pluginsLine.match(/^\s*/)?.[0] || " ";
|
|
138
|
+
lines[pluginsLineIndex] = inner ? `${indentation}plugins: [${inner}, cedarUniversalDeployPlugin()],` : `${indentation}plugins: [cedarUniversalDeployPlugin()],`;
|
|
139
|
+
return lines.join("\n");
|
|
140
|
+
}
|
|
141
|
+
let closeIndex = -1;
|
|
142
|
+
for (let i = pluginsLineIndex + 1; i < lines.length; i++) {
|
|
143
|
+
const trimmed = lines[i].trim();
|
|
144
|
+
if (trimmed === "]" || trimmed === "],") {
|
|
145
|
+
closeIndex = i;
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
if (closeIndex === -1) {
|
|
150
|
+
return content;
|
|
151
|
+
}
|
|
152
|
+
const pluginsLineIndent = pluginsLine.match(/^\s*/)?.[0] || "";
|
|
153
|
+
const firstEntryIndent = (() => {
|
|
154
|
+
for (let i = pluginsLineIndex + 1; i < closeIndex; i++) {
|
|
155
|
+
const trimmed = lines[i].trim();
|
|
156
|
+
if (trimmed) {
|
|
157
|
+
return lines[i].match(/^\s*/)?.[0] || " ";
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return pluginsLineIndent + " ";
|
|
161
|
+
})();
|
|
162
|
+
const prevLine = lines[closeIndex - 1]?.trimEnd();
|
|
163
|
+
if (prevLine && !prevLine.endsWith(",") && prevLine !== "[" && !prevLine.endsWith("[")) {
|
|
164
|
+
const commentIdx = prevLine.search(/\s+\/\/|(?<!\\)\/\*/);
|
|
165
|
+
if (commentIdx !== -1) {
|
|
166
|
+
lines[closeIndex - 1] = prevLine.slice(0, commentIdx) + "," + prevLine.slice(commentIdx);
|
|
167
|
+
} else {
|
|
168
|
+
lines[closeIndex - 1] = prevLine + ",";
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
lines.splice(
|
|
172
|
+
closeIndex,
|
|
173
|
+
0,
|
|
174
|
+
`${firstEntryIndent}cedarUniversalDeployPlugin(),`
|
|
175
|
+
);
|
|
176
|
+
return lines.join("\n");
|
|
177
|
+
}
|
|
178
|
+
export {
|
|
179
|
+
addPluginToConfig,
|
|
180
|
+
handler,
|
|
181
|
+
mergeImport
|
|
182
|
+
};
|
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.2376",
|
|
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.2376",
|
|
37
|
+
"@cedarjs/cli-helpers": "5.0.0-canary.2376",
|
|
38
|
+
"@cedarjs/fastify-web": "5.0.0-canary.2376",
|
|
39
|
+
"@cedarjs/internal": "5.0.0-canary.2376",
|
|
40
|
+
"@cedarjs/prerender": "5.0.0-canary.2376",
|
|
41
|
+
"@cedarjs/project-config": "5.0.0-canary.2376",
|
|
42
|
+
"@cedarjs/structure": "5.0.0-canary.2376",
|
|
43
|
+
"@cedarjs/telemetry": "5.0.0-canary.2376",
|
|
44
|
+
"@cedarjs/utils": "5.0.0-canary.2376",
|
|
45
|
+
"@cedarjs/vite": "5.0.0-canary.2376",
|
|
46
|
+
"@cedarjs/web-server": "5.0.0-canary.2376",
|
|
47
47
|
"@listr2/prompt-adapter-enquirer": "4.2.1",
|
|
48
48
|
"@opentelemetry/api": "1.9.0",
|
|
49
49
|
"@opentelemetry/core": "1.30.1",
|