Skip to content
This repository was archived by the owner on Apr 28, 2025. It is now read-only.

Commit 83f678e

Browse files
committed
fix remix init
1 parent bdecf9e commit 83f678e

File tree

4 files changed

+38
-63
lines changed

4 files changed

+38
-63
lines changed

nx.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
}
2121
},
2222
"cli": {
23-
"defaultProjectName": "blues-stack"
23+
"defaultProjectName": "blues-stack-template"
2424
},
2525
"pluginsConfig": {
2626
"@nrwl/js": {

project.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
{
2-
"name": "blues-stack",
2+
"name": "blues-stack-template",
33
"targets": {
44
"dev-all": {
55
"executor": "nx:run-commands",
66
"options": {
77
"commands": [
88
{
9-
"command": "nx dev:server blues-stack",
9+
"command": "nx dev:server blues-stack-template",
1010
"prefix": "[SERVER]",
1111
"color": "blue"
1212
},
1313
{
14-
"command": "nx dev:build blues-stack",
14+
"command": "nx dev:build blues-stack-template",
1515
"prefix": "[BUILD-]",
1616
"color": "green"
1717
},
1818
{
19-
"command": "nx dev:remix blues-stack",
19+
"command": "nx dev:remix blues-stack-template",
2020
"prefix": "[REMIX-]",
2121
"color": "yellow"
2222
},
2323
{
24-
"command": "nx dev:css blues-stack",
24+
"command": "nx dev:css blues-stack-template",
2525
"prefix": "[CSS---]",
2626
"color": "cyan"
2727
}

remix.init/index.js

Lines changed: 31 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -2,71 +2,49 @@ const crypto = require("crypto");
22
const fs = require("fs/promises");
33
const path = require("path");
44

5-
const toml = require("@iarna/toml");
6-
const sort = require("sort-package-json");
7-
8-
function escapeRegExp(string) {
9-
// $& means the whole matched string
10-
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
11-
}
12-
135
function getRandomString(length) {
146
return crypto.randomBytes(length).toString("hex");
157
}
168

179
async function main({ rootDirectory }) {
18-
const README_PATH = path.join(rootDirectory, "README.md");
19-
const FLY_TOML_PATH = path.join(rootDirectory, "fly.toml");
20-
const EXAMPLE_ENV_PATH = path.join(rootDirectory, ".env.example");
21-
const ENV_PATH = path.join(rootDirectory, ".env");
22-
const PACKAGE_JSON_PATH = path.join(rootDirectory, "package.json");
23-
24-
const REPLACER = "blues-stack-template";
25-
26-
const DIR_NAME = path.basename(rootDirectory);
27-
const SUFFIX = getRandomString(2);
28-
29-
const APP_NAME = (DIR_NAME + "-" + SUFFIX)
10+
const APP_NAME = path.basename(rootDirectory);
11+
const APP_ID = (APP_NAME + "-" + getRandomString(2))
3012
// get rid of anything that's not allowed in an app name
3113
.replace(/[^a-zA-Z0-9-_]/g, "-");
3214

33-
const [prodContent, readme, env, packageJson] = await Promise.all([
34-
fs.readFile(FLY_TOML_PATH, "utf-8"),
35-
fs.readFile(README_PATH, "utf-8"),
36-
fs.readFile(EXAMPLE_ENV_PATH, "utf-8"),
37-
fs.readFile(PACKAGE_JSON_PATH, "utf-8"),
38-
fs.rm(path.join(rootDirectory, ".github/ISSUE_TEMPLATE"), {
39-
recursive: true,
40-
}),
41-
fs.rm(path.join(rootDirectory, ".github/PULL_REQUEST_TEMPLATE.md")),
42-
]);
43-
15+
// update env to have SESSION_SECRET
16+
const EXAMPLE_ENV_PATH = path.join(rootDirectory, ".env.example");
17+
const ENV_PATH = path.join(rootDirectory, ".env");
18+
const env = await fs.readFile(EXAMPLE_ENV_PATH, "utf-8");
4419
const newEnv = env.replace(
4520
/^SESSION_SECRET=.*$/m,
4621
`SESSION_SECRET="${getRandomString(16)}"`
4722
);
48-
49-
const prodToml = toml.parse(prodContent);
50-
prodToml.app = prodToml.app.replace(REPLACER, APP_NAME);
51-
52-
const newReadme = readme.replace(
53-
new RegExp(escapeRegExp(REPLACER), "g"),
54-
APP_NAME
55-
);
56-
57-
const newPackageJson =
58-
JSON.stringify(
59-
sort({ ...JSON.parse(packageJson), name: APP_NAME }),
60-
null,
61-
2
62-
) + "\n";
63-
64-
await Promise.all([
65-
fs.writeFile(FLY_TOML_PATH, toml.stringify(prodToml)),
66-
fs.writeFile(README_PATH, newReadme),
67-
fs.writeFile(ENV_PATH, newEnv),
68-
fs.writeFile(PACKAGE_JSON_PATH, newPackageJson),
69-
]);
23+
await fs.writeFile(ENV_PATH, newEnv);
24+
25+
// delete files only needed for the template
26+
const filesToDelete = [
27+
".github/ISSUE_TEMPLATE",
28+
".github/PULL_REQUEST_TEMPLATE.md",
29+
];
30+
for (const file of filesToDelete) {
31+
await fs.rm(path.join(rootDirectory, file), { recursive: true });
32+
}
33+
34+
// replace "blues-stack-template" in all files with the app name
35+
const filesToReplaceIn = [
36+
"README.md",
37+
"package.json",
38+
"fly.toml",
39+
"project.json",
40+
"nx.json",
41+
];
42+
for (const file of filesToReplaceIn) {
43+
const filePath = path.join(rootDirectory, file);
44+
const contents = await fs.readFile(filePath, "utf-8");
45+
const newContents = contents.replace(/blues-stack-template/g, APP_ID);
46+
await fs.writeFile(filePath, newContents);
47+
}
7048

7149
console.log(
7250
`

remix.init/package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,5 @@
33
"private": true,
44
"main": "index.js",
55
"license": "MIT",
6-
"dependencies": {
7-
"@iarna/toml": "^2.2.5",
8-
"sort-package-json": "^1.55.0"
9-
}
6+
"dependencies": {}
107
}

0 commit comments

Comments
 (0)