@cedarjs/cli 5.0.0-canary.2538 → 5.0.0-canary.2540

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,6 +1,6 @@
1
1
  import { recordTelemetryAttributes } from "@cedarjs/cli-helpers";
2
2
  const command = "docker";
3
- const description = "Setup the default Redwood Dockerfile";
3
+ const description = "Setup the default Cedar Dockerfile";
4
4
  function builder(yargs) {
5
5
  yargs.option("force", {
6
6
  alias: "f",
@@ -5,17 +5,19 @@ import execa from "execa";
5
5
  import { Listr } from "listr2";
6
6
  import { writeFile, colors as c } from "@cedarjs/cli-helpers";
7
7
  import { dedupe } from "@cedarjs/cli-helpers/packageManager";
8
+ import { formatCedarCommand } from "@cedarjs/cli-helpers/packageManager/display";
8
9
  import { addWorkspacePackages } from "@cedarjs/cli-helpers/packageManager/packages";
9
10
  import { getConfig, getConfigPath, getPaths } from "@cedarjs/project-config";
10
11
  import { getPackageManager } from "@cedarjs/project-config/packageManager";
11
12
  import { errorTelemetry } from "@cedarjs/telemetry";
12
13
  async function handler({ force }) {
13
14
  const TEMPLATE_DIR = path.join(import.meta.dirname, "templates");
15
+ const pm = getPackageManager();
14
16
  let dockerfileTemplateContent = fs.readFileSync(
15
- path.resolve(TEMPLATE_DIR, "Dockerfile"),
17
+ path.resolve(TEMPLATE_DIR, `Dockerfile.${pm}`),
16
18
  "utf-8"
17
19
  );
18
- const dockerComposeDevTemplateContent = fs.readFileSync(
20
+ let dockerComposeDevTemplateContent = fs.readFileSync(
19
21
  path.resolve(TEMPLATE_DIR, "docker-compose.dev.yml"),
20
22
  "utf-8"
21
23
  );
@@ -39,33 +41,41 @@ async function handler({ force }) {
39
41
  const dockerignoreFilePath = path.join(getPaths().base, ".dockerignore");
40
42
  const configTomlPath = getConfigPath();
41
43
  const configFileName = path.basename(configTomlPath);
44
+ dockerComposeDevTemplateContent = dockerComposeDevTemplateContent.replace(/'{{DEV_CMD}}'/g, formatCedarCommand(["dev"])).replace(/{{CEDAR_CMD}}/g, formatCedarCommand([]));
42
45
  const tasks = new Listr(
43
46
  [
44
- {
45
- title: "Adding the official yarn workspace-tools plugin...",
46
- // The `yarn plugin` commands only exist in yarn. Docker setup is a
47
- // yarn-specific workflow (workspace-tools plugin has no npm/pnpm
48
- // equivalent), so we invoke yarn directly here.
49
- task: async (_ctx, task) => {
50
- const { stdout } = await execa(
51
- "yarn",
52
- ["plugin", "runtime", "--json"],
53
- {
54
- cwd: getPaths().base
55
- }
56
- );
57
- const hasWorkspaceToolsPlugin = stdout.trim().split("\n").map(JSON.parse).some(({ name }) => name === "@yarnpkg/plugin-workspace-tools");
58
- if (hasWorkspaceToolsPlugin) {
59
- task.skip(
60
- "The official yarn workspace-tools plugin is already installed"
47
+ // The yarn workspace-tools plugin only exists for yarn.
48
+ // For pnpm, pnpm install --prod --filter api is built-in. Workspaces are
49
+ // a first-class feature with no plugin needed. For npm, there's no
50
+ // workspace-focus equivalent at all, so npm ci --omit=dev installs
51
+ // production deps for all workspaces (slightly less optimized but
52
+ // functionally correct).
53
+ ...pm === "yarn" ? [
54
+ {
55
+ title: "Adding the official yarn workspace-tools plugin...",
56
+ task: async (_ctx, task) => {
57
+ const { stdout } = await execa(
58
+ "yarn",
59
+ ["plugin", "runtime", "--json"],
60
+ {
61
+ cwd: getPaths().base
62
+ }
61
63
  );
62
- return;
64
+ const hasWorkspaceToolsPlugin = stdout.trim().split("\n").map(JSON.parse).some(
65
+ ({ name }) => name === "@yarnpkg/plugin-workspace-tools"
66
+ );
67
+ if (hasWorkspaceToolsPlugin) {
68
+ task.skip(
69
+ "The official yarn workspace-tools plugin is already installed"
70
+ );
71
+ return;
72
+ }
73
+ return execa("yarn", ["plugin", "import", "workspace-tools"], {
74
+ cwd: getPaths().base
75
+ }).stdout;
63
76
  }
64
- return execa("yarn", ["plugin", "import", "workspace-tools"], {
65
- cwd: getPaths().base
66
- }).stdout;
67
77
  }
68
- },
78
+ ] : [],
69
79
  {
70
80
  title: "Adding @cedarjs/api-server and @cedarjs/web-server...",
71
81
  task: async (_ctx, task) => {
@@ -244,7 +254,7 @@ async function handler({ force }) {
244
254
  "Then, connect to the container and migrate your database:",
245
255
  "",
246
256
  " docker compose -f ./docker-compose.dev.yml run --rm -it console /bin/bash",
247
- " root@...:/home/node/app# yarn cedar prisma migrate dev",
257
+ " root@...:/home/node/app# " + formatCedarCommand(["prisma", "migrate", "dev"]),
248
258
  "",
249
259
  "We assume you're using Postgres. If you're not, you'll need to make other changes to switch over.",
250
260
  "Lastly, ensure you have Docker. If you don't, see https://docs.docker.com/desktop/",
@@ -0,0 +1,119 @@
1
+ # base
2
+ # ----
3
+ FROM node:24-bookworm-slim as base
4
+
5
+ RUN npm install --global corepack
6
+
7
+ # We tried to make the Dockerfile as lean as possible. In some cases, that
8
+ # means we excluded a dependency your project needs.
9
+ # By far the most common is Python. If you're running into build errors
10
+ # because `python3` isn't available, add `python3 make gcc \` before the
11
+ # `openssl \` line below and in other stages as necessary:
12
+ RUN apt-get update && apt-get install -y \
13
+ openssl \
14
+ && rm -rf /var/lib/apt/lists/*
15
+
16
+ USER node
17
+ WORKDIR /home/node/app
18
+
19
+ COPY --chown=node:node package*.json .
20
+ COPY --chown=node:node api/package.json api/
21
+ COPY --chown=node:node web/package.json web/
22
+
23
+ RUN --mount=type=cache,target=/home/node/.npm,uid=1000 \
24
+ npm ci
25
+
26
+ COPY --chown=node:node cedar.toml* redwood.toml* ./
27
+ COPY --chown=node:node graphql.config.cjs .
28
+ COPY --chown=node:node .env.defaults .env.defaults
29
+
30
+ # api build
31
+ # ---------
32
+ FROM base as api_build
33
+
34
+ COPY --chown=node:node api api
35
+ RUN npx --yes cedar build api
36
+
37
+ # web prerender build
38
+ # -------------------
39
+ FROM api_build as web_build_with_prerender
40
+
41
+ COPY --chown=node:node web web
42
+ RUN npx --yes cedar build web
43
+
44
+ # web build
45
+ # ---------
46
+ FROM base as web_build
47
+
48
+ COPY --chown=node:node web web
49
+ RUN npx --yes cedar build web --no-prerender
50
+
51
+ # api serve
52
+ # ---------
53
+ FROM node:24-bookworm-slim as api_serve
54
+
55
+ RUN npm install --global corepack
56
+
57
+ RUN apt-get update && apt-get install -y \
58
+ openssl \
59
+ && rm -rf /var/lib/apt/lists/*
60
+
61
+ USER node
62
+ WORKDIR /home/node/app
63
+
64
+ # npm doesn't have a workspace focus command, so we copy all workspace
65
+ # package.json files and install production deps for all workspaces.
66
+ COPY --chown=node:node package*.json .
67
+ COPY --chown=node:node api/package.json api/
68
+ COPY --chown=node:node web/package.json web/
69
+
70
+ RUN --mount=type=cache,target=/home/node/.npm,uid=1000 \
71
+ npm ci --omit=dev
72
+
73
+ COPY --chown=node:node cedar.toml* redwood.toml* ./
74
+ COPY --chown=node:node graphql.config.cjs .
75
+ COPY --chown=node:node .env.defaults .env.defaults
76
+
77
+ COPY --chown=node:node --from=api_build /home/node/app/api/dist /home/node/app/api/dist
78
+ COPY --chown=node:node --from=api_build /home/node/app/api/db /home/node/app/api/db
79
+ COPY --chown=node:node --from=api_build /home/node/app/node_modules/.prisma /home/node/app/node_modules/.prisma
80
+
81
+ ENV NODE_ENV=production
82
+
83
+ CMD ["node_modules/.bin/cedarjs-server", "api"]
84
+
85
+ # web serve
86
+ # ---------
87
+ FROM node:24-bookworm-slim as web_serve
88
+
89
+ RUN npm install --global corepack
90
+
91
+ USER node
92
+ WORKDIR /home/node/app
93
+
94
+ COPY --chown=node:node package*.json .
95
+ COPY --chown=node:node api/package.json api/
96
+ COPY --chown=node:node web/package.json web/
97
+
98
+ RUN --mount=type=cache,target=/home/node/.npm,uid=1000 \
99
+ npm ci --omit=dev
100
+
101
+ COPY --chown=node:node cedar.toml* redwood.toml* ./
102
+ COPY --chown=node:node graphql.config.cjs .
103
+ COPY --chown=node:node .env.defaults .env.defaults
104
+
105
+ COPY --chown=node:node --from=web_build /home/node/app/web/dist /home/node/app/web/dist
106
+
107
+ ENV NODE_ENV=production \
108
+ API_PROXY_TARGET=http://api:8911
109
+
110
+ # We use the shell form here for variable expansion.
111
+ CMD node_modules/.bin/cedar-web-server --api-proxy-target $API_PROXY_TARGET
112
+
113
+ # console
114
+ # -------
115
+ FROM base as console
116
+
117
+ COPY --chown=node:node api api
118
+ COPY --chown=node:node web web
119
+ COPY --chown=node:node scripts scripts
@@ -0,0 +1,112 @@
1
+ # base
2
+ # ----
3
+ FROM node:24-bookworm-slim as base
4
+
5
+ RUN npm install --global corepack
6
+
7
+ RUN apt-get update && apt-get install -y \
8
+ openssl \
9
+ && rm -rf /var/lib/apt/lists/*
10
+
11
+ USER node
12
+ WORKDIR /home/node/app
13
+
14
+ COPY --chown=node:node package.json .
15
+ COPY --chown=node:node pnpm-lock.yaml .
16
+ COPY --chown=node:node pnpm-workspace.yaml .
17
+ COPY --chown=node:node api/package.json api/
18
+ COPY --chown=node:node web/package.json web/
19
+
20
+ RUN --mount=type=cache,id=pnpm,target=/home/node/.pnpm/store,uid=1000 \
21
+ pnpm install --frozen-lockfile --store-dir /home/node/.pnpm/store
22
+
23
+ COPY --chown=node:node cedar.toml* redwood.toml* ./
24
+ COPY --chown=node:node graphql.config.cjs .
25
+ COPY --chown=node:node .env.defaults .env.defaults
26
+
27
+ # api build
28
+ # ---------
29
+ FROM base as api_build
30
+
31
+ COPY --chown=node:node api api
32
+ RUN pnpm exec cedar build api
33
+
34
+ # web prerender build
35
+ # -------------------
36
+ FROM api_build as web_build_with_prerender
37
+
38
+ COPY --chown=node:node web web
39
+ RUN pnpm exec cedar build web
40
+
41
+ # web build
42
+ # ---------
43
+ FROM base as web_build
44
+
45
+ COPY --chown=node:node web web
46
+ RUN pnpm exec cedar build web --no-prerender
47
+
48
+ # deploy
49
+ # ------
50
+ FROM api_build as deploy
51
+
52
+ COPY --chown=node:node --from=web_build /home/node/app/web/dist /home/node/app/web/dist
53
+
54
+ RUN pnpm deploy --filter=api --prod /home/node/app/dist/api
55
+ RUN pnpm deploy --filter=web --prod /home/node/app/dist/web
56
+
57
+ # api serve
58
+ # ---------
59
+ FROM node:24-bookworm-slim as api_serve
60
+
61
+ RUN npm install --global corepack
62
+
63
+ RUN apt-get update && apt-get install -y \
64
+ openssl \
65
+ && rm -rf /var/lib/apt/lists/*
66
+
67
+ USER node
68
+ WORKDIR /home/node/app
69
+
70
+ COPY --chown=node:node cedar.toml* redwood.toml* ./
71
+ COPY --chown=node:node graphql.config.cjs .
72
+ COPY --chown=node:node .env.defaults .env.defaults
73
+
74
+ COPY --chown=node:node --from=deploy /home/node/app/dist/api /home/node/app
75
+
76
+ COPY --chown=node:node --from=api_build /home/node/app/api/dist /home/node/app/api/dist
77
+ COPY --chown=node:node --from=api_build /home/node/app/api/db /home/node/app/api/db
78
+ COPY --chown=node:node --from=api_build /home/node/app/node_modules/.prisma /home/node/app/node_modules/.prisma
79
+
80
+ ENV NODE_ENV=production
81
+
82
+ CMD ["node_modules/.bin/cedarjs-server", "api"]
83
+
84
+ # web serve
85
+ # ---------
86
+ FROM node:24-bookworm-slim as web_serve
87
+
88
+ RUN npm install --global corepack
89
+
90
+ USER node
91
+ WORKDIR /home/node/app
92
+
93
+ COPY --chown=node:node cedar.toml* redwood.toml* ./
94
+ COPY --chown=node:node graphql.config.cjs .
95
+ COPY --chown=node:node .env.defaults .env.defaults
96
+
97
+ COPY --chown=node:node --from=deploy /home/node/app/dist/web /home/node/app
98
+
99
+ COPY --chown=node:node --from=web_build /home/node/app/web/dist /home/node/app/web/dist
100
+
101
+ ENV NODE_ENV=production \
102
+ API_PROXY_TARGET=http://api:8911
103
+
104
+ CMD node_modules/.bin/cedar-web-server --api-proxy-target $API_PROXY_TARGET
105
+
106
+ # console
107
+ # -------
108
+ FROM base as console
109
+
110
+ COPY --chown=node:node api api
111
+ COPY --chown=node:node web web
112
+ COPY --chown=node:node scripts scripts
@@ -132,7 +132,7 @@ ENV NODE_ENV=production \
132
132
  API_PROXY_TARGET=http://api:8911
133
133
 
134
134
  # We use the shell form here for variable expansion.
135
- CMD "node_modules/.bin/rw-web-server" "--api-proxy-target" "$API_PROXY_TARGET"
135
+ CMD node_modules/.bin/cedar-web-server --api-proxy-target $API_PROXY_TARGET
136
136
 
137
137
  # console
138
138
  # -------
@@ -4,7 +4,7 @@ services:
4
4
  context: .
5
5
  dockerfile: ./Dockerfile
6
6
  target: base
7
- command: yarn cedar dev
7
+ command: '{{DEV_CMD}}'
8
8
  volumes:
9
9
  - .:/home/node/app
10
10
  - node_modules:/home/node/app/node_modules
@@ -36,7 +36,7 @@ services:
36
36
  #
37
37
  # ```
38
38
  # docker compose -f ./docker-compose.dev.yml run --rm -it console /bin/bash
39
- # root@...:/home/node/app# yarn cedar prisma migrate dev
39
+ # root@...:/home/node/app# {{CEDAR_CMD}} prisma migrate dev
40
40
  # ```
41
41
  console:
42
42
  user: root
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cedarjs/cli",
3
- "version": "5.0.0-canary.2538",
3
+ "version": "5.0.0-canary.2540",
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.7",
35
35
  "@babel/preset-typescript": "7.29.7",
36
- "@cedarjs/api-server": "5.0.0-canary.2538",
37
- "@cedarjs/cli-helpers": "5.0.0-canary.2538",
38
- "@cedarjs/fastify-web": "5.0.0-canary.2538",
39
- "@cedarjs/internal": "5.0.0-canary.2538",
40
- "@cedarjs/prerender": "5.0.0-canary.2538",
41
- "@cedarjs/project-config": "5.0.0-canary.2538",
42
- "@cedarjs/structure": "5.0.0-canary.2538",
43
- "@cedarjs/telemetry": "5.0.0-canary.2538",
44
- "@cedarjs/utils": "5.0.0-canary.2538",
45
- "@cedarjs/vite": "5.0.0-canary.2538",
46
- "@cedarjs/web-server": "5.0.0-canary.2538",
36
+ "@cedarjs/api-server": "5.0.0-canary.2540",
37
+ "@cedarjs/cli-helpers": "5.0.0-canary.2540",
38
+ "@cedarjs/fastify-web": "5.0.0-canary.2540",
39
+ "@cedarjs/internal": "5.0.0-canary.2540",
40
+ "@cedarjs/prerender": "5.0.0-canary.2540",
41
+ "@cedarjs/project-config": "5.0.0-canary.2540",
42
+ "@cedarjs/structure": "5.0.0-canary.2540",
43
+ "@cedarjs/telemetry": "5.0.0-canary.2540",
44
+ "@cedarjs/utils": "5.0.0-canary.2540",
45
+ "@cedarjs/vite": "5.0.0-canary.2540",
46
+ "@cedarjs/web-server": "5.0.0-canary.2540",
47
47
  "@listr2/prompt-adapter-enquirer": "4.2.1",
48
48
  "@opentelemetry/api": "1.9.1",
49
49
  "@opentelemetry/core": "1.30.1",