@cedarjs/cli-helpers 0.0.4

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.
Files changed (124) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +3 -0
  3. package/dist/auth/authFiles.d.ts +44 -0
  4. package/dist/auth/authFiles.d.ts.map +1 -0
  5. package/dist/auth/authFiles.js +74 -0
  6. package/dist/auth/authTasks.d.ts +49 -0
  7. package/dist/auth/authTasks.d.ts.map +1 -0
  8. package/dist/auth/authTasks.js +345 -0
  9. package/dist/auth/setupHelpers.d.ts +26 -0
  10. package/dist/auth/setupHelpers.d.ts.map +1 -0
  11. package/dist/auth/setupHelpers.js +127 -0
  12. package/dist/build.d.ts +2 -0
  13. package/dist/build.d.ts.map +1 -0
  14. package/dist/cjs/auth/authFiles.d.ts +44 -0
  15. package/dist/cjs/auth/authFiles.d.ts.map +1 -0
  16. package/dist/cjs/auth/authFiles.js +109 -0
  17. package/dist/cjs/auth/authTasks.d.ts +49 -0
  18. package/dist/cjs/auth/authTasks.d.ts.map +1 -0
  19. package/dist/cjs/auth/authTasks.js +384 -0
  20. package/dist/cjs/auth/setupHelpers.d.ts +26 -0
  21. package/dist/cjs/auth/setupHelpers.d.ts.map +1 -0
  22. package/dist/cjs/auth/setupHelpers.js +151 -0
  23. package/dist/cjs/index.d.ts +12 -0
  24. package/dist/cjs/index.d.ts.map +1 -0
  25. package/dist/cjs/index.js +52 -0
  26. package/dist/cjs/lib/colors.d.ts +23 -0
  27. package/dist/cjs/lib/colors.d.ts.map +1 -0
  28. package/dist/cjs/lib/colors.js +52 -0
  29. package/dist/cjs/lib/index.d.ts +21 -0
  30. package/dist/cjs/lib/index.d.ts.map +1 -0
  31. package/dist/cjs/lib/index.js +140 -0
  32. package/dist/cjs/lib/installHelpers.d.ts +17 -0
  33. package/dist/cjs/lib/installHelpers.d.ts.map +1 -0
  34. package/dist/cjs/lib/installHelpers.js +72 -0
  35. package/dist/cjs/lib/loadEnvFiles.d.ts +5 -0
  36. package/dist/cjs/lib/loadEnvFiles.d.ts.map +1 -0
  37. package/dist/cjs/lib/loadEnvFiles.js +101 -0
  38. package/dist/cjs/lib/paths.d.ts +6 -0
  39. package/dist/cjs/lib/paths.d.ts.map +1 -0
  40. package/dist/cjs/lib/paths.js +42 -0
  41. package/dist/cjs/lib/project.d.ts +42 -0
  42. package/dist/cjs/lib/project.d.ts.map +1 -0
  43. package/dist/cjs/lib/project.js +265 -0
  44. package/dist/cjs/lib/version.d.ts +17 -0
  45. package/dist/cjs/lib/version.d.ts.map +1 -0
  46. package/dist/cjs/lib/version.js +107 -0
  47. package/dist/cjs/package.json +1 -0
  48. package/dist/cjs/telemetry/index.d.ts +20 -0
  49. package/dist/cjs/telemetry/index.d.ts.map +1 -0
  50. package/dist/cjs/telemetry/index.js +62 -0
  51. package/dist/index.d.ts +12 -0
  52. package/dist/index.d.ts.map +1 -0
  53. package/dist/index.js +20 -0
  54. package/dist/lib/colors.d.ts +23 -0
  55. package/dist/lib/colors.d.ts.map +1 -0
  56. package/dist/lib/colors.js +18 -0
  57. package/dist/lib/index.d.ts +21 -0
  58. package/dist/lib/index.d.ts.map +1 -0
  59. package/dist/lib/index.js +102 -0
  60. package/dist/lib/installHelpers.d.ts +17 -0
  61. package/dist/lib/installHelpers.d.ts.map +1 -0
  62. package/dist/lib/installHelpers.js +35 -0
  63. package/dist/lib/loadEnvFiles.d.ts +5 -0
  64. package/dist/lib/loadEnvFiles.d.ts.map +1 -0
  65. package/dist/lib/loadEnvFiles.js +64 -0
  66. package/dist/lib/paths.d.ts +6 -0
  67. package/dist/lib/paths.d.ts.map +1 -0
  68. package/dist/lib/paths.js +18 -0
  69. package/dist/lib/project.d.ts +42 -0
  70. package/dist/lib/project.d.ts.map +1 -0
  71. package/dist/lib/project.js +227 -0
  72. package/dist/lib/version.d.ts +17 -0
  73. package/dist/lib/version.d.ts.map +1 -0
  74. package/dist/lib/version.js +73 -0
  75. package/dist/package.json +1 -0
  76. package/dist/src/auth/__tests__/authFiles.test.d.ts +2 -0
  77. package/dist/src/auth/__tests__/authFiles.test.d.ts.map +1 -0
  78. package/dist/src/auth/__tests__/authTasks.test.d.ts +2 -0
  79. package/dist/src/auth/__tests__/authTasks.test.d.ts.map +1 -0
  80. package/dist/src/auth/__tests__/mockFsFiles.d.ts +14 -0
  81. package/dist/src/auth/__tests__/mockFsFiles.d.ts.map +1 -0
  82. package/dist/src/auth/__tests__/setupHelpers.test.d.ts +2 -0
  83. package/dist/src/auth/__tests__/setupHelpers.test.d.ts.map +1 -0
  84. package/dist/src/auth/authFiles.d.ts +44 -0
  85. package/dist/src/auth/authFiles.d.ts.map +1 -0
  86. package/dist/src/auth/authTasks.d.ts +49 -0
  87. package/dist/src/auth/authTasks.d.ts.map +1 -0
  88. package/dist/src/auth/setupHelpers.d.ts +26 -0
  89. package/dist/src/auth/setupHelpers.d.ts.map +1 -0
  90. package/dist/src/index.d.ts +12 -0
  91. package/dist/src/index.d.ts.map +1 -0
  92. package/dist/src/lib/__tests__/index.test.d.ts +2 -0
  93. package/dist/src/lib/__tests__/index.test.d.ts.map +1 -0
  94. package/dist/src/lib/__tests__/loadEnvFiles.test.d.ts +2 -0
  95. package/dist/src/lib/__tests__/loadEnvFiles.test.d.ts.map +1 -0
  96. package/dist/src/lib/__tests__/project.addTomlSetting.test.d.ts +2 -0
  97. package/dist/src/lib/__tests__/project.addTomlSetting.test.d.ts.map +1 -0
  98. package/dist/src/lib/__tests__/project.test.d.ts +2 -0
  99. package/dist/src/lib/__tests__/project.test.d.ts.map +1 -0
  100. package/dist/src/lib/__tests__/version.test.d.ts +2 -0
  101. package/dist/src/lib/__tests__/version.test.d.ts.map +1 -0
  102. package/dist/src/lib/colors.d.ts +23 -0
  103. package/dist/src/lib/colors.d.ts.map +1 -0
  104. package/dist/src/lib/index.d.ts +21 -0
  105. package/dist/src/lib/index.d.ts.map +1 -0
  106. package/dist/src/lib/installHelpers.d.ts +17 -0
  107. package/dist/src/lib/installHelpers.d.ts.map +1 -0
  108. package/dist/src/lib/loadEnvFiles.d.ts +5 -0
  109. package/dist/src/lib/loadEnvFiles.d.ts.map +1 -0
  110. package/dist/src/lib/paths.d.ts +6 -0
  111. package/dist/src/lib/paths.d.ts.map +1 -0
  112. package/dist/src/lib/project.d.ts +42 -0
  113. package/dist/src/lib/project.d.ts.map +1 -0
  114. package/dist/src/lib/version.d.ts +17 -0
  115. package/dist/src/lib/version.d.ts.map +1 -0
  116. package/dist/src/telemetry/index.d.ts +20 -0
  117. package/dist/src/telemetry/index.d.ts.map +1 -0
  118. package/dist/telemetry/index.d.ts +20 -0
  119. package/dist/telemetry/index.d.ts.map +1 -0
  120. package/dist/telemetry/index.js +27 -0
  121. package/dist/tsconfig.tsbuildinfo +1 -0
  122. package/dist/vitest.config.d.mts +3 -0
  123. package/dist/vitest.config.d.mts.map +1 -0
  124. package/package.json +91 -0
@@ -0,0 +1,102 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import * as babel from "@babel/core";
4
+ import { Listr } from "listr2";
5
+ import { format } from "prettier";
6
+ import { colors } from "./colors.js";
7
+ import { getPaths } from "./paths.js";
8
+ const transformTSToJS = (filename, content) => {
9
+ if (!content) {
10
+ return content;
11
+ }
12
+ const babelFileResult = babel.transform(content, {
13
+ filename,
14
+ // If you ran `yarn rw generate` in `./web` transformSync would import the `.babelrc.js` file,
15
+ // in `./web`? despite us setting `configFile: false`.
16
+ cwd: process.env.NODE_ENV === "test" ? void 0 : getPaths().base,
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`));
31
+ process.exit(1);
32
+ }
33
+ return prettify(filename.replace(/\.ts(x)?$/, ".js$1"), babelFileResult.code);
34
+ };
35
+ const getPrettierOptions = async () => {
36
+ try {
37
+ const { default: options } = await import(`file://${path.join(getPaths().base, "prettier.config.js")}`);
38
+ if (options.tailwindConfig?.startsWith(".")) {
39
+ options.tailwindConfig = path.join(
40
+ process.env.RWJS_CWD ?? process.cwd(),
41
+ options.tailwindConfig
42
+ );
43
+ }
44
+ return options;
45
+ } catch {
46
+ return void 0;
47
+ }
48
+ };
49
+ const prettify = async (templateFilename, renderedTemplate) => {
50
+ const parser = {
51
+ ".css": "css",
52
+ ".js": "babel",
53
+ ".ts": "babel-ts",
54
+ ".tsx": "babel-ts"
55
+ }[path.extname(templateFilename.replace(".template", ""))];
56
+ if (typeof parser === "undefined") {
57
+ return renderedTemplate;
58
+ }
59
+ const prettierOptions = await getPrettierOptions();
60
+ return format(renderedTemplate, {
61
+ ...prettierOptions,
62
+ parser
63
+ });
64
+ };
65
+ const writeFile = (target, contents, { existingFiles = "FAIL" } = {}, task = {}) => {
66
+ const { base } = getPaths();
67
+ task.title = `Writing \`./${path.relative(base, target)}\``;
68
+ const exists = fs.existsSync(target);
69
+ if (exists && existingFiles === "FAIL") {
70
+ throw new Error(`${target} already exists.`);
71
+ }
72
+ if (exists && existingFiles === "SKIP") {
73
+ task.skip(`Skipping update of \`./${path.relative(base, target)}\``);
74
+ return;
75
+ }
76
+ const filename = path.basename(target);
77
+ const targetDir = target.replace(filename, "");
78
+ fs.mkdirSync(targetDir, { recursive: true });
79
+ fs.writeFileSync(target, contents);
80
+ task.title = `Successfully wrote file \`./${path.relative(base, target)}\``;
81
+ };
82
+ const writeFilesTask = (files, options) => {
83
+ const { base } = getPaths();
84
+ return new Listr(
85
+ Object.keys(files).map((file) => {
86
+ const contents = files[file];
87
+ return {
88
+ title: `...waiting to write file \`./${path.relative(base, file)}\`...`,
89
+ task: (_ctx, task) => {
90
+ return writeFile(file, contents, options, task);
91
+ }
92
+ };
93
+ })
94
+ );
95
+ };
96
+ export {
97
+ getPrettierOptions,
98
+ prettify,
99
+ transformTSToJS,
100
+ writeFile,
101
+ writeFilesTask
102
+ };
@@ -0,0 +1,17 @@
1
+ export declare const addWebPackages: (webPackages: string[]) => {
2
+ title: string;
3
+ task: () => Promise<void>;
4
+ };
5
+ export declare const addApiPackages: (apiPackages: string[]) => {
6
+ title: string;
7
+ task: () => Promise<void>;
8
+ };
9
+ export declare const addRootPackages: (packages: string[], devDependency?: boolean) => {
10
+ title: string;
11
+ task: () => Promise<void>;
12
+ };
13
+ export declare const installPackages: {
14
+ title: string;
15
+ task: () => Promise<void>;
16
+ };
17
+ //# sourceMappingURL=installHelpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"installHelpers.d.ts","sourceRoot":"","sources":["../../src/lib/installHelpers.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,cAAc,gBAAiB,MAAM,EAAE;;;CAKlD,CAAA;AAEF,eAAO,MAAM,cAAc,gBAAiB,MAAM,EAAE;;;CAKlD,CAAA;AAEF,eAAO,MAAM,eAAe,aAAc,MAAM,EAAE;;;CAQjD,CAAA;AAED,eAAO,MAAM,eAAe;;;CAK3B,CAAA"}
@@ -0,0 +1,35 @@
1
+ import execa from "execa";
2
+ import { getPaths } from "./paths.js";
3
+ const addWebPackages = (webPackages) => ({
4
+ title: "Adding required web packages...",
5
+ task: async () => {
6
+ await execa("yarn", ["add", ...webPackages], { cwd: getPaths().web.base });
7
+ }
8
+ });
9
+ const addApiPackages = (apiPackages) => ({
10
+ title: "Adding required api packages...",
11
+ task: async () => {
12
+ await execa("yarn", ["add", ...apiPackages], { cwd: getPaths().api.base });
13
+ }
14
+ });
15
+ const addRootPackages = (packages, devDependency = false) => {
16
+ const addMode = devDependency ? ["add", "-D"] : ["add"];
17
+ return {
18
+ title: "Installing packages...",
19
+ task: async () => {
20
+ await execa("yarn", [...addMode, ...packages], { cwd: getPaths().base });
21
+ }
22
+ };
23
+ };
24
+ const installPackages = {
25
+ title: "Installing packages...",
26
+ task: async () => {
27
+ await execa("yarn", ["install"], { cwd: getPaths().base });
28
+ }
29
+ };
30
+ export {
31
+ addApiPackages,
32
+ addRootPackages,
33
+ addWebPackages,
34
+ installPackages
35
+ };
@@ -0,0 +1,5 @@
1
+ export declare function loadEnvFiles(): void;
2
+ export declare function loadDefaultEnvFiles(cwd: string): void;
3
+ export declare function loadNodeEnvDerivedEnvFile(cwd: string): void;
4
+ export declare function loadUserSpecifiedEnvFiles(cwd: string, loadEnvFiles: string[]): void;
5
+ //# sourceMappingURL=loadEnvFiles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loadEnvFiles.d.ts","sourceRoot":"","sources":["../../src/lib/loadEnvFiles.ts"],"names":[],"mappings":"AAUA,wBAAgB,YAAY,SAsB3B;AAED,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,QAQ9C;AAED,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,MAAM,QAcpD;AAED,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,QAW5E"}
@@ -0,0 +1,64 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { config as dotenvConfig } from "dotenv";
4
+ import { config as dotenvDefaultsConfig } from "dotenv-defaults";
5
+ import { hideBin } from "yargs/helpers";
6
+ import parser from "yargs-parser";
7
+ import { getPaths } from "@cedarjs/project-config";
8
+ function loadEnvFiles() {
9
+ if (process.env.REDWOOD_ENV_FILES_LOADED) {
10
+ return;
11
+ }
12
+ const { base } = getPaths();
13
+ loadDefaultEnvFiles(base);
14
+ loadNodeEnvDerivedEnvFile(base);
15
+ const { loadEnvFiles: loadEnvFiles2 } = parser(hideBin(process.argv), {
16
+ array: ["load-env-files"],
17
+ default: {
18
+ loadEnvFiles: []
19
+ }
20
+ });
21
+ if (loadEnvFiles2.length > 0) {
22
+ loadUserSpecifiedEnvFiles(base, loadEnvFiles2);
23
+ }
24
+ process.env.REDWOOD_ENV_FILES_LOADED = "true";
25
+ }
26
+ function loadDefaultEnvFiles(cwd) {
27
+ dotenvDefaultsConfig({
28
+ path: path.join(cwd, ".env"),
29
+ defaults: path.join(cwd, ".env.defaults"),
30
+ // @ts-expect-error - Old typings. @types/dotenv-defaults depends on dotenv
31
+ // v8. dotenv-defaults uses dotenv v14
32
+ multiline: true
33
+ });
34
+ }
35
+ function loadNodeEnvDerivedEnvFile(cwd) {
36
+ if (!process.env.NODE_ENV) {
37
+ return;
38
+ }
39
+ const nodeEnvDerivedEnvFilePath = path.join(
40
+ cwd,
41
+ `.env.${process.env.NODE_ENV}`
42
+ );
43
+ if (!fs.existsSync(nodeEnvDerivedEnvFilePath)) {
44
+ return;
45
+ }
46
+ dotenvConfig({ path: nodeEnvDerivedEnvFilePath, override: true });
47
+ }
48
+ function loadUserSpecifiedEnvFiles(cwd, loadEnvFiles2) {
49
+ for (const suffix of loadEnvFiles2) {
50
+ const envPath = path.join(cwd, `.env.${suffix}`);
51
+ if (!fs.existsSync(envPath)) {
52
+ throw new Error(
53
+ `Couldn't find an .env file at '${envPath}' as specified by '--load-env-files'`
54
+ );
55
+ }
56
+ dotenvConfig({ path: envPath, override: true });
57
+ }
58
+ }
59
+ export {
60
+ loadDefaultEnvFiles,
61
+ loadEnvFiles,
62
+ loadNodeEnvDerivedEnvFile,
63
+ loadUserSpecifiedEnvFiles
64
+ };
@@ -0,0 +1,6 @@
1
+ /**
2
+ * This wraps the core version of getPaths into something that catches the exception
3
+ * and displays a helpful error message.
4
+ */
5
+ export declare function getPaths(): import("@cedarjs/project-config").Paths;
6
+ //# sourceMappingURL=paths.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../../src/lib/paths.ts"],"names":[],"mappings":"AAQA;;;GAGG;AACH,wBAAgB,QAAQ,4CAUvB"}
@@ -0,0 +1,18 @@
1
+ import { getPaths as _getPaths } from "@cedarjs/project-config";
2
+ import { colors } from "./colors.js";
3
+ function isErrorWithMessage(e) {
4
+ return !!e.message;
5
+ }
6
+ function getPaths() {
7
+ try {
8
+ return _getPaths();
9
+ } catch (e) {
10
+ if (isErrorWithMessage(e)) {
11
+ console.error(colors.error(e.message));
12
+ }
13
+ process.exit(1);
14
+ }
15
+ }
16
+ export {
17
+ getPaths
18
+ };
@@ -0,0 +1,42 @@
1
+ import type { Config } from '@cedarjs/project-config';
2
+ export declare const getGraphqlPath: () => string | null;
3
+ export declare const graphFunctionDoesExist: () => boolean | "" | null;
4
+ export declare const isTypeScriptProject: () => boolean;
5
+ export declare const getInstalledRedwoodVersion: () => any;
6
+ /**
7
+ * Updates the project's redwood.toml file to include the specified packages plugin
8
+ *
9
+ * Uses toml parsing to determine if the plugin is already included in the file and
10
+ * only adds it if it is not.
11
+ *
12
+ * Writes the updated config to the file system by appending strings, not stringify-ing the toml.
13
+ */
14
+ export declare const updateTomlConfig: (packageName: string) => void;
15
+ export declare const updateTomlConfigTask: (packageName: string) => {
16
+ title: string;
17
+ task: () => void;
18
+ };
19
+ export declare const addEnvVarTask: (name: string, value: string, comment: string) => {
20
+ title: string;
21
+ task: () => void;
22
+ };
23
+ export declare const addEnvVar: (name: string, value: string, comment: string) => string | void;
24
+ /**
25
+ * This sets the `RWJS_CWD` env var to the redwood project directory. This is typically required for internal
26
+ * redwood packages to work correctly. For example, `@cedarjs/project-config` uses this when reading config
27
+ * or paths.
28
+ *
29
+ * @param cwd Explicitly set the redwood cwd. If not set, we'll try to determine it automatically. You likely
30
+ * only want to set this based on some specific input, like a CLI flag.
31
+ */
32
+ export declare const setRedwoodCWD: (cwd?: string) => void;
33
+ /**
34
+ * Create or update the given setting, in the given section, with the given value.
35
+ *
36
+ * If the section already exists it adds the new setting last
37
+ * If the section, and the setting, already exists, the setting is updated
38
+ * If the section does not exist it is created at the end of the file and the setting is added
39
+ * If the setting exists in the section, but is commented out, it will be uncommented and updated
40
+ */
41
+ export declare function setTomlSetting(section: keyof Config, setting: string, value: string | boolean | number): void;
42
+ //# sourceMappingURL=project.d.ts.map
@@ -0,0 +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,WAQtC,CAAA;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB,gBAAiB,MAAM,SAmDnD,CAAA;AAED,eAAO,MAAM,oBAAoB,gBAAiB,MAAM;;;CAOvD,CAAA;AAED,eAAO,MAAM,aAAa,SAAU,MAAM,SAAS,MAAM,WAAW,MAAM;;;CAOzE,CAAA;AAED,eAAO,MAAM,SAAS,SAAU,MAAM,SAAS,MAAM,WAAW,MAAM,kBAqCrE,CAAA;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,SAAU,MAAM,SAyBzC,CAAA;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAC5B,OAAO,EAAE,MAAM,MAAM,EACrB,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,GAAG,OAAO,GAAG,MAAM,QA0HjC"}
@@ -0,0 +1,227 @@
1
+ import * as fs from "node:fs";
2
+ import * as path from "node:path";
3
+ import dotenv from "dotenv";
4
+ import * as toml from "smol-toml";
5
+ import {
6
+ findUp,
7
+ getConfigPath,
8
+ getConfig,
9
+ resolveFile
10
+ } from "@cedarjs/project-config";
11
+ import { colors } from "./colors.js";
12
+ import { getPaths } from "./paths.js";
13
+ const getGraphqlPath = () => {
14
+ return resolveFile(path.join(getPaths().api.functions, "graphql"));
15
+ };
16
+ const graphFunctionDoesExist = () => {
17
+ const graphqlPath = getGraphqlPath();
18
+ return graphqlPath && fs.existsSync(graphqlPath);
19
+ };
20
+ const isTypeScriptProject = () => {
21
+ const paths = getPaths();
22
+ return fs.existsSync(path.join(paths.web.base, "tsconfig.json")) || fs.existsSync(path.join(paths.api.base, "tsconfig.json"));
23
+ };
24
+ const getInstalledRedwoodVersion = () => {
25
+ try {
26
+ const packageJson = require("../../package.json");
27
+ return packageJson.version;
28
+ } catch {
29
+ console.error(colors.error("Could not find installed Cedar version"));
30
+ process.exit(1);
31
+ }
32
+ };
33
+ const updateTomlConfig = (packageName) => {
34
+ const redwoodTomlPath = getConfigPath();
35
+ const originalTomlContent = fs.readFileSync(redwoodTomlPath, "utf-8");
36
+ let tomlToAppend = {};
37
+ const config = getConfig(redwoodTomlPath);
38
+ const cliSection = config.experimental?.cli;
39
+ if (!cliSection) {
40
+ tomlToAppend = {
41
+ experimental: {
42
+ cli: {
43
+ autoInstall: true,
44
+ plugins: [{ package: packageName, enabled: true }]
45
+ }
46
+ }
47
+ };
48
+ } else if (cliSection.plugins) {
49
+ const packageExists = cliSection.plugins.some(
50
+ (plugin) => plugin.package === packageName
51
+ );
52
+ if (!packageExists) {
53
+ tomlToAppend = {
54
+ experimental: {
55
+ cli: {
56
+ plugins: [{ package: packageName, enabled: true }]
57
+ }
58
+ }
59
+ };
60
+ }
61
+ } else {
62
+ tomlToAppend = {
63
+ experimental: {
64
+ cli: {
65
+ plugins: [{ package: packageName, enabled: true }]
66
+ }
67
+ }
68
+ };
69
+ }
70
+ const newConfig = originalTomlContent + "\n" + (Object.keys(tomlToAppend).length > 0 ? toml.stringify(tomlToAppend) + "\n" : "");
71
+ return fs.writeFileSync(redwoodTomlPath, newConfig, "utf-8");
72
+ };
73
+ const updateTomlConfigTask = (packageName) => {
74
+ return {
75
+ title: `Updating redwood.toml to configure ${packageName} ...`,
76
+ task: () => {
77
+ updateTomlConfig(packageName);
78
+ }
79
+ };
80
+ };
81
+ const addEnvVarTask = (name, value, comment) => {
82
+ return {
83
+ title: `Adding ${name} var to .env...`,
84
+ task: () => {
85
+ addEnvVar(name, value, comment);
86
+ }
87
+ };
88
+ };
89
+ const addEnvVar = (name, value, comment) => {
90
+ const envPath = path.join(getPaths().base, ".env");
91
+ let envFile = "";
92
+ const newEnvironmentVariable = [
93
+ comment && `# ${comment}`,
94
+ `${name}=${value}`,
95
+ ""
96
+ ].flat().join("\n");
97
+ if (fs.existsSync(envPath)) {
98
+ envFile = fs.readFileSync(envPath).toString();
99
+ const existingEnvVars = dotenv.parse(envFile);
100
+ if (existingEnvVars[name] && existingEnvVars[name] === value) {
101
+ return envFile;
102
+ }
103
+ if (existingEnvVars[name]) {
104
+ const p = [
105
+ `# Note: The existing environment variable ${name} was not overwritten. Uncomment to use its new value.`,
106
+ comment && `# ${comment}`,
107
+ `# ${name}=${value}`,
108
+ ""
109
+ ].flat().join("\n");
110
+ envFile += "\n" + p;
111
+ } else {
112
+ envFile += "\n" + newEnvironmentVariable;
113
+ }
114
+ } else {
115
+ envFile = newEnvironmentVariable;
116
+ }
117
+ return fs.writeFileSync(envPath, envFile);
118
+ };
119
+ const setRedwoodCWD = (cwd) => {
120
+ cwd ??= process.env.RWJS_CWD;
121
+ if (cwd) {
122
+ if (!fs.existsSync(path.join(cwd, "redwood.toml"))) {
123
+ throw new Error(`Couldn't find a "redwood.toml" file in ${cwd}`);
124
+ }
125
+ } else {
126
+ const redwoodTOMLPath = findUp("redwood.toml", process.cwd());
127
+ if (!redwoodTOMLPath) {
128
+ throw new Error(
129
+ `Couldn't find up a "redwood.toml" file from ${process.cwd()}`
130
+ );
131
+ }
132
+ if (redwoodTOMLPath) {
133
+ cwd = path.dirname(redwoodTOMLPath);
134
+ }
135
+ }
136
+ process.env.RWJS_CWD = cwd;
137
+ };
138
+ function setTomlSetting(section, setting, value) {
139
+ const redwoodTomlPath = getConfigPath();
140
+ const originalTomlContent = fs.readFileSync(redwoodTomlPath, "utf-8");
141
+ const redwoodTomlObject = toml.parse(originalTomlContent);
142
+ const sectionValue = redwoodTomlObject[section];
143
+ const existingValue = (
144
+ // I don't like this type cast, but I couldn't come up with a much better
145
+ // solution
146
+ sectionValue?.[setting]
147
+ );
148
+ if (existingValue === value) {
149
+ return;
150
+ }
151
+ let newTomlContent = originalTomlContent.replace(/\n$/, "") + `
152
+
153
+ [${section}]
154
+ ${setting} = ${value}`;
155
+ const hasExistingSettingSection = !!redwoodTomlObject?.[section];
156
+ if (hasExistingSettingSection) {
157
+ const existingSectionSettings = Object.keys(redwoodTomlObject[section]);
158
+ let inSection = false;
159
+ let indentation = "";
160
+ let insertionIndex = 1;
161
+ let updateExistingValue = false;
162
+ let updateExistingCommentedValue = false;
163
+ const tomlLines = originalTomlContent.split("\n");
164
+ tomlLines.forEach((line, index) => {
165
+ if (line.startsWith(`[${section}]`)) {
166
+ inSection = true;
167
+ insertionIndex = index + 1;
168
+ } else {
169
+ if (/^\s*\[/.test(line)) {
170
+ inSection = false;
171
+ }
172
+ if (inSection && !updateExistingValue) {
173
+ for (const existingSectionSetting of existingSectionSettings) {
174
+ const matches = line.match(
175
+ new RegExp(`^(\\s*)${existingSectionSetting}\\s*=`, "i")
176
+ );
177
+ if (!updateExistingValue && matches) {
178
+ if (!updateExistingCommentedValue) {
179
+ indentation = matches[1];
180
+ }
181
+ if (existingSectionSetting === setting) {
182
+ updateExistingValue = true;
183
+ insertionIndex = index;
184
+ indentation = matches[1];
185
+ }
186
+ }
187
+ if (!updateExistingValue && !updateExistingCommentedValue && /^\s*\w+\s*=/.test(line)) {
188
+ insertionIndex = index + 1;
189
+ }
190
+ }
191
+ if (!updateExistingValue) {
192
+ const matchesComment = line.match(
193
+ new RegExp(`^(\\s*)#(\\s*)${setting}\\s*=`, "i")
194
+ );
195
+ if (matchesComment) {
196
+ const commentIndentation = matchesComment[1].length > matchesComment[2].length ? matchesComment[1] : matchesComment[2];
197
+ if (commentIndentation.length - 1 > indentation.length) {
198
+ indentation = commentIndentation;
199
+ }
200
+ updateExistingCommentedValue = true;
201
+ insertionIndex = index;
202
+ }
203
+ }
204
+ }
205
+ }
206
+ });
207
+ tomlLines.splice(
208
+ insertionIndex,
209
+ updateExistingValue || updateExistingCommentedValue ? 1 : 0,
210
+ `${indentation}${setting} = ${value}`
211
+ );
212
+ newTomlContent = tomlLines.join("\n");
213
+ }
214
+ fs.writeFileSync(redwoodTomlPath, newTomlContent);
215
+ }
216
+ export {
217
+ addEnvVar,
218
+ addEnvVarTask,
219
+ getGraphqlPath,
220
+ getInstalledRedwoodVersion,
221
+ graphFunctionDoesExist,
222
+ isTypeScriptProject,
223
+ setRedwoodCWD,
224
+ setTomlSetting,
225
+ updateTomlConfig,
226
+ updateTomlConfigTask
227
+ };
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Check if the package at the given version is compatible with the current version of the user's RedwoodJS project. This is
3
+ * determined by checking if the package's engines.redwoodjs field intersects with the user's RedwoodJS version.
4
+ *
5
+ * If the preferred version is not compatible, the latest compatible version will be returned if one exists.
6
+ */
7
+ export declare function getCompatibilityData(packageName: string, preferredVersionOrTag: string): Promise<{
8
+ preferred: {
9
+ tag: string | undefined;
10
+ version: string;
11
+ };
12
+ compatible: {
13
+ tag: string | undefined;
14
+ version: string;
15
+ };
16
+ }>;
17
+ //# sourceMappingURL=version.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/lib/version.ts"],"names":[],"mappings":"AAgBA;;;;;GAKG;AACH,wBAAsB,oBAAoB,CACxC,WAAW,EAAE,MAAM,EACnB,qBAAqB,EAAE,MAAM;;;;;;;;;GA2F9B"}
@@ -0,0 +1,73 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import semver from "semver";
4
+ import { getPaths } from "@cedarjs/project-config";
5
+ function getCorrespondingTag(version, distTags) {
6
+ return Object.entries(distTags).find(([_, v]) => v === version)?.[0];
7
+ }
8
+ async function getCompatibilityData(packageName, preferredVersionOrTag) {
9
+ const projectPackageJson = JSON.parse(
10
+ fs.readFileSync(path.join(getPaths().base, "package.json"), {
11
+ encoding: "utf8"
12
+ })
13
+ );
14
+ const projectRedwoodVersion = projectPackageJson.devDependencies["@cedarjs/core"];
15
+ const semverVersion = semver.parse(preferredVersionOrTag);
16
+ const isUsingTag = semverVersion === null;
17
+ const res = await fetch(`https://registry.npmjs.org/${packageName}`);
18
+ const packument = await res.json();
19
+ if (packument.error !== void 0) {
20
+ throw new Error(packument.error);
21
+ }
22
+ if (isUsingTag) {
23
+ if (packument["dist-tags"][preferredVersionOrTag] === void 0) {
24
+ throw new Error(
25
+ `The package '${packageName}' does not have a tag '${preferredVersionOrTag}'`
26
+ );
27
+ }
28
+ } else {
29
+ if (packument.versions[preferredVersionOrTag] === void 0) {
30
+ throw new Error(
31
+ `The package '${packageName}' does not have a version '${preferredVersionOrTag}'`
32
+ );
33
+ }
34
+ }
35
+ const preferredVersion = isUsingTag ? packument["dist-tags"][preferredVersionOrTag] : preferredVersionOrTag;
36
+ const packageRedwoodSpecification = packument.versions[preferredVersion].engines?.redwoodjs;
37
+ if (packageRedwoodSpecification !== void 0 && semver.intersects(projectRedwoodVersion, packageRedwoodSpecification)) {
38
+ const tag = getCorrespondingTag(preferredVersion, packument["dist-tags"]);
39
+ return {
40
+ preferred: {
41
+ tag,
42
+ version: preferredVersion
43
+ },
44
+ compatible: {
45
+ tag,
46
+ version: preferredVersion
47
+ }
48
+ };
49
+ }
50
+ const versions = semver.sort(Object.keys(packument.versions));
51
+ for (let i = versions.length - 1; i >= 0; i--) {
52
+ const redwoodVersionRequired = packument.versions[versions[i]].engines?.redwoodjs;
53
+ if (redwoodVersionRequired === void 0) {
54
+ continue;
55
+ }
56
+ if (semver.intersects(projectRedwoodVersion, redwoodVersionRequired)) {
57
+ return {
58
+ preferred: {
59
+ tag: getCorrespondingTag(preferredVersion, packument["dist-tags"]),
60
+ version: preferredVersion
61
+ },
62
+ compatible: {
63
+ tag: getCorrespondingTag(versions[i], packument["dist-tags"]),
64
+ version: versions[i]
65
+ }
66
+ };
67
+ }
68
+ }
69
+ throw new Error(`No compatible version of '${packageName}' was found`);
70
+ }
71
+ export {
72
+ getCompatibilityData
73
+ };
@@ -0,0 +1 @@
1
+ {"type":"module"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=authFiles.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authFiles.test.d.ts","sourceRoot":"","sources":["../../../../src/auth/__tests__/authFiles.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=authTasks.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authTasks.test.d.ts","sourceRoot":"","sources":["../../../../src/auth/__tests__/authTasks.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,14 @@
1
+ export declare const webAppTsx: string;
2
+ export declare const graphqlTs: string;
3
+ export declare const auth0WebAuthTsTemplate: string;
4
+ export declare const clerkWebAuthTsTemplate: string;
5
+ export declare const routesTsx: string;
6
+ export declare const legacyAuthWebAppTsx: string;
7
+ export declare const customApolloAppTsx: string;
8
+ export declare const customPropsRoutesTsx: string;
9
+ export declare const useAuthRoutesTsx: string;
10
+ export declare const explicitReturnAppTsx: string;
11
+ export declare const withoutRedwoodApolloAppTsx: string;
12
+ export declare const withAuthDecoderGraphqlTs: string;
13
+ export declare const nonStandardAuthDecoderGraphqlTs: string;
14
+ //# sourceMappingURL=mockFsFiles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mockFsFiles.d.ts","sourceRoot":"","sources":["../../../../src/auth/__tests__/mockFsFiles.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS,QAoBrB,CAAA;AAED,eAAO,MAAM,SAAS,QAoBrB,CAAA;AAED,eAAO,MAAM,sBAAsB,QAyBlC,CAAA;AAED,eAAO,MAAM,sBAAsB,QAkDlC,CAAA;AAED,eAAO,MAAM,SAAS,QAqBrB,CAAA;AAED,eAAO,MAAM,mBAAmB,QA4B/B,CAAA;AAED,eAAO,MAAM,kBAAkB,QAoB9B,CAAA;AAED,eAAO,MAAM,oBAAoB,QA8BhC,CAAA;AAED,eAAO,MAAM,gBAAgB,QAkC5B,CAAA;AAED,eAAO,MAAM,oBAAoB,QA+BhC,CAAA;AAED,eAAO,MAAM,0BAA0B,QAuBtC,CAAA;AAED,eAAO,MAAM,wBAAwB,QAwBpC,CAAA;AAED,eAAO,MAAM,+BAA+B,QAwB3C,CAAA"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=setupHelpers.test.d.ts.map