Initial commit
This commit is contained in:
@@ -0,0 +1,117 @@
|
||||
import { GluegunCommand } from 'gluegun'
|
||||
|
||||
/**
|
||||
* Examples of filesystem operations with Gluegun
|
||||
*/
|
||||
const command: GluegunCommand = {
|
||||
name: 'filesystem',
|
||||
description: 'Filesystem operation examples',
|
||||
|
||||
run: async (toolbox) => {
|
||||
const { filesystem, print } = toolbox
|
||||
|
||||
print.info('=== Filesystem Examples ===\n')
|
||||
|
||||
// 1. Read file
|
||||
print.info('1. Read file')
|
||||
const packageJson = await filesystem.read('package.json', 'json')
|
||||
if (packageJson) {
|
||||
print.success(`Project: ${packageJson.name}`)
|
||||
}
|
||||
|
||||
// 2. Write file
|
||||
print.info('\n2. Write file')
|
||||
await filesystem.write('temp-output.txt', 'Hello from Gluegun!', {
|
||||
atomic: true // Ensures file is written completely or not at all
|
||||
})
|
||||
print.success('File written: temp-output.txt')
|
||||
|
||||
// 3. Check if file exists
|
||||
print.info('\n3. Check existence')
|
||||
const exists = filesystem.exists('temp-output.txt')
|
||||
print.info(`temp-output.txt exists: ${exists}`)
|
||||
|
||||
// 4. Create directory
|
||||
print.info('\n4. Create directory')
|
||||
await filesystem.dir('temp-dir/nested/deep')
|
||||
print.success('Created nested directories')
|
||||
|
||||
// 5. List files
|
||||
print.info('\n5. List files')
|
||||
const files = filesystem.list('.')
|
||||
print.info(`Files in current directory: ${files?.length || 0}`)
|
||||
|
||||
// 6. Find files with pattern
|
||||
print.info('\n6. Find files')
|
||||
const tsFiles = filesystem.find('.', { matching: '*.ts', recursive: false })
|
||||
print.info(`TypeScript files found: ${tsFiles?.length || 0}`)
|
||||
tsFiles?.slice(0, 5).forEach(file => print.info(` - ${file}`))
|
||||
|
||||
// 7. Copy file/directory
|
||||
print.info('\n7. Copy operations')
|
||||
await filesystem.copy('temp-output.txt', 'temp-dir/copy.txt')
|
||||
print.success('File copied to temp-dir/copy.txt')
|
||||
|
||||
// 8. Move/rename
|
||||
print.info('\n8. Move/rename')
|
||||
await filesystem.move('temp-output.txt', 'temp-dir/moved.txt')
|
||||
print.success('File moved to temp-dir/moved.txt')
|
||||
|
||||
// 9. Read directory tree
|
||||
print.info('\n9. Directory tree')
|
||||
const tree = filesystem.inspectTree('temp-dir')
|
||||
print.info(`Temp directory structure:`)
|
||||
print.info(JSON.stringify(tree, null, 2))
|
||||
|
||||
// 10. File info
|
||||
print.info('\n10. File info')
|
||||
const info = filesystem.inspect('temp-dir/moved.txt')
|
||||
if (info) {
|
||||
print.info(`File type: ${info.type}`)
|
||||
print.info(`File size: ${info.size} bytes`)
|
||||
}
|
||||
|
||||
// 11. Append to file
|
||||
print.info('\n11. Append to file')
|
||||
await filesystem.append('temp-dir/moved.txt', '\nAppended line')
|
||||
print.success('Content appended')
|
||||
|
||||
// 12. Read file with encoding
|
||||
print.info('\n12. Read with encoding')
|
||||
const content = await filesystem.read('temp-dir/moved.txt', 'utf8')
|
||||
print.info(`Content: ${content}`)
|
||||
|
||||
// 13. Path utilities
|
||||
print.info('\n13. Path utilities')
|
||||
const fullPath = filesystem.path('temp-dir', 'moved.txt')
|
||||
print.info(`Full path: ${fullPath}`)
|
||||
print.info(`Current directory: ${filesystem.cwd()}`)
|
||||
print.info(`Path separator: ${filesystem.separator}`)
|
||||
|
||||
// 14. Find by extension
|
||||
print.info('\n14. Find by extension')
|
||||
const jsonFiles = filesystem.find('.', {
|
||||
matching: '*.json',
|
||||
recursive: false
|
||||
})
|
||||
print.info(`JSON files: ${jsonFiles?.join(', ')}`)
|
||||
|
||||
// 15. Remove files (cleanup)
|
||||
print.info('\n15. Cleanup')
|
||||
await filesystem.remove('temp-dir')
|
||||
print.success('Removed temp directory')
|
||||
|
||||
// Summary
|
||||
print.info('\n=== Summary ===')
|
||||
print.success('Filesystem operations completed!')
|
||||
print.info('Common operations:')
|
||||
print.info(' - read/write: Handle file content')
|
||||
print.info(' - exists: Check file/directory existence')
|
||||
print.info(' - dir: Create directories')
|
||||
print.info(' - find: Search for files')
|
||||
print.info(' - copy/move: Manipulate files')
|
||||
print.info(' - remove: Delete files/directories')
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = command
|
||||
126
skills/gluegun-patterns/templates/toolbox/prompt-examples.ts.ejs
Normal file
126
skills/gluegun-patterns/templates/toolbox/prompt-examples.ts.ejs
Normal file
@@ -0,0 +1,126 @@
|
||||
import { GluegunCommand } from 'gluegun'
|
||||
|
||||
/**
|
||||
* Examples of different prompt patterns with Gluegun
|
||||
*/
|
||||
const command: GluegunCommand = {
|
||||
name: 'prompts',
|
||||
description: 'Interactive prompt examples',
|
||||
|
||||
run: async (toolbox) => {
|
||||
const { prompt, print } = toolbox
|
||||
|
||||
print.info('=== Prompt Examples ===\n')
|
||||
|
||||
// 1. Simple text input
|
||||
const nameResult = await prompt.ask({
|
||||
type: 'input',
|
||||
name: 'name',
|
||||
message: 'What is your name?',
|
||||
initial: 'John Doe'
|
||||
})
|
||||
print.info(`Hello, ${nameResult.name}!\n`)
|
||||
|
||||
// 2. Confirmation prompt
|
||||
const shouldContinue = await prompt.confirm('Do you want to continue?')
|
||||
if (!shouldContinue) {
|
||||
print.warning('Operation cancelled')
|
||||
return
|
||||
}
|
||||
|
||||
// 3. Select from list
|
||||
const frameworkResult = await prompt.ask({
|
||||
type: 'select',
|
||||
name: 'framework',
|
||||
message: 'Choose your framework:',
|
||||
choices: ['React', 'Vue', 'Angular', 'Svelte']
|
||||
})
|
||||
print.info(`Selected: ${frameworkResult.framework}\n`)
|
||||
|
||||
// 4. Multi-select
|
||||
const featuresResult = await prompt.ask({
|
||||
type: 'multiselect',
|
||||
name: 'features',
|
||||
message: 'Select features to enable:',
|
||||
choices: [
|
||||
{ name: 'TypeScript', value: 'typescript' },
|
||||
{ name: 'ESLint', value: 'eslint' },
|
||||
{ name: 'Prettier', value: 'prettier' },
|
||||
{ name: 'Testing', value: 'testing' }
|
||||
],
|
||||
initial: ['typescript', 'eslint']
|
||||
})
|
||||
print.info(`Features: ${featuresResult.features.join(', ')}\n`)
|
||||
|
||||
// 5. Password input
|
||||
const passwordResult = await prompt.ask({
|
||||
type: 'password',
|
||||
name: 'password',
|
||||
message: 'Enter password:'
|
||||
})
|
||||
print.info('Password received (hidden)\n')
|
||||
|
||||
// 6. Number input
|
||||
const portResult = await prompt.ask({
|
||||
type: 'numeral',
|
||||
name: 'port',
|
||||
message: 'Enter port number:',
|
||||
initial: 3000
|
||||
})
|
||||
print.info(`Port: ${portResult.port}\n`)
|
||||
|
||||
// 7. Autocomplete
|
||||
const colorResult = await prompt.ask({
|
||||
type: 'autocomplete',
|
||||
name: 'color',
|
||||
message: 'Choose a color:',
|
||||
choices: ['Red', 'Blue', 'Green', 'Yellow', 'Purple', 'Orange']
|
||||
})
|
||||
print.info(`Color: ${colorResult.color}\n`)
|
||||
|
||||
// 8. List input (comma-separated)
|
||||
const tagsResult = await prompt.ask({
|
||||
type: 'list',
|
||||
name: 'tags',
|
||||
message: 'Enter tags (comma-separated):'
|
||||
})
|
||||
print.info(`Tags: ${tagsResult.tags.join(', ')}\n`)
|
||||
|
||||
// 9. Snippet (multiple fields)
|
||||
const userResult = await prompt.ask({
|
||||
type: 'snippet',
|
||||
name: 'user',
|
||||
message: 'Fill out user information:',
|
||||
template: `Name: \${name}
|
||||
Email: \${email}
|
||||
Age: \${age}`
|
||||
})
|
||||
print.info('User info:')
|
||||
print.info(JSON.stringify(userResult.user.values, null, 2))
|
||||
print.info('')
|
||||
|
||||
// 10. Conditional prompts
|
||||
const projectTypeResult = await prompt.ask({
|
||||
type: 'select',
|
||||
name: 'projectType',
|
||||
message: 'Project type:',
|
||||
choices: ['web', 'mobile', 'desktop']
|
||||
})
|
||||
|
||||
if (projectTypeResult.projectType === 'web') {
|
||||
const webFrameworkResult = await prompt.ask({
|
||||
type: 'select',
|
||||
name: 'webFramework',
|
||||
message: 'Choose web framework:',
|
||||
choices: ['Next.js', 'Remix', 'SvelteKit']
|
||||
})
|
||||
print.info(`Web framework: ${webFrameworkResult.webFramework}\n`)
|
||||
}
|
||||
|
||||
// Summary
|
||||
print.success('All prompts completed!')
|
||||
print.info('See the examples above for different prompt patterns')
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = command
|
||||
@@ -0,0 +1,97 @@
|
||||
/**
|
||||
* <%= componentName %> Component
|
||||
* Generated by <%= generatorName %>
|
||||
* Created: <%= timestamp %>
|
||||
*/
|
||||
|
||||
<% if (language === 'typescript') { %>
|
||||
import { <%= imports.join(', ') %> } from '<%= importPath %>'
|
||||
|
||||
export interface <%= componentName %>Props {
|
||||
<% props.forEach(prop => { %>
|
||||
<%= prop.name %>: <%= prop.type %><%= prop.optional ? '?' : '' %>
|
||||
<% }) %>
|
||||
}
|
||||
|
||||
export class <%= componentName %> {
|
||||
<% properties.forEach(property => { %>
|
||||
private <%= property.name %>: <%= property.type %>
|
||||
<% }) %>
|
||||
|
||||
constructor(props: <%= componentName %>Props) {
|
||||
<% properties.forEach(property => { %>
|
||||
this.<%= property.name %> = props.<%= property.name %>
|
||||
<% }) %>
|
||||
}
|
||||
|
||||
<% methods.forEach(method => { %>
|
||||
<%= method.name %>(<%= method.params %>): <%= method.returnType %> {
|
||||
// TODO: Implement <%= method.name %>
|
||||
<% if (method.returnType !== 'void') { %>
|
||||
return <%= method.defaultReturn %>
|
||||
<% } %>
|
||||
}
|
||||
<% }) %>
|
||||
}
|
||||
<% } else if (language === 'javascript') { %>
|
||||
/**
|
||||
* <%= componentName %> Component
|
||||
*/
|
||||
class <%= componentName %> {
|
||||
constructor(options = {}) {
|
||||
<% properties.forEach(property => { %>
|
||||
this.<%= property.name %> = options.<%= property.name %> || <%= property.default %>
|
||||
<% }) %>
|
||||
}
|
||||
|
||||
<% methods.forEach(method => { %>
|
||||
<%= method.name %>(<%= method.params %>) {
|
||||
// TODO: Implement <%= method.name %>
|
||||
}
|
||||
<% }) %>
|
||||
}
|
||||
|
||||
module.exports = <%= componentName %>
|
||||
<% } %>
|
||||
|
||||
<% if (includeTests) { %>
|
||||
|
||||
/**
|
||||
* Tests for <%= componentName %>
|
||||
*/
|
||||
describe('<%= componentName %>', () => {
|
||||
<% methods.forEach(method => { %>
|
||||
test('<%= method.name %> should work', () => {
|
||||
// TODO: Write test for <%= method.name %>
|
||||
})
|
||||
<% }) %>
|
||||
})
|
||||
<% } %>
|
||||
|
||||
<% if (includeDocumentation) { %>
|
||||
|
||||
/**
|
||||
* DOCUMENTATION
|
||||
*
|
||||
* Usage Example:
|
||||
* ```<%= language %>
|
||||
* <% if (language === 'typescript') { %>
|
||||
* const instance = new <%= componentName %>({
|
||||
* <% props.forEach(prop => { %>
|
||||
* <%= prop.name %>: <%= prop.exampleValue %>,
|
||||
* <% }) %>
|
||||
* })
|
||||
* <% } else { %>
|
||||
* const instance = new <%= componentName %>({
|
||||
* <% properties.forEach(property => { %>
|
||||
* <%= property.name %>: <%= property.exampleValue %>,
|
||||
* <% }) %>
|
||||
* })
|
||||
* <% } %>
|
||||
*
|
||||
* <% methods.forEach(method => { %>
|
||||
* instance.<%= method.name %>(<%= method.exampleArgs %>)
|
||||
* <% }) %>
|
||||
* ```
|
||||
*/
|
||||
<% } %>
|
||||
Reference in New Issue
Block a user