Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions packages/create-melonjs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
# Changelog

## 1.1.0

### New Features
- `--template <name>` (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
Expand Down
13 changes: 0 additions & 13 deletions packages/create-melonjs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <name>` (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/)
Expand Down
68 changes: 10 additions & 58 deletions packages/create-melonjs/bin/create-melonjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,80 +5,43 @@ 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("<project-name>")} ${dim("[--template <name>]")}

${bold("Templates:")}
${dim("default")} Plain TypeScript + Vite boilerplate (default)
${dim("capacitor")} TypeScript + Vite + Capacitor wrapper for iOS/Android
${bold("Usage:")} npm create melonjs ${dim("<project-name>")}

${bold("Examples:")}
${bold("Example:")}
npm create melonjs my-game
npm create melonjs my-game --template capacitor
cd my-game
npm install
npm run dev
`);
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)) {
console.error(`\nError: directory "${projectName}" already exists.\n`);
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",
Expand All @@ -96,7 +59,7 @@ ${bold("Examples:")}
"1",
"-b",
BRANCH,
`https://github.com/${repo}.git`,
`https://github.com/${REPO}.git`,
targetDir,
],
{ stdio: "inherit" },
Expand All @@ -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("🍈")}
`);
Expand Down
2 changes: 1 addition & 1 deletion packages/create-melonjs/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
Loading