@stacksjs/actions 0.72.77 → 0.72.79

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.
Files changed (2) hide show
  1. package/dist/make-command.js +27 -36
  2. package/package.json +20 -20
@@ -1,44 +1,35 @@
1
- import{log}from"@stacksjs/logging";import*as p from"@stacksjs/path";import{get,writeFile}from"@stacksjs/storage";export async function makeCommand(options){const name=options.name;if(!name){log.error("Command name is required");return!1}const commandName=toPascalCase(name),content=generateCommandContent(commandName,options),filePath=p.commandsPath(`${commandName}.ts`);try{await writeFile(filePath,content);log.success(`Created command: ${filePath}`);if(options.register!==!1)await registerCommand(commandName,options.signature||toKebabCase(name));return!0}catch(error){log.error(`Failed to create command: ${error.message}`);return!1}}function generateCommandContent(name,options){const signature=options.signature||toKebabCase(name),description=options.description||`The ${signature} command`;return`import type { CLI } from '@stacksjs/types'
2
- import { log } from '@stacksjs/cli'
1
+ import{log}from"@stacksjs/logging";import*as p from"@stacksjs/path";import{get,writeFile}from"@stacksjs/storage";export async function makeCommand(options){const name=options.name;if(!name){log.error("Command name is required");return!1}const commandName=toPascalCase(name),content=generateCommandContent(commandName,options),filePath=p.commandsPath(`${commandName}.ts`),signature=options.signature||toKebabCase(name);try{await writeFile(filePath,content);log.success(`Created command: ${filePath}`);if(options.register)await registerCommand(commandName,signature);else log.info(`Run it with: buddy ${signature}`);return!0}catch(error){log.error(`Failed to create command: ${error.message}`);return!1}}function generateCommandContent(name,options){const signature=options.signature||toKebabCase(name),description=options.description||`The ${signature} command`;return`import { defineCommand, log } from '@stacksjs/cli'
3
2
 
4
3
  /**
5
4
  * ${name} Command
6
5
  *
7
6
  * ${description}
7
+ *
8
+ * Registered automatically - every file in app/Commands is a command.
8
9
  */
10
+ export default defineCommand({
11
+ name: '${signature}',
12
+ description: '${description}',
13
+ options: {
14
+ '--verbose': { description: 'Enable verbose output', default: false },
15
+ // Add more options here. Their types flow into \`handle\`:
16
+ // '--name <name>': 'Who to greet',
17
+ },
18
+ async handle(options) {
19
+ try {
20
+ if (options.verbose)
21
+ log.info('Running ${signature} command...')
9
22
 
10
- interface ${name}Options {
11
- verbose: boolean
12
- // Add your command options here
13
- }
14
-
15
- export default function (cli: CLI) {
16
- cli
17
- .command('${signature}', '${description}')
18
- .option('--verbose', 'Enable verbose output', { default: false })
19
- // Add more options here
20
- // .option('-n, --name <name>', 'Your name')
21
- .action(async (options: ${name}Options) => {
22
- try {
23
- if (options.verbose) {
24
- log.info('Running ${signature} command...')
25
- }
26
-
27
- log.info('No command logic implemented yet. Update this command action to add behavior.')
28
-
29
- log.success('${signature} completed successfully!')
30
- }
31
- catch (error) {
32
- log.error('${signature} failed:', error)
33
- throw error
34
- }
35
- })
23
+ log.info('No command logic implemented yet. Update this command to add behavior.')
36
24
 
37
- // Handle unknown subcommands
38
- cli.on('${signature}:*', () => {
39
- log.error('Invalid command: %s\\nSee --help for a list of available commands.', cli.args.join(' '))
40
- })
41
- }
42
- `}async function registerCommand(name,signature){const commandsPath=p.appPath("Commands.ts");try{let content=await get(commandsPath);const exportMatch=content.match(/export default \{([\s\S]*)\} satisfies/);if(exportMatch){const existingCommands=exportMatch[1]??"";if(existingCommands.includes(`'${signature}'`)){log.info(`Command '${signature}' already registered in Commands.ts`);return}const newCommand=` '${signature}': '${name}',
43
- `,updatedCommands=`${existingCommands.trimEnd()}
44
- ${newCommand}`;content=content.replace(/export default \{[\s\S]*\} satisfies/,`export default {${updatedCommands}} satisfies`);await writeFile(commandsPath,content);log.success(`Registered command '${signature}' in Commands.ts`)}}catch(error){log.warn(`Could not register command in Commands.ts: ${error.message}`);log.info("You may need to manually add it to app/Commands.ts")}}function toPascalCase(str){return str.replace(/[-_](.)/g,(_,char)=>char.toUpperCase()).replace(/^(.)/,(_,char)=>char.toUpperCase())}function toKebabCase(str){return str.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/[_\s]+/g,"-").toLowerCase()}
25
+ log.success('${signature} completed successfully!')
26
+ }
27
+ catch (error) {
28
+ log.error('${signature} failed:', error)
29
+ throw error
30
+ }
31
+ },
32
+ })
33
+ `}async function registerCommand(name,signature){const commandsPath=p.appPath("Commands.ts"),patterns=[{match:/export default \{([\s\S]*)\} satisfies/,open:"export default {",close:"} satisfies"},{match:/export default defineCommands\(\{([\s\S]*)\}\)/,open:"export default defineCommands({",close:"})"}];try{const content=await get(commandsPath),pattern=patterns.find((candidate)=>candidate.match.test(content));if(!pattern){log.info(`Command '${signature}' is live without a registry entry.`);return}const existingCommands=content.match(pattern.match)?.[1]??"";if(existingCommands.includes(`'${signature}'`)){log.info(`Command '${signature}' already registered in Commands.ts`);return}const updatedCommands=`${existingCommands.trimEnd()}
34
+ '${signature}': '${name}',
35
+ `;await writeFile(commandsPath,content.replace(pattern.match,`${pattern.open}${updatedCommands}${pattern.close}`));log.success(`Registered command '${signature}' in Commands.ts`)}catch{log.info(`Command '${signature}' is live without a registry entry.`)}}function toPascalCase(str){return str.replace(/[-_](.)/g,(_,char)=>char.toUpperCase()).replace(/^(.)/,(_,char)=>char.toUpperCase())}function toKebabCase(str){return str.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/[_\s]+/g,"-").toLowerCase()}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@stacksjs/actions",
3
3
  "type": "module",
4
4
  "sideEffects": false,
5
- "version": "0.72.77",
5
+ "version": "0.72.79",
6
6
  "description": "The Stacks actions.",
7
7
  "author": "Chris Breuer",
8
8
  "contributors": [
@@ -60,35 +60,35 @@
60
60
  "prepublishOnly": "bun run build"
61
61
  },
62
62
  "dependencies": {
63
- "@stacksjs/config": "0.72.77",
63
+ "@stacksjs/config": "0.72.79",
64
64
  "@stacksjs/bumpx": "^0.2.6",
65
65
  "@stacksjs/bunpress": "^0.2.8",
66
66
  "@stacksjs/logsmith": "^0.2.3",
67
- "@stacksjs/registry": "0.72.77",
67
+ "@stacksjs/registry": "0.72.79",
68
68
  "@stacksjs/stx": "^0.2.230",
69
69
  "@stacksjs/ts-cloud": "^0.12.4",
70
70
  "@stacksjs/ts-md": "^0.1.1"
71
71
  },
72
72
  "devDependencies": {
73
- "@stacksjs/api": "0.72.77",
74
- "@stacksjs/cli": "0.72.77",
75
- "@stacksjs/database": "0.72.77",
73
+ "@stacksjs/api": "0.72.79",
74
+ "@stacksjs/cli": "0.72.79",
75
+ "@stacksjs/database": "0.72.79",
76
76
  "@stacksjs/tlsx": "^0.13.2",
77
77
  "better-dx": "^0.2.24",
78
- "@stacksjs/dns": "0.72.77",
79
- "@stacksjs/enums": "0.72.77",
80
- "@stacksjs/env": "0.72.77",
81
- "@stacksjs/error-handling": "0.72.77",
82
- "@stacksjs/image": "0.72.77",
83
- "@stacksjs/logging": "0.72.77",
84
- "@stacksjs/path": "0.72.77",
85
- "@stacksjs/security": "0.72.77",
86
- "@stacksjs/cms": "0.72.77",
87
- "@stacksjs/sites": "0.72.77",
88
- "@stacksjs/storage": "0.72.77",
89
- "@stacksjs/strings": "0.72.77",
90
- "@stacksjs/utils": "0.72.77",
91
- "@stacksjs/validation": "0.72.77"
78
+ "@stacksjs/dns": "0.72.79",
79
+ "@stacksjs/enums": "0.72.79",
80
+ "@stacksjs/env": "0.72.79",
81
+ "@stacksjs/error-handling": "0.72.79",
82
+ "@stacksjs/image": "0.72.79",
83
+ "@stacksjs/logging": "0.72.79",
84
+ "@stacksjs/path": "0.72.79",
85
+ "@stacksjs/security": "0.72.79",
86
+ "@stacksjs/cms": "0.72.79",
87
+ "@stacksjs/sites": "0.72.79",
88
+ "@stacksjs/storage": "0.72.79",
89
+ "@stacksjs/strings": "0.72.79",
90
+ "@stacksjs/utils": "0.72.79",
91
+ "@stacksjs/validation": "0.72.79"
92
92
  },
93
93
  "peerDependencies": {
94
94
  "pickier": "^0.1.58",