@cedarjs/cli 7.0.1-next.314 → 7.0.1-next.466
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 +375 -76
- package/dist/commands/deploy/baremetal/monitors.js +66 -0
- package/dist/commands/deploy/baremetal.js +6 -0
- package/dist/commands/destroy/scaffold/scaffoldHandler.js +63 -25
- package/dist/commands/dev/devHandler.js +13 -1
- package/dist/commands/generate/dbAuth/dbAuth.js +6 -2
- package/dist/commands/generate/dbAuth/dbAuthHandler.js +57 -14
- package/dist/commands/generate/dbAuth/templates/changePassword.tsx.template +131 -0
- package/dist/commands/generate/dbAuth/templates/login.webAuthn.tsx.template +20 -12
- package/dist/commands/generate/directive/directive.js +15 -2
- package/dist/commands/generate/helpers.js +26 -0
- package/dist/commands/generate/ogImage/templates/ogImage.og.tsx.template +1 -1
- package/dist/commands/generate/package/templates/tsconfig.json.template +1 -0
- package/dist/commands/generate/realtime/templates/liveQueries/blank/blank.service.ts.template +12 -4
- package/dist/commands/generate/realtime/templates/subscriptions/blank/blank.service.ts.template +2 -2
- package/dist/commands/generate/realtime/templates/subscriptions/blank/blank.ts.template +3 -3
- package/dist/commands/generate/scaffold/scaffold.js +1 -1
- package/dist/commands/generate/scaffold/scaffoldHandler.js +83 -44
- package/dist/commands/generate/scaffold/templates/assets/scaffold.tailwind.css.template +12 -7
- package/dist/commands/generate/scaffold/templates/components/EditNameCell.tsx.template +7 -7
- package/dist/commands/generate/scaffold/templates/components/NameForm.tsx.template +7 -6
- package/dist/commands/generate/scaffold/templates/layouts/NamesScaffoldLayout.tsx.template +18 -0
- package/dist/commands/generate/scaffold/templates/lib/formatters.tsx.template +3 -3
- package/dist/commands/generate/script/templates/tsconfig.json.template +1 -0
- package/dist/commands/generate/sdl/sdlHandler.js +8 -3
- package/dist/commands/generate/service/serviceHandler.js +32 -11
- package/dist/commands/generate/service/templates/service.ts.template +21 -8
- package/dist/commands/generate/service/templates/test.ts.template +7 -5
- package/dist/commands/jobsHandler.js +5 -3
- package/dist/commands/setup/cache/templates/memcached.ts.template +14 -17
- package/dist/commands/setup/cache/templates/redis.ts.template +12 -20
- package/dist/commands/setup/deploy/helpers/index.js +3 -1
- package/dist/commands/setup/deploy/providers/baremetal.js +7 -0
- package/dist/commands/setup/deploy/providers/baremetalHandler.js +128 -20
- package/dist/commands/setup/deploy/providers/netlifyHandler.js +25 -3
- package/dist/commands/setup/deploy/templates/baremetal.js +119 -9
- package/dist/commands/setup/deploy/templates/netlifyUD.js +3 -0
- package/dist/commands/setup/jobs/jobsHandler.js +2 -0
- package/dist/commands/setup/monitoring/sentry/sentryHandler.js +5 -2
- package/dist/commands/setup/monitoring/sentry/templates/sentryApi.ts.template +1 -4
- package/dist/commands/setup/monitoring/sentry/templates/sentryWeb.ts.template +7 -4
- package/dist/commands/setup/realtime/templates/defer/fastAndSlowFields/fastAndSlowFields.ts.template +4 -1
- package/dist/commands/setup/realtime/templates/liveQueries/auctions/auctions.ts.template +12 -4
- package/dist/commands/setup/realtime/templates/subscriptions/newMessage/newMessage.ts.template +1 -1
- package/dist/commands/setup/tenancy/signupCodemod.js +2 -1
- package/dist/commands/setup/tenancy/templates/InvitePage.tsx.template +10 -1
- package/dist/commands/setup/tenancy/templates/organizations.scenarios.ts.template +0 -2
- package/dist/commands/setup/tenancy/templates/organizations.test.ts.template +0 -8
- package/dist/commands/setup/tenancy/templates/organizations.ts.template +1 -1
- package/dist/commands/setup/tenancy/templates/requireMembership.test.ts.template +1 -1
- package/dist/commands/setup/tenancy/tenancyHandler.js +1 -1
- package/dist/commands/setup/ui/libraries/tailwindcssHandler.js +61 -81
- package/dist/commands/setup/uploads/gitignore.js +17 -0
- package/dist/commands/setup/uploads/serverFile.js +93 -27
- package/dist/commands/setup/uploads/templates/uploads.ts.template +14 -5
- package/dist/commands/setup/uploads/uploadsHandler.js +22 -1
- package/dist/lib/index.js +10 -6
- package/package.json +24 -24
- package/dist/commands/setup/ui/templates/postcss.config.cjs.template +0 -9
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { QueryResolvers<% if (crud) { %>, MutationResolvers<% } %><% if (relations.length) { %>, ${singularPascalName}RelationResolvers<% } %> } from 'types/graphql'
|
|
2
2
|
|
|
3
|
-
import { db } from 'src/lib/db'
|
|
3
|
+
import { db<% if (crud && nullableJsonFields.length) { %>, Prisma<% } %> } from 'src/lib/db'
|
|
4
4
|
<%
|
|
5
5
|
// A compound `@@id([...])` key comes through as `{ fields, whereArg }`
|
|
6
6
|
// instead of a single field name -- build the destructure/where-clause
|
|
@@ -13,8 +13,8 @@ import { db } from 'src/lib/db'
|
|
|
13
13
|
? `${idName.whereArg}: { ${idFields.join(', ')} }`
|
|
14
14
|
: idName
|
|
15
15
|
const idWhereFromRoot = idIsComposite
|
|
16
|
-
? `${idName.whereArg}: { ${idFields.map((f) => `${f}: root
|
|
17
|
-
: `${idName}: root
|
|
16
|
+
? `${idName.whereArg}: { ${idFields.map((f) => `${f}: root.${f}`).join(', ')} }`
|
|
17
|
+
: `${idName}: root.${idName}`
|
|
18
18
|
%>
|
|
19
19
|
export const ${pluralCamelName}: QueryResolvers['${pluralCamelName}'] = () => {
|
|
20
20
|
return db.${singularCamelName}.findMany()
|
|
@@ -27,14 +27,27 @@ export const ${singularCamelName}: QueryResolvers['${singularCamelName}'] = ({ $
|
|
|
27
27
|
}<% } %><% if (crud) { %>
|
|
28
28
|
|
|
29
29
|
export const create${singularPascalName}: MutationResolvers['create${singularPascalName}'] = ({ input }) => {
|
|
30
|
-
return db.${singularCamelName}.create({
|
|
31
|
-
data:
|
|
30
|
+
return db.${singularCamelName}.create({<% if (nullableJsonFields.length) { %>
|
|
31
|
+
data: {
|
|
32
|
+
...input,
|
|
33
|
+
// Prisma uses Prisma.DbNull, not null, to set a Json field to NULL<% nullableJsonFields.forEach((field) => { %>
|
|
34
|
+
${field}: input.${field} === null ? Prisma.DbNull : input.${field},<% }) %>
|
|
35
|
+
},<% } else { %>
|
|
36
|
+
data: input,<% } %>
|
|
32
37
|
})
|
|
33
38
|
}
|
|
34
39
|
|
|
35
40
|
export const update${singularPascalName}: MutationResolvers['update${singularPascalName}'] = ({ ${idArgs}, input }) => {
|
|
36
|
-
return db.${singularCamelName}.update({
|
|
37
|
-
data:
|
|
41
|
+
return db.${singularCamelName}.update({<% if (updateInputRequiredFields.length || nullableJsonFields.length) { %>
|
|
42
|
+
data: {
|
|
43
|
+
...input,<% if (updateInputRequiredFields.length) { %>
|
|
44
|
+
// Every field in the GraphQL input is nullable, but Prisma doesn't
|
|
45
|
+
// accept null for required fields. undefined leaves the field unchanged<% updateInputRequiredFields.forEach((field) => { %>
|
|
46
|
+
${field}: input.${field} ?? undefined,<% }) %><% } %><% if (nullableJsonFields.length) { %>
|
|
47
|
+
// Prisma uses Prisma.DbNull, not null, to set a Json field to NULL<% nullableJsonFields.forEach((field) => { %>
|
|
48
|
+
${field}: input.${field} === null ? Prisma.DbNull : input.${field},<% }) %><% } %>
|
|
49
|
+
},<% } else { %>
|
|
50
|
+
data: input,<% } %>
|
|
38
51
|
where: { ${idWhere} },
|
|
39
52
|
})
|
|
40
53
|
}
|
|
@@ -47,6 +60,6 @@ export const delete${singularPascalName}: MutationResolvers['delete${singularPas
|
|
|
47
60
|
|
|
48
61
|
export const ${singularPascalName}: ${singularPascalName}RelationResolvers = {<% relations.forEach(relation => { %>
|
|
49
62
|
${relation}: (_obj, { root }) => {
|
|
50
|
-
return db.${singularCamelName}.findUnique({ where: { ${idWhereFromRoot} } }).${relation}()
|
|
63
|
+
return db.${singularCamelName}.findUnique<%= nullableRelations.includes(relation) ? '' : 'OrThrow' %>({ where: { ${idWhereFromRoot} } }).${relation}()
|
|
51
64
|
},<% }) %>
|
|
52
65
|
}<% } %>
|
|
@@ -7,8 +7,10 @@
|
|
|
7
7
|
// Looks for quoted strings, either by single (') or double (") quotes.
|
|
8
8
|
// When found
|
|
9
9
|
// - Removes the quotes around `scenario` variables.
|
|
10
|
-
// - Removes the quotes around `BigInt` fields.
|
|
11
|
-
|
|
10
|
+
// - Removes the quotes around `BigInt` fields. GraphQL inputs type BigInt
|
|
11
|
+
// values as numbers, so the `n` suffix is also removed when `asInput` is
|
|
12
|
+
// set
|
|
13
|
+
const transformValue = (obj, type, asInput = false) => {
|
|
12
14
|
if (type === 'DateTime') {
|
|
13
15
|
return `new Date('${obj.toISOString()}')`
|
|
14
16
|
} else if (type === 'Decimal') {
|
|
@@ -22,7 +24,7 @@
|
|
|
22
24
|
|
|
23
25
|
// BigInt
|
|
24
26
|
if (string.match(/^\"\d+n\"$/)) {
|
|
25
|
-
return string.slice(1, string.length - 1)
|
|
27
|
+
return string.slice(1, string.length - (asInput ? 2 : 1))
|
|
26
28
|
}
|
|
27
29
|
|
|
28
30
|
return string
|
|
@@ -57,7 +59,7 @@ describe('${pluralCamelName}', () => {
|
|
|
57
59
|
|
|
58
60
|
<% if (create) { %>scenario('creates a ${singularCamelName}', async (${transformValue(create).includes('scenario.') ? 'scenario: StandardScenario' : ''}) => {
|
|
59
61
|
const result = await create${singularPascalName}({
|
|
60
|
-
input: ${transformValue(create)},
|
|
62
|
+
input: ${transformValue(create, undefined, true)},
|
|
61
63
|
})
|
|
62
64
|
|
|
63
65
|
<% for (const [name, value] of Object.entries(create)) { %>
|
|
@@ -68,7 +70,7 @@ describe('${pluralCamelName}', () => {
|
|
|
68
70
|
const original = await (${singularCamelName}({ ${idName}: scenario.${singularCamelName}.one.${idName} })) as ${prismaModel}
|
|
69
71
|
const result = await update${singularPascalName}({
|
|
70
72
|
${idName}: original.${idName},
|
|
71
|
-
input: ${transformValue(update)},
|
|
73
|
+
input: ${transformValue(update, undefined, true)},
|
|
72
74
|
})
|
|
73
75
|
|
|
74
76
|
<% for (const [name, value] of Object.entries(update)) { %>
|
|
@@ -7,9 +7,11 @@ const handler = async ({
|
|
|
7
7
|
commands: _commands,
|
|
8
8
|
...options
|
|
9
9
|
}) => {
|
|
10
|
-
const positionalArgs = Array.isArray(_) ?
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
const positionalArgs = (Array.isArray(_) ? _ : []).map(String);
|
|
11
|
+
if (positionalArgs[0] === "jobs") {
|
|
12
|
+
positionalArgs.shift();
|
|
13
|
+
}
|
|
14
|
+
const args = positionalArgs.length > 0 ? positionalArgs : [""];
|
|
13
15
|
for (const [name, value] of Object.entries(options)) {
|
|
14
16
|
args.push(name.length > 1 ? `--${name}` : `-${name}`);
|
|
15
17
|
args.push(String(value));
|
|
@@ -10,21 +10,18 @@ const memJsFormattedLogger = {
|
|
|
10
10
|
log: (msg: string) => logger.error(msg),
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
// The client connects to Memcached the first time it's used. If it can't
|
|
14
|
+
// connect, the error is logged and `cache()` runs the uncached function
|
|
15
|
+
// instead
|
|
16
|
+
export const client =
|
|
17
|
+
process.env.NODE_ENV === 'test'
|
|
18
|
+
? new InMemoryClient()
|
|
19
|
+
: new MemcachedClient(process.env.CACHE_HOST, {
|
|
20
|
+
logger: memJsFormattedLogger,
|
|
21
|
+
})
|
|
14
22
|
|
|
15
|
-
|
|
16
|
-
client
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
logger: memJsFormattedLogger,
|
|
21
|
-
})
|
|
22
|
-
} catch (e) {
|
|
23
|
-
logger.error(`Could not connect to cache: ${e.message}`)
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export const { cache, cacheFindMany, cacheClient, deleteCacheKey } = createCache(client, {
|
|
28
|
-
logger,
|
|
29
|
-
timeout: 500,
|
|
30
|
-
})
|
|
23
|
+
export const { cache, cacheFindMany, cacheClient, deleteCacheKey } =
|
|
24
|
+
createCache(client, {
|
|
25
|
+
logger,
|
|
26
|
+
timeout: 500,
|
|
27
|
+
})
|
|
@@ -1,24 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createCache,
|
|
3
|
-
InMemoryClient,
|
|
4
|
-
RedisClient,
|
|
5
|
-
} from '@cedarjs/api/cache'
|
|
1
|
+
import { createCache, InMemoryClient, RedisClient } from '@cedarjs/api/cache'
|
|
6
2
|
|
|
7
3
|
import { logger } from './logger'
|
|
8
4
|
|
|
9
|
-
|
|
5
|
+
// The client connects to Redis the first time it's used. If it can't connect,
|
|
6
|
+
// the error is logged and `cache()` runs the uncached function instead
|
|
7
|
+
export const client =
|
|
8
|
+
process.env.NODE_ENV === 'test'
|
|
9
|
+
? new InMemoryClient()
|
|
10
|
+
: new RedisClient({ url: process.env.CACHE_HOST, logger })
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
client
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
} catch (e) {
|
|
17
|
-
logger.error(`Could not connect to cache: ${e.message}`)
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export const { cache, cacheFindMany, cacheClient, deleteCacheKey } = createCache(client, {
|
|
22
|
-
logger,
|
|
23
|
-
timeout: 500,
|
|
24
|
-
})
|
|
12
|
+
export const { cache, cacheFindMany, cacheClient, deleteCacheKey } =
|
|
13
|
+
createCache(client, {
|
|
14
|
+
logger,
|
|
15
|
+
timeout: 500,
|
|
16
|
+
})
|
|
@@ -131,7 +131,9 @@ function insertPluginsBeforeCedar({
|
|
|
131
131
|
if (!configArg) {
|
|
132
132
|
return null;
|
|
133
133
|
}
|
|
134
|
-
const pluginsProp = configArg.properties.find(
|
|
134
|
+
const pluginsProp = configArg.properties.find(
|
|
135
|
+
(prop) => t.isObjectProperty(prop) && (!prop.computed && t.isIdentifier(prop.key, { name: "plugins" }) || t.isStringLiteral(prop.key, { value: "plugins" }))
|
|
136
|
+
);
|
|
135
137
|
if (!t.isArrayExpression(pluginsProp?.value)) {
|
|
136
138
|
return null;
|
|
137
139
|
}
|
|
@@ -1,8 +1,15 @@
|
|
|
1
|
+
import { MONITORS } from "../../../deploy/baremetal/monitors.js";
|
|
1
2
|
import { createHandler } from "../helpers/helpers.js";
|
|
2
3
|
const command = "baremetal";
|
|
3
4
|
const description = "Setup Baremetal deploy";
|
|
5
|
+
const builder = (yargs) => yargs.option("monitor", {
|
|
6
|
+
description: "Process monitor to generate config for. Asks when not given. pm2 gets an ecosystem.config.js, systemd gets unit files in systemd/",
|
|
7
|
+
choices: MONITORS,
|
|
8
|
+
type: "string"
|
|
9
|
+
});
|
|
4
10
|
const handler = createHandler("baremetal");
|
|
5
11
|
export {
|
|
12
|
+
builder,
|
|
6
13
|
command,
|
|
7
14
|
description,
|
|
8
15
|
handler
|
|
@@ -10,38 +10,136 @@ import {
|
|
|
10
10
|
getPaths,
|
|
11
11
|
printSetupNotes
|
|
12
12
|
} from "../../../../lib/index.js";
|
|
13
|
+
import { MONITORS, isMonitor } from "../../../deploy/baremetal/monitors.js";
|
|
13
14
|
import { addFilesTask } from "../helpers/index.js";
|
|
14
|
-
import {
|
|
15
|
+
import {
|
|
16
|
+
MAINTENANCE,
|
|
17
|
+
SYSTEMD_DIR,
|
|
18
|
+
deployToml,
|
|
19
|
+
ecosystemConfig,
|
|
20
|
+
systemdJobsUnit,
|
|
21
|
+
systemdServiceUnit
|
|
22
|
+
} from "../templates/baremetal.js";
|
|
15
23
|
const configFilename = "deploy.toml";
|
|
16
|
-
const
|
|
24
|
+
const MONITOR_CHOICES = [
|
|
17
25
|
{
|
|
18
|
-
|
|
19
|
-
|
|
26
|
+
title: "pm2",
|
|
27
|
+
description: "Node process manager, configured in ecosystem.config.js",
|
|
28
|
+
value: "pm2"
|
|
20
29
|
},
|
|
21
30
|
{
|
|
22
|
-
|
|
23
|
-
|
|
31
|
+
title: "systemd (user units)",
|
|
32
|
+
description: "Units in ~/.config/systemd/user, managed by the deploy user without sudo",
|
|
33
|
+
value: "systemd-user"
|
|
24
34
|
},
|
|
25
35
|
{
|
|
26
|
-
|
|
27
|
-
|
|
36
|
+
title: "systemd (system units)",
|
|
37
|
+
description: "Units in /etc/systemd/system, managed with sudo systemctl",
|
|
38
|
+
value: "systemd-system"
|
|
28
39
|
}
|
|
29
40
|
];
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
""
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
41
|
+
const appNameFromPath = (projectPath) => {
|
|
42
|
+
const name = path.basename(projectPath).toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
43
|
+
return name || "cedar";
|
|
44
|
+
};
|
|
45
|
+
const setupFiles = ({
|
|
46
|
+
monitor,
|
|
47
|
+
jobs,
|
|
48
|
+
appName,
|
|
49
|
+
basePath,
|
|
50
|
+
webSrcPath
|
|
51
|
+
}) => {
|
|
52
|
+
const files = [];
|
|
53
|
+
let processNames;
|
|
54
|
+
if (monitor === "pm2") {
|
|
55
|
+
processNames = jobs ? ["serve", "jobs"] : ["serve"];
|
|
56
|
+
files.push({
|
|
57
|
+
path: path.join(basePath, "ecosystem.config.js"),
|
|
58
|
+
content: ecosystemConfig({ jobs })
|
|
59
|
+
});
|
|
60
|
+
} else {
|
|
61
|
+
const jobsUnit = `${appName}-jobs`;
|
|
62
|
+
processNames = jobs ? [appName, `${jobsUnit}@0`] : [appName];
|
|
63
|
+
files.push({
|
|
64
|
+
path: path.join(basePath, SYSTEMD_DIR, `${appName}.service`),
|
|
65
|
+
content: systemdServiceUnit({ appName, monitor })
|
|
66
|
+
});
|
|
67
|
+
if (jobs) {
|
|
68
|
+
files.push({
|
|
69
|
+
path: path.join(basePath, SYSTEMD_DIR, `${jobsUnit}@.service`),
|
|
70
|
+
content: systemdJobsUnit({ appName, monitor })
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
files.unshift({
|
|
75
|
+
path: path.join(basePath, configFilename),
|
|
76
|
+
content: deployToml({ monitor, processNames })
|
|
77
|
+
});
|
|
78
|
+
files.push({
|
|
79
|
+
path: path.join(webSrcPath, "maintenance.html"),
|
|
80
|
+
content: MAINTENANCE
|
|
81
|
+
});
|
|
82
|
+
return { files, processNames };
|
|
83
|
+
};
|
|
84
|
+
const notesFor = (monitor, jobs, processNames) => {
|
|
85
|
+
const notes = ["You are almost ready to go BAREMETAL!", ""];
|
|
86
|
+
if (monitor !== "pm2") {
|
|
87
|
+
notes.push(
|
|
88
|
+
`Copy the unit files in ${SYSTEMD_DIR}/ to the server before your first`,
|
|
89
|
+
"deploy. The comments at the top of each file say where they go.",
|
|
90
|
+
""
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
if (jobs) {
|
|
94
|
+
notes.push(
|
|
95
|
+
`Background jobs are set up, so deploy.toml lists a jobs worker process`,
|
|
96
|
+
`(${processNames[processNames.length - 1]}). Add one per entry in the`,
|
|
97
|
+
"`workers` array of api/src/lib/jobs.ts.",
|
|
98
|
+
""
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
notes.push(
|
|
102
|
+
"See https://cedarjs.com/docs/deploy/baremetal for the remaining",
|
|
103
|
+
"config and setup required before you can perform your first deploy."
|
|
104
|
+
);
|
|
105
|
+
return notes;
|
|
106
|
+
};
|
|
107
|
+
const promptForMonitor = async () => {
|
|
108
|
+
const { monitor } = await prompts({
|
|
109
|
+
type: "select",
|
|
110
|
+
name: "monitor",
|
|
111
|
+
message: "Which process monitor will run your app on the server?",
|
|
112
|
+
choices: MONITOR_CHOICES
|
|
113
|
+
});
|
|
114
|
+
return isMonitor(monitor) ? monitor : void 0;
|
|
115
|
+
};
|
|
116
|
+
const handler = async ({
|
|
117
|
+
force,
|
|
118
|
+
monitor: monitorOption
|
|
119
|
+
}) => {
|
|
37
120
|
recordTelemetryAttributes({
|
|
38
121
|
command: "setup deploy baremetal",
|
|
39
|
-
force
|
|
122
|
+
force,
|
|
123
|
+
monitor: monitorOption
|
|
40
124
|
});
|
|
41
|
-
if (
|
|
125
|
+
if (monitorOption !== void 0 && !isMonitor(monitorOption)) {
|
|
126
|
+
console.error(
|
|
127
|
+
c.error(
|
|
128
|
+
`Unknown monitor "${monitorOption}". Use one of ${MONITORS.join(", ")}.`
|
|
129
|
+
)
|
|
130
|
+
);
|
|
131
|
+
process.exit(1);
|
|
132
|
+
}
|
|
133
|
+
const monitor = monitorOption ?? await promptForMonitor();
|
|
134
|
+
if (!monitor) {
|
|
135
|
+
console.log("Aborting baremetal setup.");
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
const paths = getPaths();
|
|
139
|
+
if (fs.existsSync(path.join(paths.base, ".pnp.cjs"))) {
|
|
42
140
|
console.warn(
|
|
43
141
|
c.warning(
|
|
44
|
-
"Your project uses Yarn PnP (Plug'n'Play), which is not officially supported for Baremetal deployments. The generated
|
|
142
|
+
"Your project uses Yarn PnP (Plug'n'Play), which is not officially supported for Baremetal deployments. The generated process config starts the app with node_modules/.bin/cedar, 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."
|
|
45
143
|
)
|
|
46
144
|
);
|
|
47
145
|
console.log();
|
|
@@ -56,6 +154,14 @@ const handler = async ({ force }) => {
|
|
|
56
154
|
}
|
|
57
155
|
console.log();
|
|
58
156
|
}
|
|
157
|
+
const jobs = Boolean(paths.api.jobsConfig);
|
|
158
|
+
const { files, processNames } = setupFiles({
|
|
159
|
+
monitor,
|
|
160
|
+
jobs,
|
|
161
|
+
appName: appNameFromPath(paths.base),
|
|
162
|
+
basePath: paths.base,
|
|
163
|
+
webSrcPath: paths.web.src
|
|
164
|
+
});
|
|
59
165
|
const tasks = new Listr(
|
|
60
166
|
[
|
|
61
167
|
await addPackagesTask({
|
|
@@ -66,7 +172,7 @@ const handler = async ({ force }) => {
|
|
|
66
172
|
files,
|
|
67
173
|
force
|
|
68
174
|
}),
|
|
69
|
-
printSetupNotes(
|
|
175
|
+
printSetupNotes(notesFor(monitor, jobs, processNames))
|
|
70
176
|
],
|
|
71
177
|
{ rendererOptions: { collapseSubtasks: false } }
|
|
72
178
|
);
|
|
@@ -81,6 +187,8 @@ const handler = async ({ force }) => {
|
|
|
81
187
|
}
|
|
82
188
|
};
|
|
83
189
|
export {
|
|
190
|
+
appNameFromPath,
|
|
84
191
|
configFilename,
|
|
85
|
-
handler
|
|
192
|
+
handler,
|
|
193
|
+
setupFiles
|
|
86
194
|
};
|
|
@@ -56,11 +56,17 @@ function addNetlifyPluginsToViteConfigTask() {
|
|
|
56
56
|
const hasNetlifyCompat = content.includes(
|
|
57
57
|
"@universal-deploy/netlify/vite"
|
|
58
58
|
);
|
|
59
|
-
|
|
59
|
+
const hasSkewProtectionImport = content.includes(
|
|
60
|
+
"cedarNetlifySkewProtectionPlugin"
|
|
61
|
+
);
|
|
62
|
+
const hasSkewProtectionCall = content.includes(
|
|
63
|
+
"cedarNetlifySkewProtectionPlugin("
|
|
64
|
+
);
|
|
65
|
+
if (hasNetlifyPlugin && hasNetlifyCompat && hasSkewProtectionImport && hasSkewProtectionCall && content.includes("netlifyCompat(")) {
|
|
60
66
|
task.skip("Netlify plugins are already configured.");
|
|
61
67
|
return;
|
|
62
68
|
}
|
|
63
|
-
if (!hasNetlifyPlugin || !hasNetlifyCompat) {
|
|
69
|
+
if (!hasNetlifyPlugin || !hasNetlifyCompat || !hasSkewProtectionImport) {
|
|
64
70
|
const newContent = content.replace(
|
|
65
71
|
/(import\s+\{[^}]*\}\s+from\s+['"]vite['"];?)/,
|
|
66
72
|
(match) => {
|
|
@@ -71,6 +77,10 @@ ${result}`;
|
|
|
71
77
|
}
|
|
72
78
|
if (!hasNetlifyCompat) {
|
|
73
79
|
result = `import netlifyCompat from '@universal-deploy/netlify/vite'
|
|
80
|
+
${result}`;
|
|
81
|
+
}
|
|
82
|
+
if (!hasSkewProtectionImport) {
|
|
83
|
+
result = `import { cedarNetlifySkewProtectionPlugin } from '@cedarjs/vite'
|
|
74
84
|
${result}`;
|
|
75
85
|
}
|
|
76
86
|
return result;
|
|
@@ -84,6 +94,9 @@ ${result}`;
|
|
|
84
94
|
if (!hasNetlifyCompat) {
|
|
85
95
|
prepend += "import netlifyCompat from '@universal-deploy/netlify/vite'\n";
|
|
86
96
|
}
|
|
97
|
+
if (!hasSkewProtectionImport) {
|
|
98
|
+
prepend += "import { cedarNetlifySkewProtectionPlugin } from '@cedarjs/vite'\n";
|
|
99
|
+
}
|
|
87
100
|
content = prepend + content;
|
|
88
101
|
} else {
|
|
89
102
|
content = newContent;
|
|
@@ -94,12 +107,21 @@ ${result}`;
|
|
|
94
107
|
content,
|
|
95
108
|
pluginCodes: [
|
|
96
109
|
"netlify({ build: { enabled: true } })",
|
|
97
|
-
"netlifyCompat()"
|
|
110
|
+
"netlifyCompat()",
|
|
111
|
+
"cedarNetlifySkewProtectionPlugin()"
|
|
98
112
|
]
|
|
99
113
|
});
|
|
100
114
|
if (result) {
|
|
101
115
|
content = result;
|
|
102
116
|
}
|
|
117
|
+
} else if (!hasSkewProtectionCall) {
|
|
118
|
+
const result = insertPluginsBeforeCedar({
|
|
119
|
+
content,
|
|
120
|
+
pluginCodes: ["cedarNetlifySkewProtectionPlugin()"]
|
|
121
|
+
});
|
|
122
|
+
if (result) {
|
|
123
|
+
content = result;
|
|
124
|
+
}
|
|
103
125
|
}
|
|
104
126
|
fs.writeFileSync(viteConfigPath, content);
|
|
105
127
|
}
|
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
import { getPackageManager } from "@cedarjs/project-config/packageManager";
|
|
2
|
-
const
|
|
2
|
+
const SYSTEMD_DIR = "systemd";
|
|
3
|
+
const JOBS_WORKER_BIN = "api/node_modules/.bin/cedar-jobs-worker";
|
|
4
|
+
const WORKER_STOP_TIMEOUT_SECONDS = 600;
|
|
5
|
+
const JOBS_WORKER_COMMENT = `# Runs one background jobs worker. \`--index\` picks the entry of the \`workers\`
|
|
6
|
+
# array in api/src/lib/jobs.ts and \`--id\` numbers the worker within that
|
|
7
|
+
# entry, so an entry with \`count: 2\` needs a second worker with \`--id=1\`.`;
|
|
8
|
+
const ecosystemConfig = ({ jobs }) => {
|
|
9
|
+
const jobsApp = jobs ? `
|
|
10
|
+
{
|
|
11
|
+
// Runs one background jobs worker. \`--index\` picks the entry of the
|
|
12
|
+
// \`workers\` array in api/src/lib/jobs.ts and \`--id\` numbers the worker
|
|
13
|
+
// within that entry, so an entry with \`count: 2\` needs a second app
|
|
14
|
+
// with \`--id=1\`.
|
|
15
|
+
name: 'jobs',
|
|
16
|
+
cwd: 'current',
|
|
17
|
+
script: '${JOBS_WORKER_BIN}',
|
|
18
|
+
args: '--index=0 --id=0',
|
|
19
|
+
// pm2 stops the worker with SIGINT, which lets it finish the job it is
|
|
20
|
+
// running. This is how long pm2 waits for that (in ms) before killing it.
|
|
21
|
+
kill_timeout: ${WORKER_STOP_TIMEOUT_SECONDS * 1e3},
|
|
22
|
+
},` : "";
|
|
23
|
+
return `module.exports = {
|
|
3
24
|
apps: [
|
|
4
25
|
{
|
|
5
26
|
name: 'serve',
|
|
@@ -10,10 +31,79 @@ const ECOSYSTEM = `module.exports = {
|
|
|
10
31
|
exec_mode: 'cluster',
|
|
11
32
|
wait_ready: true,
|
|
12
33
|
listen_timeout: 10000,
|
|
13
|
-
}
|
|
34
|
+
},${jobsApp}
|
|
14
35
|
],
|
|
15
|
-
}
|
|
16
|
-
|
|
36
|
+
}
|
|
37
|
+
`;
|
|
38
|
+
};
|
|
39
|
+
const unitHeader = (appName, monitor) => {
|
|
40
|
+
const install = monitor === "systemd-system" ? `# sudo cp ${SYSTEMD_DIR}/*.service /etc/systemd/system/` : `# mkdir -p ~/.config/systemd/user && cp ${SYSTEMD_DIR}/*.service ~/.config/systemd/user/`;
|
|
41
|
+
const linger = monitor === "systemd-system" ? "" : `#
|
|
42
|
+
# User units only run while the user has a session, so let them run after a
|
|
43
|
+
# reboot too:
|
|
44
|
+
# sudo loginctl enable-linger $(whoami)
|
|
45
|
+
`;
|
|
46
|
+
return `# systemd unit for the ${appName} Cedar app, generated by \`cedar setup deploy baremetal\`.
|
|
47
|
+
#
|
|
48
|
+
# Copy the unit files to the server once, before the first deploy:
|
|
49
|
+
${install}
|
|
50
|
+
${linger}#
|
|
51
|
+
# Then deploy with \`--first-run\`, which reloads the unit files and enables and
|
|
52
|
+
# starts every process listed in deploy.toml.
|
|
53
|
+
#
|
|
54
|
+
# WorkingDirectory must be the \`path\` from deploy.toml followed by \`/current\`.`;
|
|
55
|
+
};
|
|
56
|
+
const unitService = (monitor, execStart, extraDirectives = "") => {
|
|
57
|
+
const user = monitor === "systemd-system" ? "\nUser=deploy" : "";
|
|
58
|
+
return `[Service]
|
|
59
|
+
WorkingDirectory=/var/www/app/current
|
|
60
|
+
# A login shell puts node and ${getPackageManager()} from a version manager such as nvm on the PATH
|
|
61
|
+
ExecStart=/bin/bash -lc '${execStart}'
|
|
62
|
+
Restart=always
|
|
63
|
+
RestartSec=5
|
|
64
|
+
Environment=NODE_ENV=production${user}${extraDirectives}`;
|
|
65
|
+
};
|
|
66
|
+
const JOBS_STOP_DIRECTIVES = `
|
|
67
|
+
# Stopping sends SIGINT so the worker finishes the job it is running before it
|
|
68
|
+
# exits. systemd waits this long for that before killing the worker.
|
|
69
|
+
KillSignal=SIGINT
|
|
70
|
+
TimeoutStopSec=${WORKER_STOP_TIMEOUT_SECONDS}`;
|
|
71
|
+
const unitInstall = (monitor) => `[Install]
|
|
72
|
+
WantedBy=${monitor === "systemd-system" ? "multi-user.target" : "default.target"}`;
|
|
73
|
+
const systemdServiceUnit = ({
|
|
74
|
+
appName,
|
|
75
|
+
monitor
|
|
76
|
+
}) => `${unitHeader(appName, monitor)}
|
|
77
|
+
|
|
78
|
+
[Unit]
|
|
79
|
+
Description=${appName} (Cedar)
|
|
80
|
+
After=network.target
|
|
81
|
+
|
|
82
|
+
${unitService(monitor, "exec node_modules/.bin/cedar serve")}
|
|
83
|
+
|
|
84
|
+
${unitInstall(monitor)}
|
|
85
|
+
`;
|
|
86
|
+
const systemdJobsUnit = ({
|
|
87
|
+
appName,
|
|
88
|
+
monitor
|
|
89
|
+
}) => `${unitHeader(appName, monitor)}
|
|
90
|
+
#
|
|
91
|
+
${JOBS_WORKER_COMMENT}
|
|
92
|
+
# Start one instance per \`workers\` entry: \`${appName}-jobs@0\`, \`${appName}-jobs@1\`
|
|
93
|
+
# and so on, and list each one in \`processNames\` in deploy.toml.
|
|
94
|
+
|
|
95
|
+
[Unit]
|
|
96
|
+
Description=${appName} background jobs worker %i (Cedar)
|
|
97
|
+
After=network.target
|
|
98
|
+
|
|
99
|
+
${unitService(monitor, `exec ${JOBS_WORKER_BIN} --index=%i --id=0`, JOBS_STOP_DIRECTIVES)}
|
|
100
|
+
|
|
101
|
+
${unitInstall(monitor)}
|
|
102
|
+
`;
|
|
103
|
+
const deployToml = ({
|
|
104
|
+
monitor,
|
|
105
|
+
processNames
|
|
106
|
+
}) => `# This file contains config for a baremetal deployment
|
|
17
107
|
#
|
|
18
108
|
# SSH connection options include:
|
|
19
109
|
#
|
|
@@ -26,6 +116,22 @@ const DEPLOY = `# This file contains config for a baremetal deployment
|
|
|
26
116
|
# * passphrase - used if your private key has a passphrase
|
|
27
117
|
# * agentForward - set to \`true\` to forward the client machine's ssh credentials
|
|
28
118
|
#
|
|
119
|
+
# Process monitor options:
|
|
120
|
+
#
|
|
121
|
+
# * monitor - "pm2", "systemd-user" or "systemd-system". Decides how processes
|
|
122
|
+
# are started for the first time, restarted and stopped
|
|
123
|
+
# * monitorCommand - overrides the command the monitor is invoked with. Defaults
|
|
124
|
+
# to \`pm2\`, \`systemctl --user\` or \`sudo systemctl\` depending on \`monitor\`,
|
|
125
|
+
# for example \`doppler run -- pm2\`
|
|
126
|
+
# * processNames - the pm2 app names or systemd unit names to (re)start
|
|
127
|
+
#
|
|
128
|
+
# After restarting the processes, the deploy requests the api side's health
|
|
129
|
+
# check endpoint on the server and fails if it doesn't respond in time:
|
|
130
|
+
#
|
|
131
|
+
# * healthCheckUrl - defaults to http://localhost:<[api].port>/graphql/health
|
|
132
|
+
# on servers that host the api side. Set to \`false\` to skip the check
|
|
133
|
+
# * healthCheckTimeout - seconds to keep retrying, defaults to 30
|
|
134
|
+
#
|
|
29
135
|
# See https://cedarjs.com/docs/deploy/baremetal for more info
|
|
30
136
|
|
|
31
137
|
[[production.servers]]
|
|
@@ -34,13 +140,14 @@ username = "user"
|
|
|
34
140
|
agentForward = true
|
|
35
141
|
sides = ["api","web"]
|
|
36
142
|
packageManagerCommand = "${getPackageManager()}"
|
|
37
|
-
|
|
143
|
+
monitor = "${monitor}"
|
|
38
144
|
path = "/var/www/app"
|
|
39
|
-
processNames = ["
|
|
145
|
+
processNames = [${processNames.map((name) => `"${name}"`).join(", ")}]
|
|
40
146
|
repo = "git@github.com:myorg/myapp.git"
|
|
41
147
|
branch = "main"
|
|
42
148
|
keepReleases = 5
|
|
43
149
|
freeSpaceRequired = 2048
|
|
150
|
+
healthCheckTimeout = 30
|
|
44
151
|
|
|
45
152
|
# If you have separate api and web servers:
|
|
46
153
|
#
|
|
@@ -123,7 +230,10 @@ And take it back down with:
|
|
|
123
230
|
</html>
|
|
124
231
|
`;
|
|
125
232
|
export {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
233
|
+
MAINTENANCE,
|
|
234
|
+
SYSTEMD_DIR,
|
|
235
|
+
deployToml,
|
|
236
|
+
ecosystemConfig,
|
|
237
|
+
systemdJobsUnit,
|
|
238
|
+
systemdServiceUnit
|
|
129
239
|
};
|
|
@@ -10,6 +10,9 @@ NODE_VERSION = "24"
|
|
|
10
10
|
|
|
11
11
|
[functions]
|
|
12
12
|
directory = "api/dist/ud"
|
|
13
|
+
# Sandboxed child scripts (\`@cedarjs/api/sandbox\`) and the packages they
|
|
14
|
+
# import. Nothing imports them, so Netlify's file tracing can't find them
|
|
15
|
+
included_files = ["api/dist/ud/sandbox-children/**"]
|
|
13
16
|
|
|
14
17
|
# To use Netlify Dev, install Netlify's CLI (\`netlify-cli\`) from NPM and use
|
|
15
18
|
# \`netlify link\` to connect your local project to a site on Netlify. Then run
|
|
@@ -76,7 +76,6 @@ const handler = async ({ force }) => {
|
|
|
76
76
|
"export const handler = createGraphQLHandler({",
|
|
77
77
|
"extraPlugins: [useSentry({",
|
|
78
78
|
" includeRawResult: true,",
|
|
79
|
-
" includeResolverArgs: true,",
|
|
80
79
|
" includeExecuteVariables: true,",
|
|
81
80
|
"})],"
|
|
82
81
|
);
|
|
@@ -112,7 +111,11 @@ const handler = async ({ force }) => {
|
|
|
112
111
|
contentLines.splice(
|
|
113
112
|
boundaryOpenIndex,
|
|
114
113
|
1,
|
|
115
|
-
"<Sentry.ErrorBoundary
|
|
114
|
+
"<Sentry.ErrorBoundary",
|
|
115
|
+
" fallback={({ error }) => (",
|
|
116
|
+
" <FatalErrorPage error={error instanceof Error ? error : undefined} />",
|
|
117
|
+
" )}",
|
|
118
|
+
">"
|
|
116
119
|
);
|
|
117
120
|
const boundaryCloseIndex = contentLines.findLastIndex(
|
|
118
121
|
(line) => line.includes("</FatalErrorBoundary>")
|