Skip to content

Commit e6b35e2

Browse files
committed
chore: wip
1 parent 145c5cb commit e6b35e2

File tree

8 files changed

+40
-22
lines changed

8 files changed

+40
-22
lines changed

.stacks/core/actions/src/helpers/utils.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as storage from '@stacksjs/storage'
22
import { italic, runCommand, runCommands } from '@stacksjs/cli'
33
import { log } from '@stacksjs/logging'
4-
import { actionsPath, functionsPath } from '@stacksjs/path'
4+
import * as p from '@stacksjs/path'
55
import { type ActionOptions, type StacksError, type SyncSubprocess } from '@stacksjs/types'
66
import { type Result, err, handleError } from '@stacksjs/error-handling'
77

@@ -36,14 +36,20 @@ export function runAction(action: string, options?: ActionOptions): Result<SyncS
3636
if (!hasAction(action))
3737
return err(handleError(`The specified action "${action}" does not exist`))
3838

39-
// we need to parse options here because they need to bw passed to the action
4039
const opts = parseOptions(options)
41-
const cmd = `bun --bun ${actionsPath(`${action}.ts ${opts}`)}`
40+
const path = p.relativeActionsPath(`${action}.ts`)
41+
const cmd = `bun --bun ${`${path} ${opts}`}`
4242

4343
if (options?.verbose)
4444
log.debug('Running action:', italic(action))
4545

46-
return runCommand(cmd, options)
46+
if (options?.cwd)
47+
return runCommand(cmd, options)
48+
49+
return runCommand(cmd, {
50+
cwd: p.projectPath(),
51+
...options
52+
})
4753
}
4854

4955
/**
@@ -63,14 +69,14 @@ export function runActions(actions: string[], options?: ActionOptions) {
6369
return err(`The specified action "${action}" does not exist`)
6470
}
6571

66-
const commands = actions.map(action => `bun ${actionsPath(`${action}.ts`)}`)
72+
const commands = actions.map(action => `bun ${p.actionsPath(`${action}.ts`)}`)
6773

6874
return runCommands(commands, options)
6975
}
7076

7177
export function hasAction(action: string) {
72-
if (storage.isFile(functionsPath(`actions/${action}.ts`)))
78+
if (storage.isFile(p.functionsPath(`actions/${action}.ts`)))
7379
return true
7480

75-
return storage.isFile(actionsPath(`${action}.ts`))
81+
return storage.isFile(p.actionsPath(`${action}.ts`))
7682
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import process from 'node:process'
2-
import { type CLI, type FreshOptions } from '@stacksjs/types'
2+
import type { CLI, FreshOptions } from '@stacksjs/types'
33
import { runAction } from '@stacksjs/actions'
44
import { intro, outro } from '@stacksjs/cli'
5+
import { projectPath } from '@stacksjs/path'
56
import { Action, ExitCode } from '@stacksjs/types'
67

78
export function fresh(buddy: CLI) {
@@ -18,7 +19,7 @@ export function fresh(buddy: CLI) {
1819
const result = runAction(Action.Fresh, options)
1920

2021
if (result.isErr()) {
21-
await outro('While running the `fresh` command, there was an issue', { startTime: perf, useSeconds: true, isError: true }, result.error as Error)
22+
await outro('While running the `fresh` command, there was an issue', { startTime: perf, useSeconds: true, isError: true }, result.error)
2223
process.exit(ExitCode.FatalError)
2324
}
2425

.stacks/core/cli/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@
3333
],
3434
"exports": {
3535
".": {
36-
"bun": "./src/index.ts"
36+
"bun": "./src/index.ts",
37+
"import": "./dist/index.js"
3738
},
3839
"./*": {
39-
"bun": "./*"
40+
"bun": "./*",
41+
"import": "./dist/*"
4042
}
4143
},
4244
"module": "dist/index.js",

.stacks/core/cli/src/helpers.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
/* eslint-disable no-console */
22
import { ExitCode, type IntroOptions, type OutroOptions } from '@stacksjs/types'
3+
import { handleError } from '@stacksjs/error-handling'
34
import { log } from '@stacksjs/logging'
45
import pkgjson from '../package.json'
56
import { spinner } from './spinner'
67
import { bgCyan, bold, cyan, dim, italic } from './utilities'
78

89
const { version } = pkgjson
910

10-
function isString(val: unknown): val is string {
11-
return typeof val === 'string'
12-
}
13-
1411
/**
1512
* Prints the intro message.
1613
*/
@@ -40,7 +37,7 @@ export function outro(text: string, options: OutroOptions, error?: Error | strin
4037
return new Promise((resolve) => {
4138
if (options.isError) {
4239
if (error)
43-
log.error(isString(error) ? new Error(error) : error)
40+
handleError(error)
4441
}
4542
else {
4643
if (options?.type === 'info')

.stacks/core/error-handling/src/handler.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@ import { italic, log } from '@stacksjs/cli'
88
export class ErrorHandler {
99
static logFile = logsPath('errors.log')
1010

11-
static handle(err: StacksError, options?: any) {
11+
static handle(err: string | StacksError, options?: any) {
12+
if (typeof err === 'string')
13+
err = new Error(err)
14+
1215
this.writeErrorToConsole(err, options)
1316
this.writeErrorToFile(err)
17+
1418
return err
1519
}
1620

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ export function actionsPath(path?: string) {
1919
return corePath(`actions/src/${path || ''}`)
2020
}
2121

22+
export function relativeActionsPath(path?: string) {
23+
return relative(projectPath(), actionsPath(path))
24+
}
25+
2226
/**
2327
* Returns the path to the `ai` directory. The AI directory
2428
* contains the core Stacks' AI logic which currently
@@ -411,6 +415,7 @@ export function xRayPath(path?: string) {
411415
export const path = {
412416
aiPath,
413417
actionsPath,
418+
relativeActionsPath,
414419
aliasPath,
415420
analyticsPath,
416421
arraysPath,

.stacks/tsconfig.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@
4040
"buddy/*": ["./core/buddy/src/*"],
4141
"eslint-plugin-stacks": ["./eslint-plugin-stacksjs/src/index.ts"],
4242
"eslint-plugin-stacksjs": ["./eslint-plugin-stacksjs/src/index.ts"],
43-
"~/app/*": ["../app/*"],
44-
"~/config/*": ["../config/*"],
43+
// "~/app/*": ["../app/*"],
44+
// "~/config/*": ["../config/*"],
4545
"~/components/*": ["../resources/components/*"],
4646
"~/functions/*": ["../resources/functions/*"],
47-
"~/lang/*": ["../lang/*"],
47+
// "~/lang/*": ["../lang/*"],
4848
"~/models/*": ["../app/models/*"],
49-
"~/resources/*": ["../resources/*"],
49+
// "~/resources/*": ["../resources/*"],
5050
"~/views/*": ["../resources/views/*"],
5151
"~/*": ["../*"]
5252
}
@@ -59,7 +59,10 @@
5959
},
6060
"include": [
6161
"./playwright.config.ts",
62-
"./**.d.ts",
62+
"../*.ts",
63+
"../*.d.ts",
64+
"../**/*.ts",
65+
"../**/*.d.ts",
6366
"./views/**/*",
6467
"./stacks/**/*",
6568
"./scripts/**/*",

bun.lockb

32 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)