Skip to content

Commit f2163e3

Browse files
committed
chore: wip
1 parent 13c293a commit f2163e3

File tree

11 files changed

+382
-33
lines changed

11 files changed

+382
-33
lines changed

.stacks/core/actions/src/clean.ts

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,14 @@
11
import { log, runCommand } from '@stacksjs/cli'
2-
import { type CleanOptions, ExitCode, NpmScript } from '@stacksjs/types'
2+
import { ExitCode, NpmScript } from '@stacksjs/types'
33

4-
export async function invoke(options?: CleanOptions) {
5-
log.info('Running clean command...')
4+
log.info('Running clean command...')
65

7-
const result = await runCommand(NpmScript.Clean, options)
6+
const result = await runCommand(NpmScript.Clean)
87

9-
if (result.isOk()) {
10-
log.success('Cleaned up')
11-
process.exit(ExitCode.Success)
12-
}
13-
14-
log.error(result.error)
15-
process.exit(ExitCode.FatalError)
8+
if (result.isOk()) {
9+
log.success('Cleaned up')
10+
process.exit(ExitCode.Success)
1611
}
1712

18-
/**
19-
* An alias of the invoke method.
20-
* @param options
21-
* @returns
22-
*/
23-
export async function clean(options: CleanOptions) {
24-
return invoke(options)
25-
}
13+
log.error(result.error)
14+
process.exit(ExitCode.FatalError)

.stacks/core/alias/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ const alias: Record<string, string> = {
7474
'@stacksjs/serverless/*': p.serverlessPath('src/*'),
7575
'@stacksjs/sms': p.smsPath('src/index.ts'),
7676
'@stacksjs/sms/*': p.smsPath('src/*'),
77+
'@stacksjs/scheduler': p.schedulerPath('src/index.ts'),
78+
'@stacksjs/scheduler/*': p.schedulerPath('src/*'),
7779
'@stacksjs/signals': p.signalsPath('src/index.ts'),
7880
'@stacksjs/signals/*': p.signalsPath('src/*'),
7981
'@stacksjs/storage': p.storagePath('src/index.ts'),

.stacks/core/buddy/src/commands/clean.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { CLI, CleanOptions } from '@stacksjs/types'
2-
import { invoke } from '@stacksjs/actions/clean'
2+
import { runAction } from '@stacksjs/actions'
3+
import { Action } from '@stacksjs/types'
34

45
async function clean(buddy: CLI) {
56
const descriptions = {
@@ -13,7 +14,7 @@ async function clean(buddy: CLI) {
1314
.option('--verbose', descriptions.verbose, { default: false })
1415
.option('--debug', descriptions.debug, { default: false })
1516
.action(async (options: CleanOptions) => {
16-
await invoke(options)
17+
await runAction(Action.Clean, options)
1718
})
1819
}
1920

.stacks/core/path/src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,10 @@ export function smsPath(path?: string) {
290290
return corePath(`sms/${path || ''}`)
291291
}
292292

293+
export function schedulerPath(path?: string) {
294+
return corePath(`scheduler/${path || ''}`)
295+
}
296+
293297
export function signalsPath(path?: string) {
294298
return corePath(`signals/${path || ''}`)
295299
}
@@ -402,6 +406,7 @@ export const path = {
402406
routerPath,
403407
routesPath,
404408
searchEnginePath,
409+
schedulerPath,
405410
settingsPath,
406411
smsPath,
407412
signalsPath,

.stacks/core/scheduler/README.md

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
# Stacks SMS
2+
3+
Stacks SMS is driver system for sending SMS messages.
4+
5+
## ☘️ Features
6+
7+
- 📦 Send SMS
8+
9+
## 🤖 Usage
10+
11+
```bash
12+
pnpm i -D @stacksjs/sms
13+
```
14+
15+
You may now use it in your project:
16+
17+
```ts
18+
import * as sms from '@stacksjs/sms'
19+
/* Then choose a driver. E.g for twilio */
20+
const notification = sms.twilio
21+
22+
notification.send(SMSOptions)
23+
24+
interface SMSOptions {
25+
to: string
26+
content: string
27+
from?: string
28+
attachments?: AttachmentOptions[]
29+
id?: string
30+
}
31+
```
32+
33+
### Drivers
34+
35+
Drivers are configured with the following environment variables:
36+
37+
#### Twilio
38+
39+
```bash
40+
TWILIO_ACCOUNT_SID=ACtest
41+
TWILIO_AUTH_TOKEN=testtoken
42+
TWILIO_FROM_NUMBER=+112345
43+
TWILIO_TO_NUMBER=+145678
44+
```
45+
46+
#### Nexmo
47+
48+
```bash
49+
VONAGE_API_KEY=VN123
50+
VONAGE_API_SECRET=testkey
51+
VONAGE_FROM_NUMBER=+112345
52+
```
53+
54+
#### Gupshup
55+
56+
```bash
57+
GUPSHUP_USER_ID=GU123
58+
GUPSHUP_PASSWORD=password
59+
```
60+
61+
#### Plivo
62+
63+
```bash
64+
PLIVO_ACCOUNT_ID=PA123
65+
PLIVO_AUTH_TOKEN=testtoken
66+
PLIVO_FROM_NUMBER=+112345
67+
```
68+
69+
#### SMS77
70+
71+
```bash
72+
SMS77_API_KEY=SA123
73+
SMS77_FROM=from@example.com
74+
```
75+
76+
#### SNS
77+
78+
```bash
79+
SMS77_API_KEY=SA123
80+
SMS77_FROM=from@example.com
81+
```
82+
83+
#### Telnyx
84+
85+
```bash
86+
TELNYX_API_KEY=TA123
87+
TELNYX_MESSAGE_PROFILE_ID=testprofileid
88+
TELNYX_FROM=from@example.com
89+
```
90+
91+
#### Termii
92+
93+
```bash
94+
TERMII_API_KEY=TermA123
95+
TERMII_SENDER=from@example.com
96+
```
97+
98+
Learn more in the docs.
99+
100+
## 🧪 Testing
101+
102+
```bash
103+
pnpm test
104+
```
105+
106+
## 📈 Changelog
107+
108+
Please see our [releases](https://github.com/stacksjs/stacks/releases) page for more information on what has changed recently.
109+
110+
## 💪🏼 Contributing
111+
112+
Please review the [Contributing Guide](https://github.com/stacksjs/contributing) for details.
113+
114+
## 🏝 Community
115+
116+
For help, discussion about best practices, or any other conversation that would benefit from being searchable:
117+
118+
[Discussions on GitHub](https://github.com/stacksjs/stacks/discussions)
119+
120+
For casual chit-chat with others using this package:
121+
122+
[Join the Stacks Discord Server](https://discord.ow3.org)
123+
124+
## 🙏🏼 Credits
125+
126+
Many thanks to the following core technologies & people who have contributed to this package:
127+
128+
- [Chris Breuer](https://github.com/chrisbbreuer)
129+
- [Novu](https://novu.co/)
130+
- [All Contributors](../../contributors)
131+
132+
## 📄 License
133+
134+
The MIT License (MIT). Please see [LICENSE](https://github.com/stacksjs/stacks/tree/main/LICENSE.md) for more information.
135+
136+
Made with ❤️

.stacks/core/scheduler/package.json

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"name": "@stacksjs/scheduler",
3+
"type": "module",
4+
"version": "0.51.0",
5+
"packageManager": "pnpm@7.29.1",
6+
"description": "The Stacks scheduler.",
7+
"author": "Chris Breuer",
8+
"license": "MIT",
9+
"funding": "https://github.com/sponsors/chrisbbreuer",
10+
"homepage": "https://github.com/stacksjs/stacks/tree/main/.stacks/core/scheduler#readme",
11+
"repository": {
12+
"type": "git",
13+
"url": "git+https://github.com/stacksjs/stacks.git",
14+
"directory": "./.stacks/core/scheduler"
15+
},
16+
"bugs": {
17+
"url": "https://github.com/stacksjs/stacks/issues"
18+
},
19+
"keywords": [
20+
"scheduler",
21+
"stacks"
22+
],
23+
"module": "dist/index.mjs",
24+
"types": "dist/index.d.ts",
25+
"contributors": [
26+
"Chris Breuer <chris@ow3.org>"
27+
],
28+
"files": [
29+
"dist",
30+
"README.md"
31+
],
32+
"engines": {
33+
"node": ">=v18.15.0",
34+
"pnpm": ">=7.29.1"
35+
},
36+
"scripts": {
37+
"build": "mkdist -d",
38+
"dev": "mkdist -d",
39+
"prepublishOnly": "pnpm run build",
40+
"typecheck": "tsc --noEmit"
41+
},
42+
"peerDependencies": {
43+
"node-cron": "3.0.2"
44+
},
45+
"devDependencies": {
46+
"@stacksjs/testing": "workspace:*",
47+
"mkdist": "^1.1.2",
48+
"typescript": "^4.9.5"
49+
}
50+
}

.stacks/core/scheduler/src/index.ts

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
import cron from 'node-cron'
2+
3+
export interface Scheduler {
4+
everySecond: () => void
5+
everySeconds: (seconds: number) => void
6+
everyMinute: () => void
7+
everyMinutes: (minutes: number) => void
8+
everyTwoMinutes: () => void
9+
everyThreeMinutes: () => void
10+
everyFourMinutes: () => void
11+
everyFiveMinutes: () => void
12+
everyTenMinutes: () => void
13+
everyFifteenMinutes: () => void
14+
everyThirtyMinutes: () => void
15+
hourly: () => void
16+
hourlyAt: (minute: number) => void
17+
everyOddHour: () => void
18+
everyHours: (hours: number) => void
19+
everyTwoHours: () => void
20+
everyThreeHours: () => void
21+
everyFourHours: () => void
22+
everySixHours: () => void
23+
daily: () => void
24+
dailyAt: (hour: number, minute: number) => void
25+
everyDays: (days: number) => void
26+
weekly: () => void
27+
quarterly: () => void
28+
yearly: () => void
29+
cron: (interval: string) => void
30+
}
31+
32+
function run(callback: Function): Scheduler {
33+
return {
34+
everySecond: () => {
35+
cron.schedule('* * * * * *', callback)
36+
},
37+
everySeconds: (seconds = 1) => {
38+
cron.schedule(`*/${seconds} * * * * *`, callback)
39+
},
40+
everyMinute: () => {
41+
cron.schedule('* * * * *', callback)
42+
},
43+
everyTwoMinutes: () => {
44+
cron.schedule('*/2 * * * *', callback)
45+
},
46+
everyThreeMinutes: () => {
47+
cron.schedule('*/3 * * * *', callback)
48+
},
49+
everyFourMinutes: () => {
50+
cron.schedule('*/4 * * * *', callback)
51+
},
52+
everyFiveMinutes: () => {
53+
cron.schedule('*/5 * * * *', callback)
54+
},
55+
everyTenMinutes: () => {
56+
cron.schedule('*/10 * * * *', callback)
57+
},
58+
everyFifteenMinutes: () => {
59+
cron.schedule('*/15 * * * *', callback)
60+
},
61+
everyThirtyMinutes: () => {
62+
cron.schedule('*/30 * * * *', callback)
63+
},
64+
everyMinutes: (minutes: number) => {
65+
cron.schedule(`*/${minutes} * * * *`, callback)
66+
},
67+
hourly: () => {
68+
cron.schedule('0 * * * *', callback)
69+
},
70+
everyHours: (hours: number) => {
71+
cron.schedule(`0 */${hours} * * *`, callback)
72+
},
73+
hourlyAt: (minute: number) => {
74+
cron.schedule(`${minute} * * * *`, callback)
75+
},
76+
everyOddHour: () => {
77+
cron.schedule('0 */2 * * *', callback)
78+
},
79+
everyTwoHours: () => {
80+
cron.schedule('0 */2 * * *', callback)
81+
},
82+
everyThreeHours: () => {
83+
cron.schedule('0 */3 * * *', callback)
84+
},
85+
everyFourHours: () => {
86+
cron.schedule('0 */4 * * *', callback)
87+
},
88+
everySixHours: () => {
89+
cron.schedule('0 */6 * * *', callback)
90+
},
91+
dailyAt: (hour: number, minute: number) => {
92+
cron.schedule(`${minute} ${hour} * * *`, callback)
93+
},
94+
daily: () => {
95+
cron.schedule('0 0 * * *', callback)
96+
},
97+
everyDays: (days: number) => {
98+
cron.schedule(`0 0 */${days} * *`, callback)
99+
},
100+
weekly: () => {
101+
cron.schedule('0 0 * * 0', callback)
102+
},
103+
quarterly: () => {
104+
cron.schedule('0 0 1 */3 *', callback)
105+
},
106+
yearly: () => {
107+
cron.schedule('0 0 1 1 *', callback)
108+
},
109+
cron: (interval: string) => {
110+
cron.schedule(interval, callback)
111+
},
112+
}
113+
}
114+
115+
export function useScheduler() {
116+
return {
117+
run,
118+
}
119+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { assert, describe, test } from 'vitest'
2+
3+
describe('example test', () => {
4+
test('assert', () => {
5+
assert.equal(1, 1)
6+
})
7+
})

0 commit comments

Comments
 (0)