Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
basic env cli
Brendan Allan6f25fd9c6bef
diff --git a/package.json b/package.jsonindex 9e84ea62f..06e4c85b4 100644--- a/package.json+++ b/package.json@@ -17,7 +17,9 @@"docker:up": "turbo run docker:up","docker:stop": "turbo run docker:stop","docker:clean": "turbo run docker:clean",- "cap-setup": "dotenv -e .env -- node scripts/setup.js"+ "cap-setup": "dotenv -e .env -- node scripts/setup.js",+ "web": "pnpm run --filter=@cap/web",+ "env-setup": "node scripts/env-cli.js"},"devDependencies": {"@turbo/gen": "^1.9.7",@@ -26,7 +28,9 @@"extract-zip": "^2.0.1","prettier": "^2.5.1","turbo": "^2.3.4",- "typescript": "^5.7.2"+ "typescript": "^5.7.2",+ "@clack/core": "^0.4.1",+ "@clack/prompts": "^0.10.0"},"packageManager": "[email protected]","name": "cap",diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 5f508f30f..a3f7a6f65 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -13,6 +13,12 @@ importers:.:devDependencies:+ '@clack/core':+ specifier: ^0.4.1+ version: 0.4.1+ '@clack/prompts':+ specifier: ^0.10.0+ version: 0.10.0'@turbo/gen':specifier: ^1.9.7version: 1.13.4(@types/[email protected])([email protected])@@ -1403,6 +1409,12 @@ packages:resolution: {integrity: sha512-vYQ+TcfktEE3GHnLZXHCzXF/sN9dw+KivH8a5cmPyd9YtQs7fZtHrEgsIjWpYycXiweKMo1Lm1RZsjxk8DH3rA==}engines: {node: '>=16.0.0', yarn: '>=1.22.18'}+ '@clack/[email protected]':+ resolution: {integrity: sha512-Pxhij4UXg8KSr7rPek6Zowm+5M22rbd2g1nfojHJkxp5YkFqiZ2+YLEM/XGVIzvGOcM0nqjIFxrpDwWRZYWYjA==}++ '@clack/[email protected]':+ resolution: {integrity: sha512-H3rCl6CwW1NdQt9rE3n373t7o5cthPv7yUoxF2ytZvyvlJv89C5RYMJu83Hed8ODgys5vpBU0GKxIRG83jd8NQ==}+'@cloudflare/[email protected]':resolution: {integrity: sha512-YLPHc8yASwjNkmcDMQMY35yiWjoKAKnhUbPRszBRS0YgH+IXtsMp61j+yTcnCE3oO2DgP0U3iejLC8FTtKDC8Q==}engines: {node: '>=16.13'}@@ -4658,10 +4670,10 @@ packages:react-dom:optional: true- '@storybook/[email protected]':- resolution: {integrity: sha512-X6cWPtBTaagi0+pIFZtJe8XjiuwjbfFks09PmSqZJMr1V/0jB/Odifa/XnKqyBHuaudnbClI1kqieBHfu4pu+g==}+ '@storybook/[email protected]':+ resolution: {integrity: sha512-gPpW5WcxvtH1aTY5KqtUMtsExjxuHRvuD+Fsw+n6HLOGVZsBs8m/uJ7ujZMnUmSsR2w/DJI5mk9uWEB01Vasdw==}peerDependencies:- storybook: ^9.0.0-alpha.6+ storybook: ^9.0.0-alpha.10vite: ^4.0.0 || ^5.0.0 || ^6.0.0'@storybook/[email protected]':@@ -4672,10 +4684,10 @@ packages:peerDependencies:storybook: ^8.3.3- '@storybook/[email protected]':- resolution: {integrity: sha512-7PjatRFh5dyYlNdwRWcauiitw71MhqXoWfj8/wU0CGWCTJr+Cn2ZYA9lgjX2GTKU3ctJDTX7gX45NpnZGXIcqw==}+ '@storybook/[email protected]':+ resolution: {integrity: sha512-p8ho/3H07TYXn+hY9uExhXy4DyNr154PmB6kSJ/7vLZkWnHXzeP54xDq4/WT9FNCF8FwwtDzRDSoJRiPqTP0kQ==}peerDependencies:- storybook: ^9.0.0-alpha.6+ storybook: ^9.0.0-alpha.10'@storybook/[email protected]':resolution: {integrity: sha512-dHYFQH3mA+EtnCkHXzicbLgsvzYjcDJ1JWsogbItZogkPHgSJM/Wr71uMkcvw8v9mmCyP4NpXJuu6bPoVsOnzg==}@@ -11842,11 +11854,6 @@ packages:resolution: {integrity: sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==}- resolution: {integrity: sha512-bLQOjaX/ADgQ20isPJRvF0iRUHIxVhYvr53Of7wGcWlO2jvtUlH5m87DsmulFVxRpNLOnI4tB6p/oh8D7kpn9Q==}- engines: {node: '>= 14'}- hasBin: true-resolution: {integrity: sha512-+hSoy/QHluxmC9kCIJyL/uyFmLmc+e5CFR5Wa+bpIhIj85LVb9ZH2nVnqrHoSvKogwODv0ClqZkmiSSaIH5LTA==}engines: {node: '>= 14'}@@ -12771,6 +12778,17 @@ snapshots:- '@chromatic-com/playwright'- react+ '@clack/[email protected]':+ dependencies:+ picocolors: 1.1.0+ sisteransi: 1.0.5++ '@clack/[email protected]':+ dependencies:+ '@clack/core': 0.4.1+ picocolors: 1.1.0+ sisteransi: 1.0.5+'@cloudflare/[email protected]':dependencies:mime: 3.0.0@@ -15948,9 +15966,9 @@ snapshots:react: 18.3.1react-dom: 18.3.1([email protected])- '@storybook/[email protected]([email protected])([email protected](@types/[email protected])([email protected]))':+ '@storybook/[email protected]([email protected])([email protected](@types/[email protected])([email protected]))':dependencies:- '@storybook/csf-plugin': 9.0.0-alpha.6([email protected])+ '@storybook/csf-plugin': 9.0.0-alpha.10([email protected])browser-assert: 1.2.1storybook: 8.3.3ts-dedent: 2.2.0@@ -15981,7 +15999,7 @@ snapshots:storybook: 8.3.3unplugin: 1.16.1- '@storybook/[email protected]([email protected])':+ '@storybook/[email protected]([email protected])':dependencies:storybook: 8.3.3unplugin: 1.16.1@@ -18829,7 +18847,7 @@ snapshots:'@typescript-eslint/parser': 5.62.0([email protected])([email protected])eslint: 8.57.1eslint-import-resolver-node: 0.3.9- eslint-import-resolver-typescript: 3.6.3(@typescript-eslint/[email protected]([email protected])([email protected]))([email protected])([email protected])([email protected])+ eslint-import-resolver-typescript: 3.6.3(@typescript-eslint/[email protected]([email protected])([email protected]))([email protected])([email protected]([email protected]))([email protected])transitivePeerDependencies:- supports-color@@ -22695,7 +22713,7 @@ snapshots:[email protected]([email protected])([email protected](@types/[email protected])([email protected])):dependencies:lilconfig: 3.1.2- yaml: 2.5.1+ yaml: 2.7.0optionalDependencies:postcss: 8.4.47ts-node: 10.9.2(@types/[email protected])([email protected])@@ -22703,7 +22721,7 @@ snapshots:[email protected]([email protected])([email protected](@types/[email protected])([email protected])):dependencies:lilconfig: 3.1.2- yaml: 2.5.1+ yaml: 2.7.0optionalDependencies:postcss: 8.4.47ts-node: 10.9.2(@types/[email protected])([email protected])@@ -23263,7 +23281,7 @@ snapshots:estree-util-value-to-estree: 3.2.1toml: 3.0.0unified: 11.0.5- yaml: 2.5.1+ yaml: 2.7.0dependencies:@@ -23777,7 +23795,7 @@ snapshots:[email protected]([email protected])([email protected](@types/[email protected])([email protected])):dependencies:- '@storybook/builder-vite': 9.0.0-alpha.6([email protected])([email protected](@types/[email protected])([email protected]))+ '@storybook/builder-vite': 9.0.0-alpha.10([email protected])([email protected](@types/[email protected])([email protected]))transitivePeerDependencies:- storybook- vite@@ -25193,8 +25211,6 @@ snapshots:- [email protected]: {}-diff --git a/scripts/env-cli.js b/scripts/env-cli.jsnew file mode 100644index 000000000..98d0380df--- /dev/null+++ b/scripts/env-cli.js@@ -0,0 +1,205 @@+// @ts-check++import * as fs from "node:fs/promises";+import * as crypto from "node:crypto";+import { log } from "@clack/prompts";+import { group } from "@clack/prompts";+import { outro } from "@clack/prompts";+import { text } from "@clack/prompts";+import { confirm } from "@clack/prompts";+import { intro, multiselect, isCancel } from "@clack/prompts";++async function main() {+ intro("Welcome to the Cap env setup CLI!");++ const targets = await multiselect({+ message: "Which apps will you be working on?",+ options: [+ { value: "desktop", label: "Desktop" },+ { value: "web", label: "Web" },+ ],+ required: true,+ });++ if (isCancel(targets)) return;++ const file = await fs+ .readFile("./target/env-profiles/default.json", "utf8")+ .catch(() => null);+ let allEnvs = file+ ? JSON.parse(file)+ : {+ VITE_ENVIRONMENT: "development",+ NODE_ENV: "development",+ CAP_AWS_ACCESS_KEY: "capS3root",+ CAP_AWS_SECRET_KEY: "capS3root",+ NEXT_PUBLIC_CAP_AWS_BUCKET: "capso",+ NEXT_PUBLIC_CAP_AWS_REGION: "us-east-1",+ NEXT_PUBLIC_CAP_AWS_ENDPOINT: "http://localhost:3902",+ DATABASE_URL: "mysql://root:@localhost:3306/planetscale",+ };++ let envs = {};++ const hasWeb = targets.includes("web");+ const hasDesktop = targets.includes("desktop");++ /** @type {boolean | symbol} */+ let usingDockerEnvironment = false;++ if (hasWeb) {+ envs.VITE_SERVER_URL = "http://localhost:3000";++ if (!allEnvs.NEXTAUTH_SECRET) {+ allEnvs.NEXTAUTH_SECRET = crypto.randomBytes(32).toString("base64");+ log.info("Generated NEXTAUTH_SECRET");+ }++ if (!allEnvs.DATABASE_ENCRYPTION_KEY) {+ allEnvs.DATABASE_ENCRYPTION_KEY = crypto.randomBytes(32).toString("hex");+ log.info("Generated DATABASE_ENCRYPTION_KEY");+ }++ usingDockerEnvironment = await confirm({+ message: "Will you be running S3 and MySQL via Docker?",+ });++ if (isCancel(usingDockerEnvironment)) return;+ if (!usingDockerEnvironment) {+ log.info("Database Envs");++ const dbValues = await group({+ DATABASE_URL: () =>+ text({+ message:+ "DATABASE_URL - Can be plain mysql:// or a PlanetScale https:// URL",+ placeholder:+ allEnvs.DATABASE_URL ??+ "mysql://root:@localhost:3306/planetscale",+ defaultValue:+ allEnvs.DATABASE_URL ??+ "mysql://root:@localhost:3306/planetscale",+ }),+ DATABASE_MIGRATION_URL: (v) => {+ if (v.results.DATABASE_URL?.startsWith("http")) {+ log.info("Planetscale HTTP URL detected");+ return text({+ message: "DATABASE_MIGRATION_URL",+ });+ }+ },+ });++ envs.DATABASE_URL = dbValues.DATABASE_URL;+ if (dbValues.DATABASE_MIGRATION_URL)+ envs.DATABASE_MIGRATION_URL = dbValues.DATABASE_MIGRATION_URL;++ log.info("S3 Envs");++ const s3Values = await group(+ {+ CAP_AWS_ACCESS_KEY: () =>+ text({+ message: "CAP_AWS_ACCESS_KEY",+ placeholder: allEnvs.CAP_AWS_ACCESS_KEY,+ defaultValue: allEnvs.CAP_AWS_ACCESS_KEY,+ }),+ CAP_AWS_SECRET_KEY: () =>+ text({+ message: "CAP_AWS_SECRET_KEY",+ placeholder: allEnvs.CAP_AWS_SECRET_KEY,+ defaultValue: allEnvs.CAP_AWS_SECRET_KEY,+ }),+ NEXT_PUBLIC_CAP_AWS_BUCKET: () =>+ text({+ message: "NEXT_PUBLIC_CAP_AWS_BUCKET",+ defaultValue: allEnvs.NEXT_PUBLIC_CAP_AWS_BUCKET,+ placeholder: allEnvs.NEXT_PUBLIC_CAP_AWS_BUCKET,+ }),+ NEXT_PUBLIC_CAP_AWS_REGION: () =>+ text({+ message: "NEXT_PUBLIC_CAP_AWS_REGION",+ defaultValue: allEnvs.NEXT_PUBLIC_CAP_AWS_REGION,+ placeholder: allEnvs.NEXT_PUBLIC_CAP_AWS_REGION,+ }),+ NEXT_PUBLIC_CAP_AWS_ENDPOINT: () =>+ text({+ message: "NEXT_PUBLIC_CAP_AWS_ENDPOINT",+ defaultValue: allEnvs.NEXT_PUBLIC_CAP_AWS_ENDPOINT,+ placeholder: allEnvs.NEXT_PUBLIC_CAP_AWS_ENDPOINT,+ }),+ NEXT_PUBLIC_CAP_AWS_BUCKET_URL: () =>+ text({ message: "NEXT_PUBLIC_CAP_AWS_BUCKET_URL" }),+ CAP_CLOUDFRONT_DISTRIBUTION_ID: () =>+ text({ message: "CAP_CLOUDFRONT_DISTRIBUTION_ID" }),+ },+ { onCancel: () => process.exit(0) }+ );++ envs = { ...envs, ...s3Values };+ }+ } else {+ envs.VITE_SERVER_URL = "http://cap.so";+ }++ if (hasDesktop) {+ const values = await group(+ {+ VITE_VERCEL_AUTOMATION_BYPASS_SECRET: () =>+ text({+ message:+ "VITE_VERCEL_AUTOMATION_BYPASS_SECRET - skip if you're not a Cap team member",+ placeholder: allEnvs.VITE_VERCEL_AUTOMATION_BYPASS_SECRET,+ defaultValue: allEnvs.VITE_VERCEL_AUTOMATION_BYPASS_SECRET,+ }),+ },+ { onCancel: () => process.exit(0) }+ );++ for (const [key, value] of Object.entries(values)) {+ if (value === undefined || value === "undefined") continue;+ envs[key] = value;+ }+ }++ await fs.writeFile(+ ".env.test",+ Object.entries(envs)+ .map(([key, value]) => `${key}=${value}`)+ .join("\n")+ );++ log.info(`Written ${Object.keys(envs).length} envs`);++ allEnvs = { ...allEnvs, ...envs };+ await fs.mkdir("./target/env-profiles", { recursive: true });+ await fs.writeFile(+ "./target/env-profiles/default.json",+ JSON.stringify(allEnvs, null, 4)+ );++ const DESKTOP_MSG = "'pnpm dev:desktop' to start the desktop app";+ const WEB_DOCKER_MSG =+ "'pnpm dev:web' to start the web app + Docker services";+ const WEB_MSG = "'pnpm web dev' to start the web app";++ if (hasWeb) {+ if (hasDesktop) {+ if (usingDockerEnvironment) {+ outro(`Run ${DESKTOP_MSG}, and ${WEB_DOCKER_MSG}`);+ } else {+ outro(`Run ${DESKTOP_MSG}, and ${WEB_MSG}`);+ }+ } else {+ if (usingDockerEnvironment) {+ outro(`Run ${WEB_DOCKER_MSG}`);+ } else {+ outro(`Run ${WEB_MSG}`);+ }+ }+ } else if (hasDesktop) {+ outro(`Run ${DESKTOP_MSG}`);+ }+}++await main();