brick-engine-cli 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/.github/workflows/publish.yml +75 -0
  2. package/README.adoc +98 -0
  3. package/bin/brick-cli.js +12 -0
  4. package/dist/commands/init/index.d.ts +1 -0
  5. package/dist/commands/init/index.js +67 -0
  6. package/dist/commands/init/package/dependencies.d.ts +2 -0
  7. package/dist/commands/init/package/dependencies.js +12 -0
  8. package/dist/commands/init/package/devDependencies.d.ts +2 -0
  9. package/dist/commands/init/package/devDependencies.js +77 -0
  10. package/dist/commands/init/package/package.d.ts +18 -0
  11. package/dist/commands/init/package/package.js +43 -0
  12. package/dist/commands/init/package/scripts.d.ts +2 -0
  13. package/dist/commands/init/package/scripts.js +37 -0
  14. package/dist/commands/init/template.d.ts +2 -0
  15. package/dist/commands/init/template.js +55 -0
  16. package/dist/commands/init/types.d.ts +15 -0
  17. package/dist/commands/init/types.js +2 -0
  18. package/dist/commands/publish/index.d.ts +4 -0
  19. package/dist/commands/publish/index.js +154 -0
  20. package/dist/config/constants.d.ts +2 -0
  21. package/dist/config/constants.js +5 -0
  22. package/dist/index.d.ts +1 -0
  23. package/dist/index.js +43 -0
  24. package/package.json +28 -0
  25. package/src/commands/init/index.ts +91 -0
  26. package/src/commands/init/package/dependencies.ts +11 -0
  27. package/src/commands/init/package/devDependencies.ts +76 -0
  28. package/src/commands/init/package/package.ts +48 -0
  29. package/src/commands/init/package/scripts.ts +36 -0
  30. package/src/commands/init/template.ts +32 -0
  31. package/src/commands/init/types.ts +17 -0
  32. package/src/commands/publish/index.ts +201 -0
  33. package/src/config/constants.ts +2 -0
  34. package/src/index.ts +39 -0
  35. package/templates/.prettierrc +8 -0
  36. package/templates/eslint.config.mjs +18 -0
  37. package/templates/src/bootstrap.ts +4 -0
  38. package/templates/src/index.ts +104 -0
  39. package/templates/tsconfig.json +13 -0
  40. package/templates/webpack.config.js +98 -0
  41. package/tsconfig.json +16 -0
@@ -0,0 +1,75 @@
1
+ name: Publish and Deploy
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ - master
8
+
9
+ jobs:
10
+ publish:
11
+ runs-on: ubuntu-latest
12
+ permissions:
13
+ contents: write
14
+ packages: write
15
+
16
+ steps:
17
+ - name: Checkout repository
18
+ uses: actions/checkout@v4
19
+ with:
20
+ fetch-depth: 0 # ensures history is available for tag and push
21
+ token: ${{ secrets.GITHUB_TOKEN }} # Needed to push back to the repository
22
+
23
+ - name: Setup Node.js
24
+ uses: actions/setup-node@v4
25
+ with:
26
+ node-version: "22"
27
+ registry-url: "https://registry.npmjs.org/"
28
+
29
+ - name: Validate NPM Token
30
+ run: npm whoami
31
+ env:
32
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
33
+
34
+ - name: Install dependencies
35
+ run: npm ci
36
+
37
+ - name: Inject Secrets
38
+ run: |
39
+ sed -i "s|%%SUPABASE_URL%%|${{ secrets.SUPABASE_URL }}|g" src/config/constants.ts
40
+ sed -i "s|%%SUPABASE_ANON_KEY%%|${{ secrets.SUPABASE_ANON_KEY }}|g" src/config/constants.ts
41
+
42
+ - name: Build project
43
+ run: npm run build
44
+
45
+ - name: Configure Git
46
+ run: |
47
+ git config --global user.name 'LeonardoPinheiroLacerda'
48
+ git config --global user.email 'leon.lacerda2015@gmail.com'
49
+
50
+ - name: Bump Version
51
+ run: |
52
+ npm version patch --no-git-tag-version
53
+ VERSION=$(node -p "require('./package.json').version")
54
+ echo "VERSION=$VERSION" >> $GITHUB_ENV
55
+ git add package.json package-lock.json
56
+ git commit -m "chore: bump version to v${VERSION} [skip ci]"
57
+ git tag -a "v${VERSION}" -m "Version ${VERSION}"
58
+
59
+ - name: Push adjustments
60
+ run: |
61
+ git push origin HEAD:${{ github.ref }}
62
+ git push origin --tags
63
+
64
+ - name: Publish to NPM
65
+ run: npm publish --access public
66
+ env:
67
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
68
+
69
+ - name: Create GitHub Release
70
+ env:
71
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
72
+ run: |
73
+ gh release create "v${{ env.VERSION }}" \
74
+ --title "Release v${{ env.VERSION }}" \
75
+ --generate-notes
package/README.adoc ADDED
@@ -0,0 +1,98 @@
1
+ = Brick Engine CLI
2
+ :toc: left
3
+ :sectnums:
4
+
5
+ CLI to scaffold Brick Engine projects.
6
+
7
+ == Introduction
8
+
9
+ `brick-engine-cli` is a command-line tool designed to accelerate game development using the **Brick Engine**. It automates the creation of the project's initial structure, configures build tools and code quality settings, allowing you to start programming your game immediately.
10
+
11
+ == Installation and Usage
12
+
13
+ You can use this tool in two main ways:
14
+
15
+ === 1. Use Without Installation (Recommended)
16
+
17
+ The fastest way to get started is using `npx`, which runs the latest version of the tool without requiring a global installation on your system:
18
+
19
+ [source,bash]
20
+ ----
21
+ npx brick-engine-cli init <project-name>
22
+ ----
23
+
24
+ === 2. Global Installation
25
+
26
+ If you prefer to have the command permanently available in your terminal, you can install it globally via `npm`:
27
+
28
+ [source,bash]
29
+ ----
30
+ npm install -g brick-engine-cli
31
+ ----
32
+
33
+ After installation, you can use the command directly:
34
+
35
+ [source,bash]
36
+ ----
37
+ brick-engine-cli init <project-name>
38
+ ----
39
+
40
+ == Commands
41
+
42
+ === `init <name>`
43
+
44
+ Initializes a new Brick Engine project in a directory with the provided name.
45
+
46
+ During the process, you will be asked about:
47
+ * Project description.
48
+ * Whether you want to use **ESLint** to ensure code quality.
49
+ * Whether you want to use **Prettier** for automatic formatting.
50
+
51
+ === `publish`
52
+
53
+ Publishes your game to the Brick Engine platform.
54
+
55
+ Before uploading, this command automatically builds the project to generate an optimized bundle. Once uploaded, the game enters a review process before becoming publicly available.
56
+
57
+ During the execution, you will be prompted for:
58
+ * **Developer email**: Used to send notifications regarding the game's review status (approval or rejection).
59
+
60
+ Upon successful submission, the CLI outputs the Game ID, Version, Bundle URL, and the current status of the publication. The command also safely rejects duplicate publication attempts for the same version.
61
+
62
+ == Template Scripts
63
+
64
+ Generated projects come with the following scripts in `package.json`:
65
+
66
+ === Development and Build
67
+
68
+ [cols="1,3"]
69
+ |===
70
+ | Command | Description
71
+
72
+ | `npm start`
73
+ | Starts the development server with hot reload and opens the browser in `standalone` mode.
74
+
75
+ | `npm run build:standalone`
76
+ | Generates the production version of the game in the `/dist` folder for independent web hosting.
77
+
78
+ | `npm run build:bundle`
79
+ | Generates an optimized bundle to be loaded at link:https://brickengine.com.br[brickengine.com.br], where you can play all previously published games directly in the browser.
80
+
81
+ | `npm run serve`
82
+ | Starts a local HTTP server to test the production version generated in `/dist`.
83
+ |===
84
+
85
+ === Code Quality (Optional)
86
+
87
+ If you selected these options during `init`:
88
+
89
+ [cols="1,3"]
90
+ |===
91
+ | Command | Description
92
+
93
+ | `npm run format`
94
+ | Automatically formats the code using **Prettier**.
95
+
96
+ | `npm run lint`
97
+ | Runs **ESLint** to find issues in the code.
98
+ |===
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env node
2
+
3
+ // Try to load the compiled index.js
4
+ let main;
5
+ try {
6
+ main = require('../dist/index.js');
7
+ } catch (e) {
8
+ console.error('Error: CLI not built. Please run "npm run build" in the CLI package.');
9
+ process.exit(1);
10
+ }
11
+
12
+ main.run();
@@ -0,0 +1 @@
1
+ export declare function initCommand(projectName: string): Promise<void>;
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.initCommand = initCommand;
7
+ const path_1 = __importDefault(require("path"));
8
+ const fs_extra_1 = __importDefault(require("fs-extra"));
9
+ const chalk_1 = __importDefault(require("chalk"));
10
+ const inquirer_1 = __importDefault(require("inquirer"));
11
+ const template_1 = require("./template");
12
+ const package_1 = __importDefault(require("./package/package"));
13
+ async function initCommand(projectName) {
14
+ const targetDir = path_1.default.resolve(process.cwd(), projectName);
15
+ const templateDir = path_1.default.resolve(__dirname, "../../../templates");
16
+ // Check if directory already exists
17
+ if (fs_extra_1.default.existsSync(targetDir)) {
18
+ throw new Error(`Directory ${projectName} already exists.`);
19
+ }
20
+ console.log(chalk_1.default.bold.blue("\n🧱 Brick Engine CLI") +
21
+ chalk_1.default.gray(" - Scaffolding your next masterpiece\n"));
22
+ // Ask user if they want to use Prettier and ESLint
23
+ const answers = await inquirer_1.default.prompt([
24
+ {
25
+ type: "input",
26
+ name: "description",
27
+ message: "How would you describe your game?",
28
+ default: "A fantastic game built with Brick Engine",
29
+ },
30
+ {
31
+ type: "confirm",
32
+ name: "usePrettier",
33
+ message: "Would you like to use Prettier for code formatting?",
34
+ default: true,
35
+ },
36
+ {
37
+ type: "confirm",
38
+ name: "useESLint",
39
+ message: "Would you like to use ESLint for linting?",
40
+ default: true,
41
+ },
42
+ ]);
43
+ try {
44
+ console.log("");
45
+ // Create project directory
46
+ await fs_extra_1.default.ensureDir(targetDir);
47
+ console.log(`${chalk_1.default.green("✔")} Directory ${chalk_1.default.cyan(projectName)} created.`);
48
+ await (0, template_1.moveTemplate)(templateDir, targetDir, answers);
49
+ console.log(`${chalk_1.default.green("✔")} Template files copied.`);
50
+ const pkgJson = (0, package_1.default)(projectName, answers);
51
+ await fs_extra_1.default.writeFile(path_1.default.join(targetDir, "package.json"), JSON.stringify(pkgJson, null, 2));
52
+ console.log(`${chalk_1.default.green("✔")} package.json created.`);
53
+ console.log(`\n✨ ${chalk_1.default.bold.green("Success!")} Project ${chalk_1.default.cyan(projectName)} is ready.\n`);
54
+ console.log(chalk_1.default.bold("Next steps:"));
55
+ console.log(chalk_1.default.gray("───────────────────────────────────"));
56
+ console.log(` 1. ${chalk_1.default.cyan(`cd ${projectName}`)}`);
57
+ console.log(` 2. ${chalk_1.default.cyan("npm install")}`);
58
+ console.log(` 3. ${chalk_1.default.cyan("npm start")}`);
59
+ console.log(chalk_1.default.gray("───────────────────────────────────"));
60
+ console.log(`\n🌐 Local URL (after starting): ${chalk_1.default.underline.blue("http://localhost:8080")}`);
61
+ console.log(`📖 Documentation: ${chalk_1.default.underline.gray("https://github.com/LeonardoPinheiroLacerda/brick-engine")}\n`);
62
+ }
63
+ catch (error) {
64
+ console.error(chalk_1.default.red("\n✖ Initialization failed."));
65
+ throw error;
66
+ }
67
+ }
@@ -0,0 +1,2 @@
1
+ import { Answers, Dependency } from "../types";
2
+ export default function devDependencies(answers: Answers): Dependency[];
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = devDependencies;
4
+ function devDependencies(answers) {
5
+ return [
6
+ {
7
+ name: "brick-engine-js",
8
+ version: "latest",
9
+ shouldInstall: true,
10
+ },
11
+ ];
12
+ }
@@ -0,0 +1,2 @@
1
+ import { Answers, Dependency } from "../types";
2
+ export default function devDependencies(answers: Answers): Dependency[];
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = devDependencies;
4
+ function devDependencies(answers) {
5
+ return [
6
+ {
7
+ name: "prettier",
8
+ version: "^3.1.0",
9
+ shouldInstall: answers.usePrettier,
10
+ },
11
+ {
12
+ name: "eslint",
13
+ version: "^9.20.0",
14
+ shouldInstall: answers.useESLint,
15
+ },
16
+ {
17
+ name: "typescript-eslint",
18
+ version: "^8.24.0",
19
+ shouldInstall: answers.useESLint,
20
+ },
21
+ {
22
+ name: "@eslint/js",
23
+ version: "^9.20.0",
24
+ shouldInstall: answers.useESLint,
25
+ },
26
+ {
27
+ name: "globals",
28
+ version: "^15.15.0",
29
+ shouldInstall: answers.useESLint,
30
+ },
31
+ {
32
+ name: "copy-webpack-plugin",
33
+ version: "^13.0.1",
34
+ shouldInstall: true,
35
+ },
36
+ {
37
+ name: "css-loader",
38
+ version: "^7.1.4",
39
+ shouldInstall: true,
40
+ },
41
+ {
42
+ name: "html-webpack-plugin",
43
+ version: "^5.6.6",
44
+ shouldInstall: true,
45
+ },
46
+ {
47
+ name: "mini-css-extract-plugin",
48
+ version: "^2.10.0",
49
+ shouldInstall: true,
50
+ },
51
+ {
52
+ name: "ts-loader",
53
+ version: "^9.5.4",
54
+ shouldInstall: true,
55
+ },
56
+ {
57
+ name: "typescript",
58
+ version: "^5.9.3",
59
+ shouldInstall: true,
60
+ },
61
+ {
62
+ name: "webpack",
63
+ version: "^5.105.2",
64
+ shouldInstall: true,
65
+ },
66
+ {
67
+ name: "webpack-cli",
68
+ version: "^6.0.1",
69
+ shouldInstall: true,
70
+ },
71
+ {
72
+ name: "webpack-dev-server",
73
+ version: "^5.2.3",
74
+ shouldInstall: true,
75
+ },
76
+ ];
77
+ }
@@ -0,0 +1,18 @@
1
+ import { Answers } from "../types";
2
+ export default function packageJson(name: string, answers: Answers): {
3
+ name: string;
4
+ description: string;
5
+ version: string;
6
+ type: string;
7
+ main: string;
8
+ keywords: never[];
9
+ author: string;
10
+ license: string;
11
+ scripts: Record<string, string>;
12
+ dependencies: Record<string, string>;
13
+ devDependencies: Record<string, string>;
14
+ overrides: {
15
+ ajv: string;
16
+ minimatch: string;
17
+ };
18
+ };
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.default = packageJson;
7
+ const dependencies_1 = __importDefault(require("./dependencies"));
8
+ const devDependencies_1 = __importDefault(require("./devDependencies"));
9
+ const scripts_1 = __importDefault(require("./scripts"));
10
+ function packageJson(name, answers) {
11
+ return {
12
+ name,
13
+ description: answers.description,
14
+ version: "1.0.0",
15
+ type: "module",
16
+ main: "index.js",
17
+ keywords: [],
18
+ author: "",
19
+ license: "ISC",
20
+ scripts: (0, scripts_1.default)(answers).reduce((acc, s) => {
21
+ if (s.shouldInstall) {
22
+ acc[s.name] = s.command;
23
+ }
24
+ return acc;
25
+ }, {}),
26
+ dependencies: (0, dependencies_1.default)(answers).reduce((acc, d) => {
27
+ if (d.shouldInstall) {
28
+ acc[d.name] = d.version;
29
+ }
30
+ return acc;
31
+ }, {}),
32
+ devDependencies: (0, devDependencies_1.default)(answers).reduce((acc, d) => {
33
+ if (d.shouldInstall) {
34
+ acc[d.name] = d.version;
35
+ }
36
+ return acc;
37
+ }, {}),
38
+ overrides: {
39
+ ajv: "^8.18.0",
40
+ minimatch: "^10.2.1",
41
+ },
42
+ };
43
+ }
@@ -0,0 +1,2 @@
1
+ import { Answers, Scripts } from "../types";
2
+ export default function scripts(answers: Answers): Scripts[];
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = scripts;
4
+ function scripts(answers) {
5
+ return [
6
+ {
7
+ name: "format",
8
+ command: 'prettier --write "src/**/*.ts"',
9
+ shouldInstall: answers.usePrettier,
10
+ },
11
+ {
12
+ name: "lint",
13
+ command: 'eslint "src/**/*.ts"',
14
+ shouldInstall: answers.useESLint,
15
+ },
16
+ {
17
+ name: "build:bundle",
18
+ command: "webpack --mode production --env bundle=bundle",
19
+ shouldInstall: true,
20
+ },
21
+ {
22
+ name: "build:standalone",
23
+ command: "webpack --mode production --env bundle=standalone",
24
+ shouldInstall: true,
25
+ },
26
+ {
27
+ name: "start",
28
+ command: "webpack serve --open --env bundle=standalone",
29
+ shouldInstall: true,
30
+ },
31
+ {
32
+ name: "serve",
33
+ command: "npx http-server ./dist --cors",
34
+ shouldInstall: true,
35
+ },
36
+ ];
37
+ }
@@ -0,0 +1,2 @@
1
+ import { Answers } from "./types";
2
+ export declare function moveTemplate(templateDir: string, targetDir: string, answers: Answers): Promise<void>;
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.moveTemplate = moveTemplate;
37
+ const fs = __importStar(require("fs-extra"));
38
+ const path = __importStar(require("path"));
39
+ async function moveTemplate(templateDir, targetDir, answers) {
40
+ const options = {
41
+ ".prettierrc": answers.usePrettier,
42
+ "eslint.config.mjs": answers.useESLint,
43
+ };
44
+ await fs.copy(templateDir, targetDir, {
45
+ filter: (src) => {
46
+ const basename = path.basename(src);
47
+ // If the file is specifically disabled in options, don't copy it
48
+ if (options[basename] === false) {
49
+ return false;
50
+ }
51
+ // Otherwise, return true (copy)
52
+ return true;
53
+ },
54
+ });
55
+ }
@@ -0,0 +1,15 @@
1
+ export type Answers = {
2
+ description: string;
3
+ usePrettier: boolean;
4
+ useESLint: boolean;
5
+ };
6
+ export type Dependency = {
7
+ name: string;
8
+ version: string;
9
+ shouldInstall: boolean;
10
+ };
11
+ export type Scripts = {
12
+ name: string;
13
+ command: string;
14
+ shouldInstall: boolean;
15
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ export declare function publishCommand(options: {
2
+ url?: string;
3
+ key?: string;
4
+ }): Promise<void>;