diff --git a/.env.dist b/.env.dist index 8637f18..6fd9b83 100644 --- a/.env.dist +++ b/.env.dist @@ -1,4 +1,5 @@ -# Env vars added by Remix Forge +# Base envs +APP_NAME="{{env:APP_NAME}}" APP_URL="http://localhost:3000" SESSION_SECRET="{{uuid}}" diff --git a/.gitpod.yml b/.gitpod.yml deleted file mode 100644 index f992fc1..0000000 --- a/.gitpod.yml +++ /dev/null @@ -1,41 +0,0 @@ -# This configuration file was automatically generated by Gitpod. -# Please adjust to your needs (see https://www.gitpod.io/docs/introduction/learn-gitpod/gitpod-yaml) -# and commit this file to your remote git repository to share the goodness with others. - -# Learn more from ready-to-use templates: https://www.gitpod.io/docs/introduction/getting-started/quickstart - -tasks: - - name: Restore .env file - # https://www.gitpod.io/guides/automate-env-files-with-gitpod-environment-variables - # After making changes to .env, run this line to persist it to $DOTENV - # gp env DOTENV="$(base64 .env | tr -d '\n')" - command: | - if [ -f .env ]; then - # If this workspace already has a .env, don't override it - # Local changes survive a workspace being opened and closed - # but they will not persist between separate workspaces for the same repo - echo "Found .env in workspace" - else - if [ -z "${DOTENV}" ]; then - # There is no $DOTENV from a previous workspace - # Default to the example .env - echo "Setting example .env" - cp .env.example .env - else - # Environment variables set this way are shared between all your workspaces for this repo - # The lines below will read $DOTENV and print a .env file - echo "Restoring .env from Gitpod" - echo "${DOTENV}" | base64 -d > .env - fi - fi - - - name: App - init: npm install && npm run build - command: npm run dev - -vscode: - extensions: - - ms-azuretools.vscode-docker - - esbenp.prettier-vscode - - dbaeumer.vscode-eslint - - bradlc.vscode-tailwindcss diff --git a/remix.config.js b/remix.config.js index 73c6fb4..e1057c7 100644 --- a/remix.config.js +++ b/remix.config.js @@ -1,24 +1,16 @@ -import path from "node:path"; - /** @type {import('@remix-run/dev').AppConfig} */ -export default { - cacheDirectory: "./node_modules/.cache/remix", - ignoredRouteFiles: ["**/.*", "**/*.test.{js,jsx,ts,tsx}"], - publicPath: "/_static/build/", - server: "server.ts", - serverBuildPath: "server/index.mjs", - serverModuleFormat: "esm", - routes: (defineRoutes) => - defineRoutes((route) => { - if (process.env.NODE_ENV === "production") return; - console.log("⚠️ Test routes enabled."); +const config = { + ignoredRouteFiles: ["**/.*"], + // appDirectory: "app", + // assetsBuildDirectory: "public/build", + // publicPath: "/build/", + // serverBuildPath: "build/index.js", + // serverDependenciesToBundle: ["react-hook-form"], + // serverModuleFormat: "cjs", + serverModuleFormat: "esm", +}; - const appDir = path.join(process.cwd(), "app"); +// module.exports = config; - route( - "__tests/create-user", - path.relative(appDir, "cypress/support/test-routes/create-user.ts"), - ); - }), -}; +export default config; diff --git a/remix.init/index.js b/remix.init/index.js index b771e8c..4723e51 100644 --- a/remix.init/index.js +++ b/remix.init/index.js @@ -10,8 +10,6 @@ const semver = require("semver"); const { match } = require("ts-pattern"); const ejs = require("ejs"); -const { v4: uuidV4 } = require("uuid"); - const getPackageManagerCommand = (packageManager) => match(packageManager) .with("bun", () => ({ @@ -65,8 +63,6 @@ const getPackageManagerVersion = (packageManager) => // Copied over from https://github.com/nrwl/nx/blob/bd9b33eaef0393d01f747ea9a2ac5d2ca1fb87c6/packages/nx/src/utils/package-manager.ts#L105-L114 execSync(`${packageManager} --version`).toString("utf-8").trim(); -const getRandomString = (length) => crypto.randomBytes(length).toString("hex"); - const updatePackageJson = ({ APP_NAME, packageJson }) => { const { scripts: { @@ -85,41 +81,20 @@ const updatePackageJson = ({ APP_NAME, packageJson }) => { }; const main = async ({ packageManager, rootDirectory }) => { - const APP_ARC_PATH = path.join(rootDirectory, "./app.arc"); - const EXAMPLE_ENV_PATH = path.join(rootDirectory, ".env.dist"); - const ENV_PATH = path.join(rootDirectory, ".env"); const README_PATH = path.join(rootDirectory, "README.md"); const DIR_NAME = path.basename(rootDirectory); - const SUFFIX = getRandomString(2); - const APP_NAME = (DIR_NAME + "-" + SUFFIX) + const APP_NAME = DIR_NAME // get rid of anything that's not allowed in an app name .replace(/[^a-zA-Z0-9-_]/g, "-"); - const [appArc, env, readme, packageJson] = await Promise.all([ - fs.readFile(APP_ARC_PATH, "utf-8"), - fs.readFile(EXAMPLE_ENV_PATH, "utf-8"), - fs.readFile(README_PATH, "utf-8"), - PackageJson.load(rootDirectory), - ]); - - const generateNewEnv = () => { - return env.split("\n").map((line) => { - if (!line || line.length === 0) return line; - const [key, value] = line.split("="); - - const new_value = match(key) - .with("APP_NAME", () => APP_NAME) - .with("APP_KEY", () => uuidV4()) - .with("SESSION_SECRET", () => uuidV4()) - .otherwise(() => value); + process.env.APP_NAME = APP_NAME; - return [key, new_value].join("="); - }); - }; - - const newEnv = generateNewEnv().join("\n"); + const [readme, packageJson] = await Promise.all([ + fs.readFile(README_PATH, "utf-8"), + PackageJson.load(rootDirectory), + ]); const initInstructions = ` - First run this stack's \`remix.init\` script and commit the changes it makes to your project. @@ -139,22 +114,44 @@ const main = async ({ packageManager, rootDirectory }) => { updatePackageJson({ APP_NAME, packageJson }); await Promise.all([ - fs.writeFile( - APP_ARC_PATH, - appArc.replace("grunge-stack-template", APP_NAME), - ), - fs.writeFile(ENV_PATH, newEnv), fs.writeFile(README_PATH, newReadme), packageJson.save(), fs.copyFile( path.join(rootDirectory, "remix.init", "gitignore"), path.join(rootDirectory, ".gitignore"), ), - // fs.rm(path.join(rootDirectory, ".github", "workflows", "format-repo.yml")), - // fs.rm(path.join(rootDirectory, ".github", "workflows", "lint-repo.yml")), - // fs.rm(path.join(rootDirectory, ".github", "workflows", "no-response.yml")), fs.rm(path.join(rootDirectory, ".github", "dependabot.yml")), fs.rm(path.join(rootDirectory, "LICENSE.md")), + + ...["build", "deploy"].map((workflow) => { + return new Promise((resolve) => { + ejs.renderFile( + path.join( + rootDirectory, + "remix.init", + "workflows", + `${workflow}.yml.ejs`, + ), + answers, + (err, str) => { + if (err) { + console.error(err); + return; + } + + fs.writeFile( + path.join( + rootDirectory, + ".github", + "workflows", + `${workflow}.yml`, + ), + str, + ).then(resolve); + }, + ); + }); + }), ]); await askSetupQuestions({ packageManager, rootDirectory }).catch((error) => { @@ -237,6 +234,11 @@ async function askSetupQuestions({ packageManager, rootDirectory }) { }); } + execSync(pm.run("env:gen"), { + cwd: rootDirectory, + stdio: "inherit", + }); + console.log( `✅ Project is ready! Start development with "${pm.run("dev")}"`, ); diff --git a/.github/workflows/deploy.yml b/remix.init/workflows/deploy.yml.ejs similarity index 100% rename from .github/workflows/deploy.yml rename to remix.init/workflows/deploy.yml.ejs diff --git a/server.ts b/server.ts deleted file mode 100644 index d425242..0000000 --- a/server.ts +++ /dev/null @@ -1,10 +0,0 @@ -import * as build from "@remix-run/dev/server-build"; - -if (process.env.NODE_ENV !== "production") { - require("./mocks"); -} - -export const handler = createRequestHandler({ - build, - mode: process.env.NODE_ENV, -});