forked from remix-run/remix
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support custom
entry.server
file in Vercel Vite Preset (#89)
- Loading branch information
1 parent
1e53248
commit 283fb95
Showing
4 changed files
with
1,115 additions
and
28 deletions.
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
.github/workflow_scripts/get-entry-server-template-shas.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
let fs = require("fs"); | ||
let { spawnSync } = require("child_process"); | ||
let { createHash } = require("crypto"); | ||
|
||
let results = {}; | ||
|
||
function hash(entryServerPath, commitId) { | ||
let entryServerContents = fs.readFileSync(entryServerPath, "utf8"); | ||
let sha = createHash("sha256").update(entryServerContents).digest("hex"); | ||
|
||
if (!results[sha]) { | ||
results[sha] = { | ||
templates: [], | ||
commits: [], | ||
}; | ||
} | ||
|
||
if (!results[sha].templates.includes(entryServerPath)) { | ||
results[sha].templates.push(entryServerPath); | ||
} | ||
if (!results[sha].commits.includes(commitId)) { | ||
results[sha].commits.push(commitId); | ||
} | ||
} | ||
|
||
async function main() { | ||
let r = spawnSync( | ||
"git", | ||
[ | ||
"log", | ||
'--pretty=format:"%h"', | ||
"templates/*/app/entry.server.*", | ||
"packages/remix-dev/config/defaults/entry.server.*", | ||
], | ||
{ | ||
shell: true, | ||
} | ||
); | ||
let commitIds = r.stdout.toString("utf8").trim().split("\n"); | ||
|
||
for (let commitId of commitIds) { | ||
console.log({ commitId }); | ||
spawnSync("git", ["checkout", commitId]); | ||
|
||
// find templates | ||
for (let template of fs.readdirSync("templates")) { | ||
// skip dotfiles | ||
if (template.startsWith(".")) continue; | ||
|
||
let entryServerName = fs | ||
.readdirSync(`templates/${template}/app`) | ||
.find((f) => f.startsWith("entry.server.")); | ||
if (!entryServerName) { | ||
continue; | ||
} | ||
|
||
let entryServerPath = `templates/${template}/app/${entryServerName}`; | ||
hash(entryServerPath, commitId); | ||
} | ||
|
||
// find defaults | ||
try { | ||
for (let def of fs.readdirSync("packages/remix-dev/config/defaults")) { | ||
if (!def.startsWith("entry.server.")) continue; | ||
hash(`packages/remix-dev/config/defaults/${def}`, commitId); | ||
} | ||
} catch (err) { | ||
// `entry.server` was required at some point, so there were no defaults | ||
if (err.code !== "ENOENT") throw err; | ||
} | ||
} | ||
|
||
console.log(results); | ||
fs.writeFileSync( | ||
"entry-server-shas.json", | ||
JSON.stringify(results, null, 2) + "\n" | ||
); | ||
} | ||
|
||
main().catch((err) => { | ||
console.error(err); | ||
process.exitCode = 1; | ||
}); |
Oops, something went wrong.