@cedarjs/cli 2.2.0-rc.34 → 2.2.0
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/{rwfw.js → cfw.js} +11 -14
- package/dist/commands/consoleHandler.js +1 -1
- package/dist/commands/deploy/baremetal/baremetalHandler.js +1 -1
- package/dist/commands/deploy/serverlessHandler.js +1 -1
- package/dist/commands/destroy/scaffold/scaffoldHandler.js +1 -1
- package/dist/commands/generate/cell/cellHandler.js +1 -1
- package/dist/commands/generate/cell/templates/test.js.template +2 -2
- package/dist/commands/generate/component/templates/test.tsx.template +1 -1
- package/dist/commands/generate/dbAuth/dbAuth.js +1 -1
- package/dist/commands/generate/dbAuth/dbAuthHandler.js +1 -1
- package/dist/commands/generate/directive/directiveHandler.js +6 -16
- package/dist/commands/generate/directive/templates/transformer.directive.ts.template +1 -1
- package/dist/commands/generate/directive/templates/validator.directive.ts.template +1 -1
- package/dist/commands/generate/function/functionHandler.js +10 -35
- package/dist/commands/generate/function/templates/function.ts.template +3 -3
- package/dist/commands/generate/function/templates/scenarios.ts.template +1 -1
- package/dist/commands/generate/function/templates/test.ts.template +2 -2
- package/dist/commands/generate/helpers.js +1 -1
- package/dist/commands/generate/job/jobHandler.js +26 -35
- package/dist/commands/generate/job/templates/scenarios.ts.template +1 -1
- package/dist/commands/generate/layout/templates/test.tsx.template +1 -1
- package/dist/commands/generate/model/model.js +1 -1
- package/dist/commands/generate/page/templates/test.tsx.template +1 -1
- package/dist/commands/generate/scaffold/scaffoldHandler.js +1 -1
- package/dist/commands/generate/sdl/sdlHandler.js +14 -47
- package/dist/commands/generate/service/serviceHandler.js +18 -21
- package/dist/commands/generate/service/templates/test.ts.template +2 -2
- package/dist/commands/generate/yargsCommandHelpers.js +12 -4
- package/dist/commands/generate/yargsHandlerHelpers.js +38 -14
- package/dist/commands/prerenderHandler.js +2 -2
- package/dist/commands/record.js +1 -1
- package/dist/commands/setup/auth/auth.js +1 -1
- package/dist/commands/setup/cache/cacheHandler.js +1 -1
- package/dist/commands/setup/deploy/providers/baremetalHandler.js +1 -1
- package/dist/commands/setup/deploy/providers/netlifyHandler.js +1 -1
- package/dist/commands/setup/deploy/providers/serverless.js +1 -1
- package/dist/commands/setup/deploy/providers/serverlessHandler.js +3 -3
- package/dist/commands/setup/deploy/providers/vercelHandler.js +1 -1
- package/dist/commands/setup/deploy/templates/baremetal.js +1 -1
- package/dist/commands/setup/docker/dockerHandler.js +1 -1
- package/dist/commands/setup/tsconfig/tsconfigHandler.js +1 -1
- package/dist/commands/setup/uploads/uploadsHandler.js +3 -3
- package/dist/commands/upgrade.js +269 -13
- package/dist/lib/exit.js +5 -9
- package/dist/lib/index.js +1 -1
- package/dist/lib/pluralHelpers.js +1 -1
- package/dist/lib/schemaHelpers.js +1 -1
- package/package.json +26 -25
- /package/dist/lib/{rwPluralize.js → cedarPluralize.js} +0 -0
package/dist/{rwfw.js → cfw.js}
RENAMED
|
@@ -6,28 +6,25 @@ import fs from "fs-extra";
|
|
|
6
6
|
import { terminalLink } from "termi-link";
|
|
7
7
|
import { getConfigPath } from "@cedarjs/project-config";
|
|
8
8
|
const config = new Configstore("@cedarjs/cli");
|
|
9
|
-
const
|
|
10
|
-
if (!
|
|
11
|
-
console.error("Error: You must specify the path to
|
|
12
|
-
console.error("Usage: `
|
|
9
|
+
const CFW_PATH = process.env.CFW_PATH || process.env.RWFW_PATH || process.env.RW_PATH || config.get("CFW_PATH") || config.get("RWFW_PATH");
|
|
10
|
+
if (!CFW_PATH) {
|
|
11
|
+
console.error("Error: You must specify the path to Cedar Framework");
|
|
12
|
+
console.error("Usage: `CFW_PATH=~/gh/cedarjs/cedar yarn cfw <command>");
|
|
13
13
|
process.exit(1);
|
|
14
14
|
}
|
|
15
|
-
if (!fs.existsSync(
|
|
15
|
+
if (!fs.existsSync(CFW_PATH)) {
|
|
16
16
|
console.error(
|
|
17
|
-
`Error: The specified path to
|
|
17
|
+
`Error: The specified path to Cedar Framework (${CFW_PATH}) does not exist.`
|
|
18
18
|
);
|
|
19
|
-
console.error("Usage: `
|
|
19
|
+
console.error("Usage: `CFW_PATH=~/gh/cedarjs/cedar yarn cfw <command>");
|
|
20
20
|
process.exit(1);
|
|
21
21
|
}
|
|
22
|
-
const
|
|
23
|
-
config.set("
|
|
22
|
+
const absCfwPath = path.resolve(process.cwd(), CFW_PATH);
|
|
23
|
+
config.set("CFW_PATH", absCfwPath);
|
|
24
24
|
const projectPath = path.dirname(
|
|
25
25
|
getConfigPath(process.env.RWJS_CWD ?? process.cwd())
|
|
26
26
|
);
|
|
27
|
-
console.log(
|
|
28
|
-
"Redwood Framework Tools Path:",
|
|
29
|
-
terminalLink(absRwFwPath, absRwFwPath)
|
|
30
|
-
);
|
|
27
|
+
console.log("Cedar Framework Tools Path:", terminalLink(absCfwPath, absCfwPath));
|
|
31
28
|
let command = process.argv.slice(2);
|
|
32
29
|
const helpCommands = ["help", "--help"];
|
|
33
30
|
if (!command.length || command.some((cmd) => helpCommands.includes(cmd))) {
|
|
@@ -36,7 +33,7 @@ if (!command.length || command.some((cmd) => helpCommands.includes(cmd))) {
|
|
|
36
33
|
try {
|
|
37
34
|
execa.sync("yarn", [...command], {
|
|
38
35
|
stdio: "inherit",
|
|
39
|
-
cwd:
|
|
36
|
+
cwd: absCfwPath,
|
|
40
37
|
env: {
|
|
41
38
|
RWJS_CWD: projectPath
|
|
42
39
|
}
|
|
@@ -9,7 +9,7 @@ const paths = getPaths();
|
|
|
9
9
|
const loadPrismaClient = (replContext) => {
|
|
10
10
|
const createdRequire = createRequire(import.meta.url);
|
|
11
11
|
const { db } = createdRequire(path.join(paths.api.lib, "db"));
|
|
12
|
-
db[Symbol.for("nodejs.util.inspect.custom")] = "PrismaClient";
|
|
12
|
+
db[/* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom")] = "PrismaClient";
|
|
13
13
|
replContext.db = db;
|
|
14
14
|
};
|
|
15
15
|
const consoleHistoryFile = path.join(paths.generated.base, "console_history");
|
|
@@ -25,7 +25,7 @@ const DEFAULT_SERVER_CONFIG = {
|
|
|
25
25
|
const pathJoin = path.posix.join;
|
|
26
26
|
const throwMissingConfig = (name) => {
|
|
27
27
|
throw new Error(
|
|
28
|
-
`"${name}" config option not set. See https://
|
|
28
|
+
`"${name}" config option not set. See https://cedarjs.com/docs/deployment/baremetal#deploytoml`
|
|
29
29
|
);
|
|
30
30
|
};
|
|
31
31
|
const verifyConfig = (config, yargs) => {
|
|
@@ -157,7 +157,7 @@ const handler = async (yargs) => {
|
|
|
157
157
|
"To do this run `yarn serverless` on each of the sides, and connect your account",
|
|
158
158
|
"",
|
|
159
159
|
"Find more information in our docs:",
|
|
160
|
-
c.underline("https://
|
|
160
|
+
c.underline("https://cedarjs.com/docs/deploy#serverless")
|
|
161
161
|
];
|
|
162
162
|
console.log(
|
|
163
163
|
boxen(message.join("\n"), {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Listr } from "listr2";
|
|
2
2
|
import pascalcase from "pascalcase";
|
|
3
3
|
import { recordTelemetryAttributes } from "@cedarjs/cli-helpers";
|
|
4
|
+
import { pluralize } from "../../../lib/cedarPluralize.js";
|
|
4
5
|
import c from "../../../lib/colors.js";
|
|
5
6
|
import {
|
|
6
7
|
deleteFilesTask,
|
|
@@ -9,7 +10,6 @@ import {
|
|
|
9
10
|
removeRoutesFromRouterTask,
|
|
10
11
|
writeFile
|
|
11
12
|
} from "../../../lib/index.js";
|
|
12
|
-
import { pluralize } from "../../../lib/rwPluralize.js";
|
|
13
13
|
import { verifyModelName } from "../../../lib/schemaHelpers.js";
|
|
14
14
|
import {
|
|
15
15
|
files,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import pascalcase from "pascalcase";
|
|
2
2
|
import { generate as generateTypes } from "@cedarjs/internal/dist/generate/generate";
|
|
3
|
+
import { isPlural, singularize } from "../../../lib/cedarPluralize.js";
|
|
3
4
|
import { nameVariants, transformTSToJS } from "../../../lib/index.js";
|
|
4
5
|
import { isWordPluralizable } from "../../../lib/pluralHelpers.js";
|
|
5
6
|
import { addFunctionToRollback } from "../../../lib/rollback.js";
|
|
6
|
-
import { isPlural, singularize } from "../../../lib/rwPluralize.js";
|
|
7
7
|
import { getSchema } from "../../../lib/schemaHelpers.js";
|
|
8
8
|
import { forcePluralizeWord, removeGeneratorName } from "../helpers.js";
|
|
9
9
|
import {
|
|
@@ -6,8 +6,8 @@ import { standard } from './${pascalName}Cell.mock'
|
|
|
6
6
|
// Generated boilerplate tests do not account for all circumstances
|
|
7
7
|
// and can fail without adjustments, e.g. Float and DateTime types.
|
|
8
8
|
// Please refer to the RedwoodJS Testing Docs:
|
|
9
|
-
// https://
|
|
10
|
-
// https://
|
|
9
|
+
// https://cedarjs.com/docs/testing#testing-cells
|
|
10
|
+
// https://cedarjs.com/docs/testing#jest-expect-type-considerations
|
|
11
11
|
|
|
12
12
|
describe('${pascalName}Cell', () => {
|
|
13
13
|
it('renders Loading successfully', () => {
|
|
@@ -3,7 +3,7 @@ import { render } from '@cedarjs/testing/web'
|
|
|
3
3
|
import ${pascalName} from './${pascalName}'
|
|
4
4
|
|
|
5
5
|
// Improve this test with help from the Redwood Testing Doc:
|
|
6
|
-
// https://
|
|
6
|
+
// https://cedarjs.com/docs/testing#testing-components
|
|
7
7
|
|
|
8
8
|
describe('${pascalName}', () => {
|
|
9
9
|
it('renders successfully', () => {
|
|
@@ -39,7 +39,7 @@ const builder = (yargs) => {
|
|
|
39
39
|
}).epilogue(
|
|
40
40
|
`Also see the ${terminalLink(
|
|
41
41
|
"CedarJS dbAuth Reference",
|
|
42
|
-
"https://
|
|
42
|
+
"https://cedarjs.com/docs/auth/dbauth"
|
|
43
43
|
)}`
|
|
44
44
|
);
|
|
45
45
|
Object.entries(getYargsDefaults()).forEach(([option, config]) => {
|
|
@@ -263,7 +263,7 @@ const tasks = ({
|
|
|
263
263
|
{
|
|
264
264
|
type: "confirm",
|
|
265
265
|
name: "answer",
|
|
266
|
-
message: "Enable WebAuthn support (TouchID/FaceID) on LoginPage? See https://
|
|
266
|
+
message: "Enable WebAuthn support (TouchID/FaceID) on LoginPage? See https://cedarjs.com/docs/auth/dbAuth#webAuthn",
|
|
267
267
|
default: false
|
|
268
268
|
},
|
|
269
269
|
{ enquirer: ctx.enquirer }
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import path from "path";
|
|
2
1
|
import camelcase from "camelcase";
|
|
3
2
|
import execa from "execa";
|
|
4
3
|
import { Listr } from "listr2";
|
|
@@ -6,11 +5,7 @@ import prompts from "prompts";
|
|
|
6
5
|
import { recordTelemetryAttributes } from "@cedarjs/cli-helpers";
|
|
7
6
|
import { getConfig } from "@cedarjs/project-config";
|
|
8
7
|
import c from "../../../lib/colors.js";
|
|
9
|
-
import {
|
|
10
|
-
getPaths,
|
|
11
|
-
writeFilesTask,
|
|
12
|
-
transformTSToJS
|
|
13
|
-
} from "../../../lib/index.js";
|
|
8
|
+
import { writeFilesTask, transformTSToJS } from "../../../lib/index.js";
|
|
14
9
|
import {
|
|
15
10
|
prepareForRollback,
|
|
16
11
|
addFunctionToRollback
|
|
@@ -25,28 +20,23 @@ const files = async ({ name, typescript = false, type, tests }) => {
|
|
|
25
20
|
throw new Error("You must specify a directive type");
|
|
26
21
|
}
|
|
27
22
|
const camelName = camelcase(name);
|
|
28
|
-
const
|
|
23
|
+
const extension = typescript ? ".ts" : ".js";
|
|
29
24
|
const directiveFile = await templateForComponentFile({
|
|
30
25
|
name,
|
|
31
|
-
extension
|
|
26
|
+
extension,
|
|
32
27
|
generator: "directive",
|
|
28
|
+
apiPathSection: "directives",
|
|
33
29
|
templatePath: `${type}.directive.ts.template`,
|
|
34
|
-
outputPath: path.join(getPaths().api.directives, camelName, outputFilename),
|
|
35
30
|
templateVars: { camelName }
|
|
36
31
|
});
|
|
37
32
|
const files2 = [directiveFile];
|
|
38
33
|
if (tests) {
|
|
39
|
-
const testOutputFilename = `${camelcase(name)}.test.${typescript ? "ts" : "js"}`;
|
|
40
34
|
const testFile = await templateForComponentFile({
|
|
41
35
|
name,
|
|
42
|
-
extension:
|
|
36
|
+
extension: `.test${extension}`,
|
|
43
37
|
generator: "directive",
|
|
38
|
+
apiPathSection: "directives",
|
|
44
39
|
templatePath: `${type}.directive.test.ts.template`,
|
|
45
|
-
outputPath: path.join(
|
|
46
|
-
getPaths().api.directives,
|
|
47
|
-
camelName,
|
|
48
|
-
testOutputFilename
|
|
49
|
-
),
|
|
50
40
|
templateVars: { camelName }
|
|
51
41
|
});
|
|
52
42
|
files2.push(testFile);
|
|
@@ -28,7 +28,7 @@ const transform: TransformerDirectiveFunc = ({ context, resolvedValue }) => {
|
|
|
28
28
|
|
|
29
29
|
// You can also modify your directive to take arguments
|
|
30
30
|
// and use the directiveArgs object provided to this function to get values
|
|
31
|
-
// See documentation here: https://
|
|
31
|
+
// See documentation here: https://cedarjs.com/docs/directives
|
|
32
32
|
|
|
33
33
|
return resolvedValue.replace('foo', 'bar')
|
|
34
34
|
}
|
|
@@ -27,7 +27,7 @@ const validate: ValidatorDirectiveFunc = ({ context, directiveArgs }) => {
|
|
|
27
27
|
|
|
28
28
|
// You can also modify your directive to take arguments
|
|
29
29
|
// and use the directiveArgs object provided to this function to get values
|
|
30
|
-
// See documentation here: https://
|
|
30
|
+
// See documentation here: https://cedarjs.com/docs/directives
|
|
31
31
|
logger.debug(directiveArgs, 'directiveArgs in ${camelName} directive')
|
|
32
32
|
|
|
33
33
|
|
|
@@ -1,15 +1,9 @@
|
|
|
1
|
-
import path from "path";
|
|
2
|
-
import camelcase from "camelcase";
|
|
3
1
|
import { Listr } from "listr2";
|
|
4
2
|
import { terminalLink } from "termi-link";
|
|
5
3
|
import { recordTelemetryAttributes } from "@cedarjs/cli-helpers";
|
|
6
4
|
import { errorTelemetry } from "@cedarjs/telemetry";
|
|
7
5
|
import c from "../../../lib/colors.js";
|
|
8
|
-
import {
|
|
9
|
-
getPaths,
|
|
10
|
-
transformTSToJS,
|
|
11
|
-
writeFilesTask
|
|
12
|
-
} from "../../../lib/index.js";
|
|
6
|
+
import { transformTSToJS, writeFilesTask } from "../../../lib/index.js";
|
|
13
7
|
import { prepareForRollback } from "../../../lib/rollback.js";
|
|
14
8
|
import { validateName } from "../helpers.js";
|
|
15
9
|
import { templateForComponentFile } from "../yargsHandlerHelpers.js";
|
|
@@ -20,51 +14,32 @@ const files = async ({
|
|
|
20
14
|
...rest
|
|
21
15
|
}) => {
|
|
22
16
|
const extension = generateTypescript ? ".ts" : ".js";
|
|
23
|
-
const functionName = camelcase(name);
|
|
24
17
|
const outputFiles = [];
|
|
25
18
|
const functionFiles = await templateForComponentFile({
|
|
26
|
-
name
|
|
27
|
-
componentName: functionName,
|
|
19
|
+
name,
|
|
28
20
|
extension,
|
|
29
21
|
apiPathSection: "functions",
|
|
30
22
|
generator: "function",
|
|
31
23
|
templatePath: "function.ts.template",
|
|
32
|
-
templateVars: { ...rest, typescript: generateTypescript }
|
|
33
|
-
outputPath: path.join(
|
|
34
|
-
getPaths().api.functions,
|
|
35
|
-
functionName,
|
|
36
|
-
`${functionName}${extension}`
|
|
37
|
-
)
|
|
24
|
+
templateVars: { ...rest, typescript: generateTypescript }
|
|
38
25
|
});
|
|
39
26
|
outputFiles.push(functionFiles);
|
|
40
27
|
if (generateTests) {
|
|
41
28
|
const testFile = await templateForComponentFile({
|
|
42
|
-
name
|
|
43
|
-
|
|
44
|
-
extension,
|
|
29
|
+
name,
|
|
30
|
+
extension: `.test${extension}`,
|
|
45
31
|
apiPathSection: "functions",
|
|
46
32
|
generator: "function",
|
|
47
33
|
templatePath: "test.ts.template",
|
|
48
|
-
templateVars: { ...rest }
|
|
49
|
-
outputPath: path.join(
|
|
50
|
-
getPaths().api.functions,
|
|
51
|
-
functionName,
|
|
52
|
-
`${functionName}.test${extension}`
|
|
53
|
-
)
|
|
34
|
+
templateVars: { ...rest }
|
|
54
35
|
});
|
|
55
36
|
const scenarioFile = await templateForComponentFile({
|
|
56
|
-
name
|
|
57
|
-
|
|
58
|
-
extension,
|
|
37
|
+
name,
|
|
38
|
+
extension: `.scenarios${extension}`,
|
|
59
39
|
apiPathSection: "functions",
|
|
60
40
|
generator: "function",
|
|
61
41
|
templatePath: "scenarios.ts.template",
|
|
62
|
-
templateVars: { ...rest }
|
|
63
|
-
outputPath: path.join(
|
|
64
|
-
getPaths().api.functions,
|
|
65
|
-
functionName,
|
|
66
|
-
`${functionName}.scenarios${extension}`
|
|
67
|
-
)
|
|
42
|
+
templateVars: { ...rest }
|
|
68
43
|
});
|
|
69
44
|
outputFiles.push(testFile);
|
|
70
45
|
outputFiles.push(scenarioFile);
|
|
@@ -115,7 +90,7 @@ const handler = async ({ name, force, ...rest }) => {
|
|
|
115
90
|
console.info(
|
|
116
91
|
`Please consult the ${terminalLink(
|
|
117
92
|
"Serverless Function Considerations",
|
|
118
|
-
"https://
|
|
93
|
+
"https://cedarjs.com/docs/serverless-functions#security-considerations"
|
|
119
94
|
)} in the RedwoodJS documentation for more information.`
|
|
120
95
|
);
|
|
121
96
|
console.info("");
|
|
@@ -9,7 +9,7 @@ import { logger } from 'src/lib/logger'
|
|
|
9
9
|
* Important: When deployed, a custom serverless function is an open API endpoint and
|
|
10
10
|
* is your responsibility to secure appropriately.
|
|
11
11
|
*
|
|
12
|
-
* @see {@link https://
|
|
12
|
+
* @see {@link https://cedarjs.com/docs/serverless-functions#security-considerations|Serverless Function Considerations}
|
|
13
13
|
* in the RedwoodJS documentation for more information.
|
|
14
14
|
*<% if (!typescript) { %>
|
|
15
15
|
* @typedef { import('aws-lambda').APIGatewayEvent } APIGatewayEvent
|
|
@@ -19,7 +19,7 @@ import { logger } from 'src/lib/logger'
|
|
|
19
19
|
* function, and execution environment.
|
|
20
20
|
*/
|
|
21
21
|
export const handler = async (event: APIGatewayEvent, _context: Context) => {
|
|
22
|
-
logger.info(`<%= '$' %>{event.httpMethod} <%= '$' %>{event.path}: <%=
|
|
22
|
+
logger.info(`<%= '$' %>{event.httpMethod} <%= '$' %>{event.path}: <%= camelName %> function`)
|
|
23
23
|
|
|
24
24
|
return {
|
|
25
25
|
statusCode: 200,
|
|
@@ -27,7 +27,7 @@ export const handler = async (event: APIGatewayEvent, _context: Context) => {
|
|
|
27
27
|
'Content-Type': 'application/json',
|
|
28
28
|
},
|
|
29
29
|
body: JSON.stringify({
|
|
30
|
-
data: '${
|
|
30
|
+
data: '${camelName} function',
|
|
31
31
|
}),
|
|
32
32
|
}
|
|
33
33
|
}
|
|
@@ -2,7 +2,7 @@ import type { ScenarioData } from '@cedarjs/testing/api'
|
|
|
2
2
|
|
|
3
3
|
export const standard = defineScenario({
|
|
4
4
|
// Define the "fixture" to write into your test database here
|
|
5
|
-
// See guide: https://
|
|
5
|
+
// See guide: https://cedarjs.com/docs/testing#scenarios
|
|
6
6
|
})
|
|
7
7
|
|
|
8
8
|
export type StandardScenario = ScenarioData<unknown>
|
|
@@ -3,7 +3,7 @@ import { mockHttpEvent, mockContext } from '@cedarjs/testing/api'
|
|
|
3
3
|
import { handler } from './${name}'
|
|
4
4
|
|
|
5
5
|
// Improve this test with help from the Redwood Testing Doc:
|
|
6
|
-
// https://
|
|
6
|
+
// https://cedarjs.com/docs/testing#testing-functions
|
|
7
7
|
|
|
8
8
|
describe('${name} function', () => {
|
|
9
9
|
|
|
@@ -22,7 +22,7 @@ describe('${name} function', () => {
|
|
|
22
22
|
})
|
|
23
23
|
|
|
24
24
|
// You can also use scenarios to test your api functions
|
|
25
|
-
// See guide here: https://
|
|
25
|
+
// See guide here: https://cedarjs.com/docs/testing#scenarios
|
|
26
26
|
//
|
|
27
27
|
// scenario('Scenario test', async () => {
|
|
28
28
|
//
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { paramCase } from "change-case";
|
|
2
2
|
import pascalcase from "pascalcase";
|
|
3
|
-
import { pluralize, isPlural, isSingular } from "../../lib/
|
|
3
|
+
import { pluralize, isPlural, isSingular } from "../../lib/cedarPluralize.js";
|
|
4
4
|
const pathName = (path, name) => {
|
|
5
5
|
let routePath = path;
|
|
6
6
|
if (path && path.startsWith("{") && path.endsWith("}")) {
|
|
@@ -13,70 +13,61 @@ import {
|
|
|
13
13
|
} from "../../../lib/index.js";
|
|
14
14
|
import { prepareForRollback } from "../../../lib/rollback.js";
|
|
15
15
|
import { validateName } from "../helpers.js";
|
|
16
|
-
import {
|
|
16
|
+
import { templateForFile } from "../yargsHandlerHelpers.js";
|
|
17
17
|
const normalizeName = (name) => {
|
|
18
18
|
return changeCase.pascalCase(name).replace(/Job$/, "");
|
|
19
19
|
};
|
|
20
20
|
const files = async ({
|
|
21
21
|
name,
|
|
22
22
|
queueName,
|
|
23
|
-
typescript
|
|
23
|
+
typescript,
|
|
24
24
|
tests: generateTests = true,
|
|
25
25
|
...rest
|
|
26
26
|
}) => {
|
|
27
|
-
const extension = generateTypescript ? ".ts" : ".js";
|
|
28
|
-
const outputFiles = [];
|
|
29
27
|
const jobName = normalizeName(name);
|
|
30
|
-
const
|
|
28
|
+
const componentName = `${jobName}Job`;
|
|
29
|
+
const extension = typescript ? ".ts" : ".js";
|
|
30
|
+
const jobFiles = await templateForFile({
|
|
31
31
|
name: jobName,
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
apiPathSection: "jobs",
|
|
32
|
+
side: "api",
|
|
33
|
+
sidePathSection: "jobs",
|
|
35
34
|
generator: "job",
|
|
35
|
+
outputPath: path.join(componentName, componentName + extension),
|
|
36
36
|
templatePath: "job.ts.template",
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
`${jobName}Job`,
|
|
41
|
-
`${jobName}Job${extension}`
|
|
42
|
-
)
|
|
37
|
+
// TODO: Remove `name` here. It's already passed to the template by the
|
|
38
|
+
// helper function we're using
|
|
39
|
+
templateVars: { name: jobName, queueName, ...rest }
|
|
43
40
|
});
|
|
41
|
+
const outputFiles = [];
|
|
44
42
|
outputFiles.push(jobFiles);
|
|
45
43
|
if (generateTests) {
|
|
46
|
-
const testFile = await
|
|
44
|
+
const testFile = await templateForFile({
|
|
47
45
|
name: jobName,
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
apiPathSection: "jobs",
|
|
46
|
+
side: "api",
|
|
47
|
+
sidePathSection: "jobs",
|
|
51
48
|
generator: "job",
|
|
49
|
+
outputPath: path.join(componentName, componentName + `.test${extension}`),
|
|
52
50
|
templatePath: "test.ts.template",
|
|
53
|
-
templateVars: { ...rest }
|
|
54
|
-
outputPath: path.join(
|
|
55
|
-
getPaths().api.jobs,
|
|
56
|
-
`${jobName}Job`,
|
|
57
|
-
`${jobName}Job.test${extension}`
|
|
58
|
-
)
|
|
51
|
+
templateVars: { ...rest }
|
|
59
52
|
});
|
|
60
|
-
const scenarioFile = await
|
|
53
|
+
const scenarioFile = await templateForFile({
|
|
61
54
|
name: jobName,
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
apiPathSection: "jobs",
|
|
55
|
+
side: "api",
|
|
56
|
+
sidePathSection: "jobs",
|
|
65
57
|
generator: "job",
|
|
66
|
-
templatePath: "scenarios.ts.template",
|
|
67
|
-
templateVars: { ...rest },
|
|
68
58
|
outputPath: path.join(
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
59
|
+
componentName,
|
|
60
|
+
componentName + `.scenarios${extension}`
|
|
61
|
+
),
|
|
62
|
+
templatePath: "scenarios.ts.template",
|
|
63
|
+
templateVars: { ...rest }
|
|
73
64
|
});
|
|
74
65
|
outputFiles.push(testFile);
|
|
75
66
|
outputFiles.push(scenarioFile);
|
|
76
67
|
}
|
|
77
68
|
return outputFiles.reduce(async (accP, [outputPath, content]) => {
|
|
78
69
|
const acc = await accP;
|
|
79
|
-
const template =
|
|
70
|
+
const template = typescript ? content : await transformTSToJS(outputPath, content);
|
|
80
71
|
return {
|
|
81
72
|
[outputPath]: template,
|
|
82
73
|
...acc
|
|
@@ -2,7 +2,7 @@ import type { ScenarioData } from '@cedarjs/testing/api'
|
|
|
2
2
|
|
|
3
3
|
export const standard = defineScenario({
|
|
4
4
|
// Define the "fixture" to write into your test database here
|
|
5
|
-
// See guide: https://
|
|
5
|
+
// See guide: https://cedarjs.com/docs/testing#scenarios
|
|
6
6
|
})
|
|
7
7
|
|
|
8
8
|
export type StandardScenario = ScenarioData<unknown>
|
|
@@ -3,7 +3,7 @@ import { render } from '@cedarjs/testing/web'
|
|
|
3
3
|
import ${pascalName}Layout from './${pascalName}Layout'
|
|
4
4
|
|
|
5
5
|
// Improve this test with help from the Redwood Testing Doc:
|
|
6
|
-
// https://
|
|
6
|
+
// https://cedarjs.com/docs/testing#testing-pages-layouts
|
|
7
7
|
|
|
8
8
|
describe('${pascalName}Layout', () => {
|
|
9
9
|
it('renders successfully', () => {
|
|
@@ -13,7 +13,7 @@ const builder = (yargs) => {
|
|
|
13
13
|
}).epilogue(
|
|
14
14
|
`Also see the ${terminalLink(
|
|
15
15
|
"RedwoodRecord Reference",
|
|
16
|
-
"https://
|
|
16
|
+
"https://cedarjs.com/docs/redwoodrecord"
|
|
17
17
|
)}`
|
|
18
18
|
);
|
|
19
19
|
Object.entries(getYargsDefaults()).forEach(([option, config]) => {
|
|
@@ -3,7 +3,7 @@ import { render } from '@cedarjs/testing/web'
|
|
|
3
3
|
import ${pascalName}Page from './${pascalName}Page'
|
|
4
4
|
|
|
5
5
|
// Improve this test with help from the Redwood Testing Doc:
|
|
6
|
-
// https://
|
|
6
|
+
// https://cedarjs.com/docs/testing#testing-pages-layouts
|
|
7
7
|
|
|
8
8
|
describe('${pascalName}Page', () => {
|
|
9
9
|
it('renders successfully', () => {
|
|
@@ -9,6 +9,7 @@ import pascalcase from "pascalcase";
|
|
|
9
9
|
import { recordTelemetryAttributes } from "@cedarjs/cli-helpers";
|
|
10
10
|
import { generate as generateTypes } from "@cedarjs/internal/dist/generate/generate";
|
|
11
11
|
import { getConfig } from "@cedarjs/project-config";
|
|
12
|
+
import { pluralize, singularize } from "../../../lib/cedarPluralize.js";
|
|
12
13
|
import c from "../../../lib/colors.js";
|
|
13
14
|
import {
|
|
14
15
|
generateTemplate,
|
|
@@ -26,7 +27,6 @@ import {
|
|
|
26
27
|
prepareForRollback,
|
|
27
28
|
addFunctionToRollback
|
|
28
29
|
} from "../../../lib/rollback.js";
|
|
29
|
-
import { pluralize, singularize } from "../../../lib/rwPluralize.js";
|
|
30
30
|
import { getSchema, verifyModelName } from "../../../lib/schemaHelpers.js";
|
|
31
31
|
import {
|
|
32
32
|
relationsForModel,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import path from "path";
|
|
2
1
|
import ansis from "ansis";
|
|
3
2
|
import boxen from "boxen";
|
|
4
3
|
import camelcase from "camelcase";
|
|
@@ -7,18 +6,13 @@ import { recordTelemetryAttributes } from "@cedarjs/cli-helpers";
|
|
|
7
6
|
import { generate as generateTypes } from "@cedarjs/internal/dist/generate/generate";
|
|
8
7
|
import { getConfig } from "@cedarjs/project-config";
|
|
9
8
|
import { errorTelemetry } from "@cedarjs/telemetry";
|
|
9
|
+
import { pluralize } from "../../../lib/cedarPluralize.js";
|
|
10
10
|
import c from "../../../lib/colors.js";
|
|
11
|
-
import {
|
|
12
|
-
generateTemplate,
|
|
13
|
-
transformTSToJS,
|
|
14
|
-
getPaths,
|
|
15
|
-
writeFilesTask
|
|
16
|
-
} from "../../../lib/index.js";
|
|
11
|
+
import { transformTSToJS, writeFilesTask } from "../../../lib/index.js";
|
|
17
12
|
import {
|
|
18
13
|
prepareForRollback,
|
|
19
14
|
addFunctionToRollback
|
|
20
15
|
} from "../../../lib/rollback.js";
|
|
21
|
-
import { pluralize } from "../../../lib/rwPluralize.js";
|
|
22
16
|
import {
|
|
23
17
|
getSchema,
|
|
24
18
|
getEnum,
|
|
@@ -26,7 +20,7 @@ import {
|
|
|
26
20
|
} from "../../../lib/schemaHelpers.js";
|
|
27
21
|
import { relationsForModel } from "../helpers.js";
|
|
28
22
|
import { files as serviceFiles } from "../service/serviceHandler.js";
|
|
29
|
-
import {
|
|
23
|
+
import { templateForFile } from "../yargsHandlerHelpers.js";
|
|
30
24
|
const DEFAULT_IGNORE_FIELDS_FOR_INPUT = ["createdAt", "updatedAt"];
|
|
31
25
|
const missingIdConsoleMessage = () => {
|
|
32
26
|
const line1 = ansis.bold.yellow("WARNING") + ": Cannot generate CRUD SDL without an `@id` database column.";
|
|
@@ -34,7 +28,7 @@ const missingIdConsoleMessage = () => {
|
|
|
34
28
|
const line3 = "you'll need to update your schema definition to include";
|
|
35
29
|
const line4 = "an `@id` column. Read more here: ";
|
|
36
30
|
const line5 = ansis.underline.blue(
|
|
37
|
-
"https://
|
|
31
|
+
"https://cedarjs.com/docs/schema-relations"
|
|
38
32
|
);
|
|
39
33
|
console.error(
|
|
40
34
|
boxen(line1 + "\n\n" + line2 + "\n" + line3 + "\n" + line4 + "\n" + line5, {
|
|
@@ -164,52 +158,25 @@ const files = async ({
|
|
|
164
158
|
tests,
|
|
165
159
|
typescript
|
|
166
160
|
}) => {
|
|
167
|
-
const
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
createInput,
|
|
172
|
-
updateInput,
|
|
173
|
-
idInput,
|
|
174
|
-
idType: idType2,
|
|
175
|
-
idName: idName2,
|
|
176
|
-
relations,
|
|
177
|
-
enums
|
|
178
|
-
} = await sdlFromSchemaModel(name, crud, docs);
|
|
179
|
-
const templatePath = customOrDefaultTemplatePath({
|
|
161
|
+
const extension = typescript ? "ts" : "js";
|
|
162
|
+
const sdlData = await sdlFromSchemaModel(name, crud, docs);
|
|
163
|
+
const [outputPath, content] = await templateForFile({
|
|
164
|
+
name,
|
|
180
165
|
side: "api",
|
|
166
|
+
sidePathSection: "graphql",
|
|
181
167
|
generator: "sdl",
|
|
182
|
-
templatePath: "sdl.ts.template"
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
docs,
|
|
186
|
-
modelName,
|
|
187
|
-
modelDescription,
|
|
188
|
-
name,
|
|
189
|
-
crud,
|
|
190
|
-
query,
|
|
191
|
-
createInput,
|
|
192
|
-
updateInput,
|
|
193
|
-
idInput,
|
|
194
|
-
idType: idType2,
|
|
195
|
-
idName: idName2,
|
|
196
|
-
enums
|
|
168
|
+
templatePath: "sdl.ts.template",
|
|
169
|
+
templateVars: { docs, name, crud, ...sdlData },
|
|
170
|
+
outputPath: `${camelcase(pluralize(name))}.sdl.${extension}`
|
|
197
171
|
});
|
|
198
|
-
const
|
|
199
|
-
let outputPath = path.join(
|
|
200
|
-
getPaths().api.graphql,
|
|
201
|
-
`${camelcase(pluralize(name))}.sdl.${extension}`
|
|
202
|
-
);
|
|
203
|
-
if (typescript) {
|
|
204
|
-
template = await transformTSToJS(outputPath, template);
|
|
205
|
-
}
|
|
172
|
+
const template = typescript ? content : await transformTSToJS(outputPath, content);
|
|
206
173
|
return {
|
|
207
174
|
[outputPath]: template,
|
|
208
175
|
...await serviceFiles({
|
|
209
176
|
name,
|
|
210
177
|
crud,
|
|
211
178
|
tests,
|
|
212
|
-
relations,
|
|
179
|
+
relations: sdlData.relations,
|
|
213
180
|
typescript
|
|
214
181
|
})
|
|
215
182
|
};
|