@cedarjs/cli-helpers 9.0.0-canary.1784 → 9.0.0-canary.3124
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/auth/authFiles.d.ts +9 -1
- package/dist/auth/authFiles.d.ts.map +1 -1
- package/dist/auth/authFiles.js +44 -22
- package/dist/auth/authTasks.d.ts +1 -1
- package/dist/auth/authTasks.d.ts.map +1 -1
- package/dist/auth/authTasks.js +21 -14
- package/dist/auth/setupHelpers.d.ts +3 -1
- package/dist/auth/setupHelpers.d.ts.map +1 -1
- package/dist/auth/setupHelpers.js +2 -1
- package/dist/lib/colors.d.ts +7 -5
- package/dist/lib/colors.d.ts.map +1 -1
- package/dist/lib/index.d.ts +1 -1
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/index.js +9 -22
- package/dist/lib/installHelpers.d.ts.map +1 -1
- package/dist/lib/installHelpers.js +14 -7
- package/dist/lib/loadEnvFiles.js +2 -2
- package/dist/lib/project.d.ts.map +1 -1
- package/dist/lib/project.js +10 -10
- package/dist/lib/transpileTSToJS.d.ts +18 -0
- package/dist/lib/transpileTSToJS.d.ts.map +1 -0
- package/dist/lib/transpileTSToJS.js +38 -0
- package/dist/lib/tty.d.ts +11 -0
- package/dist/lib/tty.d.ts.map +1 -0
- package/dist/lib/tty.js +16 -0
- package/dist/lib/version.js +5 -5
- package/dist/packageManager/display.d.ts +100 -0
- package/dist/packageManager/display.d.ts.map +1 -0
- package/dist/packageManager/display.js +115 -0
- package/dist/packageManager/exec.d.ts +77 -0
- package/dist/packageManager/exec.d.ts.map +1 -0
- package/dist/packageManager/exec.js +108 -0
- package/dist/packageManager/index.d.ts +13 -0
- package/dist/packageManager/index.d.ts.map +1 -0
- package/dist/packageManager/index.js +43 -0
- package/dist/packageManager/packages.d.ts +39 -0
- package/dist/packageManager/packages.d.ts.map +1 -0
- package/dist/packageManager/packages.js +54 -0
- package/dist/packageManager/workspaces.d.ts +4 -0
- package/dist/packageManager/workspaces.d.ts.map +1 -0
- package/dist/packageManager/workspaces.js +59 -0
- package/dist/telemetry/index.d.ts +1 -1
- package/dist/telemetry/index.d.ts.map +1 -1
- package/dist/telemetry/index.js +3 -1
- package/package.json +114 -40
- package/LICENSE +0 -21
- package/dist/build.d.ts +0 -2
- package/dist/build.d.ts.map +0 -1
- package/dist/cjs/auth/authFiles.d.ts +0 -44
- package/dist/cjs/auth/authFiles.d.ts.map +0 -1
- package/dist/cjs/auth/authFiles.js +0 -109
- package/dist/cjs/auth/authTasks.d.ts +0 -49
- package/dist/cjs/auth/authTasks.d.ts.map +0 -1
- package/dist/cjs/auth/authTasks.js +0 -384
- package/dist/cjs/auth/setupHelpers.d.ts +0 -26
- package/dist/cjs/auth/setupHelpers.d.ts.map +0 -1
- package/dist/cjs/auth/setupHelpers.js +0 -141
- package/dist/cjs/index.d.ts +0 -12
- package/dist/cjs/index.d.ts.map +0 -1
- package/dist/cjs/index.js +0 -52
- package/dist/cjs/lib/colors.d.ts +0 -22
- package/dist/cjs/lib/colors.d.ts.map +0 -1
- package/dist/cjs/lib/colors.js +0 -52
- package/dist/cjs/lib/index.d.ts +0 -22
- package/dist/cjs/lib/index.d.ts.map +0 -1
- package/dist/cjs/lib/index.js +0 -146
- package/dist/cjs/lib/installHelpers.d.ts +0 -17
- package/dist/cjs/lib/installHelpers.d.ts.map +0 -1
- package/dist/cjs/lib/installHelpers.js +0 -72
- package/dist/cjs/lib/loadEnvFiles.d.ts +0 -5
- package/dist/cjs/lib/loadEnvFiles.d.ts.map +0 -1
- package/dist/cjs/lib/loadEnvFiles.js +0 -99
- package/dist/cjs/lib/paths.d.ts +0 -6
- package/dist/cjs/lib/paths.d.ts.map +0 -1
- package/dist/cjs/lib/paths.js +0 -42
- package/dist/cjs/lib/project.d.ts +0 -44
- package/dist/cjs/lib/project.d.ts.map +0 -1
- package/dist/cjs/lib/project.js +0 -269
- package/dist/cjs/lib/version.d.ts +0 -17
- package/dist/cjs/lib/version.d.ts.map +0 -1
- package/dist/cjs/lib/version.js +0 -107
- package/dist/cjs/package.json +0 -1
- package/dist/cjs/telemetry/index.d.ts +0 -20
- package/dist/cjs/telemetry/index.d.ts.map +0 -1
- package/dist/cjs/telemetry/index.js +0 -62
- package/dist/index.d.ts +0 -12
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -20
- package/dist/package.json +0 -1
- package/dist/src/auth/__tests__/authFiles.test.d.ts +0 -2
- package/dist/src/auth/__tests__/authFiles.test.d.ts.map +0 -1
- package/dist/src/auth/__tests__/authTasks.test.d.ts +0 -2
- package/dist/src/auth/__tests__/authTasks.test.d.ts.map +0 -1
- package/dist/src/auth/__tests__/mockFsFiles.d.ts +0 -14
- package/dist/src/auth/__tests__/mockFsFiles.d.ts.map +0 -1
- package/dist/src/auth/__tests__/setupHelpers.test.d.ts +0 -2
- package/dist/src/auth/__tests__/setupHelpers.test.d.ts.map +0 -1
- package/dist/src/auth/authFiles.d.ts +0 -44
- package/dist/src/auth/authFiles.d.ts.map +0 -1
- package/dist/src/auth/authTasks.d.ts +0 -49
- package/dist/src/auth/authTasks.d.ts.map +0 -1
- package/dist/src/auth/setupHelpers.d.ts +0 -26
- package/dist/src/auth/setupHelpers.d.ts.map +0 -1
- package/dist/src/index.d.ts +0 -12
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/lib/__tests__/index.test.d.ts +0 -2
- package/dist/src/lib/__tests__/index.test.d.ts.map +0 -1
- package/dist/src/lib/__tests__/loadEnvFiles.test.d.ts +0 -2
- package/dist/src/lib/__tests__/loadEnvFiles.test.d.ts.map +0 -1
- package/dist/src/lib/__tests__/project.addTomlSetting.test.d.ts +0 -2
- package/dist/src/lib/__tests__/project.addTomlSetting.test.d.ts.map +0 -1
- package/dist/src/lib/__tests__/project.test.d.ts +0 -2
- package/dist/src/lib/__tests__/project.test.d.ts.map +0 -1
- package/dist/src/lib/__tests__/version.test.d.ts +0 -2
- package/dist/src/lib/__tests__/version.test.d.ts.map +0 -1
- package/dist/src/lib/colors.d.ts +0 -22
- package/dist/src/lib/colors.d.ts.map +0 -1
- package/dist/src/lib/index.d.ts +0 -22
- package/dist/src/lib/index.d.ts.map +0 -1
- package/dist/src/lib/installHelpers.d.ts +0 -17
- package/dist/src/lib/installHelpers.d.ts.map +0 -1
- package/dist/src/lib/loadEnvFiles.d.ts +0 -5
- package/dist/src/lib/loadEnvFiles.d.ts.map +0 -1
- package/dist/src/lib/paths.d.ts +0 -6
- package/dist/src/lib/paths.d.ts.map +0 -1
- package/dist/src/lib/project.d.ts +0 -44
- package/dist/src/lib/project.d.ts.map +0 -1
- package/dist/src/lib/version.d.ts +0 -17
- package/dist/src/lib/version.d.ts.map +0 -1
- package/dist/src/telemetry/index.d.ts +0 -20
- package/dist/src/telemetry/index.d.ts.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/dist/vitest.config.d.mts +0 -3
- package/dist/vitest.config.d.mts.map +0 -1
package/dist/auth/authFiles.d.ts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
interface FilesArgs {
|
|
2
2
|
basedir: string;
|
|
3
3
|
webAuthn: boolean;
|
|
4
|
+
/**
|
|
5
|
+
* Selects the `*.oauth.*` template variant, the same way `webAuthn` selects
|
|
6
|
+
* the `*.webAuthn.*` variant. When both are true, the most specific
|
|
7
|
+
* template available is preferred (`*.webAuthn.oauth.*`), falling back to
|
|
8
|
+
* a single-variant or the base template when a more specific one doesn't
|
|
9
|
+
* exist for a given template file.
|
|
10
|
+
*/
|
|
11
|
+
oauth?: boolean;
|
|
4
12
|
}
|
|
5
13
|
/**
|
|
6
14
|
* Get the api side file paths and file contents to write
|
|
@@ -14,7 +22,7 @@ interface FilesArgs {
|
|
|
14
22
|
* }
|
|
15
23
|
* ```
|
|
16
24
|
*/
|
|
17
|
-
export declare const apiSideFiles: ({ basedir, webAuthn }: FilesArgs) => Promise<Record<string, string>>;
|
|
25
|
+
export declare const apiSideFiles: ({ basedir, webAuthn, oauth, }: FilesArgs) => Promise<Record<string, string>>;
|
|
18
26
|
/**
|
|
19
27
|
* Loops through the keys in `filesRecord` and generates unique file paths if
|
|
20
28
|
* they conflict with existing files
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authFiles.d.ts","sourceRoot":"","sources":["../../src/auth/authFiles.ts"],"names":[],"mappings":"AASA,UAAU,SAAS;IACjB,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"authFiles.d.ts","sourceRoot":"","sources":["../../src/auth/authFiles.ts"],"names":[],"mappings":"AASA,UAAU,SAAS;IACjB,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,OAAO,CAAA;IACjB;;;;;;OAMG;IACH,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB;AA+DD;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,YAAY,GAAU,+BAIhC,SAAS,oCA4CX,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,uBAAuB,CACrC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACnC,QAAQ,EAAE,MAAM,0BAwCjB"}
|
package/dist/auth/authFiles.js
CHANGED
|
@@ -4,37 +4,59 @@ import pascalcase from "pascalcase";
|
|
|
4
4
|
import { transformTSToJS } from "../lib/index.js";
|
|
5
5
|
import { getPaths } from "../lib/paths.js";
|
|
6
6
|
import { isTypeScriptProject } from "../lib/project.js";
|
|
7
|
-
const
|
|
7
|
+
const VARIANT_TAGS = ["webAuthn", "oauth"];
|
|
8
|
+
function parseTemplateFileName(fileName) {
|
|
9
|
+
const parts = fileName.split(".");
|
|
10
|
+
const baseName = parts[0];
|
|
11
|
+
const ext = parts.at(-2);
|
|
12
|
+
const tags = parts.slice(1, -2).filter((part) => VARIANT_TAGS.includes(part));
|
|
13
|
+
return { baseName, tags, ext };
|
|
14
|
+
}
|
|
15
|
+
function pickTemplateVariants(templateFiles, activeTags) {
|
|
16
|
+
const candidatesByKey = /* @__PURE__ */ new Map();
|
|
17
|
+
for (const fileName of templateFiles) {
|
|
18
|
+
const { baseName, tags, ext } = parseTemplateFileName(fileName);
|
|
19
|
+
const key = `${baseName}.${ext}`;
|
|
20
|
+
const candidates = candidatesByKey.get(key) ?? [];
|
|
21
|
+
candidates.push({ fileName, tags });
|
|
22
|
+
candidatesByKey.set(key, candidates);
|
|
23
|
+
}
|
|
24
|
+
const picked = [];
|
|
25
|
+
for (const candidates of candidatesByKey.values()) {
|
|
26
|
+
const applicable = candidates.filter(
|
|
27
|
+
(candidate) => candidate.tags.every((tag) => activeTags.includes(tag))
|
|
28
|
+
);
|
|
29
|
+
const mostSpecific = applicable.reduce(
|
|
30
|
+
(best, candidate) => candidate.tags.length > best.tags.length ? candidate : best
|
|
31
|
+
);
|
|
32
|
+
picked.push(mostSpecific);
|
|
33
|
+
}
|
|
34
|
+
return picked;
|
|
35
|
+
}
|
|
36
|
+
const apiSideFiles = async ({
|
|
37
|
+
basedir,
|
|
38
|
+
webAuthn,
|
|
39
|
+
oauth = false
|
|
40
|
+
}) => {
|
|
8
41
|
const apiSrcPath = getPaths().api.src;
|
|
9
42
|
const apiBaseTemplatePath = path.join(basedir, "templates", "api");
|
|
10
43
|
const templateDirectories = fs.readdirSync(apiBaseTemplatePath);
|
|
11
44
|
let filesRecord = {};
|
|
45
|
+
const activeTags = [
|
|
46
|
+
...webAuthn ? ["webAuthn"] : [],
|
|
47
|
+
...oauth ? ["oauth"] : []
|
|
48
|
+
];
|
|
12
49
|
for (const dir of templateDirectories) {
|
|
13
50
|
const templateFiles = fs.readdirSync(path.join(apiBaseTemplatePath, dir));
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
let outputFileName = fileName.replace(/\.template$/, "");
|
|
51
|
+
const pickedVariants = pickTemplateVariants(templateFiles, activeTags);
|
|
52
|
+
const filePaths = pickedVariants.map(({ fileName }) => {
|
|
53
|
+
const { baseName, ext } = parseTemplateFileName(fileName);
|
|
54
|
+
let outputFileName = `${baseName}.${ext}`;
|
|
19
55
|
if (!isTypeScriptProject()) {
|
|
20
56
|
outputFileName = outputFileName.replace(/\.ts(x?)$/, ".js$1");
|
|
21
57
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
const webAuthnFileName = fileName.split(".").reverse().map((part, i) => i === 1 ? "webAuthn." + part : part).reverse().join(".");
|
|
26
|
-
if (templateFiles.includes(webAuthnFileName)) {
|
|
27
|
-
return { templateFileName: webAuthnFileName, outputFileName };
|
|
28
|
-
} else {
|
|
29
|
-
return { templateFileName: fileName, outputFileName };
|
|
30
|
-
}
|
|
31
|
-
}).map((f) => {
|
|
32
|
-
const templateFilePath = path.join(
|
|
33
|
-
apiBaseTemplatePath,
|
|
34
|
-
dir,
|
|
35
|
-
f.templateFileName
|
|
36
|
-
);
|
|
37
|
-
const outputFilePath = path.join(apiSrcPath, dir, f.outputFileName);
|
|
58
|
+
const templateFilePath = path.join(apiBaseTemplatePath, dir, fileName);
|
|
59
|
+
const outputFilePath = path.join(apiSrcPath, dir, outputFileName);
|
|
38
60
|
return { templateFilePath, outputFilePath };
|
|
39
61
|
});
|
|
40
62
|
for (const paths of filePaths) {
|
package/dist/auth/authTasks.d.ts
CHANGED
|
@@ -31,7 +31,7 @@ export declare const addConfigToRoutes: () => {
|
|
|
31
31
|
*
|
|
32
32
|
* @returns Listr task
|
|
33
33
|
*/
|
|
34
|
-
export declare const generateAuthApiFiles: <Renderer extends typeof ListrRenderer>(basedir: string, webAuthn: boolean) => ListrTask<AuthGeneratorCtx, Renderer>;
|
|
34
|
+
export declare const generateAuthApiFiles: <Renderer extends typeof ListrRenderer>(basedir: string, webAuthn: boolean, oauth?: boolean) => ListrTask<AuthGeneratorCtx, Renderer>;
|
|
35
35
|
export declare const addAuthConfigToGqlApi: <Renderer extends typeof ListrRenderer, FallbackRenderer extends typeof ListrRenderer>(authDecoderImport?: string) => {
|
|
36
36
|
title: string;
|
|
37
37
|
task: (ctx: AuthGeneratorCtx, _task: ListrTaskWrapper<AuthGeneratorCtx, Renderer, FallbackRenderer>) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authTasks.d.ts","sourceRoot":"","sources":["../../src/auth/authTasks.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAA;
|
|
1
|
+
{"version":3,"file":"authTasks.d.ts","sourceRoot":"","sources":["../../src/auth/authTasks.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAA;AA2BxE,eAAO,MAAM,aAAa,cAA2B,CAAA;AAwDrD,eAAO,MAAM,YAAY,GAAI,+CAG1B;IACD,qBAAqB,EAAE,OAAO,CAAA;IAC9B,iBAAiB,CAAC,EAAE,MAAM,CAAA;CAC3B,SAgDA,CAAA;AAmCD,eAAO,MAAM,eAAe,GAAI,SAAS,MAAM,YAE9C,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,GAAI,SAAS,MAAM,WA6CjD,CAAA;AAuED;;;GAGG;AACH,eAAO,MAAM,iBAAiB,GAC5B,QAAQ,SAAS,OAAO,aAAa,OAClC,SAAS,CAAC,gBAAgB,EAAE,QAAQ,CA8CxC,CAAA;AAED,eAAO,MAAM,aAAa,GAAI,SAAS,MAAM,EAAE,UAAU,OAAO;;gBAgC1C,gBAAgB;CA0CrC,CAAA;AAED,eAAO,MAAM,iBAAiB;;;CAmB7B,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,GAAI,QAAQ,SAAS,OAAO,aAAa,EACxE,SAAS,MAAM,EACf,UAAU,OAAO,EACjB,eAAa,KACZ,SAAS,CAAC,gBAAgB,EAAE,QAAQ,CAgDtC,CAAA;AASD,eAAO,MAAM,qBAAqB,GAChC,QAAQ,SAAS,OAAO,aAAa,EACrC,gBAAgB,SAAS,OAAO,aAAa,EAE7C,oBAAoB,MAAM;;gBAInB,gBAAgB,SACd,gBAAgB,CAAC,gBAAgB,EAAE,QAAQ,EAAE,gBAAgB,CAAC;CAcvE,CAAA;AAEF,MAAM,MAAM,aAAa,GACrB,OAAO,GACP,SAAS,GACT,SAAS,GACT,SAAS,CAAA;AAEb,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,aAAa,CAAA;IACxB,QAAQ,EAAE,MAAM,CAAA;IAChB,KAAK,EAAE,OAAO,CAAA;CACf;AAED,eAAO,MAAM,gBAAgB,GAC3B,QAAQ,SAAS,OAAO,aAAa,EACrC,gBAAgB,SAAS,OAAO,aAAa,EAE7C,OAAO,OAAO;;gBAKL,gBAAgB,QACf,gBAAgB,CAAC,gBAAgB,EAAE,QAAQ,EAAE,gBAAgB,CAAC;CA2CzE,CAAA"}
|
package/dist/auth/authTasks.js
CHANGED
|
@@ -13,6 +13,10 @@ import {
|
|
|
13
13
|
import { apiSideFiles, generateUniqueFileNames } from "./authFiles.js";
|
|
14
14
|
const AUTH_PROVIDER_HOOK_IMPORT = `import { AuthProvider, useAuth } from './auth.js'`;
|
|
15
15
|
const AUTH_HOOK_IMPORT = `import { useAuth } from './auth.js'`;
|
|
16
|
+
const APOLLO_PROVIDER_COMPONENT_NAMES = [
|
|
17
|
+
"CedarApolloProvider",
|
|
18
|
+
"RedwoodApolloProvider"
|
|
19
|
+
];
|
|
16
20
|
const getWebAppPath = () => getPaths().web.app;
|
|
17
21
|
function addAuthDecoderToCreateGraphQLHandler(content) {
|
|
18
22
|
if (!new RegExp("(?=(^.*?createGraphQLHandler))\\1.*\\bauthDecoder", "s").test(
|
|
@@ -128,10 +132,10 @@ const addAuthProviderToApp = (content, setupMode) => {
|
|
|
128
132
|
content = removeAuthProvider(content);
|
|
129
133
|
}
|
|
130
134
|
const match = content.match(
|
|
131
|
-
/(\s+)(<
|
|
135
|
+
/(\s+)(<(?:Cedar|Redwood)Provider.*?>)(.*)(<\/(?:Cedar|Redwood)Provider>)/s
|
|
132
136
|
);
|
|
133
137
|
if (!match) {
|
|
134
|
-
throw new Error("Could not find <
|
|
138
|
+
throw new Error("Could not find <CedarProvider> in App.{jsx,tsx}");
|
|
135
139
|
}
|
|
136
140
|
if (/\s+<AuthProvider>/.test(content)) {
|
|
137
141
|
return content;
|
|
@@ -139,16 +143,16 @@ const addAuthProviderToApp = (content, setupMode) => {
|
|
|
139
143
|
const [
|
|
140
144
|
_,
|
|
141
145
|
newlineAndIndent,
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
146
|
+
cedarProviderOpen,
|
|
147
|
+
cedarProviderChildren,
|
|
148
|
+
cedarProviderClose
|
|
145
149
|
] = match;
|
|
146
|
-
const
|
|
150
|
+
const cedarProviderChildrenLines = cedarProviderChildren.split("\n").map((line, index) => {
|
|
147
151
|
return `${index === 0 ? "" : " "}` + line;
|
|
148
152
|
});
|
|
149
|
-
const renderContent = newlineAndIndent +
|
|
153
|
+
const renderContent = newlineAndIndent + cedarProviderOpen + newlineAndIndent + ` <AuthProvider>` + cedarProviderChildrenLines.join("\n") + `</AuthProvider>` + newlineAndIndent + cedarProviderClose;
|
|
150
154
|
return content.replace(
|
|
151
|
-
/\s+<
|
|
155
|
+
/\s+<(?:Cedar|Redwood)Provider.*?>.*<\/(?:Cedar|Redwood)Provider>/s,
|
|
152
156
|
renderContent
|
|
153
157
|
);
|
|
154
158
|
};
|
|
@@ -184,13 +188,16 @@ const addConfigToWebApp = () => {
|
|
|
184
188
|
);
|
|
185
189
|
}
|
|
186
190
|
content = addAuthProviderToApp(content, ctx.setupMode);
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
191
|
+
const apolloProviderComponentName = APOLLO_PROVIDER_COMPONENT_NAMES.find(
|
|
192
|
+
(componentName) => new RegExp(`\\s*<${componentName}`).test(content)
|
|
193
|
+
);
|
|
194
|
+
if (apolloProviderComponentName) {
|
|
195
|
+
if (!hasUseAuthHook(apolloProviderComponentName, content)) {
|
|
196
|
+
content = addUseAuthHook(apolloProviderComponentName, content);
|
|
190
197
|
}
|
|
191
198
|
} else {
|
|
192
199
|
task.output = colors.warning(
|
|
193
|
-
"Could not find <
|
|
200
|
+
"Could not find <CedarApolloProvider>.\nIf you are using a custom GraphQL Client you will have to make sure it gets access to your `useAuth`, if it needs it."
|
|
194
201
|
);
|
|
195
202
|
}
|
|
196
203
|
fs.writeFileSync(webAppPath, content);
|
|
@@ -257,7 +264,7 @@ const addConfigToRoutes = () => {
|
|
|
257
264
|
}
|
|
258
265
|
};
|
|
259
266
|
};
|
|
260
|
-
const generateAuthApiFiles = (basedir, webAuthn) => {
|
|
267
|
+
const generateAuthApiFiles = (basedir, webAuthn, oauth = false) => {
|
|
261
268
|
return {
|
|
262
269
|
title: "Generating auth api side files...",
|
|
263
270
|
task: async (ctx, task) => {
|
|
@@ -266,7 +273,7 @@ const generateAuthApiFiles = (basedir, webAuthn) => {
|
|
|
266
273
|
"Could not find api/src directory. Cannot continue setup!"
|
|
267
274
|
);
|
|
268
275
|
}
|
|
269
|
-
let filesRecord = await apiSideFiles({ basedir, webAuthn });
|
|
276
|
+
let filesRecord = await apiSideFiles({ basedir, webAuthn, oauth });
|
|
270
277
|
let existingFiles = "FAIL";
|
|
271
278
|
if (ctx.setupMode === "FORCE") {
|
|
272
279
|
existingFiles = "OVERWRITE";
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ListrTask } from 'listr2';
|
|
2
2
|
import type { Argv } from 'yargs';
|
|
3
3
|
import type { AuthGeneratorCtx } from './authTasks.js';
|
|
4
|
+
export type { AuthGeneratorCtx };
|
|
4
5
|
export declare const standardAuthBuilder: (yargs: Argv) => Argv<{
|
|
5
6
|
force: boolean;
|
|
6
7
|
} & {
|
|
@@ -12,6 +13,7 @@ export interface AuthHandlerArgs {
|
|
|
12
13
|
provider: string;
|
|
13
14
|
authDecoderImport?: string;
|
|
14
15
|
webAuthn?: boolean;
|
|
16
|
+
oauth?: boolean;
|
|
15
17
|
webPackages?: string[];
|
|
16
18
|
apiPackages?: string[];
|
|
17
19
|
extraTasks?: (ListrTask<AuthGeneratorCtx> | undefined)[];
|
|
@@ -22,5 +24,5 @@ export interface AuthHandlerArgs {
|
|
|
22
24
|
* basedir assumes that you must have a templates folder in that directory.
|
|
23
25
|
* See folder structure of auth providers in packages/auth-providers/<provider>/setup/src
|
|
24
26
|
*/
|
|
25
|
-
export declare const standardAuthHandler: ({ basedir, forceArg, provider, authDecoderImport, webAuthn, webPackages, apiPackages, extraTasks, notes, verbose, }: AuthHandlerArgs) => Promise<void>;
|
|
27
|
+
export declare const standardAuthHandler: ({ basedir, forceArg, provider, authDecoderImport, webAuthn, oauth, webPackages, apiPackages, extraTasks, notes, verbose, }: AuthHandlerArgs) => Promise<void>;
|
|
26
28
|
//# sourceMappingURL=setupHelpers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setupHelpers.d.ts","sourceRoot":"","sources":["../../src/auth/setupHelpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAA;AAGvC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,OAAO,CAAA;AAWjC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AAUtD,eAAO,MAAM,mBAAmB,GAAI,OAAO,IAAI;;;;EAoB9C,CAAA;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,OAAO,CAAA;IACjB,QAAQ,EAAE,MAAM,CAAA;IAChB,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAA;IACtB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAA;IACtB,UAAU,CAAC,EAAE,CAAC,SAAS,CAAC,gBAAgB,CAAC,GAAG,SAAS,CAAC,EAAE,CAAA;IACxD,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;IAChB,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AASD;;;GAGG;AACH,eAAO,MAAM,mBAAmB,GAAU,
|
|
1
|
+
{"version":3,"file":"setupHelpers.d.ts","sourceRoot":"","sources":["../../src/auth/setupHelpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAA;AAGvC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,OAAO,CAAA;AAWjC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AAUtD,YAAY,EAAE,gBAAgB,EAAE,CAAA;AAEhC,eAAO,MAAM,mBAAmB,GAAI,OAAO,IAAI;;;;EAoB9C,CAAA;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,OAAO,CAAA;IACjB,QAAQ,EAAE,MAAM,CAAA;IAChB,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,WAAW,CAAC,EAAE,MAAM,EAAE,CAAA;IACtB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAA;IACtB,UAAU,CAAC,EAAE,CAAC,SAAS,CAAC,gBAAgB,CAAC,GAAG,SAAS,CAAC,EAAE,CAAA;IACxD,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;IAChB,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AASD;;;GAGG;AACH,eAAO,MAAM,mBAAmB,GAAU,4HAYvC,eAAe,kBAiFjB,CAAA"}
|
|
@@ -42,6 +42,7 @@ const standardAuthHandler = async ({
|
|
|
42
42
|
provider,
|
|
43
43
|
authDecoderImport,
|
|
44
44
|
webAuthn = false,
|
|
45
|
+
oauth = false,
|
|
45
46
|
webPackages = [],
|
|
46
47
|
apiPackages = [],
|
|
47
48
|
extraTasks,
|
|
@@ -51,7 +52,7 @@ const standardAuthHandler = async ({
|
|
|
51
52
|
const tasks = new Listr(
|
|
52
53
|
[
|
|
53
54
|
setAuthSetupMode(forceArg),
|
|
54
|
-
generateAuthApiFiles(basedir, webAuthn),
|
|
55
|
+
generateAuthApiFiles(basedir, webAuthn, oauth),
|
|
55
56
|
addConfigToWebApp(),
|
|
56
57
|
createWebAuth(basedir, webAuthn),
|
|
57
58
|
addConfigToRoutes(),
|
package/dist/lib/colors.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
2
|
+
* Canonical color/style palette for all Cedar CLI packages.
|
|
3
|
+
*
|
|
4
|
+
* Import from here rather than defining local copies:
|
|
5
|
+
* import { colors } from '@cedarjs/cli-helpers/colors'
|
|
6
|
+
*
|
|
7
|
+
* If you need a color that isn't here, add it here rather than
|
|
8
|
+
* introducing a one-off in another package.
|
|
7
9
|
*/
|
|
8
10
|
export declare const colors: {
|
|
9
11
|
error: import("ansis").Ansis;
|
package/dist/lib/colors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"colors.d.ts","sourceRoot":"","sources":["../../src/lib/colors.ts"],"names":[],"mappings":"AAEA
|
|
1
|
+
{"version":3,"file":"colors.d.ts","sourceRoot":"","sources":["../../src/lib/colors.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,eAAO,MAAM,MAAM;;;;;;;;;;;;;CAalB,CAAA"}
|
package/dist/lib/index.d.ts
CHANGED
|
@@ -18,5 +18,5 @@ export declare const writeFile: <Renderer extends typeof ListrRenderer>(target:
|
|
|
18
18
|
*/
|
|
19
19
|
export declare const writeFilesTask: <Renderer extends typeof ListrRenderer>(files: Record<string, string>, options: {
|
|
20
20
|
existingFiles: ExistingFiles;
|
|
21
|
-
}) => Listr<never, Renderer,
|
|
21
|
+
}) => Listr<never, Renderer, Renderer>;
|
|
22
22
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,gBAAgB,EAChB,aAAa,EAEd,MAAM,QAAQ,CAAA;AACf,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,gBAAgB,EAChB,aAAa,EAEd,MAAM,QAAQ,CAAA;AACf,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAA;AAW9B,eAAO,MAAM,eAAe,GAAI,UAAU,MAAM,EAAE,SAAS,MAAM,6BAgBhE,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,kBAAkB,oBAsB9B,CAAA;AAED,eAAO,MAAM,QAAQ,GACnB,kBAAkB,MAAM,EACxB,kBAAkB,MAAM,KACvB,OAAO,CAAC,MAAM,CAwBhB,CAAA;AAED,MAAM,MAAM,aAAa,GAAG,WAAW,GAAG,MAAM,GAAG,MAAM,CAAA;AAEzD,eAAO,MAAM,SAAS,GAAI,QAAQ,SAAS,OAAO,aAAa,EAC7D,QAAQ,MAAM,EACd,UAAU,MAAM,EAChB,oBAA4B;IAAE,aAAa,CAAC,EAAE,aAAa,CAAA;CAAO,EAGlE,OAAM,gBAAgB,CAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ,CAI/C,SAoBF,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,cAAc,GAAI,QAAQ,SAAS,OAAO,aAAa,EAClE,OAAO,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC7B,SAAS;IAAE,aAAa,EAAE,aAAa,CAAA;CAAE,qCAuB1C,CAAA"}
|
package/dist/lib/index.js
CHANGED
|
@@ -1,43 +1,30 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
|
+
import { pathToFileURL } from "node:url";
|
|
2
3
|
import path from "path";
|
|
3
|
-
import * as babel from "@babel/core";
|
|
4
4
|
import { Listr } from "listr2";
|
|
5
5
|
import { format } from "prettier";
|
|
6
6
|
import { colors } from "./colors.js";
|
|
7
7
|
import { getPaths } from "./paths.js";
|
|
8
|
+
import { transpileTSToJS } from "./transpileTSToJS.js";
|
|
8
9
|
const transformTSToJS = (filename, content) => {
|
|
9
10
|
if (!content) {
|
|
10
11
|
return content;
|
|
11
12
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
configFile: false,
|
|
18
|
-
plugins: [
|
|
19
|
-
[
|
|
20
|
-
"@babel/plugin-transform-typescript",
|
|
21
|
-
{
|
|
22
|
-
isTSX: true,
|
|
23
|
-
allExtensions: true
|
|
24
|
-
}
|
|
25
|
-
]
|
|
26
|
-
],
|
|
27
|
-
retainLines: true
|
|
28
|
-
});
|
|
29
|
-
if (!babelFileResult?.code) {
|
|
30
|
-
console.error(colors.error(`Could not transform ${filename} to JS`));
|
|
13
|
+
let code;
|
|
14
|
+
try {
|
|
15
|
+
code = transpileTSToJS(filename, content);
|
|
16
|
+
} catch (e) {
|
|
17
|
+
console.error(colors.error(e instanceof Error ? e.message : String(e)));
|
|
31
18
|
process.exit(1);
|
|
32
19
|
}
|
|
33
|
-
return prettify(filename.replace(/\.ts(x)?$/, ".js$1"),
|
|
20
|
+
return prettify(filename.replace(/\.ts(x)?$/, ".js$1"), code);
|
|
34
21
|
};
|
|
35
22
|
const getPrettierOptions = async () => {
|
|
36
23
|
try {
|
|
37
24
|
const cjsPath = path.join(getPaths().base, "prettier.config.cjs");
|
|
38
25
|
const mjsPath = path.join(getPaths().base, "prettier.config.mjs");
|
|
39
26
|
const prettierConfigPath = fs.existsSync(cjsPath) ? cjsPath : mjsPath;
|
|
40
|
-
const { default: options } = await import(
|
|
27
|
+
const { default: options } = await import(pathToFileURL(prettierConfigPath).href);
|
|
41
28
|
if (options.tailwindConfig?.startsWith(".")) {
|
|
42
29
|
options.tailwindConfig = path.join(
|
|
43
30
|
process.env.CEDAR_CWD ?? process.env.RWJS_CWD ?? process.cwd(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"installHelpers.d.ts","sourceRoot":"","sources":["../../src/lib/installHelpers.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"installHelpers.d.ts","sourceRoot":"","sources":["../../src/lib/installHelpers.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,cAAc,GAAI,aAAa,MAAM,EAAE;;;CAMlD,CAAA;AAEF,eAAO,MAAM,cAAc,GAAI,aAAa,MAAM,EAAE;;;CAMlD,CAAA;AAEF,eAAO,MAAM,eAAe,GAAI,UAAU,MAAM,EAAE,EAAE,uBAAqB;;;CAQxE,CAAA;AAED,eAAO,MAAM,eAAe;;;CAM3B,CAAA"}
|
|
@@ -1,30 +1,37 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {
|
|
2
|
+
addWorkspacePackages,
|
|
3
|
+
addRootPackages as pmAddRootPackages,
|
|
4
|
+
installPackages as pmInstallPackages
|
|
5
|
+
} from "../packageManager/packages.js";
|
|
2
6
|
import { getPaths } from "./paths.js";
|
|
3
7
|
const addWebPackages = (webPackages) => ({
|
|
4
|
-
title:
|
|
8
|
+
title: `Adding required web packages...`,
|
|
5
9
|
task: async () => {
|
|
6
|
-
|
|
10
|
+
const cwd = getPaths().web.base;
|
|
11
|
+
await addWorkspacePackages("web", webPackages, { cwd });
|
|
7
12
|
}
|
|
8
13
|
});
|
|
9
14
|
const addApiPackages = (apiPackages) => ({
|
|
10
15
|
title: "Adding required api packages...",
|
|
11
16
|
task: async () => {
|
|
12
|
-
|
|
17
|
+
const cwd = getPaths().api.base;
|
|
18
|
+
await addWorkspacePackages("api", apiPackages, { cwd });
|
|
13
19
|
}
|
|
14
20
|
});
|
|
15
21
|
const addRootPackages = (packages, devDependency = false) => {
|
|
16
|
-
const addMode = devDependency ? ["add", "-D"] : ["add"];
|
|
17
22
|
return {
|
|
18
23
|
title: "Installing packages...",
|
|
19
24
|
task: async () => {
|
|
20
|
-
|
|
25
|
+
const cwd = getPaths().base;
|
|
26
|
+
await pmAddRootPackages(packages, { cwd, dev: devDependency });
|
|
21
27
|
}
|
|
22
28
|
};
|
|
23
29
|
};
|
|
24
30
|
const installPackages = {
|
|
25
31
|
title: "Installing packages...",
|
|
26
32
|
task: async () => {
|
|
27
|
-
|
|
33
|
+
const cwd = getPaths().base;
|
|
34
|
+
await pmInstallPackages({ cwd });
|
|
28
35
|
}
|
|
29
36
|
};
|
|
30
37
|
export {
|
package/dist/lib/loadEnvFiles.js
CHANGED
|
@@ -6,7 +6,7 @@ import { hideBin } from "yargs/helpers";
|
|
|
6
6
|
import parser from "yargs-parser";
|
|
7
7
|
import { getPaths } from "@cedarjs/project-config";
|
|
8
8
|
function loadEnvFiles() {
|
|
9
|
-
if (process.env.
|
|
9
|
+
if (process.env.CEDAR_ENV_FILES_LOADED) {
|
|
10
10
|
return;
|
|
11
11
|
}
|
|
12
12
|
const { base } = getPaths();
|
|
@@ -21,7 +21,7 @@ function loadEnvFiles() {
|
|
|
21
21
|
if (loadEnvFiles2.length > 0) {
|
|
22
22
|
loadUserSpecifiedEnvFiles(base, loadEnvFiles2);
|
|
23
23
|
}
|
|
24
|
-
process.env.
|
|
24
|
+
process.env.CEDAR_ENV_FILES_LOADED = "true";
|
|
25
25
|
}
|
|
26
26
|
function loadDefaultEnvFiles(cwd) {
|
|
27
27
|
dotenvDefaultsConfig({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../../src/lib/project.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAWrD,eAAO,MAAM,cAAc,qBAE1B,CAAA;AAED,eAAO,MAAM,sBAAsB,2BAGlC,CAAA;AAED,eAAO,MAAM,mBAAmB,eAM/B,CAAA;AAED,eAAO,MAAM,0BAA0B,
|
|
1
|
+
{"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../../src/lib/project.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAWrD,eAAO,MAAM,cAAc,qBAE1B,CAAA;AAED,eAAO,MAAM,sBAAsB,2BAGlC,CAAA;AAED,eAAO,MAAM,mBAAmB,eAM/B,CAAA;AAED,eAAO,MAAM,0BAA0B,WAStC,CAAA;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,gBAAgB,GAAI,aAAa,MAAM,SAkDnD,CAAA;AAED,eAAO,MAAM,oBAAoB,GAAI,aAAa,MAAM;;;CAOvD,CAAA;AAED,eAAO,MAAM,aAAa,GAAI,MAAM,MAAM,EAAE,OAAO,MAAM,EAAE,SAAS,MAAM;;;CAOzE,CAAA;AAED,eAAO,MAAM,SAAS,GAAI,MAAM,MAAM,EAAE,OAAO,MAAM,EAAE,SAAS,MAAM,kBAqCrE,CAAA;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,GAAG,CAAC,EAAE,MAAM,QAmCzC;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAC5B,OAAO,EAAE,MAAM,MAAM,EACrB,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,GAAG,OAAO,GAAG,MAAM,QA0HjC"}
|
package/dist/lib/project.js
CHANGED
|
@@ -23,7 +23,8 @@ const isTypeScriptProject = () => {
|
|
|
23
23
|
};
|
|
24
24
|
const getInstalledRedwoodVersion = () => {
|
|
25
25
|
try {
|
|
26
|
-
const
|
|
26
|
+
const packageJsonPath = path.join(import.meta.dirname, "../../package.json");
|
|
27
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
|
|
27
28
|
return packageJson.version;
|
|
28
29
|
} catch {
|
|
29
30
|
console.error(colors.error("Could not find installed Cedar version"));
|
|
@@ -34,7 +35,7 @@ const updateTomlConfig = (packageName) => {
|
|
|
34
35
|
const configTomlPath = getConfigPath();
|
|
35
36
|
const originalTomlContent = fs.readFileSync(configTomlPath, "utf-8");
|
|
36
37
|
let tomlToAppend = {};
|
|
37
|
-
const config = getConfig(
|
|
38
|
+
const config = getConfig();
|
|
38
39
|
const cliSection = config.experimental?.cli;
|
|
39
40
|
if (!cliSection) {
|
|
40
41
|
tomlToAppend = {
|
|
@@ -137,13 +138,12 @@ function setRedwoodCWD(cwd) {
|
|
|
137
138
|
cwd = path.dirname(configTomlPath);
|
|
138
139
|
}
|
|
139
140
|
process.env.CEDAR_CWD = cwd;
|
|
140
|
-
process.env.RWJS_CWD = cwd;
|
|
141
141
|
}
|
|
142
142
|
function setTomlSetting(section, setting, value) {
|
|
143
|
-
const
|
|
144
|
-
const originalTomlContent = fs.readFileSync(
|
|
145
|
-
const
|
|
146
|
-
const sectionValue =
|
|
143
|
+
const cedarTomlPath = getConfigPath();
|
|
144
|
+
const originalTomlContent = fs.readFileSync(cedarTomlPath, "utf-8");
|
|
145
|
+
const cedarTomlObject = toml.parse(originalTomlContent);
|
|
146
|
+
const sectionValue = cedarTomlObject[section];
|
|
147
147
|
const existingValue = (
|
|
148
148
|
// I don't like this type cast, but I couldn't come up with a much better
|
|
149
149
|
// solution
|
|
@@ -156,9 +156,9 @@ function setTomlSetting(section, setting, value) {
|
|
|
156
156
|
|
|
157
157
|
[${section}]
|
|
158
158
|
${setting} = ${value}`;
|
|
159
|
-
const hasExistingSettingSection = !!
|
|
159
|
+
const hasExistingSettingSection = !!cedarTomlObject?.[section];
|
|
160
160
|
if (hasExistingSettingSection) {
|
|
161
|
-
const existingSectionSettings = Object.keys(
|
|
161
|
+
const existingSectionSettings = Object.keys(cedarTomlObject[section]);
|
|
162
162
|
let inSection = false;
|
|
163
163
|
let indentation = "";
|
|
164
164
|
let insertionIndex = 1;
|
|
@@ -215,7 +215,7 @@ function setTomlSetting(section, setting, value) {
|
|
|
215
215
|
);
|
|
216
216
|
newTomlContent = tomlLines.join("\n");
|
|
217
217
|
}
|
|
218
|
-
fs.writeFileSync(
|
|
218
|
+
fs.writeFileSync(cedarTomlPath, newTomlContent);
|
|
219
219
|
}
|
|
220
220
|
export {
|
|
221
221
|
addEnvVar,
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Strips the TypeScript syntax from `content` and returns the resulting
|
|
3
|
+
* JavaScript source. Everything that is not TypeScript syntax, including JSX,
|
|
4
|
+
* comments, blank lines and indentation, is kept byte-for-byte, so the output
|
|
5
|
+
* only needs formatting.
|
|
6
|
+
*
|
|
7
|
+
* `import type` statements, `type` specifiers and imports whose bindings are
|
|
8
|
+
* only used as types are removed. Lines that only held removed syntax (for
|
|
9
|
+
* example an `import type` line or an `interface` body) are dropped so they
|
|
10
|
+
* do not turn into stray blank lines.
|
|
11
|
+
*
|
|
12
|
+
* `filename` is used for error messages. The content is always parsed as TSX
|
|
13
|
+
* because templates can contain JSX regardless of their extension.
|
|
14
|
+
*
|
|
15
|
+
* Throws when sucrase reports a syntax error.
|
|
16
|
+
*/
|
|
17
|
+
export declare function transpileTSToJS(filename: string, content: string): string;
|
|
18
|
+
//# sourceMappingURL=transpileTSToJS.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transpileTSToJS.d.ts","sourceRoot":"","sources":["../../src/lib/transpileTSToJS.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,UAwBhE"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { transform } from "sucrase";
|
|
2
|
+
const BLANK_LINE_REGEX = /^[ \t]*$/;
|
|
3
|
+
function transpileTSToJS(filename, content) {
|
|
4
|
+
let code;
|
|
5
|
+
try {
|
|
6
|
+
code = transform(content, {
|
|
7
|
+
// `jsx` is required to parse JSX at all. `jsxRuntime: 'preserve'` keeps
|
|
8
|
+
// the JSX untouched so the project's own build compiles it.
|
|
9
|
+
transforms: ["typescript", "jsx"],
|
|
10
|
+
jsxRuntime: "preserve",
|
|
11
|
+
// Keep modern ECMAScript syntax (optional chaining, class fields, ...)
|
|
12
|
+
// as written.
|
|
13
|
+
disableESTransforms: true,
|
|
14
|
+
keepUnusedImports: false,
|
|
15
|
+
filePath: filename
|
|
16
|
+
}).code;
|
|
17
|
+
} catch (e) {
|
|
18
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
19
|
+
throw new Error(
|
|
20
|
+
`Could not transform ${filename} from TypeScript to JavaScript:
|
|
21
|
+
${message}`
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
return dropEmptiedLines(content, code);
|
|
25
|
+
}
|
|
26
|
+
function dropEmptiedLines(input, output) {
|
|
27
|
+
const inputLines = input.split("\n");
|
|
28
|
+
const outputLines = output.split("\n");
|
|
29
|
+
if (inputLines.length !== outputLines.length) {
|
|
30
|
+
return output;
|
|
31
|
+
}
|
|
32
|
+
return outputLines.filter(
|
|
33
|
+
(line, index) => !BLANK_LINE_REGEX.test(line) || BLANK_LINE_REGEX.test(inputLines[index])
|
|
34
|
+
).join("\n");
|
|
35
|
+
}
|
|
36
|
+
export {
|
|
37
|
+
transpileTSToJS
|
|
38
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prompting libraries (e.g. `prompts`) hang indefinitely when stdin isn't a
|
|
3
|
+
* TTY - piped input, CI, or a backgrounded process never sends a keypress,
|
|
4
|
+
* so the prompt neither resolves nor throws.
|
|
5
|
+
*
|
|
6
|
+
* Call this immediately before any interactive confirm/prompt that's only
|
|
7
|
+
* reached when a flag was left unset, so a non-interactive invocation exits
|
|
8
|
+
* with a clear, actionable error instead of hanging.
|
|
9
|
+
*/
|
|
10
|
+
export declare function requireTTYOrExit(flagHint: string): void;
|
|
11
|
+
//# sourceMappingURL=tty.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tty.d.ts","sourceRoot":"","sources":["../../src/lib/tty.ts"],"names":[],"mappings":"AAIA;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAYvD"}
|
package/dist/lib/tty.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { errorTelemetry } from "@cedarjs/telemetry";
|
|
2
|
+
import { colors } from "./colors.js";
|
|
3
|
+
function requireTTYOrExit(flagHint) {
|
|
4
|
+
if (process.stdin.isTTY) {
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
const error = new Error(
|
|
8
|
+
`Cannot prompt for confirmation in a non-interactive terminal. Please pass ${flagHint} explicitly.`
|
|
9
|
+
);
|
|
10
|
+
errorTelemetry(process.argv, error.message);
|
|
11
|
+
console.error(colors.error(error.message));
|
|
12
|
+
process.exit(1);
|
|
13
|
+
}
|
|
14
|
+
export {
|
|
15
|
+
requireTTYOrExit
|
|
16
|
+
};
|
package/dist/lib/version.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "path";
|
|
3
|
-
import
|
|
3
|
+
import { rangesIntersect, sort, tryParse } from "verkit";
|
|
4
4
|
import { getPaths } from "@cedarjs/project-config";
|
|
5
5
|
function getCorrespondingTag(version, distTags) {
|
|
6
6
|
return Object.entries(distTags).find(([_, v]) => v === version)?.[0];
|
|
@@ -12,7 +12,7 @@ async function getCompatibilityData(packageName, preferredVersionOrTag) {
|
|
|
12
12
|
})
|
|
13
13
|
);
|
|
14
14
|
const projectRedwoodVersion = projectPackageJson.devDependencies["@cedarjs/core"];
|
|
15
|
-
const semverVersion =
|
|
15
|
+
const semverVersion = tryParse(preferredVersionOrTag);
|
|
16
16
|
const isUsingTag = semverVersion === null;
|
|
17
17
|
const res = await fetch(`https://registry.npmjs.org/${packageName}`);
|
|
18
18
|
const packument = await res.json();
|
|
@@ -34,7 +34,7 @@ async function getCompatibilityData(packageName, preferredVersionOrTag) {
|
|
|
34
34
|
}
|
|
35
35
|
const preferredVersion = isUsingTag ? packument["dist-tags"][preferredVersionOrTag] : preferredVersionOrTag;
|
|
36
36
|
const packageRedwoodSpecification = packument.versions[preferredVersion].engines?.redwoodjs;
|
|
37
|
-
if (packageRedwoodSpecification !== void 0 &&
|
|
37
|
+
if (packageRedwoodSpecification !== void 0 && rangesIntersect(projectRedwoodVersion, packageRedwoodSpecification)) {
|
|
38
38
|
const tag = getCorrespondingTag(preferredVersion, packument["dist-tags"]);
|
|
39
39
|
return {
|
|
40
40
|
preferred: {
|
|
@@ -47,13 +47,13 @@ async function getCompatibilityData(packageName, preferredVersionOrTag) {
|
|
|
47
47
|
}
|
|
48
48
|
};
|
|
49
49
|
}
|
|
50
|
-
const versions =
|
|
50
|
+
const versions = sort(Object.keys(packument.versions));
|
|
51
51
|
for (let i = versions.length - 1; i >= 0; i--) {
|
|
52
52
|
const redwoodVersionRequired = packument.versions[versions[i]].engines?.redwoodjs;
|
|
53
53
|
if (redwoodVersionRequired === void 0) {
|
|
54
54
|
continue;
|
|
55
55
|
}
|
|
56
|
-
if (
|
|
56
|
+
if (rangesIntersect(projectRedwoodVersion, redwoodVersionRequired)) {
|
|
57
57
|
return {
|
|
58
58
|
preferred: {
|
|
59
59
|
tag: getCorrespondingTag(preferredVersion, packument["dist-tags"]),
|