Skip to content

Commit

Permalink
feat: remove all TypeScript references when isTypeScript is passed …
Browse files Browse the repository at this point in the history
…as `false` to `remix.init`
  • Loading branch information
MichaelDeBoey committed Apr 20, 2022
1 parent bf438e1 commit 9a81275
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
"build:remix": "remix build",
"build:server": "esbuild --platform=node --format=cjs ./server.ts --outdir=build",
"dev": "run-p dev:*",
"dev:server": "cross-env NODE_ENV=development node --inspect --require ./node_modules/dotenv/config --require ./mocks ./build/server.js",
"dev:build": "cross-env NODE_ENV=development npm run build:server -- --watch",
"dev:remix": "cross-env NODE_ENV=development remix watch",
"dev:css": "cross-env NODE_ENV=development npm run generate:css -- --watch",
"dev:remix": "cross-env NODE_ENV=development remix watch",
"dev:server": "cross-env NODE_ENV=development node --inspect --require ./node_modules/dotenv/config --require ./mocks ./build/server.js",
"docker": "docker-compose up -d",
"format": "prettier --write .",
"generate:css": "tailwindcss -o ./app/styles/tailwind.css",
Expand Down
37 changes: 28 additions & 9 deletions remix.init/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const fs = require("fs/promises");
const path = require("path");

const toml = require("@iarna/toml");
const sort = require("sort-package-json");
const sortPackageJson = require("sort-package-json");

function escapeRegExp(string) {
// $& means the whole matched string
Expand All @@ -14,7 +14,7 @@ function getRandomString(length) {
return crypto.randomBytes(length).toString("hex");
}

async function main({ rootDirectory }) {
async function main({ isTypeScript, rootDirectory }) {
const README_PATH = path.join(rootDirectory, "README.md");
const FLY_TOML_PATH = path.join(rootDirectory, "fly.toml");
const EXAMPLE_ENV_PATH = path.join(rootDirectory, ".env.example");
Expand Down Expand Up @@ -54,18 +54,37 @@ async function main({ rootDirectory }) {
APP_NAME
);

const newPackageJson =
JSON.stringify(
sort({ ...JSON.parse(packageJson), name: APP_NAME }),
null,
2
) + "\n";
const { devDependencies, prisma, scripts, ...oldPackageJson } =
JSON.parse(packageJson);
const newPackageJson = {
...oldPackageJson,
name: APP_NAME,
devDependencies: isTypeScript
? devDependencies
: Object.fromEntries(
Object.entries(devDependencies).filter(
([key]) => !["ts-node", "tsconfig-paths"].includes(key)
)
),
prisma: isTypeScript ? prisma : { seed: "node prisma/seed.js" },
scripts: isTypeScript
? scripts
: {
...scripts,
"build:server":
"esbuild --platform=node --format=cjs ./server.js --outdir=build",
typecheck: undefined,
validate: 'run-p "test -- --run" lint test:e2e:run',
},
};
const newPackageJsonString =
JSON.stringify(sortPackageJson(newPackageJson), null, 2) + "\n";

await Promise.all([
fs.writeFile(FLY_TOML_PATH, toml.stringify(prodToml)),
fs.writeFile(README_PATH, newReadme),
fs.writeFile(ENV_PATH, newEnv),
fs.writeFile(PACKAGE_JSON_PATH, newPackageJson),
fs.writeFile(PACKAGE_JSON_PATH, newPackageJsonString),
]);

console.log(
Expand Down

0 comments on commit 9a81275

Please sign in to comment.