@stacksjs/buddy 0.58.48 → 0.58.49

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.
@@ -0,0 +1,140 @@
1
+ import process from 'node:process'
2
+ import {
3
+ generateComponentMeta,
4
+ generateIdeHelpers,
5
+ generateLibEntries,
6
+ generateMigrations,
7
+ generatePkgxConfig,
8
+ generateTypes,
9
+ generateVsCodeCustomData,
10
+ generateWebTypes,
11
+ invoke as startGenerationProcess,
12
+ } from '@stacksjs/actions'
13
+ import { prompt } from '@stacksjs/cli'
14
+ import { type CLI, ExitCode, type GeneratorOptions } from '@stacksjs/types'
15
+ import { isString } from '@stacksjs/validation'
16
+
17
+ export function generate(buddy: CLI) {
18
+ const descriptions = {
19
+ command: 'Automagically build any of your libraries/packages for production use. Select any of the following packages',
20
+ types: 'Generate your TypeScript types',
21
+ entries: 'Generate your function & Component Library Entry Points',
22
+ webTypes: 'Generate web-types.json for IDEs',
23
+ customData: 'Generate VS Code custom data (custom-elements.json) for IDEs',
24
+ ideHelpers: 'Generate IDE helpers',
25
+ componentMeta: 'Generate component meta information',
26
+ pkgx: 'Generate the pkgx configuration file',
27
+ select: 'What are you trying to generate?',
28
+ project: 'Target a specific project',
29
+ verbose: 'Enable verbose output',
30
+ }
31
+
32
+ buddy
33
+ .command('generate', descriptions.command)
34
+ .option('-t, --types', descriptions.types)
35
+ .option('-e, --entries', descriptions.entries)
36
+ .option('-w, --web-types', descriptions.webTypes)
37
+ .option('-c, --custom-data', descriptions.customData)
38
+ .option('-i, --ide-helpers', descriptions.ideHelpers)
39
+ .option('-c, --component-meta', descriptions.componentMeta)
40
+ .option('-p, --pkgx', descriptions.pkgx)
41
+ .option('-p, --project', descriptions.project, { default: false })
42
+ .option('--verbose', descriptions.verbose, { default: false })
43
+ .action(async (options: GeneratorOptions) => {
44
+ if (hasNoOptions(options)) {
45
+ let answers = await prompt.require()
46
+ .multiselect(descriptions.select, {
47
+ options: [
48
+ { label: '1.) TypeScript Types', value: 'types' },
49
+ { label: '2.) Library Entry Points', value: 'entries' },
50
+ { label: '3.) Web Types', value: 'web-types' },
51
+ { label: '4.) VS Code Custom Data', value: 'custom-data' },
52
+ { label: '5.) IDE Helpers', value: 'ide-helpers' },
53
+ { label: '6.) Component Meta', value: 'component-meta' },
54
+ ],
55
+ })
56
+
57
+ if (isString(answers))
58
+ answers = [answers]
59
+
60
+ // creates an object out of array and sets answers to true
61
+ options = (answers as Array<any>).reduce((a: any, v: any) => ({ ...a, [v]: true }), {})
62
+ }
63
+
64
+ await startGenerationProcess(options)
65
+
66
+ process.exit(ExitCode.Success)
67
+ })
68
+
69
+ buddy
70
+ .command('generate:types', descriptions.types)
71
+ .option('-p, --project', descriptions.project, { default: false })
72
+ .option('--verbose', descriptions.verbose, { default: false })
73
+ .alias('types:generate')
74
+ .action(async (options: GeneratorOptions) => {
75
+ await generateTypes(options)
76
+ })
77
+
78
+ buddy
79
+ .command('generate:entries', descriptions.entries)
80
+ .option('-p, --project', descriptions.project, { default: false })
81
+ .option('--verbose', descriptions.verbose, { default: false })
82
+ .action(async (options: GeneratorOptions) => {
83
+ await generateLibEntries(options)
84
+ })
85
+
86
+ buddy
87
+ .command('generate:web-types', descriptions.webTypes)
88
+ .option('-p, --project', descriptions.project, { default: false })
89
+ .option('--verbose', descriptions.verbose, { default: false })
90
+ .action(async (options: GeneratorOptions) => {
91
+ await generateWebTypes(options)
92
+ })
93
+
94
+ buddy
95
+ .command('generate:vscode-custom-data', descriptions.customData)
96
+ .option('-p, --project', descriptions.project, { default: false })
97
+ .option('--verbose', descriptions.verbose, { default: false })
98
+ .action(async (options: GeneratorOptions) => {
99
+ await generateVsCodeCustomData(options)
100
+ })
101
+
102
+ buddy
103
+ .command('generate:ide-helpers', descriptions.ideHelpers)
104
+ .option('-p, --project', descriptions.project, { default: false })
105
+ .option('--verbose', descriptions.verbose, { default: false })
106
+ .action(async (options: GeneratorOptions) => {
107
+ await generateIdeHelpers(options)
108
+ })
109
+
110
+ buddy
111
+ .command('generate:component-meta', descriptions.componentMeta)
112
+ .option('-p, --project', descriptions.project, { default: false })
113
+ .option('--verbose', descriptions.verbose, { default: false })
114
+ .action(async (options: GeneratorOptions) => {
115
+ await generateComponentMeta(options)
116
+ })
117
+
118
+ buddy
119
+ .command('generate:pkgx-config', descriptions.pkgx)
120
+ .option('-p, --project', descriptions.project, { default: false })
121
+ .option('--verbose', descriptions.verbose, { default: false })
122
+ .action(() => {
123
+ generatePkgxConfig()
124
+ })
125
+
126
+ buddy
127
+ .command('generate:migrations', 'Generate Migrations')
128
+ .action(() => {
129
+ generateMigrations()
130
+ })
131
+
132
+ buddy.on('generate:*', () => {
133
+ console.error('Invalid command: %s\nSee --help for a list of available commands.', buddy.args.join(' '))
134
+ process.exit(1)
135
+ })
136
+ }
137
+
138
+ function hasNoOptions(options: GeneratorOptions) {
139
+ return !options.types && !options.entries && !options.webTypes && !options.customData && !options.ideHelpers && !options.componentMeta
140
+ }
@@ -0,0 +1,55 @@
1
+ import process from 'node:process'
2
+ import { ExitCode } from '@stacksjs/types'
3
+ import type { CLI } from '@stacksjs/types'
4
+ import { config } from '@stacksjs/config'
5
+
6
+ // import { path } from '@stacksjs/path'
7
+ import { runCommandSync } from '@stacksjs/cli'
8
+
9
+ // function runCommand(command: string): Promise<string> {
10
+ // return new Promise((resolve, reject) => {
11
+ // exec(command, { shell: true, cwd: path.projectPath() }, (error, stdout, stderr) => {
12
+ // if (error) {
13
+ // console.error(`exec error: ${error}`)
14
+ // reject(error)
15
+ // } else {
16
+ // console.log(error, stdout, stderr)
17
+ // resolve(stdout)
18
+ // }
19
+ // })
20
+ // })
21
+ // }
22
+
23
+ // import { Action } from '@stacksjs/enums'
24
+ // import { runAction } from '@stacksjs/actions'
25
+
26
+ interface HttpOptions {
27
+ verbose?: boolean
28
+ }
29
+
30
+ export function http(buddy: CLI) {
31
+ const descriptions = {
32
+ http: 'Send an HTTP request to a domain',
33
+ project: 'Target a specific project',
34
+ verbose: 'Enable verbose output',
35
+ }
36
+
37
+ buddy
38
+ .command('http [domain]', descriptions.http)
39
+ .option('-p, --project', descriptions.project, { default: false })
40
+ // .option('--verbose', descriptions.verbose, { default: false })
41
+ .action(async (domain: string | undefined, options: HttpOptions) => {
42
+ // Convert options object to command-line options string
43
+ const optionsString = Object.entries(options)
44
+ .filter(([key, value]) => key !== '--' && key.length > 1 && value !== false) // filter out '--' key and short options
45
+ .map(([key, value]) => `--${key} ${value}`)
46
+ .join(' ')
47
+
48
+ const command = `http GET ${domain || config.app.url} ${optionsString}`
49
+ // eslint-disable-next-line no-console
50
+ console.log(`Running command: ${command}`)
51
+ runCommandSync(command)
52
+
53
+ process.exit(ExitCode.Success)
54
+ })
55
+ }
@@ -0,0 +1,30 @@
1
+ export * from './build'
2
+ export * from './changelog'
3
+ export * from './clean'
4
+ export * from './cloud'
5
+ export * from './commit'
6
+ export * from './configure'
7
+ export * from './create'
8
+ export * from './deploy'
9
+ export * from './dev'
10
+ export * from './domains'
11
+ export * from './dns'
12
+ export * from './example'
13
+ export * from './fresh'
14
+ export * from './generate'
15
+ export * from './http'
16
+ export * from './lint'
17
+ export * from './inspire'
18
+ export * from './install'
19
+ export * from './key'
20
+ export * from './make'
21
+ export * from './migrate'
22
+ export * from './prepublish'
23
+ export * from './release'
24
+ export * from './seed'
25
+ export * from './setup'
26
+ export * from './test'
27
+ export * from './tinker'
28
+ export * from './types'
29
+ export * from './upgrade'
30
+ export * from './version'
@@ -0,0 +1,24 @@
1
+ import process from 'node:process'
2
+ import { ExitCode } from '@stacksjs/types'
3
+ import type { CLI } from '@stacksjs/types'
4
+ import { runAction } from '@stacksjs/actions'
5
+ import { intro, outro } from '@stacksjs/cli'
6
+ import { Action } from '@stacksjs/enums'
7
+
8
+ export function inspire(buddy: CLI) {
9
+ buddy
10
+ .command('inspire', 'Inspire yourself with a random quote')
11
+ .option('--two', 'Show two quotes', { default: false })
12
+ .action(async () => {
13
+ const perf = await intro('buddy inspire')
14
+ const result = await runAction(Action.Inspire)
15
+
16
+ if (result.isErr()) {
17
+ await outro('While running the inspire command, there was an issue', { startTime: perf, useSeconds: true }, result.error)
18
+ process.exit()
19
+ }
20
+
21
+ await outro('Your quote is: ...', { startTime: perf, useSeconds: true })
22
+ process.exit(ExitCode.Success)
23
+ })
24
+ }
@@ -0,0 +1,28 @@
1
+ import process from 'node:process'
2
+ import type { CLI, InstallOptions } from '@stacksjs/types'
3
+ import { runCommand } from '@stacksjs/cli'
4
+ import { path as p } from '@stacksjs/path'
5
+
6
+ export function install(buddy: CLI) {
7
+ const descriptions = {
8
+ install: 'Install your dependencies',
9
+ project: 'Target a specific project',
10
+ verbose: 'Enable verbose output',
11
+ }
12
+
13
+ buddy
14
+ .command('install', descriptions.install)
15
+ .option('-p, --project', descriptions.project, { default: false })
16
+ .option('-v, --verbose', descriptions.verbose, { default: false })
17
+ .action(async (options: InstallOptions) => {
18
+ await runCommand('bun install', {
19
+ ...options,
20
+ cwd: p.projectPath(),
21
+ })
22
+ })
23
+
24
+ buddy.on('install:*', () => {
25
+ console.error('Invalid command: %s\nSee --help for a list of available commands.', buddy.args.join(' '))
26
+ process.exit(1)
27
+ })
28
+ }
@@ -0,0 +1,34 @@
1
+ import process from 'node:process'
2
+ import type { CLI, KeyOptions } from '@stacksjs/types'
3
+ import { intro, log, outro } from '@stacksjs/cli'
4
+ import { Action } from '@stacksjs/enums'
5
+ import { runAction } from '@stacksjs/actions'
6
+
7
+ export function key(buddy: CLI) {
8
+ const descriptions = {
9
+ command: 'Generate & set the application key.',
10
+ project: 'Target a specific project',
11
+ verbose: 'Enable verbose output',
12
+ }
13
+
14
+ buddy
15
+ .command('key:generate', descriptions.command)
16
+ .option('-p, --project', descriptions.project, { default: false })
17
+ .option('--verbose', descriptions.verbose, { default: false })
18
+ .action(async (options: KeyOptions) => {
19
+ await intro('buddy key:generate')
20
+ const result = await runAction(Action.KeyGenerate, options)
21
+
22
+ if (result.isErr()) {
23
+ log.error('Failed to set random application key.', result.error)
24
+ process.exit()
25
+ }
26
+
27
+ await outro('Random application key set.')
28
+ })
29
+
30
+ buddy.on('key:*', () => {
31
+ console.error('Invalid command: %s\nSee --help for a list of available commands.', buddy.args.join(' '))
32
+ process.exit(1)
33
+ })
34
+ }
@@ -0,0 +1,53 @@
1
+ import process from 'node:process'
2
+ import type { CLI, LintOptions } from '@stacksjs/types'
3
+ import { intro, log, outro } from '@stacksjs/cli'
4
+ import { Action } from '@stacksjs/enums'
5
+ import { runAction } from '@stacksjs/actions'
6
+
7
+ export function lint(buddy: CLI) {
8
+ const descriptions = {
9
+ lint: 'Automagically lints your project codebase',
10
+ lintFix: 'Automagically fixes all lint errors',
11
+ project: 'Target a specific project',
12
+ verbose: 'Enable verbose output',
13
+ }
14
+
15
+ buddy
16
+ .command('lint', descriptions.lint)
17
+ .option('-f, --fix', descriptions.lintFix, { default: false })
18
+ .option('-p, --project', descriptions.project, { default: false })
19
+ .option('--verbose', descriptions.verbose, { default: false })
20
+ .action(async (options: LintOptions) => {
21
+ const startTime = await intro('buddy lint')
22
+ const result = await runAction(Action.Lint, options)
23
+
24
+ // console.log('res', result)
25
+ if (result.isErr()) {
26
+ await outro('While running `buddy lint`, there was an issue', { startTime, useSeconds: true }, result.error)
27
+ process.exit()
28
+ }
29
+
30
+ await outro('Linted your project', { startTime, useSeconds: true })
31
+ })
32
+
33
+ buddy
34
+ .command('lint:fix', descriptions.lintFix)
35
+ .option('-p, --project', descriptions.project, { default: false })
36
+ .option('--verbose', descriptions.verbose, { default: false })
37
+ .action(async (options: LintOptions) => {
38
+ log.info('Fixing lint errors...')
39
+ const result = await runAction(Action.LintFix, { ...options })
40
+
41
+ if (result.isErr()) {
42
+ log.error('There was an error lint fixing your code.', result.error)
43
+ process.exit()
44
+ }
45
+
46
+ log.success('Fixed lint errors')
47
+ })
48
+
49
+ buddy.on('lint:*', () => {
50
+ console.error('Invalid command: %s\nSee --help for a list of available commands.', buddy.args.join(' '))
51
+ process.exit(1)
52
+ })
53
+ }
@@ -0,0 +1,269 @@
1
+ import process from 'node:process'
2
+ import {
3
+ createModel,
4
+ createNotification,
5
+ invoke,
6
+ makeComponent,
7
+ makeDatabase,
8
+ makeFunction,
9
+ makeLanguage,
10
+ makePage,
11
+ makeStack,
12
+ } from '@stacksjs/actions'
13
+ import { intro, italic, outro, prompt } from '@stacksjs/cli'
14
+ import { log } from '@stacksjs/logging'
15
+ import type { CLI, MakeOptions } from '@stacksjs/types'
16
+ import { ExitCode } from '@stacksjs/types'
17
+ import { isString } from '@stacksjs/validation'
18
+
19
+ export function make(buddy: CLI) {
20
+ const descriptions = {
21
+ model: 'Create a new model',
22
+ component: 'Create a new component',
23
+ page: 'Create a new page',
24
+ function: 'Create a new function',
25
+ language: 'Create a new language',
26
+ database: 'Create a new database',
27
+ migration: 'Create a new migration',
28
+ factory: 'Create a new factory',
29
+ notification: 'Create a new notification',
30
+ stack: 'Create a new new stack',
31
+ select: 'What are you trying to make?',
32
+ project: 'Target a specific project',
33
+ verbose: 'Enable verbose output',
34
+ }
35
+
36
+ buddy
37
+ .command('make', 'The make command')
38
+ .option('-c, --component', descriptions.component, { default: false })
39
+ .option('-p, --page', descriptions.page, { default: false })
40
+ .option('-f, --function', descriptions.function, { default: false })
41
+ .option('-l, --language', descriptions.language, { default: false })
42
+ .option('-d, --database', descriptions.database, { default: false })
43
+ .option('-m, --migration', descriptions.migration, { default: false })
44
+ .option('-f, --factory', descriptions.factory, { default: false })
45
+ .option('-n, --notification', descriptions.notification, { default: false })
46
+ .option('-s, --stack', descriptions.stack, { default: false })
47
+ .option('-p, --project', descriptions.project, { default: false })
48
+ .option('--verbose', descriptions.verbose, { default: false })
49
+ .action(async (options: MakeOptions) => {
50
+ const name = buddy.args[0]
51
+
52
+ if (!name) {
53
+ log.error('You need to specify a name. Read more about the documentation here.')
54
+ process.exit()
55
+ }
56
+
57
+ if (hasNoOptions(options)) {
58
+ let answers = await prompt.require()
59
+ .multiselect(descriptions.select, {
60
+ options: [
61
+ { label: 'Page', value: 'page' },
62
+ { label: 'Function', value: 'function' },
63
+ { label: 'Component', value: 'component' },
64
+ { label: 'Notification', value: 'notification' },
65
+ { label: 'Language', value: 'language' },
66
+ { label: 'Database', value: 'database' },
67
+ { label: 'Migration', value: 'migration' },
68
+ { label: 'Factory', value: 'factory' },
69
+ { label: 'Stack', value: 'stack' },
70
+ ],
71
+ })
72
+
73
+ if (answers !== null)
74
+ process.exit(ExitCode.InvalidArgument)
75
+
76
+ if (isString(answers))
77
+ answers = [answers]
78
+
79
+ // creates an object out of array and sets answers to true
80
+ options = answers.reduce((a: any, v: any) => ({ ...a, [v]: true }), {})
81
+ }
82
+
83
+ await invoke(options)
84
+
85
+ process.exit(ExitCode.Success)
86
+ })
87
+
88
+ buddy
89
+ .command('make:component', descriptions.component)
90
+ .option('-n, --name', 'The name of the component')
91
+ .option('-p, --project', descriptions.project, { default: false })
92
+ .option('--verbose', descriptions.verbose, { default: false })
93
+ .action(async (options: MakeOptions) => {
94
+ const name = buddy.args[0] || options.name
95
+ options.name = name
96
+
97
+ if (!name) {
98
+ log.error('You need to specify a name. Read more about the documentation here.')
99
+ process.exit()
100
+ }
101
+
102
+ await makeComponent(options)
103
+ })
104
+
105
+ buddy
106
+ .command('make:database', descriptions.database)
107
+ .option('-n, --name', 'The name of the database')
108
+ .option('-p, --project', descriptions.project, { default: false })
109
+ .option('--verbose', descriptions.verbose, { default: false })
110
+ .action((options: MakeOptions) => {
111
+ const name = buddy.args[0] || options.name
112
+ options.name = name
113
+
114
+ if (!name) {
115
+ log.error('You need to specify a name. Read more about the documentation here.')
116
+ process.exit()
117
+ }
118
+
119
+ makeDatabase(options)
120
+ })
121
+
122
+ buddy
123
+ .command('make:factory', descriptions.factory)
124
+ .option('-n, --name', 'The name of the factory')
125
+ .option('-p, --project', descriptions.project, { default: false })
126
+ .option('--verbose', descriptions.verbose, { default: false })
127
+ .action((options: MakeOptions) => {
128
+ const name = buddy.args[0] || options.name
129
+ options.name = name
130
+
131
+ if (!name) {
132
+ log.error('You need to specify a name. Read more about the documentation here.')
133
+ process.exit()
134
+ }
135
+
136
+ // makeFactory(options)
137
+ })
138
+
139
+ buddy
140
+ .command('make:view', descriptions.page)
141
+ .alias('make:page')
142
+ .option('-n, --name', 'The name of the page')
143
+ .option('-p, --project', descriptions.project, { default: false })
144
+ .option('--verbose', descriptions.verbose, { default: false })
145
+ .action(async (options: MakeOptions) => {
146
+ const name = buddy.args[0] || options.name
147
+ options.name = name
148
+
149
+ if (!name) {
150
+ log.error('You need to specify a name. Read more about the documentation here.')
151
+ process.exit()
152
+ }
153
+
154
+ await makePage(options)
155
+ })
156
+
157
+ buddy
158
+ .command('make:function', descriptions.function)
159
+ .option('-n, --name', 'The name of the function')
160
+ .option('-p, --project', descriptions.project, { default: false })
161
+ .option('--verbose', descriptions.verbose, { default: false })
162
+ .action(async (options: MakeOptions) => {
163
+ await makeFunction(options)
164
+ })
165
+
166
+ buddy
167
+ .command('make:lang', descriptions.language)
168
+ .option('-n, --name', 'The name of the language')
169
+ .option('-p, --project', descriptions.project, { default: false })
170
+ .option('--verbose', descriptions.verbose, { default: false })
171
+ .action(async (options: MakeOptions) => {
172
+ const name = buddy.args[0] || options.name
173
+ options.name = name
174
+
175
+ if (!name) {
176
+ log.error('You need to specify a name. Read more about the documentation here.')
177
+ process.exit()
178
+ }
179
+
180
+ await makeLanguage(options)
181
+ })
182
+
183
+ buddy
184
+ .command('make:notification', descriptions.notification)
185
+ .option('-n, --name', 'The name of the notification')
186
+ .option('-e, --email', 'Is it an email notification?', { default: true })
187
+ .option('-c, --chat', 'Is it a chat notification?', { default: false })
188
+ .option('-s, --sms', 'Is it a SMS notification?', { default: false })
189
+ .option('-p, --project', descriptions.project, { default: false })
190
+ .option('--verbose', descriptions.verbose, { default: false })
191
+ .action(async (options: MakeOptions) => {
192
+ const perf = await intro('buddy make:notification')
193
+
194
+ const name = buddy.args[0] || options.name
195
+ options.name = name
196
+
197
+ if (!name) {
198
+ log.error('You need to specify a name. Read more about the documentation here.')
199
+ process.exit()
200
+ }
201
+
202
+ const result = await createNotification(options)
203
+
204
+ if (!result) {
205
+ await outro('While running the make:notification command, there was an issue', { startTime: perf, useSeconds: true })
206
+ process.exit()
207
+ }
208
+
209
+ await outro(`Created your ${italic(name)} notification.`, { startTime: perf, useSeconds: true })
210
+ process.exit(ExitCode.Success)
211
+ })
212
+
213
+ buddy
214
+ .command('make:stack', descriptions.stack)
215
+ .option('-n, --name', 'The name of the stack')
216
+ .option('-p, --project', descriptions.project, { default: false })
217
+ .option('--verbose', descriptions.verbose, { default: false })
218
+ .action((options: MakeOptions) => {
219
+ const name = buddy.args[0] || options.name
220
+ options.name = name
221
+
222
+ if (!name) {
223
+ log.error('You need to specify a name. Read more about the documentation here.')
224
+ process.exit()
225
+ }
226
+
227
+ makeStack(options)
228
+ })
229
+
230
+ buddy
231
+ .command('make:model', descriptions.model)
232
+ .option('-n, --name', 'The name of the model')
233
+ .action(async (options: MakeOptions) => {
234
+ const name = buddy.args[0] || options.name
235
+ options.name = name
236
+
237
+ if (!name) {
238
+ log.error('You need to specify a model name')
239
+ process.exit()
240
+ }
241
+
242
+ await createModel(options)
243
+ })
244
+
245
+ buddy
246
+ .command('make:migration', descriptions.migration)
247
+ .option('-n, --name', 'The name of the migration')
248
+ .option('-e, --env', 'The environment to run the migration in', { default: 'dev' })
249
+ .action((options: MakeOptions) => {
250
+ const name = buddy.args[0] || options.name
251
+ options.name = name
252
+
253
+ if (!name) {
254
+ log.error('You need to specify a migration name')
255
+ process.exit()
256
+ }
257
+
258
+ log.info(path, name)
259
+ })
260
+
261
+ buddy.on('make:*', () => {
262
+ console.error('Invalid command: %s\nSee --help for a list of available commands.', buddy.args.join(' '))
263
+ process.exit(1)
264
+ })
265
+ }
266
+
267
+ function hasNoOptions(options: MakeOptions) {
268
+ return !options.component && !options.page && !options.function && !options.language && !options.database && !options.migration && !options.notification && !options.stack
269
+ }