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.
- package/.github/workflows/publish.yml +75 -0
- package/README.adoc +98 -0
- package/bin/brick-cli.js +12 -0
- package/dist/commands/init/index.d.ts +1 -0
- package/dist/commands/init/index.js +67 -0
- package/dist/commands/init/package/dependencies.d.ts +2 -0
- package/dist/commands/init/package/dependencies.js +12 -0
- package/dist/commands/init/package/devDependencies.d.ts +2 -0
- package/dist/commands/init/package/devDependencies.js +77 -0
- package/dist/commands/init/package/package.d.ts +18 -0
- package/dist/commands/init/package/package.js +43 -0
- package/dist/commands/init/package/scripts.d.ts +2 -0
- package/dist/commands/init/package/scripts.js +37 -0
- package/dist/commands/init/template.d.ts +2 -0
- package/dist/commands/init/template.js +55 -0
- package/dist/commands/init/types.d.ts +15 -0
- package/dist/commands/init/types.js +2 -0
- package/dist/commands/publish/index.d.ts +4 -0
- package/dist/commands/publish/index.js +154 -0
- package/dist/config/constants.d.ts +2 -0
- package/dist/config/constants.js +5 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +43 -0
- package/package.json +28 -0
- package/src/commands/init/index.ts +91 -0
- package/src/commands/init/package/dependencies.ts +11 -0
- package/src/commands/init/package/devDependencies.ts +76 -0
- package/src/commands/init/package/package.ts +48 -0
- package/src/commands/init/package/scripts.ts +36 -0
- package/src/commands/init/template.ts +32 -0
- package/src/commands/init/types.ts +17 -0
- package/src/commands/publish/index.ts +201 -0
- package/src/config/constants.ts +2 -0
- package/src/index.ts +39 -0
- package/templates/.prettierrc +8 -0
- package/templates/eslint.config.mjs +18 -0
- package/templates/src/bootstrap.ts +4 -0
- package/templates/src/index.ts +104 -0
- package/templates/tsconfig.json +13 -0
- package/templates/webpack.config.js +98 -0
- package/tsconfig.json +16 -0
|
@@ -0,0 +1,154 @@
|
|
|
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.publishCommand = publishCommand;
|
|
7
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
10
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
|
11
|
+
const child_process_1 = require("child_process");
|
|
12
|
+
const constants_1 = require("../../config/constants");
|
|
13
|
+
async function publishCommand(options) {
|
|
14
|
+
const currentDir = process.cwd();
|
|
15
|
+
const pkgPath = path_1.default.join(currentDir, "package.json");
|
|
16
|
+
const bundlePath = path_1.default.join(currentDir, "dist", "game.bundle.js");
|
|
17
|
+
console.log(chalk_1.default.bold.blue("\n🧱 Brick Engine CLI") +
|
|
18
|
+
chalk_1.default.gray(" - Publishing your masterpiece\n"));
|
|
19
|
+
if (!fs_extra_1.default.existsSync(pkgPath)) {
|
|
20
|
+
console.error(chalk_1.default.red("✖ Error: No package.json found. Are you in a Brick Engine project directory?"));
|
|
21
|
+
process.exit(1);
|
|
22
|
+
}
|
|
23
|
+
// The bundle path will be checked after the build step now
|
|
24
|
+
// Resolve Supabase URL and Key
|
|
25
|
+
let supabaseUrl = options.url || process.env.SUPABASE_URL;
|
|
26
|
+
if (!supabaseUrl && constants_1.SUPABASE_URL && !constants_1.SUPABASE_URL.startsWith("%%")) {
|
|
27
|
+
supabaseUrl = constants_1.SUPABASE_URL;
|
|
28
|
+
}
|
|
29
|
+
let supabaseAnonKey = options.key || process.env.SUPABASE_ANON_KEY;
|
|
30
|
+
if (!supabaseAnonKey &&
|
|
31
|
+
constants_1.SUPABASE_ANON_KEY &&
|
|
32
|
+
!constants_1.SUPABASE_ANON_KEY.startsWith("%%")) {
|
|
33
|
+
supabaseAnonKey = constants_1.SUPABASE_ANON_KEY;
|
|
34
|
+
}
|
|
35
|
+
const prompts = [];
|
|
36
|
+
if (!supabaseUrl) {
|
|
37
|
+
prompts.push({
|
|
38
|
+
type: "input",
|
|
39
|
+
name: "supabaseUrl",
|
|
40
|
+
message: "Enter your Supabase Project URL:",
|
|
41
|
+
validate: (input) => input.length > 0 ? true : "Supabase URL is required.",
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
if (!supabaseAnonKey) {
|
|
45
|
+
prompts.push({
|
|
46
|
+
type: "password",
|
|
47
|
+
name: "supabaseAnonKey",
|
|
48
|
+
message: "Enter your Supabase Anon Key:",
|
|
49
|
+
validate: (input) => input.length > 0 ? true : "Supabase Anon Key is required.",
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
prompts.push({
|
|
53
|
+
type: "input",
|
|
54
|
+
name: "gameName",
|
|
55
|
+
message: "Enter your game name:",
|
|
56
|
+
});
|
|
57
|
+
prompts.push({
|
|
58
|
+
type: "input",
|
|
59
|
+
name: "developerEmail",
|
|
60
|
+
message: "Enter your developer email (to receive approval/rejection reasons):",
|
|
61
|
+
});
|
|
62
|
+
const pkg = await fs_extra_1.default.readJson(pkgPath);
|
|
63
|
+
const gameId = pkg.name;
|
|
64
|
+
const version = pkg.version;
|
|
65
|
+
prompts.push({
|
|
66
|
+
type: "confirm",
|
|
67
|
+
name: "confirmPublish",
|
|
68
|
+
message: `Ready to publish ${chalk_1.default.cyan(gameId)} v${version}?`,
|
|
69
|
+
default: true,
|
|
70
|
+
});
|
|
71
|
+
const answers = await inquirer_1.default.prompt(prompts);
|
|
72
|
+
const gameName = answers.gameName;
|
|
73
|
+
if (!answers.confirmPublish) {
|
|
74
|
+
console.log(chalk_1.default.yellow("\nPublishing cancelled."));
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
supabaseUrl = supabaseUrl || answers.supabaseUrl;
|
|
78
|
+
supabaseAnonKey = supabaseAnonKey || answers.supabaseAnonKey;
|
|
79
|
+
const developerEmail = pkg.author || answers.developerEmail;
|
|
80
|
+
console.log("");
|
|
81
|
+
console.log(`${chalk_1.default.green("✔")} Preparing to publish ${chalk_1.default.cyan(gameName)} v${version}...`);
|
|
82
|
+
const formData = new FormData();
|
|
83
|
+
formData.append("game_id", gameId);
|
|
84
|
+
formData.append("game_name", gameName);
|
|
85
|
+
formData.append("version", version);
|
|
86
|
+
if (developerEmail) {
|
|
87
|
+
formData.append("developer_email", developerEmail);
|
|
88
|
+
}
|
|
89
|
+
console.log(chalk_1.default.gray("\n Running build script..."));
|
|
90
|
+
try {
|
|
91
|
+
(0, child_process_1.execSync)("rm -rf dist && npm run build:bundle", {
|
|
92
|
+
stdio: "inherit",
|
|
93
|
+
cwd: currentDir,
|
|
94
|
+
});
|
|
95
|
+
console.log(`${chalk_1.default.green("✔")} Build completed successfully.\n`);
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
console.error(chalk_1.default.red("\n✖ Error: Build failed. Please fix the errors in your project before publishing."));
|
|
99
|
+
process.exit(1);
|
|
100
|
+
}
|
|
101
|
+
if (!fs_extra_1.default.existsSync(bundlePath)) {
|
|
102
|
+
console.error(chalk_1.default.red("✖ Error: Game bundle not found. The build script did not generate 'dist/game.bundle.js'."));
|
|
103
|
+
process.exit(1);
|
|
104
|
+
}
|
|
105
|
+
const bundleBuffer = await fs_extra_1.default.readFile(bundlePath);
|
|
106
|
+
const bundleBlob = new Blob([bundleBuffer], {
|
|
107
|
+
type: "application/javascript",
|
|
108
|
+
});
|
|
109
|
+
formData.append("bundle", bundleBlob, "game.bundle.js");
|
|
110
|
+
const endpoint = `${supabaseUrl}/functions/v1/publish`;
|
|
111
|
+
try {
|
|
112
|
+
const response = await fetch(endpoint, {
|
|
113
|
+
method: "POST",
|
|
114
|
+
headers: {
|
|
115
|
+
Authorization: `Bearer ${supabaseAnonKey}`,
|
|
116
|
+
},
|
|
117
|
+
body: formData,
|
|
118
|
+
});
|
|
119
|
+
if (!response.ok) {
|
|
120
|
+
const errorText = await response.text();
|
|
121
|
+
let errorMessage = errorText;
|
|
122
|
+
try {
|
|
123
|
+
const errorJson = JSON.parse(errorText);
|
|
124
|
+
errorMessage = errorJson.error || errorJson.message || errorText;
|
|
125
|
+
}
|
|
126
|
+
catch (e) {
|
|
127
|
+
// use raw text
|
|
128
|
+
}
|
|
129
|
+
throw new Error(`Failed to publish: ${response.status} ${response.statusText}\n${errorMessage}`);
|
|
130
|
+
}
|
|
131
|
+
const result = await response.json();
|
|
132
|
+
console.log(`${chalk_1.default.green("✔")} Bundle uploaded securely.`);
|
|
133
|
+
console.log(`\n✨ ${chalk_1.default.bold.green("Success!")} ${result.message}\n`);
|
|
134
|
+
if (result.request && result.request.id) {
|
|
135
|
+
console.log(chalk_1.default.bold("Publish Details:"));
|
|
136
|
+
console.log(chalk_1.default.gray("───────────────────────────────────"));
|
|
137
|
+
console.log(` Request ID: ${chalk_1.default.cyan(result.request.id)}`);
|
|
138
|
+
console.log(` Game ID: ${chalk_1.default.cyan(gameId)}`);
|
|
139
|
+
console.log(` Game Name: ${chalk_1.default.cyan(gameName)}`);
|
|
140
|
+
console.log(` Version: ${chalk_1.default.cyan(version)}`);
|
|
141
|
+
console.log(` Bundle: ${chalk_1.default.cyan(result.request.bundle_url)}`);
|
|
142
|
+
console.log(` Status: ${chalk_1.default.yellow("Under Review")}`);
|
|
143
|
+
console.log(chalk_1.default.gray("───────────────────────────────────\n"));
|
|
144
|
+
console.log(chalk_1.default.blue("ℹ️ Your game is now under review."));
|
|
145
|
+
if (developerEmail) {
|
|
146
|
+
console.log(chalk_1.default.blue(`An email will be sent to ${chalk_1.default.bold(developerEmail)} informing if it was approved or rejected (with reasons).`));
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
console.error(chalk_1.default.red(`\n✖ Publish failed: ${error.message}`));
|
|
152
|
+
process.exit(1);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export declare const SUPABASE_URL = "https://uiexmpkqvbkprhifiyaj.supabase.co";
|
|
2
|
+
export declare const SUPABASE_ANON_KEY = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InVpZXhtcGtxdmJrcHJoaWZpeWFqIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NzE4NTY3ODIsImV4cCI6MjA4NzQzMjc4Mn0.OHI8RBANokqtgRBytBTO0FiB_p_JHjq0mW2wwfzlZDs";
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SUPABASE_ANON_KEY = exports.SUPABASE_URL = void 0;
|
|
4
|
+
exports.SUPABASE_URL = "https://uiexmpkqvbkprhifiyaj.supabase.co";
|
|
5
|
+
exports.SUPABASE_ANON_KEY = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InVpZXhtcGtxdmJrcHJoaWZpeWFqIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NzE4NTY3ODIsImV4cCI6MjA4NzQzMjc4Mn0.OHI8RBANokqtgRBytBTO0FiB_p_JHjq0mW2wwfzlZDs";
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function run(): void;
|
package/dist/index.js
ADDED
|
@@ -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.run = run;
|
|
7
|
+
const commander_1 = require("commander");
|
|
8
|
+
const init_1 = require("./commands/init");
|
|
9
|
+
const publish_1 = require("./commands/publish");
|
|
10
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
11
|
+
function run() {
|
|
12
|
+
commander_1.program
|
|
13
|
+
.name("brick-engine-cli")
|
|
14
|
+
.description("CLI to scaffold Brick Engine projects")
|
|
15
|
+
.version("1.0.0");
|
|
16
|
+
commander_1.program
|
|
17
|
+
.command("init <name>")
|
|
18
|
+
.description("Initialize a new Brick Engine project")
|
|
19
|
+
.action(async (name) => {
|
|
20
|
+
try {
|
|
21
|
+
await (0, init_1.initCommand)(name);
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
console.error(chalk_1.default.red(`Error: ${error.message}`));
|
|
25
|
+
process.exit(1);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
commander_1.program
|
|
29
|
+
.command("publish")
|
|
30
|
+
.description("Publish your game to the Brick Engine Artifactory")
|
|
31
|
+
.option("-u, --url <url>", "Supabase URL")
|
|
32
|
+
.option("-k, --key <key>", "Supabase Anon Key")
|
|
33
|
+
.action(async (options) => {
|
|
34
|
+
try {
|
|
35
|
+
await (0, publish_1.publishCommand)(options);
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
console.error(chalk_1.default.red(`Error: ${error.message}`));
|
|
39
|
+
process.exit(1);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
commander_1.program.parse(process.argv);
|
|
43
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "brick-engine-cli",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "CLI to scaffold Brick Game projects",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"brick-engine-cli": "bin/brick-cli.js"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "tsc",
|
|
11
|
+
"watch": "tsc -w",
|
|
12
|
+
"prepublishOnly": "npm run build"
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@types/inquirer": "^8.2.12",
|
|
16
|
+
"brick-engine-js": "^1.0.14",
|
|
17
|
+
"chalk": "^4.1.2",
|
|
18
|
+
"commander": "^11.1.0",
|
|
19
|
+
"dotenv": "^17.3.1",
|
|
20
|
+
"fs-extra": "^11.2.0",
|
|
21
|
+
"inquirer": "^8.2.7"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@types/fs-extra": "^11.0.4",
|
|
25
|
+
"@types/node": "^20.11.0",
|
|
26
|
+
"typescript": "^5.3.3"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import fs from "fs-extra";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
import inquirer from "inquirer";
|
|
5
|
+
import { moveTemplate } from "./template";
|
|
6
|
+
import { Answers } from "./types";
|
|
7
|
+
import packageJson from "./package/package";
|
|
8
|
+
|
|
9
|
+
export async function initCommand(projectName: string) {
|
|
10
|
+
const targetDir = path.resolve(process.cwd(), projectName);
|
|
11
|
+
const templateDir = path.resolve(__dirname, "../../../templates");
|
|
12
|
+
|
|
13
|
+
// Check if directory already exists
|
|
14
|
+
if (fs.existsSync(targetDir)) {
|
|
15
|
+
throw new Error(`Directory ${projectName} already exists.`);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
console.log(
|
|
19
|
+
chalk.bold.blue("\n🧱 Brick Engine CLI") +
|
|
20
|
+
chalk.gray(" - Scaffolding your next masterpiece\n"),
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
// Ask user if they want to use Prettier and ESLint
|
|
24
|
+
const answers: Answers = await inquirer.prompt([
|
|
25
|
+
{
|
|
26
|
+
type: "input",
|
|
27
|
+
name: "description",
|
|
28
|
+
message: "How would you describe your game?",
|
|
29
|
+
default: "A fantastic game built with Brick Engine",
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
type: "confirm",
|
|
33
|
+
name: "usePrettier",
|
|
34
|
+
message: "Would you like to use Prettier for code formatting?",
|
|
35
|
+
default: true,
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
type: "confirm",
|
|
39
|
+
name: "useESLint",
|
|
40
|
+
message: "Would you like to use ESLint for linting?",
|
|
41
|
+
default: true,
|
|
42
|
+
},
|
|
43
|
+
]);
|
|
44
|
+
|
|
45
|
+
try {
|
|
46
|
+
console.log("");
|
|
47
|
+
|
|
48
|
+
// Create project directory
|
|
49
|
+
await fs.ensureDir(targetDir);
|
|
50
|
+
console.log(
|
|
51
|
+
`${chalk.green("✔")} Directory ${chalk.cyan(projectName)} created.`,
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
await moveTemplate(templateDir, targetDir, answers);
|
|
55
|
+
console.log(`${chalk.green("✔")} Template files copied.`);
|
|
56
|
+
|
|
57
|
+
const pkgJson = packageJson(projectName, answers);
|
|
58
|
+
await fs.writeFile(
|
|
59
|
+
path.join(targetDir, "package.json"),
|
|
60
|
+
JSON.stringify(pkgJson, null, 2),
|
|
61
|
+
);
|
|
62
|
+
console.log(`${chalk.green("✔")} package.json created.`);
|
|
63
|
+
|
|
64
|
+
console.log(
|
|
65
|
+
`\n✨ ${chalk.bold.green("Success!")} Project ${chalk.cyan(
|
|
66
|
+
projectName,
|
|
67
|
+
)} is ready.\n`,
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
console.log(chalk.bold("Next steps:"));
|
|
71
|
+
console.log(chalk.gray("───────────────────────────────────"));
|
|
72
|
+
console.log(` 1. ${chalk.cyan(`cd ${projectName}`)}`);
|
|
73
|
+
console.log(` 2. ${chalk.cyan("npm install")}`);
|
|
74
|
+
console.log(` 3. ${chalk.cyan("npm start")}`);
|
|
75
|
+
console.log(chalk.gray("───────────────────────────────────"));
|
|
76
|
+
|
|
77
|
+
console.log(
|
|
78
|
+
`\n🌐 Local URL (after starting): ${chalk.underline.blue(
|
|
79
|
+
"http://localhost:8080",
|
|
80
|
+
)}`,
|
|
81
|
+
);
|
|
82
|
+
console.log(
|
|
83
|
+
`📖 Documentation: ${chalk.underline.gray(
|
|
84
|
+
"https://github.com/LeonardoPinheiroLacerda/brick-engine",
|
|
85
|
+
)}\n`,
|
|
86
|
+
);
|
|
87
|
+
} catch (error) {
|
|
88
|
+
console.error(chalk.red("\n✖ Initialization failed."));
|
|
89
|
+
throw error;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { Answers, Dependency } from "../types";
|
|
2
|
+
|
|
3
|
+
export default function devDependencies(answers: Answers): Dependency[] {
|
|
4
|
+
return [
|
|
5
|
+
{
|
|
6
|
+
name: "prettier",
|
|
7
|
+
version: "^3.1.0",
|
|
8
|
+
shouldInstall: answers.usePrettier,
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
name: "eslint",
|
|
12
|
+
version: "^9.20.0",
|
|
13
|
+
shouldInstall: answers.useESLint,
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
name: "typescript-eslint",
|
|
17
|
+
version: "^8.24.0",
|
|
18
|
+
shouldInstall: answers.useESLint,
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
name: "@eslint/js",
|
|
22
|
+
version: "^9.20.0",
|
|
23
|
+
shouldInstall: answers.useESLint,
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
name: "globals",
|
|
27
|
+
version: "^15.15.0",
|
|
28
|
+
shouldInstall: answers.useESLint,
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
name: "copy-webpack-plugin",
|
|
32
|
+
version: "^13.0.1",
|
|
33
|
+
shouldInstall: true,
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
name: "css-loader",
|
|
37
|
+
version: "^7.1.4",
|
|
38
|
+
shouldInstall: true,
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
name: "html-webpack-plugin",
|
|
42
|
+
version: "^5.6.6",
|
|
43
|
+
shouldInstall: true,
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
name: "mini-css-extract-plugin",
|
|
47
|
+
version: "^2.10.0",
|
|
48
|
+
shouldInstall: true,
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
name: "ts-loader",
|
|
52
|
+
version: "^9.5.4",
|
|
53
|
+
shouldInstall: true,
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
name: "typescript",
|
|
57
|
+
version: "^5.9.3",
|
|
58
|
+
shouldInstall: true,
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
name: "webpack",
|
|
62
|
+
version: "^5.105.2",
|
|
63
|
+
shouldInstall: true,
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
name: "webpack-cli",
|
|
67
|
+
version: "^6.0.1",
|
|
68
|
+
shouldInstall: true,
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
name: "webpack-dev-server",
|
|
72
|
+
version: "^5.2.3",
|
|
73
|
+
shouldInstall: true,
|
|
74
|
+
},
|
|
75
|
+
];
|
|
76
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Answers } from "../types";
|
|
2
|
+
import dependencies from "./dependencies";
|
|
3
|
+
import devDependencies from "./devDependencies";
|
|
4
|
+
import scripts from "./scripts";
|
|
5
|
+
|
|
6
|
+
export default function packageJson(name: string, answers: Answers) {
|
|
7
|
+
return {
|
|
8
|
+
name,
|
|
9
|
+
description: answers.description,
|
|
10
|
+
version: "1.0.0",
|
|
11
|
+
type: "module",
|
|
12
|
+
main: "index.js",
|
|
13
|
+
keywords: [],
|
|
14
|
+
author: "",
|
|
15
|
+
license: "ISC",
|
|
16
|
+
scripts: scripts(answers).reduce(
|
|
17
|
+
(acc, s) => {
|
|
18
|
+
if (s.shouldInstall) {
|
|
19
|
+
acc[s.name] = s.command;
|
|
20
|
+
}
|
|
21
|
+
return acc;
|
|
22
|
+
},
|
|
23
|
+
{} as Record<string, string>,
|
|
24
|
+
),
|
|
25
|
+
dependencies: dependencies(answers).reduce(
|
|
26
|
+
(acc, d) => {
|
|
27
|
+
if (d.shouldInstall) {
|
|
28
|
+
acc[d.name] = d.version;
|
|
29
|
+
}
|
|
30
|
+
return acc;
|
|
31
|
+
},
|
|
32
|
+
{} as Record<string, string>,
|
|
33
|
+
),
|
|
34
|
+
devDependencies: devDependencies(answers).reduce(
|
|
35
|
+
(acc, d) => {
|
|
36
|
+
if (d.shouldInstall) {
|
|
37
|
+
acc[d.name] = d.version;
|
|
38
|
+
}
|
|
39
|
+
return acc;
|
|
40
|
+
},
|
|
41
|
+
{} as Record<string, string>,
|
|
42
|
+
),
|
|
43
|
+
overrides: {
|
|
44
|
+
ajv: "^8.18.0",
|
|
45
|
+
minimatch: "^10.2.1",
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Answers, Scripts } from "../types";
|
|
2
|
+
|
|
3
|
+
export default function scripts(answers: Answers): Scripts[] {
|
|
4
|
+
return [
|
|
5
|
+
{
|
|
6
|
+
name: "format",
|
|
7
|
+
command: 'prettier --write "src/**/*.ts"',
|
|
8
|
+
shouldInstall: answers.usePrettier,
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
name: "lint",
|
|
12
|
+
command: 'eslint "src/**/*.ts"',
|
|
13
|
+
shouldInstall: answers.useESLint,
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
name: "build:bundle",
|
|
17
|
+
command: "webpack --mode production --env bundle=bundle",
|
|
18
|
+
shouldInstall: true,
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
name: "build:standalone",
|
|
22
|
+
command: "webpack --mode production --env bundle=standalone",
|
|
23
|
+
shouldInstall: true,
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
name: "start",
|
|
27
|
+
command: "webpack serve --open --env bundle=standalone",
|
|
28
|
+
shouldInstall: true,
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
name: "serve",
|
|
32
|
+
command: "npx http-server ./dist --cors",
|
|
33
|
+
shouldInstall: true,
|
|
34
|
+
},
|
|
35
|
+
];
|
|
36
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import * as fs from "fs-extra";
|
|
2
|
+
import * as path from "path";
|
|
3
|
+
import { Answers } from "./types";
|
|
4
|
+
|
|
5
|
+
type Options = {
|
|
6
|
+
[fileName: string]: boolean;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export async function moveTemplate(
|
|
10
|
+
templateDir: string,
|
|
11
|
+
targetDir: string,
|
|
12
|
+
answers: Answers,
|
|
13
|
+
) {
|
|
14
|
+
const options: Options = {
|
|
15
|
+
".prettierrc": answers.usePrettier,
|
|
16
|
+
"eslint.config.mjs": answers.useESLint,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
await fs.copy(templateDir, targetDir, {
|
|
20
|
+
filter: (src) => {
|
|
21
|
+
const basename = path.basename(src);
|
|
22
|
+
|
|
23
|
+
// If the file is specifically disabled in options, don't copy it
|
|
24
|
+
if (options[basename] === false) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Otherwise, return true (copy)
|
|
29
|
+
return true;
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type Answers = {
|
|
2
|
+
description: string;
|
|
3
|
+
usePrettier: boolean;
|
|
4
|
+
useESLint: boolean;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export type Dependency = {
|
|
8
|
+
name: string;
|
|
9
|
+
version: string;
|
|
10
|
+
shouldInstall: boolean;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export type Scripts = {
|
|
14
|
+
name: string;
|
|
15
|
+
command: string;
|
|
16
|
+
shouldInstall: boolean;
|
|
17
|
+
};
|