Initial commit

This commit is contained in:
Zhongwei Li
2025-11-30 09:04:14 +08:00
commit 70c36b5eff
248 changed files with 47482 additions and 0 deletions

View File

@@ -0,0 +1,125 @@
import { GluegunToolbox } from 'gluegun'
/**
* <%= pluginName %> Plugin
* <%= pluginDescription %>
*/
module.exports = (toolbox: GluegunToolbox) => {
const { print, filesystem, template } = toolbox
// Plugin initialization
print.debug('<%= pluginName %> plugin loaded')
// Add plugin namespace to toolbox
toolbox.<%= pluginNamespace %> = {
/**
* Plugin version
*/
version: '<%= version %>',
/**
* Check if plugin is initialized
*/
isInitialized: (): boolean => {
const configPath = '<%= configPath %>'
return filesystem.exists(configPath)
},
/**
* Initialize plugin configuration
*/
initialize: async (options: any = {}): Promise<void> => {
print.info('Initializing <%= pluginName %>...')
// Create config from template
await template.generate({
template: '<%= configTemplate %>',
target: '<%= configPath %>',
props: {
...options,
createdAt: new Date().toISOString()
}
})
print.success('<%= pluginName %> initialized')
},
/**
* Get plugin configuration
*/
getConfig: async (): Promise<any> => {
const configPath = '<%= configPath %>'
if (!filesystem.exists(configPath)) {
print.warning('<%= pluginName %> not initialized')
return null
}
return await filesystem.read(configPath, 'json')
},
/**
* Update plugin configuration
*/
updateConfig: async (updates: any): Promise<void> => {
const config = await toolbox.<%= pluginNamespace %>.getConfig()
if (!config) {
print.error('Cannot update config: <%= pluginName %> not initialized')
return
}
const updatedConfig = { ...config, ...updates }
await filesystem.write('<%= configPath %>', updatedConfig, { jsonIndent: 2 })
print.success('Configuration updated')
},
<% if (hasCommands) { %>
/**
* Execute plugin-specific operation
*/
execute: async (operation: string, params: any = {}): Promise<any> => {
print.info(`Executing <%= pluginName %> operation: ${operation}`)
switch (operation) {
case '<%= operation1 %>':
return await handle<%= operation1Pascal %>(toolbox, params)
case '<%= operation2 %>':
return await handle<%= operation2Pascal %>(toolbox, params)
default:
print.error(`Unknown operation: ${operation}`)
return null
}
}
<% } %>
}
}
<% if (hasCommands) { %>
/**
* Handle <%= operation1 %> operation
*/
async function handle<%= operation1Pascal %>(toolbox: GluegunToolbox, params: any) {
const { print } = toolbox
print.info('Handling <%= operation1 %>...')
// Implementation
return { success: true }
}
/**
* Handle <%= operation2 %> operation
*/
async function handle<%= operation2Pascal %>(toolbox: GluegunToolbox, params: any) {
const { print } = toolbox
print.info('Handling <%= operation2 %>...')
// Implementation
return { success: true }
}
<% } %>

View File

@@ -0,0 +1,93 @@
import { GluegunToolbox } from 'gluegun'
/**
* <%= pluginName %> Plugin with Commands
* Demonstrates how to add commands via plugins
*/
module.exports = (toolbox: GluegunToolbox) => {
const { print, runtime } = toolbox
print.debug('<%= pluginName %> plugin loaded')
// Register plugin commands
runtime.addPlugin({
name: '<%= pluginName %>',
commands: [
{
name: '<%= command1Name %>',
description: '<%= command1Description %>',
run: async (toolbox) => {
const { print, parameters } = toolbox
print.info('Running <%= command1Name %> from <%= pluginName %>')
// Command logic
const arg = parameters.first
if (arg) {
print.success(`Processed: ${arg}`)
} else {
print.warning('No argument provided')
}
}
},
{
name: '<%= command2Name %>',
description: '<%= command2Description %>',
run: async (toolbox) => {
const { print, filesystem, template } = toolbox
print.info('Running <%= command2Name %> from <%= pluginName %>')
// Generate from template
await template.generate({
template: '<%= template2 %>',
target: '<%= output2 %>',
props: {
pluginName: '<%= pluginName %>',
timestamp: new Date().toISOString()
}
})
print.success('Generated successfully')
}
}
]
})
// Add plugin utilities to toolbox
toolbox.<%= pluginNamespace %> = {
/**
* Shared utility function
*/
sharedUtility: (input: string): string => {
print.debug(`<%= pluginName %> processing: ${input}`)
return input.toUpperCase()
},
/**
* Validate plugin requirements
*/
validateRequirements: async (): Promise<boolean> => {
const { filesystem, system } = toolbox
// Check for required files
<% requiredFiles.forEach(file => { %>
if (!filesystem.exists('<%= file %>')) {
print.error('Missing required file: <%= file %>')
return false
}
<% }) %>
// Check for required commands
<% requiredCommands.forEach(cmd => { %>
const has<%= cmd %> = await system.which('<%= cmd %>')
if (!has<%= cmd %>) {
print.error('Missing required command: <%= cmd %>')
return false
}
<% }) %>
return true
}
}
}