├── .prettierrc
├── .gitignore
├── src
├── env.d.ts
├── template
│ ├── src
│ │ └── main.ts
│ └── vite.config.ts
├── packageManagers.ts
└── index.ts
├── vite.config.ts
├── tsconfig.json
├── package.json
├── CHANGELOG.md
├── README.md
└── pnpm-lock.yaml
/.prettierrc:
--------------------------------------------------------------------------------
1 | {
2 | "tabWidth": 4
3 | }
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | dist
3 | .DS_Store
--------------------------------------------------------------------------------
/src/env.d.ts:
--------------------------------------------------------------------------------
1 | declare module "*?raw" {
2 | const content: any;
3 | export default content;
4 | }
5 |
--------------------------------------------------------------------------------
/vite.config.ts:
--------------------------------------------------------------------------------
1 | import { node } from "@liuli-util/vite-plugin-node";
2 | import { defineConfig } from "vite";
3 |
4 | export default defineConfig({
5 | plugins: [node()],
6 | appType: "custom",
7 | });
8 |
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "module": "NodeNext",
4 | "allowImportingTsExtensions": true,
5 | "noEmit": true,
6 | "typeRoots": [
7 | "src/env.d.ts"
8 | ]
9 | }
10 | }
--------------------------------------------------------------------------------
/src/template/src/main.ts:
--------------------------------------------------------------------------------
1 | import kaplay from "kaplay";
2 | // import "kaplay/global"; // uncomment if you want to use without the k. prefix
3 |
4 | const k = kaplay();
5 |
6 | k.loadRoot("./"); // A good idea for Itch.io publishing later
7 | k.loadSprite("bean", "sprites/bean.png");
8 |
9 | k.add([k.pos(120, 80), k.sprite("bean")]);
10 |
11 | k.onClick(() => k.addKaboom(k.mousePos()));
12 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "create-kaplay",
3 | "description": "Start a KAPLAY project in no time",
4 | "version": "3.1.3",
5 | "license": "MIT",
6 | "homepage": "https://kaplayjs.com/",
7 | "repository": "github:marklovers/create-kaplay",
8 | "type": "module",
9 | "bin": "dist/index.js",
10 | "files": [
11 | "dist/index.js",
12 | "README.md"
13 | ],
14 | "scripts": {
15 | "build": "vite build",
16 | "dev": "nodemon --watch ./src --ext \"ts,json\" --exec pnpm run build"
17 | },
18 | "packageManager": "pnpm@9.5.0+sha512.140036830124618d624a2187b50d04289d5a087f326c9edfc0ccd733d76c4f52c3a313d4fc148794a2a9d81553016004e6742e8cf850670268a7387fc220c903",
19 | "devDependencies": {
20 | "@liuli-util/vite-plugin-node": "^0.9.0",
21 | "@types/node": "^20.14.11",
22 | "kaplay": "^3001.0.2",
23 | "nodemon": "^3.1.4",
24 | "typescript": "^5.5.3",
25 | "vite": "^5.3.4",
26 | "vite-node": "^2.0.3"
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/packageManagers.ts:
--------------------------------------------------------------------------------
1 | type PackageManager = "npm" | "yarn" | "pnpm" | "bun" | "cnpm";
2 |
3 | export function detectPackageManager(): PackageManager {
4 | if (!process.env.npm_config_user_agent) return;
5 | const specifier = process.env.npm_config_user_agent.split(" ")[0];
6 | const name = specifier.substring(0, specifier.lastIndexOf("/"));
7 |
8 | if (name === "npminstall") return "cnpm";
9 |
10 | return name as PackageManager;
11 | }
12 |
13 | export const packageInstalls = {
14 | "npm": "install",
15 | "yarn": "add",
16 | "pnpm": "install",
17 | "bun": "install",
18 | "cnpm": "install",
19 | };
20 |
21 | export const packageRunScripts = (script: string) => ({
22 | "npm": `run ${script}`,
23 | "yarn": `${script}`,
24 | "pnpm": `run ${script}`,
25 | "bun": `run ${script}`,
26 | "cnpm": `run ${script}`,
27 | });
28 |
29 | export const packageExecutions = {
30 | "npm": `npx`,
31 | "yarn": `yarn`,
32 | "pnpm": `pnpm`,
33 | "bun": `bunx`,
34 | "cnpm": `cnpm`,
35 | };
36 |
--------------------------------------------------------------------------------
/src/template/vite.config.ts:
--------------------------------------------------------------------------------
1 | import { defineConfig } from "vite";
2 |
3 | const kaplayCongrats = () => {
4 | return {
5 | name: "vite-plugin-kaplay-hello",
6 | buildEnd() {
7 | const line =
8 | "---------------------------------------------------------";
9 | const msg = `🦖 Awesome pal! Send your game to us:\n\n💎 Discord: https://discord.com/invite/aQ6RuQm3TF \n💖 Donate to KAPLAY: https://opencollective.com/kaplay\n\ (you can disable this msg on vite.config)`;
10 |
11 | process.stdout.write(`\n${line}\n${msg}\n${line}\n`);
12 | },
13 | };
14 | };
15 |
16 | export default defineConfig({
17 | // index.html out file will start with a relative path for script
18 | base: "./",
19 | server: {
20 | port: 3001,
21 | },
22 | build: {
23 | // disable this for low bundle sizes
24 | sourcemap: true,
25 | rollupOptions: {
26 | output: {
27 | manualChunks: {
28 | kaplay: ["kaplay"],
29 | },
30 | },
31 | },
32 | },
33 | plugins: [
34 | // Disable messages removing this line
35 | kaplayCongrats(),
36 | ],
37 | });
38 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Changelog
2 |
3 | All notable changes to this project will be documented in this file.
4 |
5 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7 |
8 | ## [3.1.3]
9 |
10 | ### Fixed
11 |
12 | - Fixed little thing - @lajbel
13 |
14 | ## [3.1.2]
15 |
16 | ### Fixed
17 |
18 | - Fixed example assets not working - @OrangeNote
19 |
20 | ## [3.0.1]
21 |
22 | ### Fixed
23 |
24 | - fix: folders www now point to dist
25 | - fix: vite now disables HMR
26 |
27 | ## [3.0.0]
28 |
29 | ### Added
30 |
31 | - feat: new vite template
32 |
33 | ## [2.7.0]
34 |
35 | ### Added
36 |
37 | - feat: fetch sprites from the example by @lajbel
38 | - feat: add short option "-s" for spaces by @Shoozza in
39 | https://github.com/marklovers/create-kaplay/pull/7
40 |
41 | ### [Fixed]
42 |
43 | - fix: readme issues by @Shoozza
44 | - fix: vertical scrollbar issue by @Shoozza in
45 | https://github.com/marklovers/create-kaplay/pull/4
46 | - fix: invisible comment line in help due to color choice by @Shoozza in
47 | https://github.com/marklovers/create-kaplay/pull/5
48 | - fix: invalid commandline example by @Shoozza in
49 | https://github.com/marklovers/create-kaplay/pull/8
50 | - fix: typo in help example description by @Shoozza in
51 | https://github.com/marklovers/create-kaplay/pull/6
52 | - fix: examples not being fetched at all by @lajbel
53 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # create-kaplay 🦖
2 |
3 | A CLI tool to create a new [KAPLAY](https://kaplayjs.com) project in no time.
4 |
5 | It will create a project template using [Vite](https://vitejs.dev), this will
6 | give you:
7 |
8 | - A modern setup 🚀
9 | - A fast development server ⚡
10 | - Build for production and generate static assets 🏗️
11 | - A simple and fast bundler 📦
12 | - TypeScript support out of the box 🦄
13 |
14 | If you want to package your game for desktop, you can use the `--desktop` option
15 | to enable [Tauri](https://tauri.app) support. Follow the
16 | [Tauri prerequisites guide](https://tauri.app/v1/guides/getting-started/prerequisites)
17 | to get started.
18 |
19 | ## EXAMPLE
20 |
21 | ```sh
22 | # quick start with default config
23 | create-kaplay mygame
24 |
25 | # calling with options
26 | create-kaplay --typescript --desktop mygame
27 | ```
28 |
29 | ## USAGE
30 |
31 | ```sh
32 | create-kaplay [OPTIONS]
33 | ```
34 |
35 | ## OPTIONS
36 |
37 | ```
38 | -h, --help Print help message
39 | -t, --typescript Use TypeScript
40 | -d, --desktop Enable packaging for desktop release (uses tauri and requires rust to be installed)
41 | -e, --example Start from an example listed on play.kaplayjs.com
42 | -s --spaces Use spaces instead of tabs for generated files
43 | -v, --version