-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(create-mud): simplify without create-create-app
- Loading branch information
Showing
13 changed files
with
1,205 additions
and
466 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
|
@@ -99,6 +99,7 @@ public/ | |
|
||
# End of https://www.gitignore.io/api/node | ||
|
||
templates | ||
|
||
# Created by `pnpm test` | ||
test-project |
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
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,4 @@ | ||
#!/usr/bin/env node | ||
|
||
// workaround for https://github.com/pnpm/pnpm/issues/1801 | ||
import "../dist/cli.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 |
---|---|---|
|
@@ -4,18 +4,22 @@ | |
"description": "Create a new MUD project", | ||
"license": "MIT", | ||
"author": "Lattice <[email protected]>", | ||
"bin": "dist/cli.js", | ||
"type": "module", | ||
"bin": "bin/cli.js", | ||
"files": [ | ||
"dist" | ||
"bin", | ||
"dist", | ||
"templates" | ||
], | ||
"scripts": { | ||
"build": "pnpm run build:js", | ||
"build:js": "tsup && tsx ./scripts/copy-templates.ts", | ||
"build:js": "pnpm clean && tsup && pnpm run copy-templates", | ||
"clean": "pnpm run clean:js", | ||
"clean:js": "shx rm -rf dist", | ||
"copy-templates": "tsx ./scripts/copy-templates.ts", | ||
"dev": "tsup --watch", | ||
"prepublishOnly": "npm run clean && npm run build", | ||
"test": "pnpm run test:vanilla && pnpm run test:react && pnpm run test:react-ecs && pnpm run test:phaser && pnpm run test:threejs", | ||
"test": "pnpm clean && pnpm run copy-templates && pnpm vitest && pnpm run test:vanilla && pnpm run test:react && pnpm run test:react-ecs && pnpm run test:phaser && pnpm run test:threejs", | ||
"test:ci": "pnpm run test", | ||
"test:phaser": "dist/cli.js test-project --template phaser && shx rm -rf test-project", | ||
"test:react": "dist/cli.js test-project --template react && shx rm -rf test-project", | ||
|
@@ -24,9 +28,11 @@ | |
"test:vanilla": "dist/cli.js test-project --template vanilla && shx rm -rf test-project" | ||
}, | ||
"dependencies": { | ||
"create-create-app": "git+https://github.com/holic/create-create-app#74376c59b48a04aabbe94d9cacfe9cb1cecccd63" | ||
"fast-glob": "^3.3.3", | ||
"yargs-interactive": "^3.0.1" | ||
}, | ||
"devDependencies": { | ||
"@types/yargs-interactive": "^2.1.6", | ||
"execa": "^7.0.0" | ||
}, | ||
"publishConfig": { | ||
|
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
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,62 @@ | ||
import fs from "node:fs/promises"; | ||
import path from "node:path"; | ||
import { fileURLToPath } from "node:url"; | ||
import yargsInteractive from "yargs-interactive"; | ||
import glob from "fast-glob"; | ||
import packageJson from "../../package.json"; | ||
import { templates } from "../common"; | ||
import { exists } from "../exists"; | ||
|
||
const __filename = fileURLToPath(import.meta.url); | ||
const __dirname = path.dirname(__filename); | ||
|
||
async function run() { | ||
yargsInteractive() | ||
.usage("$0 [args]") | ||
.interactive({ | ||
interactive: { default: true }, | ||
name: { | ||
describe: "Name your project", | ||
type: "input", | ||
}, | ||
template: { | ||
describe: "Pick a template", | ||
type: "list", | ||
choices: templates, | ||
}, | ||
"mud-version": { | ||
type: "input", | ||
describe: "The version of MUD packages to use, defaults to latest", | ||
default: packageJson.version, | ||
}, | ||
}) | ||
.then(async (args) => { | ||
if (!args.name) throw new Error("No project name provided."); | ||
|
||
const targetDir = path.join(process.cwd(), args.name); | ||
if (await exists(targetDir)) { | ||
throw new Error(`Target directory "${targetDir}" already exists.`); | ||
} | ||
|
||
const sourceDir = path.join(__dirname, "..", "templates", args.template); | ||
const files = await glob("**/*", { cwd: sourceDir, dot: true }); | ||
|
||
for (const filename of files) { | ||
const sourceFile = path.join(sourceDir, filename); | ||
const targetFile = path.join(targetDir, filename); | ||
|
||
await fs.mkdir(path.dirname(targetFile), { recursive: true }); | ||
|
||
if (/package\.json$/.test(sourceFile)) { | ||
const source = await fs.readFile(sourceFile, "utf-8"); | ||
await fs.writeFile(targetFile, source.replaceAll(/{{mud-version}}/g, args.mudVersion), "utf-8"); | ||
} else { | ||
await fs.copyFile(sourceFile, targetFile); | ||
} | ||
} | ||
|
||
console.log(`\nDone! Play in the MUD with \`cd ${args.name}\` and \`pnpm run dev\`\n`); | ||
}); | ||
} | ||
|
||
run(); |
This file was deleted.
Oops, something went wrong.
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,14 @@ | ||
import { describe, expect, it } from "vitest"; | ||
import { glob } from "glob"; | ||
import { templates } from "./common"; | ||
|
||
describe("templates", () => { | ||
it("matches what is in the file system", async () => { | ||
const availableTemplates = await glob("*", { | ||
maxDepth: 1, | ||
cwd: `${__dirname}/../dist/templates`, | ||
}); | ||
expect(templates).toEqual(expect.arrayContaining(availableTemplates)); | ||
expect(availableTemplates).toEqual(expect.arrayContaining(templates)); | ||
}); | ||
}); |
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,3 @@ | ||
// We define these here to keep them in the order we want to present in the CLI. | ||
// Tests will ensure this list stays up to date. | ||
export const templates = ["react", "react-ecs", "phaser", "threejs", "vanilla"]; |
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,10 @@ | ||
import fs from "node:fs/promises"; | ||
|
||
export async function exists(path: string) { | ||
try { | ||
await fs.access(path); | ||
return true; | ||
} catch { | ||
return false; | ||
} | ||
} |
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
Oops, something went wrong.