@cedarjs/cli 4.2.1-next.0 → 4.2.1-next.258
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 -12
- 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
|
@@ -13,18 +13,18 @@ import {
|
|
|
13
13
|
EXPERIMENTAL_TOPIC_ID
|
|
14
14
|
} from "./setupStreamingSsr.js";
|
|
15
15
|
import { printTaskEpilogue } from "./util.js";
|
|
16
|
-
const handler = async (
|
|
17
|
-
const
|
|
16
|
+
const handler = async (options) => {
|
|
17
|
+
const cedarPaths = getPaths();
|
|
18
18
|
const configPath = getConfigPath();
|
|
19
19
|
const configContent = fs.readFileSync(configPath, "utf-8");
|
|
20
20
|
const ts = isTypeScriptProject();
|
|
21
|
-
const ext = path.extname(
|
|
22
|
-
|
|
23
|
-
[
|
|
21
|
+
const ext = path.extname(cedarPaths.web.entryClient || "");
|
|
22
|
+
function buildTaskData() {
|
|
23
|
+
return [
|
|
24
24
|
{
|
|
25
25
|
title: "Check prerequisites",
|
|
26
26
|
task: () => {
|
|
27
|
-
if (!
|
|
27
|
+
if (!cedarPaths.web.entryClient || !cedarPaths.web.viteConfig) {
|
|
28
28
|
throw new Error(
|
|
29
29
|
"Vite needs to be setup before you can enable Streaming SSR"
|
|
30
30
|
);
|
|
@@ -49,7 +49,7 @@ const handler = async ({ force, verbose }) => {
|
|
|
49
49
|
}
|
|
50
50
|
);
|
|
51
51
|
} else {
|
|
52
|
-
if (force) {
|
|
52
|
+
if (options.force) {
|
|
53
53
|
task.output = "Overwriting config in cedar.toml";
|
|
54
54
|
writeFile(
|
|
55
55
|
configPath,
|
|
@@ -75,8 +75,7 @@ const handler = async ({ force, verbose }) => {
|
|
|
75
75
|
);
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
|
-
}
|
|
79
|
-
rendererOptions: { persistentOutput: true }
|
|
78
|
+
}
|
|
80
79
|
},
|
|
81
80
|
{
|
|
82
81
|
title: `Adding entry.client${ext}...`,
|
|
@@ -90,10 +89,13 @@ const handler = async ({ force, verbose }) => {
|
|
|
90
89
|
),
|
|
91
90
|
"utf-8"
|
|
92
91
|
);
|
|
93
|
-
let entryClientPath =
|
|
92
|
+
let entryClientPath = cedarPaths.web.entryClient;
|
|
93
|
+
if (!entryClientPath) {
|
|
94
|
+
throw new Error("entryClient is not set");
|
|
95
|
+
}
|
|
94
96
|
const entryClientContent = ts ? entryClientTemplate : await transformTSToJS(entryClientPath, entryClientTemplate);
|
|
95
|
-
let overwriteExisting = force;
|
|
96
|
-
if (!force) {
|
|
97
|
+
let overwriteExisting = options.force;
|
|
98
|
+
if (!options.force) {
|
|
97
99
|
const prompt = task.prompt(ListrEnquirerPromptAdapter);
|
|
98
100
|
overwriteExisting = await prompt.run({
|
|
99
101
|
type: "Confirm",
|
|
@@ -106,8 +108,7 @@ You'll manually need to merge it with your existing entry.client${ext} file.`;
|
|
|
106
108
|
}
|
|
107
109
|
}
|
|
108
110
|
writeFile(entryClientPath, entryClientContent, { overwriteExisting });
|
|
109
|
-
}
|
|
110
|
-
rendererOptions: { persistentOutput: true }
|
|
111
|
+
}
|
|
111
112
|
},
|
|
112
113
|
{
|
|
113
114
|
title: `Adding entry.server${ext}...`,
|
|
@@ -122,12 +123,12 @@ You'll manually need to merge it with your existing entry.client${ext} file.`;
|
|
|
122
123
|
"utf-8"
|
|
123
124
|
);
|
|
124
125
|
const entryServerPath = path.join(
|
|
125
|
-
|
|
126
|
+
cedarPaths.web.src,
|
|
126
127
|
`entry.server${ext}`
|
|
127
128
|
);
|
|
128
129
|
const entryServerContent = ts ? entryServerTemplate : await transformTSToJS(entryServerPath, entryServerTemplate);
|
|
129
130
|
writeFile(entryServerPath, entryServerContent, {
|
|
130
|
-
overwriteExisting: force
|
|
131
|
+
overwriteExisting: options.force
|
|
131
132
|
});
|
|
132
133
|
}
|
|
133
134
|
},
|
|
@@ -143,10 +144,10 @@ You'll manually need to merge it with your existing entry.client${ext} file.`;
|
|
|
143
144
|
),
|
|
144
145
|
"utf-8"
|
|
145
146
|
);
|
|
146
|
-
const documentPath = path.join(
|
|
147
|
+
const documentPath = path.join(cedarPaths.web.src, `Document${ext}`);
|
|
147
148
|
const documentContent = ts ? documentTemplate : await transformTSToJS(documentPath, documentTemplate);
|
|
148
149
|
writeFile(documentPath, documentContent, {
|
|
149
|
-
overwriteExisting: force
|
|
150
|
+
overwriteExisting: options.force
|
|
150
151
|
});
|
|
151
152
|
}
|
|
152
153
|
},
|
|
@@ -163,18 +164,18 @@ You'll manually need to merge it with your existing entry.client${ext} file.`;
|
|
|
163
164
|
"utf-8"
|
|
164
165
|
);
|
|
165
166
|
const tsconfigPath = path.join(
|
|
166
|
-
|
|
167
|
+
cedarPaths.web.base,
|
|
167
168
|
ts ? "tsconfig.json" : "jsconfig.json"
|
|
168
169
|
);
|
|
169
170
|
writeFile(tsconfigPath, tsconfigTemplate, {
|
|
170
|
-
overwriteExisting: force
|
|
171
|
+
overwriteExisting: options.force
|
|
171
172
|
});
|
|
172
173
|
}
|
|
173
174
|
},
|
|
174
175
|
{
|
|
175
176
|
title: 'Adding resolution for "@apollo/client-react-streaming/superjson"',
|
|
176
177
|
task: () => {
|
|
177
|
-
const pkgJsonPath = path.join(
|
|
178
|
+
const pkgJsonPath = path.join(cedarPaths.base, "package.json");
|
|
178
179
|
const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, "utf-8"));
|
|
179
180
|
const resolutions = pkgJson.resolutions || {};
|
|
180
181
|
resolutions["@apollo/client-react-streaming/superjson"] = "^1.12.2";
|
|
@@ -188,18 +189,32 @@ You'll manually need to merge it with your existing entry.client${ext} file.`;
|
|
|
188
189
|
printTaskEpilogue(command, description, EXPERIMENTAL_TOPIC_ID);
|
|
189
190
|
}
|
|
190
191
|
}
|
|
191
|
-
]
|
|
192
|
-
|
|
193
|
-
rendererOptions: { collapseSubtasks: false, persistentOutput: true },
|
|
194
|
-
renderer: verbose ? "verbose" : "default"
|
|
195
|
-
}
|
|
196
|
-
);
|
|
192
|
+
];
|
|
193
|
+
}
|
|
197
194
|
try {
|
|
198
|
-
|
|
195
|
+
if (options.verbose) {
|
|
196
|
+
await new Listr(buildTaskData(), {
|
|
197
|
+
exitOnError: true,
|
|
198
|
+
renderer: "verbose"
|
|
199
|
+
}).run();
|
|
200
|
+
} else {
|
|
201
|
+
await new Listr(
|
|
202
|
+
buildTaskData().map((t) => ({
|
|
203
|
+
...t,
|
|
204
|
+
rendererOptions: { persistentOutput: true }
|
|
205
|
+
})),
|
|
206
|
+
{
|
|
207
|
+
exitOnError: true,
|
|
208
|
+
rendererOptions: { collapseSubtasks: false }
|
|
209
|
+
}
|
|
210
|
+
).run();
|
|
211
|
+
}
|
|
199
212
|
} catch (e) {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
process.
|
|
213
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
214
|
+
const exitCode = e instanceof Error && "exitCode" in e && typeof e.exitCode === "number" ? e.exitCode : 1;
|
|
215
|
+
errorTelemetry(process.argv, message);
|
|
216
|
+
console.error(c.error(message));
|
|
217
|
+
process.exit(exitCode);
|
|
203
218
|
}
|
|
204
219
|
};
|
|
205
220
|
export {
|
|
@@ -4,29 +4,29 @@ import App from './App'
|
|
|
4
4
|
import Routes from './Routes'
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* When `#
|
|
7
|
+
* When `#cedar-app` isn't empty then it's very likely that you're using
|
|
8
8
|
* pre-rendering. So React attaches event listeners to the existing markup
|
|
9
9
|
* rather than replacing it.
|
|
10
10
|
* https://react.dev/reference/react-dom/client/hydrateRoot
|
|
11
11
|
*/
|
|
12
|
-
const
|
|
12
|
+
const cedarAppElement = document.getElementById('cedar-app')
|
|
13
13
|
|
|
14
|
-
if (!
|
|
14
|
+
if (!cedarAppElement) {
|
|
15
15
|
throw new Error(
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
'Could not find an element with ID "cedar-app". Please ensure it exists ' +
|
|
17
|
+
'in your `web/index.html` file.'
|
|
18
18
|
)
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
if (
|
|
21
|
+
if (cedarAppElement.children?.length > 0) {
|
|
22
22
|
hydrateRoot(
|
|
23
|
-
|
|
23
|
+
cedarAppElement,
|
|
24
24
|
<App>
|
|
25
25
|
<Routes />
|
|
26
26
|
</App>
|
|
27
27
|
)
|
|
28
28
|
} else {
|
|
29
|
-
const root = createRoot(
|
|
29
|
+
const root = createRoot(cedarAppElement)
|
|
30
30
|
root.render(
|
|
31
31
|
<App>
|
|
32
32
|
<Routes />
|
|
@@ -5,21 +5,21 @@ import { Document } from './Document'
|
|
|
5
5
|
import Routes from './Routes'
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* When `#
|
|
8
|
+
* When `#cedar-app` isn't empty then it's very likely that you're using
|
|
9
9
|
* prerendering. So React attaches event listeners to the existing markup
|
|
10
10
|
* rather than replacing it.
|
|
11
11
|
* https://react.dev/reference/react-dom/client/hydrateRoot
|
|
12
12
|
*/
|
|
13
|
-
const
|
|
13
|
+
const cedarAppElement = document.getElementById('cedar-app')
|
|
14
14
|
|
|
15
|
-
if (!
|
|
15
|
+
if (!cedarAppElement) {
|
|
16
16
|
throw new Error(
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
'Could not find an element with ID "cedar-app". Please ensure it exists ' +
|
|
18
|
+
'in your `web/index.html` file.'
|
|
19
19
|
)
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
if (
|
|
22
|
+
if (cedarAppElement.children?.length > 0) {
|
|
23
23
|
hydrateRoot(
|
|
24
24
|
document,
|
|
25
25
|
<Document css={window.__assetMap?.()?.css}>
|
|
@@ -2,6 +2,7 @@ import fs from "node:fs";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import ansis from "ansis";
|
|
4
4
|
import { terminalLink } from "termi-link";
|
|
5
|
+
import { formatCedarCommand } from "@cedarjs/cli-helpers/packageManager/display";
|
|
5
6
|
import { getPaths } from "../../lib/index.js";
|
|
6
7
|
import { isTypeScriptProject, serverFileExists } from "../../lib/project.js";
|
|
7
8
|
function link(topicId, isTerminal = false) {
|
|
@@ -41,7 +42,7 @@ function printTaskEpilogue(command, description, topicId) {
|
|
|
41
42
|
const isServerFileSetup = () => {
|
|
42
43
|
if (!serverFileExists()) {
|
|
43
44
|
throw new Error(
|
|
44
|
-
|
|
45
|
+
`CedarJS Realtime requires a serverful environment. Please run \`${formatCedarCommand(["setup", "server-file"])}\` first.`
|
|
45
46
|
);
|
|
46
47
|
}
|
|
47
48
|
return true;
|
|
@@ -56,7 +57,7 @@ const realtimeExists = () => {
|
|
|
56
57
|
const isRealtimeSetup = () => {
|
|
57
58
|
if (!realtimeExists()) {
|
|
58
59
|
throw new Error(
|
|
59
|
-
|
|
60
|
+
`Adding realtime events requires that CedarJS Realtime is setup. Please run \`${formatCedarCommand(["setup", "realtime"])}\` first.`
|
|
60
61
|
);
|
|
61
62
|
}
|
|
62
63
|
return true;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import pascalcase from "pascalcase";
|
|
2
|
+
import { formatCedarCommand } from "@cedarjs/cli-helpers/packageManager/display";
|
|
2
3
|
import { generate as generateTypes } from "@cedarjs/internal/dist/generate/generate";
|
|
3
4
|
import { isPlural, singularize } from "@cedarjs/utils/cedarPluralize";
|
|
4
|
-
import { nameVariants,
|
|
5
|
+
import { nameVariants, transformTSToJSMap } from "../../../lib/index.js";
|
|
5
6
|
import { isWordPluralizable } from "../../../lib/pluralHelpers.js";
|
|
6
7
|
import { addFunctionToRollback } from "../../../lib/rollback.js";
|
|
7
8
|
import { getSchema } from "../../../lib/schemaHelpers.js";
|
|
@@ -18,8 +19,15 @@ import {
|
|
|
18
19
|
uniqueOperationName
|
|
19
20
|
} from "./utils/utils.js";
|
|
20
21
|
const COMPONENT_SUFFIX = "Cell";
|
|
21
|
-
const
|
|
22
|
-
const files = async ({
|
|
22
|
+
const CEDAR_WEB_PATH_NAME = "components";
|
|
23
|
+
const files = async ({
|
|
24
|
+
name,
|
|
25
|
+
typescript = false,
|
|
26
|
+
list = false,
|
|
27
|
+
query,
|
|
28
|
+
stories,
|
|
29
|
+
tests
|
|
30
|
+
}) => {
|
|
23
31
|
let cellName = removeGeneratorName(name, "cell");
|
|
24
32
|
let idName = "id";
|
|
25
33
|
let idType;
|
|
@@ -27,7 +35,7 @@ const files = async ({ name, typescript, ...argv }) => {
|
|
|
27
35
|
let model = null;
|
|
28
36
|
let templateNameSuffix = "";
|
|
29
37
|
let typeName = cellName;
|
|
30
|
-
const shouldGenerateList = (isWordPluralizable(cellName) ? isPlural(cellName) :
|
|
38
|
+
const shouldGenerateList = (isWordPluralizable(cellName) ? isPlural(cellName) : list) || list;
|
|
31
39
|
try {
|
|
32
40
|
model = await getSchema(pascalcase(singularize(cellName)));
|
|
33
41
|
idName = getIdName(model);
|
|
@@ -41,7 +49,7 @@ const files = async ({ name, typescript, ...argv }) => {
|
|
|
41
49
|
cellName = forcePluralizeWord(cellName);
|
|
42
50
|
templateNameSuffix = "List";
|
|
43
51
|
}
|
|
44
|
-
let operationName =
|
|
52
|
+
let operationName = query;
|
|
45
53
|
if (operationName) {
|
|
46
54
|
const userSpecifiedOperationNameIsUnique = await operationNameIsUnique(operationName);
|
|
47
55
|
if (!userSpecifiedOperationNameIsUnique) {
|
|
@@ -57,7 +65,7 @@ const files = async ({ name, typescript, ...argv }) => {
|
|
|
57
65
|
name: cellName,
|
|
58
66
|
suffix: COMPONENT_SUFFIX,
|
|
59
67
|
extension,
|
|
60
|
-
webPathSection:
|
|
68
|
+
webPathSection: CEDAR_WEB_PATH_NAME,
|
|
61
69
|
generator: "cell",
|
|
62
70
|
templatePath: `cell${templateNameSuffix}.tsx.template`,
|
|
63
71
|
templateVars: {
|
|
@@ -70,7 +78,7 @@ const files = async ({ name, typescript, ...argv }) => {
|
|
|
70
78
|
name: cellName,
|
|
71
79
|
suffix: COMPONENT_SUFFIX,
|
|
72
80
|
extension: `.test${extension}`,
|
|
73
|
-
webPathSection:
|
|
81
|
+
webPathSection: CEDAR_WEB_PATH_NAME,
|
|
74
82
|
generator: "cell",
|
|
75
83
|
templatePath: "test.js.template",
|
|
76
84
|
templateVars: {
|
|
@@ -82,7 +90,7 @@ const files = async ({ name, typescript, ...argv }) => {
|
|
|
82
90
|
name: cellName,
|
|
83
91
|
suffix: COMPONENT_SUFFIX,
|
|
84
92
|
extension: `.stories${extension}`,
|
|
85
|
-
webPathSection:
|
|
93
|
+
webPathSection: CEDAR_WEB_PATH_NAME,
|
|
86
94
|
generator: "cell",
|
|
87
95
|
templatePath: "stories.tsx.template"
|
|
88
96
|
});
|
|
@@ -90,7 +98,7 @@ const files = async ({ name, typescript, ...argv }) => {
|
|
|
90
98
|
name: cellName,
|
|
91
99
|
suffix: COMPONENT_SUFFIX,
|
|
92
100
|
extension: typescript ? ".mock.ts" : ".mock.js",
|
|
93
|
-
webPathSection:
|
|
101
|
+
webPathSection: CEDAR_WEB_PATH_NAME,
|
|
94
102
|
generator: "cell",
|
|
95
103
|
templatePath: `mock${templateNameSuffix}.ts.template`,
|
|
96
104
|
templateVars: {
|
|
@@ -100,23 +108,16 @@ const files = async ({ name, typescript, ...argv }) => {
|
|
|
100
108
|
}
|
|
101
109
|
});
|
|
102
110
|
const files2 = [cellFile];
|
|
103
|
-
if (
|
|
111
|
+
if (stories) {
|
|
104
112
|
files2.push(storiesFile);
|
|
105
113
|
}
|
|
106
|
-
if (
|
|
114
|
+
if (tests) {
|
|
107
115
|
files2.push(testFile);
|
|
108
116
|
}
|
|
109
|
-
if (
|
|
117
|
+
if (stories || tests) {
|
|
110
118
|
files2.push(mockFile);
|
|
111
119
|
}
|
|
112
|
-
return files2
|
|
113
|
-
const acc = await accP;
|
|
114
|
-
const template = typescript ? content : await transformTSToJS(outputPath, content);
|
|
115
|
-
return {
|
|
116
|
-
[outputPath]: template,
|
|
117
|
-
...acc
|
|
118
|
-
};
|
|
119
|
-
}, Promise.resolve({}));
|
|
120
|
+
return transformTSToJSMap(files2, typescript);
|
|
120
121
|
};
|
|
121
122
|
const handler = createHandler({
|
|
122
123
|
componentName: "cell",
|
|
@@ -141,7 +142,7 @@ const handler = createHandler({
|
|
|
141
142
|
addFunctionToRollback(generateTypes, true);
|
|
142
143
|
} else {
|
|
143
144
|
task.skip(
|
|
144
|
-
`Skipping type generation: no SDL defined for "${queryFieldName}". To generate types, run '
|
|
145
|
+
`Skipping type generation: no SDL defined for "${queryFieldName}". To generate types, run '${formatCedarCommand(["generate", "sdl", queryFieldName])}'.`
|
|
145
146
|
);
|
|
146
147
|
}
|
|
147
148
|
}
|
|
@@ -1,14 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { transformTSToJSMap } from "../../../lib/index.js";
|
|
2
2
|
import {
|
|
3
3
|
createHandler,
|
|
4
4
|
templateForComponentFile
|
|
5
5
|
} from "../yargsHandlerHelpers.js";
|
|
6
|
-
const
|
|
7
|
-
const files = async ({
|
|
6
|
+
const CEDAR_WEB_PATH_NAME = "components";
|
|
7
|
+
const files = async ({
|
|
8
|
+
name,
|
|
9
|
+
typescript = false,
|
|
10
|
+
stories,
|
|
11
|
+
tests
|
|
12
|
+
}) => {
|
|
8
13
|
const extension = typescript ? ".tsx" : ".jsx";
|
|
9
14
|
const componentFile = await templateForComponentFile({
|
|
10
15
|
name,
|
|
11
|
-
webPathSection:
|
|
16
|
+
webPathSection: CEDAR_WEB_PATH_NAME,
|
|
12
17
|
extension,
|
|
13
18
|
generator: "component",
|
|
14
19
|
templatePath: "component.tsx.template"
|
|
@@ -16,34 +21,27 @@ const files = async ({ name, typescript = false, ...argv }) => {
|
|
|
16
21
|
const testFile = await templateForComponentFile({
|
|
17
22
|
name,
|
|
18
23
|
extension: `.test${extension}`,
|
|
19
|
-
webPathSection:
|
|
24
|
+
webPathSection: CEDAR_WEB_PATH_NAME,
|
|
20
25
|
generator: "component",
|
|
21
26
|
templatePath: "test.tsx.template"
|
|
22
27
|
});
|
|
23
28
|
const storiesFile = await templateForComponentFile({
|
|
24
29
|
name,
|
|
25
30
|
extension: `.stories${extension}`,
|
|
26
|
-
webPathSection:
|
|
31
|
+
webPathSection: CEDAR_WEB_PATH_NAME,
|
|
27
32
|
generator: "component",
|
|
28
33
|
// Using two different template files here because we have a TS-specific
|
|
29
34
|
// information in a comment in the .tsx template
|
|
30
35
|
templatePath: typescript ? "stories.tsx.template" : "stories.jsx.template"
|
|
31
36
|
});
|
|
32
37
|
const files2 = [componentFile];
|
|
33
|
-
if (
|
|
38
|
+
if (stories) {
|
|
34
39
|
files2.push(storiesFile);
|
|
35
40
|
}
|
|
36
|
-
if (
|
|
41
|
+
if (tests) {
|
|
37
42
|
files2.push(testFile);
|
|
38
43
|
}
|
|
39
|
-
return files2
|
|
40
|
-
const acc = await accP;
|
|
41
|
-
const template = typescript ? content : await transformTSToJS(outputPath, content);
|
|
42
|
-
return {
|
|
43
|
-
[outputPath]: template,
|
|
44
|
-
...acc
|
|
45
|
-
};
|
|
46
|
-
}, Promise.resolve({}));
|
|
44
|
+
return transformTSToJSMap(files2, typescript);
|
|
47
45
|
};
|
|
48
46
|
const handler = createHandler({
|
|
49
47
|
componentName: "component",
|
|
@@ -3,6 +3,7 @@ import { paramCase } from "change-case";
|
|
|
3
3
|
import { Listr } from "listr2";
|
|
4
4
|
import { terminalLink } from "termi-link";
|
|
5
5
|
import { recordTelemetryAttributes, colors as c } from "@cedarjs/cli-helpers";
|
|
6
|
+
import { formatCedarCommand } from "@cedarjs/cli-helpers/packageManager/display";
|
|
6
7
|
import { getDataMigrationsPath } from "@cedarjs/project-config";
|
|
7
8
|
import {
|
|
8
9
|
generateTemplate,
|
|
@@ -11,15 +12,16 @@ import {
|
|
|
11
12
|
} from "../../../lib/index.js";
|
|
12
13
|
import { prepareForRollback } from "../../../lib/rollback.js";
|
|
13
14
|
import { validateName } from "../helpers.js";
|
|
14
|
-
|
|
15
|
-
const
|
|
15
|
+
function getPostRunInstructions() {
|
|
16
|
+
const text = c.warning("After writing your migration, you can run it with:");
|
|
17
|
+
const command2 = formatCedarCommand(["dataMigrate", "up"]);
|
|
18
|
+
return `Next steps...
|
|
16
19
|
|
|
17
|
-
${
|
|
18
|
-
"After writing your migration, you can run it with:"
|
|
19
|
-
)}
|
|
20
|
+
${text}
|
|
20
21
|
|
|
21
|
-
|
|
22
|
+
${command2}
|
|
22
23
|
`;
|
|
24
|
+
}
|
|
23
25
|
const TEMPLATE_PATHS = {
|
|
24
26
|
js: path.resolve(
|
|
25
27
|
import.meta.dirname,
|
|
@@ -54,22 +56,30 @@ const command = "data-migration <name>";
|
|
|
54
56
|
const aliases = ["dataMigration", "dm"];
|
|
55
57
|
const description = "Generate a data migration";
|
|
56
58
|
const builder = (yargs) => {
|
|
57
|
-
yargs.positional("name", {
|
|
59
|
+
return yargs.positional("name", {
|
|
58
60
|
description: "A descriptor of what this data migration does",
|
|
59
|
-
type: "string"
|
|
61
|
+
type: "string",
|
|
62
|
+
demandOption: true
|
|
60
63
|
}).option("rollback", {
|
|
61
64
|
description: "Revert all generator actions if an error occurs",
|
|
62
65
|
type: "boolean",
|
|
63
66
|
default: true
|
|
67
|
+
}).option("force", {
|
|
68
|
+
alias: "f",
|
|
69
|
+
default: false,
|
|
70
|
+
description: "Overwrite existing files",
|
|
71
|
+
type: "boolean"
|
|
72
|
+
}).option("typescript", {
|
|
73
|
+
alias: "ts",
|
|
74
|
+
default: false,
|
|
75
|
+
description: "Generate TypeScript files",
|
|
76
|
+
type: "boolean"
|
|
64
77
|
}).epilogue(
|
|
65
78
|
`Also see the ${terminalLink(
|
|
66
79
|
"CedarJS CLI Reference",
|
|
67
80
|
"https://cedarjs.com/docs/cli-commands#generate-datamigration"
|
|
68
81
|
)}`
|
|
69
82
|
);
|
|
70
|
-
Object.entries(getYargsDefaults()).forEach(([option, config]) => {
|
|
71
|
-
yargs.option(option, config);
|
|
72
|
-
});
|
|
73
83
|
};
|
|
74
84
|
const handler = async (args) => {
|
|
75
85
|
recordTelemetryAttributes({
|
|
@@ -89,7 +99,7 @@ const handler = async (args) => {
|
|
|
89
99
|
{
|
|
90
100
|
title: "Next steps...",
|
|
91
101
|
task: (_ctx, task) => {
|
|
92
|
-
task.title =
|
|
102
|
+
task.title = getPostRunInstructions();
|
|
93
103
|
}
|
|
94
104
|
}
|
|
95
105
|
].filter(Boolean),
|
|
@@ -101,7 +111,7 @@ const handler = async (args) => {
|
|
|
101
111
|
}
|
|
102
112
|
await tasks.run();
|
|
103
113
|
} catch (e) {
|
|
104
|
-
console.log(c.error(e.message));
|
|
114
|
+
console.log(c.error(e instanceof Error ? e.message : String(e)));
|
|
105
115
|
process.exit(1);
|
|
106
116
|
}
|
|
107
117
|
};
|
|
@@ -111,5 +121,6 @@ export {
|
|
|
111
121
|
command,
|
|
112
122
|
description,
|
|
113
123
|
files,
|
|
124
|
+
getPostRunInstructions,
|
|
114
125
|
handler
|
|
115
126
|
};
|