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,82 @@
import { GluegunCommand } from 'gluegun'
const command: GluegunCommand = {
name: '<%= name %>',
description: 'Interact with <%= apiName %> API',
run: async (toolbox) => {
const { http, print, parameters, prompt } = toolbox
// Get API configuration
const apiKey = process.env.<%= apiKeyEnv %> || parameters.options.key
if (!apiKey) {
print.error('API key is required')
print.info('Set <%= apiKeyEnv %> environment variable or use --key option')
return
}
// Create API client
const api = http.create({
baseURL: '<%= apiBaseUrl %>',
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json'
},
timeout: 10000
})
// Show spinner while loading
const spinner = print.spin('Fetching data from <%= apiName %>...')
try {
// Make API request
const response = await api.get('<%= endpoint %>')
// Check response
if (!response.ok) {
spinner.fail(`API Error: ${response.problem}`)
if (response.data) {
print.error(JSON.stringify(response.data, null, 2))
}
return
}
spinner.succeed('Data fetched successfully')
// Display results
const data = response.data
<% if (displayFormat === 'table') { %>
// Display as table
const tableData = data.map(item => [
item.<%= field1 %>,
item.<%= field2 %>,
item.<%= field3 %>
])
print.table([
['<%= header1 %>', '<%= header2 %>', '<%= header3 %>'],
...tableData
])
<% } else { %>
// Display as JSON
print.info(JSON.stringify(data, null, 2))
<% } %>
// Optional: Save to file
const shouldSave = await prompt.confirm('Save results to file?')
if (shouldSave) {
const filename = `<%= outputFile %>`
await toolbox.filesystem.write(filename, JSON.stringify(data, null, 2))
print.success(`Saved to ${filename}`)
}
} catch (error) {
spinner.fail('Request failed')
print.error(error.message)
}
}
}
module.exports = command

View File

@@ -0,0 +1,33 @@
import { GluegunCommand } from 'gluegun'
const command: GluegunCommand = {
name: '<%= name %>',
description: '<%= description %>',
run: async (toolbox) => {
const { print, parameters } = toolbox
// Get parameters
const options = parameters.options
const args = parameters.array
// Command logic
print.info(`Running <%= name %> command`)
// Process arguments
if (args.length === 0) {
print.warning('No arguments provided')
return
}
// Example: Process each argument
for (const arg of args) {
print.info(`Processing: ${arg}`)
}
// Success message
print.success('<%= name %> completed successfully')
}
}
module.exports = command

View File

@@ -0,0 +1,57 @@
import { GluegunCommand } from 'gluegun'
const command: GluegunCommand = {
name: 'generate',
alias: ['g'],
description: 'Generate <%= type %> from template',
run: async (toolbox) => {
const { template, print, parameters, filesystem, strings } = toolbox
// Get name from parameters
const name = parameters.first
if (!name) {
print.error('Name is required')
print.info('Usage: <%= cliName %> generate <name>')
return
}
// Convert to different cases
const pascalName = strings.pascalCase(name)
const camelName = strings.camelCase(name)
const kebabName = strings.kebabCase(name)
// Generate from template
const target = `<%= outputPath %>/${kebabName}.<%= extension %>`
try {
await template.generate({
template: '<%= templateFile %>',
target,
props: {
name: pascalName,
camelName,
kebabName,
timestamp: new Date().toISOString()
}
})
print.success(`Generated <%= type %>: ${target}`)
// Optional: Add to index
<% if (addToIndex) { %>
const indexPath = '<%= outputPath %>/index.ts'
if (filesystem.exists(indexPath)) {
await filesystem.append(indexPath, `export { ${pascalName} } from './${kebabName}'\n`)
print.info(`Added export to ${indexPath}`)
}
<% } %>
} catch (error) {
print.error(`Failed to generate <%= type %>: ${error.message}`)
}
}
}
module.exports = command