diff --git a/packages/create-melonjs/CHANGELOG.md b/packages/create-melonjs/CHANGELOG.md index ec2c8f02c..38ced3115 100644 --- a/packages/create-melonjs/CHANGELOG.md +++ b/packages/create-melonjs/CHANGELOG.md @@ -1,10 +1,5 @@ # Changelog -## 1.1.0 - -### New Features -- `--template ` (alias `-t`) flag to pick a starter template. `default` (current behavior, points at `melonjs/typescript-boilerplate`) and `capacitor` (points at `melonjs/typescript-boilerplate-capacitor` for iOS/Android wrapping via Capacitor) are recognized; any other value errors out with the list of known templates. Output now reports which template was used and prints template-specific next-step instructions (capacitor includes `cap add` / `cap copy` / `cap open`). - ## 1.0.1 ### Bug Fixes diff --git a/packages/create-melonjs/README.md b/packages/create-melonjs/README.md index f6f4ca726..5fae52d6d 100644 --- a/packages/create-melonjs/README.md +++ b/packages/create-melonjs/README.md @@ -18,19 +18,6 @@ This downloads the [melonJS TypeScript boilerplate](https://github.com/melonjs/t - [Vite](https://vitejs.dev) — fast dev server and bundler - [Debug plugin](https://github.com/melonjs/debug-plugin) — auto-loaded in development mode -## Templates - -Pick a different starter with `--template ` (or `-t`): - -```bash -npm create melonjs my-game --template capacitor -``` - -| name | source | description | -| --- | --- | --- | -| `default` | [`melonjs/typescript-boilerplate`](https://github.com/melonjs/typescript-boilerplate) | Plain TypeScript + Vite (used when no `--template` flag is passed). | -| `capacitor` | [`melonjs/typescript-boilerplate-capacitor`](https://github.com/melonjs/typescript-boilerplate-capacitor) | TypeScript + Vite + [Capacitor](https://capacitorjs.com/) wrapper for iOS / Android, pre-wired with [`@melonjs/capacitor-plugin`](https://github.com/melonjs/melonJS/tree/master/packages/capacitor-plugin). | - ## Links - [melonJS Documentation](https://melonjs.github.io/melonJS/) diff --git a/packages/create-melonjs/bin/create-melonjs.js b/packages/create-melonjs/bin/create-melonjs.js index 9d16cfb5e..2e728db46 100755 --- a/packages/create-melonjs/bin/create-melonjs.js +++ b/packages/create-melonjs/bin/create-melonjs.js @@ -5,49 +5,22 @@ import { spawnSync } from "node:child_process"; import { existsSync, readFileSync, rmSync, writeFileSync } from "node:fs"; import { join, resolve } from "node:path"; -const TEMPLATES = { - default: "melonjs/typescript-boilerplate", - capacitor: "melonjs/typescript-boilerplate-capacitor", -}; +const REPO = "melonjs/typescript-boilerplate"; const BRANCH = "main"; const green = (text) => `\x1b[32m${text}\x1b[0m`; const bold = (text) => `\x1b[1m${text}\x1b[0m`; const dim = (text) => `\x1b[2m${text}\x1b[0m`; -function parseArgs(argv) { - const args = { positional: [], template: "default" }; - for (let i = 0; i < argv.length; i++) { - const token = argv[i]; - if (token === "--template" || token === "-t") { - args.template = argv[++i]; - } else if (token?.startsWith("--template=")) { - args.template = token.slice("--template=".length); - } else if (token?.startsWith("-")) { - console.error(`\nError: unknown flag "${token}".\n`); - process.exit(1); - } else { - args.positional.push(token); - } - } - return args; -} - function main() { - const { positional, template } = parseArgs(process.argv.slice(2)); - const projectName = positional[0]; + const projectName = process.argv[2]; if (!projectName) { console.log(` -${bold("Usage:")} npm create melonjs ${dim("")} ${dim("[--template ]")} - -${bold("Templates:")} - ${dim("default")} Plain TypeScript + Vite boilerplate (default) - ${dim("capacitor")} TypeScript + Vite + Capacitor wrapper for iOS/Android +${bold("Usage:")} npm create melonjs ${dim("")} -${bold("Examples:")} +${bold("Example:")} npm create melonjs my-game - npm create melonjs my-game --template capacitor cd my-game npm install npm run dev @@ -55,14 +28,6 @@ ${bold("Examples:")} process.exit(1); } - const repo = TEMPLATES[template]; - if (!repo) { - console.error( - `\nError: unknown template "${template}". Known templates: ${Object.keys(TEMPLATES).join(", ")}.\n`, - ); - process.exit(1); - } - const targetDir = resolve(projectName); if (existsSync(targetDir)) { @@ -70,15 +35,13 @@ ${bold("Examples:")} process.exit(1); } - console.log( - `\nCreating a new melonJS game in ${green(targetDir)} (template: ${bold(template)})...\n`, - ); + console.log(`\nCreating a new melonJS game in ${green(targetDir)}...\n`); // download the boilerplate // try degit first (fast, no git history) const degitResult = spawnSync( "npx", - ["--yes", "degit", `${repo}#${BRANCH}`, targetDir], + ["--yes", "degit", `${REPO}#${BRANCH}`, targetDir], { stdio: "inherit", shell: process.platform === "win32", @@ -96,7 +59,7 @@ ${bold("Examples:")} "1", "-b", BRANCH, - `https://github.com/${repo}.git`, + `https://github.com/${REPO}.git`, targetDir, ], { stdio: "inherit" }, @@ -120,25 +83,14 @@ ${bold("Examples:")} writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + "\n"); } - const nextSteps = - template === "capacitor" - ? ` ${dim("$")} cd ${projectName} - ${dim("$")} npm install - ${dim("$")} npm run dev ${dim("# develop in the browser")} - ${dim("$")} npm run build - ${dim("$")} npx cap add ios ${dim("# or: npx cap add android")} - ${dim("$")} npx cap copy - ${dim("$")} npx cap open ios ${dim("# build & run from Xcode / Android Studio")}` - : ` ${dim("$")} cd ${projectName} - ${dim("$")} npm install - ${dim("$")} npm run dev`; - console.log(` ${green("Done!")} Created ${bold(projectName)}. Next steps: -${nextSteps} + ${dim("$")} cd ${projectName} + ${dim("$")} npm install + ${dim("$")} npm run dev Happy game making! ${green("🍈")} `); diff --git a/packages/create-melonjs/package.json b/packages/create-melonjs/package.json index 07b36c898..92496fb08 100644 --- a/packages/create-melonjs/package.json +++ b/packages/create-melonjs/package.json @@ -1,6 +1,6 @@ { "name": "create-melonjs", - "version": "1.1.0", + "version": "1.0.1", "description": "Create a new melonJS game project", "type": "module", "license": "MIT",