feat(scripts): add TypeScript and JavaScript plugin generator wrappers
Some checks failed
Build / build (pull_request) Failing after 57s
Some checks failed
Build / build (pull_request) Failing after 57s
This commit is contained in:
parent
64f0d81eb5
commit
fdb7b54333
@ -19,7 +19,9 @@
|
||||
"lint:ci": "eslint --ext .ts --rule \"prettier/prettier: off\" .",
|
||||
"lint:fix": "eslint --fix --ext .ts .",
|
||||
"prettier": "prettier --write .",
|
||||
"update-translations": "cd scripts && node update-translations.js"
|
||||
"update-translations": "cd scripts && node update-translations.js",
|
||||
"new-plugin-ts": "node scripts/new-plugin-ts.js",
|
||||
"new-plugin-js": "node scripts/new-plugin-js.js"
|
||||
},
|
||||
"license": "GNU",
|
||||
"dependencies": {
|
||||
|
238
scripts/create-plugin-core.js
Normal file
238
scripts/create-plugin-core.js
Normal file
@ -0,0 +1,238 @@
|
||||
/**
|
||||
* Plugin Generator Script
|
||||
* Creates new plugin templates for both TypeScript and JavaScript
|
||||
*/
|
||||
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
class PluginGenerator {
|
||||
constructor() {
|
||||
this.pluginsDir = path.resolve("plugins");
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new plugin
|
||||
*/
|
||||
createPlugin(name, language = "ts") {
|
||||
if (!name) {
|
||||
console.error("❌ Plugin name is required!");
|
||||
console.log("Usage: node create-plugin.js <plugin-name> [ts|js]");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
if (!["ts", "js"].includes(language)) {
|
||||
console.error("❌ Language must be 'ts' or 'js'");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const pluginDir = path.join(this.pluginsDir, name);
|
||||
|
||||
// Check if plugin already exists
|
||||
if (fs.existsSync(pluginDir)) {
|
||||
console.error(`❌ Plugin '${name}' already exists!`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log(`🚀 Creating ${language.toUpperCase()} plugin: ${name}`);
|
||||
|
||||
// Create plugin directory
|
||||
this.createDirectory(pluginDir);
|
||||
|
||||
// Create plugin files
|
||||
this.createPluginManifest(pluginDir, name);
|
||||
|
||||
if (language === "ts") {
|
||||
this.createTypeScriptPlugin(pluginDir, name);
|
||||
} else {
|
||||
this.createJavaScriptPlugin(pluginDir, name);
|
||||
}
|
||||
|
||||
console.log(`✅ Plugin '${name}' created successfully!`);
|
||||
console.log(`📁 Location: ${pluginDir}`);
|
||||
console.log(`🔧 Next steps:`);
|
||||
console.log(` 1. Edit ${path.join(pluginDir, `index.${language}`)} to implement your plugin logic`);
|
||||
console.log(` 2. Update ${path.join(pluginDir, "plugin.json")} if needed`);
|
||||
console.log(` 3. Run 'npm run build' to build the plugin`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create directory if it doesn't exist
|
||||
*/
|
||||
createDirectory(dirPath) {
|
||||
if (!fs.existsSync(dirPath)) {
|
||||
fs.mkdirSync(dirPath, { recursive: true });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create plugin manifest file
|
||||
*/
|
||||
createPluginManifest(pluginDir, name) {
|
||||
const manifest = {
|
||||
name: name,
|
||||
version: "1.0.0",
|
||||
description: `${name} plugin for Warframe Emulator`,
|
||||
main: "index.js",
|
||||
author: "Your Name",
|
||||
license: "GNU",
|
||||
config: {
|
||||
enabled: true
|
||||
},
|
||||
dependencies: {},
|
||||
tags: ["custom"]
|
||||
};
|
||||
|
||||
const manifestPath = path.join(pluginDir, "plugin.json");
|
||||
fs.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2));
|
||||
console.log(`📝 Created: plugin.json`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create TypeScript plugin template
|
||||
*/
|
||||
createTypeScriptPlugin(pluginDir, name) {
|
||||
const template = `import { IPlugin } from "@/src/types/pluginTypes";
|
||||
import { logger } from "@/src/utils/logger";
|
||||
|
||||
export default class ${name} implements IPlugin {
|
||||
public name = "${name}";
|
||||
public version = "1.0.0";
|
||||
public description = "${name} plugin for Warframe Emulator";
|
||||
|
||||
async initialize(): Promise<void> {
|
||||
logger.info(\`[\${this.name}] Plugin initialized successfully!\`);
|
||||
|
||||
// Add your plugin initialization logic here
|
||||
// For example:
|
||||
// - Register new routes
|
||||
// - Add new API endpoints
|
||||
// - Set up event listeners
|
||||
// - Connect to external services
|
||||
|
||||
await Promise.resolve(); // Remove this line and add your actual logic
|
||||
}
|
||||
|
||||
async cleanup(): Promise<void> {
|
||||
logger.info(\`[\${this.name}] Plugin cleanup completed\`);
|
||||
|
||||
// Add your cleanup logic here
|
||||
// For example:
|
||||
// - Close database connections
|
||||
// - Clear timers/intervals
|
||||
// - Remove event listeners
|
||||
// - Cleanup resources
|
||||
|
||||
await Promise.resolve(); // Remove this line and add your actual logic
|
||||
}
|
||||
|
||||
// Add your custom methods here
|
||||
// Example:
|
||||
// public async customMethod(): Promise<void> {
|
||||
// logger.info(\`[\${this.name}] Custom method called\`);
|
||||
// }
|
||||
}
|
||||
`;
|
||||
|
||||
const pluginPath = path.join(pluginDir, "index.ts");
|
||||
fs.writeFileSync(pluginPath, template);
|
||||
console.log(`📝 Created: index.ts`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create JavaScript plugin template
|
||||
*/
|
||||
createJavaScriptPlugin(pluginDir, name) {
|
||||
const template = `/**
|
||||
* ${name} Plugin
|
||||
* ${name} plugin for Warframe Emulator
|
||||
*/
|
||||
import {logger} from "../../src/utils/logger.js";
|
||||
|
||||
class ${name} {
|
||||
constructor() {
|
||||
this.name = "${name}";
|
||||
this.version = "1.0.0";
|
||||
this.description = "${name} plugin for Warframe Emulator";
|
||||
}
|
||||
|
||||
async initialize() {
|
||||
logger.info(\`[\${this.name}] Plugin initialized successfully!\`);
|
||||
|
||||
// Add your plugin initialization logic here
|
||||
// For example:
|
||||
// - Register new routes
|
||||
// - Add new API endpoints
|
||||
// - Set up event listeners
|
||||
// - Connect to external services
|
||||
|
||||
return Promise.resolve(); // Remove this line and add your actual logic
|
||||
}
|
||||
|
||||
async cleanup() {
|
||||
logger.info(\`[\${this.name}] Plugin cleanup completed\`);
|
||||
|
||||
// Add your cleanup logic here
|
||||
// For example:
|
||||
// - Close database connections
|
||||
// - Clear timers/intervals
|
||||
// - Remove event listeners
|
||||
// - Cleanup resources
|
||||
|
||||
return Promise.resolve(); // Remove this line and add your actual logic
|
||||
}
|
||||
|
||||
// Add your custom methods here
|
||||
// Example:
|
||||
// async customMethod() {
|
||||
// console.log(\`[\${this.name}] Custom method called\`);
|
||||
// }
|
||||
}
|
||||
|
||||
export default ${name};
|
||||
`;
|
||||
|
||||
const pluginPath = path.join(pluginDir, "index.js");
|
||||
fs.writeFileSync(pluginPath, template);
|
||||
console.log(`📝 Created: index.js`);
|
||||
|
||||
// Create package.json for ES module support
|
||||
const packageJson = {
|
||||
"type": "module"
|
||||
};
|
||||
const packagePath = path.join(pluginDir, "package.json");
|
||||
fs.writeFileSync(packagePath, JSON.stringify(packageJson, null, 2));
|
||||
console.log(`📝 Created: package.json`);
|
||||
}
|
||||
}
|
||||
|
||||
// Parse command line arguments
|
||||
const args = process.argv.slice(2);
|
||||
const pluginName = args[0];
|
||||
const language = args[1] || "ts";
|
||||
|
||||
// Validate plugin name
|
||||
if (!pluginName) {
|
||||
console.error("❌ Plugin name is required!");
|
||||
console.log("Usage:");
|
||||
console.log(" node scripts/create-plugin.js <plugin-name> [ts|js]");
|
||||
console.log("");
|
||||
console.log("Examples:");
|
||||
console.log(" node scripts/create-plugin.js MyAwesomePlugin ts");
|
||||
console.log(" node scripts/create-plugin.js MyJSPlugin js");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Validate plugin name format
|
||||
if (!/^[A-Za-z][A-Za-z0-9_]*$/.test(pluginName)) {
|
||||
console.error("❌ Plugin name must start with a letter and contain only letters, numbers, and underscores!");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Create the plugin
|
||||
if (require.main === module) {
|
||||
const generator = new PluginGenerator();
|
||||
generator.createPlugin(pluginName, language);
|
||||
}
|
||||
|
||||
module.exports = { PluginGenerator };
|
19
scripts/new-plugin-js.js
Normal file
19
scripts/new-plugin-js.js
Normal file
@ -0,0 +1,19 @@
|
||||
/**
|
||||
* JavaScript Plugin Generator Wrapper
|
||||
*/
|
||||
|
||||
const { PluginGenerator } = require('./create-plugin-core');
|
||||
|
||||
// Get plugin name from command line arguments
|
||||
const pluginName = process.argv[2];
|
||||
|
||||
if (!pluginName) {
|
||||
console.error("❌ Plugin name is required!");
|
||||
console.log("Usage: npm run new-plugin-js <plugin-name>");
|
||||
console.log("Example: npm run new-plugin-js MyJSPlugin");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Create JavaScript plugin
|
||||
const generator = new PluginGenerator();
|
||||
generator.createPlugin(pluginName, "js");
|
19
scripts/new-plugin-ts.js
Normal file
19
scripts/new-plugin-ts.js
Normal file
@ -0,0 +1,19 @@
|
||||
/**
|
||||
* TypeScript Plugin Generator Wrapper
|
||||
*/
|
||||
|
||||
const { PluginGenerator } = require('./create-plugin-core');
|
||||
|
||||
// Get plugin name from command line arguments
|
||||
const pluginName = process.argv[2];
|
||||
|
||||
if (!pluginName) {
|
||||
console.error("❌ Plugin name is required!");
|
||||
console.log("Usage: npm run new-plugin-ts <plugin-name>");
|
||||
console.log("Example: npm run new-plugin-ts MyAwesomePlugin");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Create TypeScript plugin
|
||||
const generator = new PluginGenerator();
|
||||
generator.createPlugin(pluginName, "ts");
|
Loading…
x
Reference in New Issue
Block a user