Skip to content

Commit 43aff66

Browse files
committed
chore: wip
chore: wip chore: wip
1 parent e8fa1fc commit 43aff66

File tree

11 files changed

+193
-41
lines changed

11 files changed

+193
-41
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ buddy make:component HelloWorld # scaffolds a component
5757
buddy make:function HelloWorld # scaffolds a function
5858
buddy make:view hello-world # scaffolds a page (https://my-project.test/hello-world)
5959

60+
buddy list # lists all available commands
6061
buddy --help
6162
```
6263

app/Schedule.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { run } from '@stacksjs/scheduler'
22

3-
export default function scheduler() {
3+
export default function () {
44
run.command('bun /home/some/script.js').everySecond()
55
run.command('bun /home/some/other/script.ts').everyMinute()
66
run.action('./actions/SomeAction.ts').everyFiveMinutes() // could use a better dummy example 😅
77
run.job('./jobs/DummyJob.ts').everyTenMinutes()
88
run.exec('bun /home/some/script.ts').everyMinute()
99
run.call(() => {
10-
// ...
10+
console.log('This is a fancy callback that runs weekly on Mondays at 1:00 PM PT')
1111
}).weekly().mondays().at('13:00').timezone('America/Los_Angeles')
1212
}

storage/framework/buddy

Lines changed: 0 additions & 2 deletions
This file was deleted.

storage/framework/core/buddy/src/cli.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ async function main() {
3535
cmd.http(buddy)
3636
cmd.install(buddy)
3737
cmd.lint(buddy)
38+
cmd.list(buddy)
3839
// cmd.make(buddy)
3940
// cmd.migrate(buddy)
4041
cmd.release(buddy)
@@ -61,6 +62,7 @@ async function main() {
6162
console.error(`Expected a default export function in ${file}, but got:`, dynamicImport.default)
6263
}
6364

65+
buddy.help()
6466
buddy.parse()
6567
}
6668

storage/framework/core/buddy/src/commands/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export * from './fresh'
1414
export * from './generate'
1515
export * from './http'
1616
export * from './lint'
17+
export * from './list'
1718
export * from './inspire'
1819
export * from './install'
1920
export * from './key'
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import process from 'node:process'
2+
import type { CLI, CliOptions } from '@stacksjs/types'
3+
import { $ } from 'bun'
4+
import { projectPath } from '@stacksjs/path'
5+
6+
export function list(buddy: CLI) {
7+
const descriptions = {
8+
list: 'List all of the project-specific Buddy commands',
9+
project: 'Target a specific project',
10+
verbose: 'Enable verbose output',
11+
}
12+
13+
buddy
14+
.command('list', descriptions.list)
15+
.option('-p, --project', descriptions.project, { default: false })
16+
.option('--verbose', descriptions.verbose, { default: false })
17+
.action(async () => {
18+
$.cwd(projectPath())
19+
const test = await $`buddy --help`.text()
20+
const commandsSection = test.match(/Commands:.*?(?=For more info, run any command with the)/s)?.[0]
21+
22+
if (commandsSection) {
23+
const cleanedCommands = commandsSection
24+
.replace('Commands:', '') // Remove "Commands:"
25+
.replace(/^\s+/gm, '') // Trim leading whitespace from the start of each line
26+
27+
// eslint-disable-next-line no-console
28+
console.log(cleanedCommands)
29+
return
30+
}
31+
32+
console.error('#1 - Please reach out to our Discord for helper: https://discord.gg/stacksjs')
33+
})
34+
35+
buddy.on('list:*', () => {
36+
console.error('Invalid command: %s\nSee --help for a list of available commands.', buddy.args.join(' '))
37+
process.exit(1)
38+
})
39+
}

storage/framework/core/buddy/src/commands/setup.ts

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import process from 'node:process'
22
import { path as p } from '@stacksjs/path'
33
import { handleError } from '@stacksjs/error-handling'
4-
import { storage } from '@stacksjs/storage'
4+
import { writeFile } from '@stacksjs/storage'
55
import { log, runCommand } from '@stacksjs/cli'
66
import { ExitCode } from '@stacksjs/types'
77
import type { CLI, CliOptions } from '@stacksjs/types'
8+
import { $ } from 'bun'
89

910
export function setup(buddy: CLI) {
1011
const descriptions = {
1112
setup: 'This command ensures your project is setup correctly',
13+
ohMyZsh: 'Enable Oh My Zsh',
1214
project: 'Target a specific project',
1315
verbose: 'Enable verbose output',
1416
}
@@ -28,6 +30,43 @@ export function setup(buddy: CLI) {
2830
await initializeProject(options)
2931
})
3032

33+
buddy
34+
.command('setup:oh-my-zsh', descriptions.ohMyZsh)
35+
.option('--verbose', descriptions.verbose, { default: false })
36+
.action(async (_options?: CliOptions) => {
37+
const zshrcPath = await $`echo $HOME/.zshrc`.text()
38+
console.log('zshrcPath', zshrcPath)
39+
let data = await $`cat ${zshrcPath}`.text()
40+
console.log('data', data)
41+
42+
// Manipulate the data
43+
const pluginLineRegex = /plugins=\(([^)]+)\)/
44+
const match = data.match(pluginLineRegex)
45+
46+
if (match) {
47+
// 1. Find the plugins line
48+
const plugins = match[1].split(' ')
49+
50+
// 2. Add buddy to the list of plugins if it's not already there
51+
if (!plugins.includes('buddy')) {
52+
plugins.push('buddy')
53+
const newPluginLine = `plugins=(${plugins.join(' ')})`
54+
// 3. Replace the old plugin line with the new one
55+
data = data.replace(pluginLineRegex, newPluginLine)
56+
// 4. Write the data back to the file
57+
await writeFile(zshrcPath, data)
58+
59+
// need to copy plugin to ~/.oh-my-zsh/custom/plugins
60+
const pluginPath = p.frameworkPath('core/zsh-buddy/buddy.plugin.zsh')
61+
const customPath = '~/.oh-my-zsh/custom/plugins/buddy'
62+
63+
await runCommand(`cp -r ${pluginPath} ${customPath}`)
64+
}
65+
}
66+
67+
log.success('Oh My Zsh setup complete')
68+
})
69+
3170
buddy.on('setup:*', () => {
3271
console.error('Invalid command: %s\nSee --help for a list of available commands.', buddy.args.join(' '))
3372
process.exit(ExitCode.FatalError)

storage/framework/core/cloud/buddy

Lines changed: 0 additions & 2 deletions
This file was deleted.

storage/framework/core/scheduler/src/index.ts

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export interface Schedule {
88
exec: (cmd: string) => this
99
call: (callback: () => void) => this
1010
everyMinute: () => this
11-
everySecond: () => this
11+
everySecond: (callback: () => void, options?: SchedulerOption) => CronJob
1212
everyFiveMinutes: () => this
1313
everyTenMinutes: () => this
1414
everyThirtyMinutes: () => this
@@ -34,44 +34,44 @@ export interface Schedule {
3434
at: (time: string) => this
3535
}
3636

37-
export interface Scheduler {
38-
everySecond: () => void
39-
everySeconds: (seconds: number) => void
40-
everyMinute: () => void
41-
everyMinutes: (minutes: number) => void
42-
everyTwoMinutes: () => void
43-
everyThreeMinutes: () => void
44-
everyFourMinutes: () => void
45-
everyFiveMinutes: () => void
46-
everyTenMinutes: () => void
47-
everyFifteenMinutes: () => void
48-
everyThirtyMinutes: () => void
49-
hourly: () => void
50-
hourlyAt: (minute: number) => void
51-
everyOddHour: () => void
52-
everyHours: (hours: number) => void
53-
everyTwoHours: () => void
54-
everyThreeHours: () => void
55-
everyFourHours: () => void
56-
everySixHours: () => void
57-
daily: () => void
58-
dailyAt: (hour: number, minute: number) => void
59-
everyDays: (days: number) => void
60-
weekly: () => void
61-
quarterly: () => void
62-
yearly: () => void
63-
cron: (interval: string, timezone?: string) => void
64-
}
37+
// export interface Scheduler {
38+
// everySecond: () => void
39+
// everySeconds: (seconds: number) => void
40+
// everyMinute: () => void
41+
// everyMinutes: (minutes: number) => void
42+
// everyTwoMinutes: () => void
43+
// everyThreeMinutes: () => void
44+
// everyFourMinutes: () => void
45+
// everyFiveMinutes: () => void
46+
// everyTenMinutes: () => void
47+
// everyFifteenMinutes: () => void
48+
// everyThirtyMinutes: () => void
49+
// hourly: () => void
50+
// hourlyAt: (minute: number) => void
51+
// everyOddHour: () => void
52+
// everyHours: (hours: number) => void
53+
// everyTwoHours: () => void
54+
// everyThreeHours: () => void
55+
// everyFourHours: () => void
56+
// everySixHours: () => void
57+
// daily: () => void
58+
// dailyAt: (hour: number, minute: number) => void
59+
// everyDays: (days: number) => void
60+
// weekly: () => void
61+
// quarterly: () => void
62+
// yearly: () => void
63+
// cron: (interval: string, timezone?: string) => void
64+
// }
6565

6666
interface SchedulerOption {
6767
timezone: string // TODO: create a better type
6868
enable: boolean
6969
}
7070

71-
export function run(callback: Function, options?: SchedulerOption): Scheduler {
71+
export function run(): Schedule {
7272
return {
73-
everySecond: () => {
74-
new CronJob(
73+
everySecond(callback: Function, options?: SchedulerOption) {
74+
const job = new CronJob(
7575
'* * * * * *',
7676
() => {
7777
callback()
@@ -80,6 +80,8 @@ export function run(callback: Function, options?: SchedulerOption): Scheduler {
8080
options?.enable ?? true,
8181
options?.timezone ?? 'America/Los_Angeles',
8282
)
83+
84+
return job
8385
},
8486

8587
everySeconds: (seconds = 1) => {

storage/framework/core/zsh-buddy/README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@ This package contains the zsh-buddy plugin.
44

55
## ☘️ Features
66

7-
- ...
7+
- It will find and execute `buddy` from anywhere within the project file tree _(and you don't need to prefix it with php or ./)_
8+
- It provides auto-completion for `buddy` commands _(that also work anywhere within the project)_
9+
- You can specify an editor to automatically open new files created by `buddy make:*` commands
810

911
## 🤖 Usage
1012

11-
...
13+
```
14+
buddy setup:oh-my-zsh
15+
```
1216

1317
To view the full documentation, please visit [https://stacksjs.org/ui](https://stacksjs.org/zsh).
1418

0 commit comments

Comments
 (0)