Skip to content

Commit

Permalink
Update .env.dist and remix.config.js
Browse files Browse the repository at this point in the history
  • Loading branch information
MajorTom327 committed Jan 31, 2024
1 parent c571e16 commit 646cada
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 111 deletions.
3 changes: 2 additions & 1 deletion .env.dist
Original file line number Diff line number Diff line change
@@ -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}}"

Expand Down
41 changes: 0 additions & 41 deletions .gitpod.yml

This file was deleted.

32 changes: 12 additions & 20 deletions remix.config.js
Original file line number Diff line number Diff line change
@@ -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;
80 changes: 41 additions & 39 deletions remix.init/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => ({
Expand Down Expand Up @@ -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: {
Expand All @@ -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.
Expand All @@ -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) => {
Expand Down Expand Up @@ -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")}"`,
);
Expand Down
File renamed without changes.
10 changes: 0 additions & 10 deletions server.ts

This file was deleted.

0 comments on commit 646cada

Please sign in to comment.