@stacksjs/path 0.70.54 → 0.70.55

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/package.json +3 -2
  2. package/src/index.ts +1738 -0
package/src/index.ts ADDED
@@ -0,0 +1,1738 @@
1
+ import type { ParsedPath } from 'node:path'
2
+ import { existsSync } from 'node:fs'
3
+ import os from 'node:os'
4
+ import {
5
+ basename,
6
+ delimiter,
7
+ dirname,
8
+ extname,
9
+ isAbsolute,
10
+ join,
11
+ normalize,
12
+ parse,
13
+
14
+ relative,
15
+ resolve,
16
+ sep,
17
+ toNamespacedPath,
18
+ } from 'node:path'
19
+ import process from 'node:process'
20
+
21
+ // Lazy import logging to avoid circular dependency (logging imports path)
22
+ async function debugLog(message: string) {
23
+ try {
24
+ const { log } = await import('@stacksjs/logging')
25
+ log.debug(message)
26
+ }
27
+ catch {
28
+ // Logging not available, silently ignore
29
+ console.debug(message)
30
+ }
31
+ }
32
+
33
+ /**
34
+ * Returns the path to the `actions` directory. The `actions` directory
35
+ * contains the core Stacks' actions.
36
+ *
37
+ * @param path - The relative path to the file or directory.
38
+ * @returns The absolute path to the file or directory.
39
+ * @example
40
+ * ```ts
41
+ * import { actionsPath } from '@stacksjs/path'
42
+ *
43
+ * console.log(actionsPath('path/to/action.ts')) // Outputs the absolute path to 'path/to/action.ts' within the `actions` directory
44
+ * ```
45
+ */
46
+ export function actionsPath(path?: string): string {
47
+ return corePath(`actions/${path || ''}`)
48
+ }
49
+
50
+ export function relativeActionsPath(path?: string): string {
51
+ return relative(projectPath(), actionsPath(path))
52
+ }
53
+
54
+ export function userActionsPath(path?: string, options?: { relative: true }): string {
55
+ const absolutePath = appPath(`Actions/${path || ''}`)
56
+
57
+ if (options?.relative)
58
+ return relative(process.cwd(), absolutePath)
59
+
60
+ return absolutePath
61
+ }
62
+
63
+ export function builtUserActionsPath(path?: string, options?: { relative: boolean }): string {
64
+ const absolutePath = frameworkPath(`actions/${path || ''}`)
65
+
66
+ if (options?.relative)
67
+ return relative(process.cwd(), absolutePath)
68
+
69
+ return absolutePath
70
+ }
71
+
72
+ export function userComponentsPath(path?: string): string {
73
+ return libsPath(`components/${path || ''}`)
74
+ }
75
+
76
+ export function userViewsPath(path?: string): string {
77
+ return resourcesPath(`views/${path || ''}`)
78
+ }
79
+
80
+ export function userFunctionsPath(path?: string): string {
81
+ return `${resolveUserLibBase(projectPath('functions'), resourcesPath('functions'))}/${path || ''}`
82
+ }
83
+
84
+ /**
85
+ * Pick where a user lib folder (`components` / `functions`) lives
86
+ * (stacksjs/stacks#929). A root-level `<project>/components` (or
87
+ * `/functions`) folder wins when it exists; otherwise the conventional
88
+ * `resources/<name>`. Lets apps keep these at the project root without
89
+ * losing the `resources/`-nested default.
90
+ *
91
+ * Pure + injectable `exists` so the selection is unit-testable without
92
+ * touching the real filesystem.
93
+ */
94
+ export function resolveUserLibBase(
95
+ rootDir: string,
96
+ resourcesDir: string,
97
+ exists: (p: string) => boolean = existsSync,
98
+ ): string {
99
+ return exists(rootDir) ? rootDir : resourcesDir
100
+ }
101
+
102
+ /**
103
+ * Returns the path to the user-defined `Jobs` directory.
104
+ *
105
+ * @param path - The relative path to the file or directory within the `Jobs` directory.
106
+ * @returns The absolute path to the specified file or directory within the user-defined `Jobs` directory.
107
+ * @example
108
+ * ```ts
109
+ * import { userJobsPath } from '@stacksjs/path'
110
+ *
111
+ * console.log(userJobsPath('MyJob.ts')) // Outputs the absolute path to 'MyJob.ts' within the user-defined `Jobs` directory.
112
+ * ```
113
+ */
114
+ export function userJobsPath(path?: string): string {
115
+ return appPath(`Jobs/${path || ''}`)
116
+ }
117
+
118
+ /**
119
+ * Returns the path to the user-defined `Controllers` directory.
120
+ *
121
+ * @param path - The relative path to the file or directory within the `Controllers` directory.
122
+ * @returns The absolute path to the specified file or directory within the user-defined `Controllers` directory.
123
+ */
124
+ export function userControllersPath(path?: string): string {
125
+ return appPath(`Controllers/${path || ''}`)
126
+ }
127
+
128
+ /**
129
+ * Returns the path to the user-defined `Listeners` directory.
130
+ *
131
+ * @param path - The relative path to the file or directory within the `Listeners` directory.
132
+ * @returns The absolute path to the specified file or directory within the user-defined `Listeners` directory.
133
+ * @example
134
+ * ```ts
135
+ * import { userListenersPath } from '@stacksjs/path'
136
+ *
137
+ * console.log(userListenersPath('MyListener.ts')) // Outputs the absolute path to 'MyListener.ts' within the user-defined `Listeners` directory.
138
+ * ```
139
+ */
140
+ export function userListenersPath(path?: string): string {
141
+ return appPath(`Listeners/${path || ''}`)
142
+ }
143
+
144
+ /**
145
+ * Returns the path to the user-defined `Middleware` directory.
146
+ *
147
+ * @param path - The relative path to the file or directory within the Middleware directory.
148
+ * @returns The absolute path to the specified file or directory within the user-defined Middleware directory.
149
+ * @example
150
+ * ```ts
151
+ * import { userMiddlewarePath } from '@stacksjs/path'
152
+ *
153
+ * console.log(userMiddlewarePath('MyMiddleware.ts')) // Outputs the absolute path to 'MyMiddleware.ts' within the user-defined Middleware directory.
154
+ * ```
155
+ */
156
+ export function userMiddlewarePath(path?: string): string {
157
+ return appPath(`Middleware/${path || ''}`)
158
+ }
159
+
160
+ /**
161
+ * Returns the path to the user-defined `Models` directory.
162
+ *
163
+ * @param path - The relative path to the file or directory within the `Models` directory.
164
+ * @returns The absolute path to the specified file or directory within the user-defined `Models` directory.
165
+ * @example
166
+ * ```ts
167
+ * import { userModelsPath } from '@stacksjs/path'
168
+ *
169
+ * console.log(userModelsPath('MyModel.ts')) // Outputs the absolute path to 'MyModel.ts' within the user-defined `Models` directory.
170
+ * ```
171
+ */
172
+ export function userModelsPath(path?: string): string {
173
+ return appPath(`Models/${path || ''}`)
174
+ }
175
+
176
+ /**
177
+ * Returns the path to the user-defined `Notifications` directory.
178
+ *
179
+ * @param path - The relative path to the file or directory within the `Notifications` directory.
180
+ * @returns The absolute path to the specified file or directory within the user-defined `Notifications` directory.
181
+ * @example
182
+ * ```ts
183
+ * import { userNotificationsPath } from '@stacksjs/path'
184
+ *
185
+ * console.log(userNotificationsPath('MyNotification.ts')) // Outputs the absolute path to 'MyNotification.ts' within the user-defined `Notifications` directory.
186
+ * ```
187
+ */
188
+ export function userNotificationsPath(path?: string): string {
189
+ return appPath(`Notifications/${path || ''}`)
190
+ }
191
+
192
+ /**
193
+ * Returns the path to the user-defined `Mail` directory.
194
+ *
195
+ * Mailable classes live here, one file per email type. The companion
196
+ * stx template lives in `resources/emails/<kebab-name>.stx` and is
197
+ * resolved by `@stacksjs/email`'s template loader at send time.
198
+ *
199
+ * @param path - The relative path to the file or directory within the `Mail` directory.
200
+ * @returns The absolute path to the specified file or directory within the user-defined `Mail` directory.
201
+ * @example
202
+ * ```ts
203
+ * import { userMailPath } from '@stacksjs/path'
204
+ *
205
+ * console.log(userMailPath('Welcome.ts')) // Outputs the absolute path to 'Welcome.ts' within the user-defined `Mail` directory.
206
+ * ```
207
+ */
208
+ export function userMailPath(path?: string): string {
209
+ return appPath(`Mail/${path || ''}`)
210
+ }
211
+
212
+ /**
213
+ * Returns the path to the user-defined `resources/emails` directory
214
+ * where stx email templates live. The make:mail scaffolder writes a
215
+ * companion stx file alongside each Mailable class.
216
+ */
217
+ export function userEmailsPath(path?: string): string {
218
+ return resourcesPath(`emails/${path || ''}`)
219
+ }
220
+
221
+ export function userDatabasePath(path?: string): string {
222
+ return projectPath(`database/${path || ''}`)
223
+ }
224
+
225
+ export function userMigrationsPath(path?: string): string {
226
+ return userDatabasePath(`migrations/${path || ''}`)
227
+ }
228
+
229
+ /**
230
+ * Returns the path to the user-defined `Events.ts` file.
231
+ *
232
+ * @returns The absolute path to the `Events.ts` file within the user-defined directory.
233
+ * @example
234
+ * ```ts
235
+ * import { userEventsPath } from '@stacksjs/path'
236
+ *
237
+ * console.log(userEventsPath()) // Outputs the absolute path to 'Events.ts' within the user-defined directory.
238
+ * ```
239
+ */
240
+ export function userEventsPath(): string {
241
+ return appPath(`Events.ts`)
242
+ }
243
+
244
+ /**
245
+ * Returns the path to the `ai` directory. The AI directory
246
+ * contains the core Stacks' AI logic which currently
247
+ * is a wrapper of the OpenAI API.
248
+ *
249
+ * @param path - relative path to the file or directory
250
+ * @returns string - absolute path to the file or directory
251
+ *
252
+ * @example
253
+ * ```ts
254
+ * import { aiPath } from '@stacksjs/path'
255
+ *
256
+ * console.log(aiPath('src/drivers/example.ts')) // Outputs the absolute path to 'openai.ts' within the AI directory
257
+ * ```
258
+ */
259
+ export function aiPath(path?: string): string {
260
+ return corePath(`ai/${path || ''}`)
261
+ }
262
+
263
+ /**
264
+ * Returns the path to the `assets` directory within the `resources` directory.
265
+ *
266
+ * @param path - The relative path to the file or directory within the `assets` directory.
267
+ * @returns The absolute path to the specified file or directory within the `assets` directory.
268
+ * @example
269
+ * ```ts
270
+ * import { assetsPath } from '@stacksjs/path'
271
+ *
272
+ * console.log(assetsPath('images/logo.png')) // Outputs the absolute path to 'images/logo.png' within the `assets` directory.
273
+ * ```
274
+ */
275
+ export function assetsPath(path?: string): string {
276
+ return resourcesPath(`assets/${path || ''}`)
277
+ }
278
+
279
+ /**
280
+ * Returns the path to the `alias` directory within the core directory.
281
+ *
282
+ * @returns The absolute path to the `alias` directory.
283
+ * @example
284
+ * ```ts
285
+ * import { aliasPath } from '@stacksjs/path'
286
+ *
287
+ * console.log(aliasPath()) // Outputs the absolute path to the `alias` directory.
288
+ * ```
289
+ */
290
+ export function aliasPath(): string {
291
+ return corePath('alias/src/index.ts')
292
+ }
293
+
294
+ /**
295
+ * Returns the path to the `buddy` directory, optionally relative to the current working directory.
296
+ *
297
+ * @param path - The relative path to the file or directory within the buddy directory.
298
+ * @param options - Optional. An object containing configuration settings.
299
+ * @param options.relative - If true, returns the path relative to the current working directory.
300
+ * @returns The absolute or relative path to the specified file or directory within the buddy * @returns The absolute or relative path to the specified file or directory within the buddy directory.
301
+ * @example
302
+ * ```ts
303
+ * import { buddyPath } from '@stacksjs/path'
304
+ *
305
+ * console.log(buddyPath('config/buddy.json')) // Outputs the absolute path to 'config/buddy.json' within the buddy directory.
306
+ * console.log(buddyPath('config/buddy.json', { relative: true })) // Outputs the relative path to 'config/buddy.json' within the buddy directory.
307
+ * ```
308
+ */
309
+ export function buddyPath(path?: string, options?: { relative?: boolean }): string {
310
+ const absolutePath = corePath(`buddy/${path || ''}`)
311
+
312
+ if (options?.relative)
313
+ return relative(process.cwd(), absolutePath)
314
+
315
+ return absolutePath
316
+ }
317
+
318
+ /**
319
+ * Returns the path to the `runtime` directory within the framework directory.
320
+ *
321
+ * @param path - The relative path to the file or directory within the runtime directory.
322
+ * @returns The absolute path to the specified file or directory within the runtime directory.
323
+ * @example
324
+ * ```ts
325
+ * import { runtimePath } from '@stacksjs/path'
326
+ *
327
+ * console.log(runtimePath('runtime-config.json')) // Outputs the absolute path to 'runtime-config.json' within the runtime directory.
328
+ * ```
329
+ */
330
+ export function runtimePath(path?: string): string {
331
+ return frameworkPath(`buddy/${path || ''}`)
332
+ }
333
+
334
+ /**
335
+ * Returns the path to the `analytics` directory within the core directory.
336
+ *
337
+ * @param path - The relative path to the file or directory within the `analytics` directory.
338
+ * @returns The absolute path to the specified file or directory within the `analytics` directory.
339
+ * @example
340
+ * ```ts
341
+ * import { analyticsPath } from '@stacksjs/path'
342
+ *
343
+ * console.log(analyticsPath('data/report.csv')) // Outputs the absolute path to 'data/report.csv' within the `analytics` directory.
344
+ * ```
345
+ */
346
+ export function analyticsPath(path?: string): string {
347
+ return corePath(`analytics/${path || ''}`)
348
+ }
349
+
350
+ /**
351
+ * Returns the path to the `arrays` directory within the core directory.
352
+ *
353
+ * @param path - The relative path to the file or directory within the `arrays` directory.
354
+ * @returns The absolute path to the specified file or directory within the `arrays` directory.
355
+ * @example
356
+ * ```ts
357
+ * import { arraysPath } from '@stacksjs/path'
358
+ *
359
+ * console.log(arraysPath('list.txt')) // Outputs the absolute path to 'list.txt' within the `arrays` directory.
360
+ * ```
361
+ */
362
+ export function arraysPath(path?: string): string {
363
+ return corePath(`arrays/${path || ''}`)
364
+ }
365
+
366
+ /**
367
+ * Returns the path to the `app` directory, optionally relative to the project directory.
368
+ *
369
+ * @param path - The relative path to the file or directory within the app directory.
370
+ * @returns The absolute path to the specified file or directory within the app directory.
371
+ * @example
372
+ * ```ts
373
+ * import { appPath } from '@stacksjs/path'
374
+ *
375
+ * console.log(appPath('Actions/DummyAction.ts')) // Outputs the absolute path to 'Actions/DummyAction.ts' within the app directory.
376
+ * ```
377
+ */
378
+ export function appPath(path?: string, options?: { relative?: boolean, cwd?: string }): string {
379
+ const absolutePath = projectPath(`app/${path || ''}`)
380
+
381
+ if (options?.relative)
382
+ return relative(options.cwd || process.cwd(), absolutePath)
383
+
384
+ return absolutePath
385
+ }
386
+
387
+ /**
388
+ * Returns the path to the defaults `app` directory within the framework directory.
389
+ * This is where default Actions, Controllers, etc. are stored.
390
+ *
391
+ * @param path - The relative path to the file or directory within the defaults app directory.
392
+ * @returns The absolute path to the specified file or directory within the defaults app directory.
393
+ */
394
+ export function defaultsAppPath(path?: string): string {
395
+ return frameworkPath(`defaults/app/${path || ''}`)
396
+ }
397
+
398
+ /**
399
+ * Returns the path to the defaults `resources` directory within the framework directory.
400
+ * This is where default views, components, layouts, etc. are stored.
401
+ *
402
+ * @param path - The relative path to the file or directory within the defaults resources directory.
403
+ * @returns The absolute path to the specified file or directory within the defaults resources directory.
404
+ */
405
+ export function defaultsResourcesPath(path?: string): string {
406
+ return frameworkPath(`defaults/resources/${path || ''}`)
407
+ }
408
+
409
+ /**
410
+ * Returns the path to the `auth` directory within the core directory.
411
+ *
412
+ * @param path - The relative path to the file or directory within the auth directory.
413
+ * @returns The absolute path to the specified file or directory within the auth directory.
414
+ * @example
415
+ * ```ts
416
+ * import { authPath } from '@stacksjs/path'
417
+ *
418
+ * console.log(authPath('login.ts')) // Outputs the absolute path to 'login.ts' within the auth directory.
419
+ * ```
420
+ */
421
+ export function authPath(path?: string): string {
422
+ return corePath(`auth/${path || ''}`)
423
+ }
424
+
425
+ /**
426
+ * Returns the path to the `auth` directory within the core directory.
427
+ *
428
+ * @param path - The relative path to the file or directory within the auth directory.
429
+ * @returns The absolute path to the specified file or directory within the auth directory.
430
+ * @example
431
+ * ```ts
432
+ * import { coreApiPath } from '@stacksjs/path'
433
+ *
434
+ * console.log(coreApiPath('login.ts')) // Outputs the absolute path to 'login.ts' within the auth directory.
435
+ * ```
436
+ */
437
+ export function coreApiPath(path?: string): string {
438
+ return corePath(`api/${path || ''}`)
439
+ }
440
+
441
+ /**
442
+ * Returns the path to the build directory. The build directory
443
+ * contains Stacks' build engine & its tooling integrations.
444
+ *
445
+ * @param path string - relative path to the file or directory
446
+ * @returns string - absolute path to the file or directory
447
+ * @example
448
+ * ```ts
449
+ * buildPath('functions.stx')
450
+ * buildPath('components.ts')
451
+ * ```
452
+ */
453
+ export function buildPath(path?: string): string {
454
+ return corePath(`build/${path || ''}`)
455
+ }
456
+
457
+ /**
458
+ * Returns the path to the build engine directory.
459
+ *
460
+ * @param path - The relative path to the file or directory within the build engine directory.
461
+ * @returns The absolute path to the specified file or directory within the build engine directory.
462
+ */
463
+ export function buildEnginePath(path?: string): string {
464
+ return buildPath(`${path || ''}`)
465
+ }
466
+
467
+ /**
468
+ * Returns the path to the `libs` directory within the framework directory.
469
+ *
470
+ * @param path - The relative path to the file or directory within the `libs` directory.
471
+ * @returns The absolute path to the specified file or directory within the `libs` directory.
472
+ */
473
+ export function libsPath(path?: string): string {
474
+ return frameworkPath(`libs/${path || ''}`)
475
+ }
476
+
477
+ /**
478
+ * Returns the path to the user `libs` directory within the root project directory.
479
+ *
480
+ * @param path - The relative path to the file or directory within the `libs` directory.
481
+ * @returns The absolute path to the specified file or directory within the `libs` directory.
482
+ */
483
+ export function userLibsPath(path?: 'components' | 'functions' | string): string {
484
+ return resourcesPath(`${path || ''}`)
485
+ }
486
+
487
+ /**
488
+ * Returns the path to the `entries` directory within the `libs` directory.
489
+ *
490
+ * @param path - The relative path to the file or directory within the `entries` directory.
491
+ * @returns The absolute path to the specified file or directory within the `entries` directory.
492
+ */
493
+ export function libsEntriesPath(path?: string): string {
494
+ return libsPath(`entries/${path || ''}`)
495
+ }
496
+
497
+ /**
498
+ * Returns the path to the `cache` directory within the core directory.
499
+ *
500
+ * @param path - The relative path to the file or directory within the cache directory.
501
+ * @returns The absolute path to the specified file or directory within the cache directory.
502
+ */
503
+ export function cachePath(path?: string): string {
504
+ return corePath(`cache/${path || ''}`)
505
+ }
506
+
507
+ /**
508
+ * Returns the path to the `chat` directory within the core directory.
509
+ *
510
+ * @param path - The relative path to the file or directory within the chat directory.
511
+ * @returns The absolute path to the specified file or directory within the chat directory.
512
+ */
513
+ export function chatPath(path?: string): string {
514
+ return corePath(`chat/${path || ''}`)
515
+ }
516
+
517
+ /**
518
+ * Returns the path to the `charts` directory within the core directory.
519
+ *
520
+ * @param path - The relative path to the file or directory within the charts directory.
521
+ * @returns The absolute path to the specified file or directory within the charts directory.
522
+ */
523
+ export function chartsPath(path?: string): string {
524
+ return corePath(`charts/${path || ''}`)
525
+ }
526
+
527
+ /**
528
+ * Returns the path to the `cli` directory within the core directory.
529
+ *
530
+ * @param path - The relative path to the file or directory within the cli directory.
531
+ * @returns The absolute path to the specified file or directory within the cli directory.
532
+ */
533
+ export function cliPath(path?: string): string {
534
+ return corePath(`cli/${path || ''}`)
535
+ }
536
+
537
+ /**
538
+ * Returns the path to the `cloud` directory within the core directory.
539
+ *
540
+ * @param path - The relative path to the file or directory within the cloud directory.
541
+ * @returns The absolute path to the specified file or directory within the cloud directory.
542
+ */
543
+ export function cloudPath(path?: string): string {
544
+ return corePath(`cloud/${path || ''}`)
545
+ }
546
+
547
+ /**
548
+ * Returns the path to the `cloud` directory within the framework directory.
549
+ *
550
+ * @param path - The relative path to the file or directory within the framework cloud directory.
551
+ * @returns The absolute path to the specified file or directory within the framework cloud directory.
552
+ */
553
+ export function frameworkCloudPath(path?: string): string {
554
+ return frameworkPath(`cloud/${path || ''}`)
555
+ }
556
+
557
+ /**
558
+ * Returns the path to the `collections` directory within the core directory.
559
+ *
560
+ * @param path - The relative path to the file or directory within the `collections` directory.
561
+ * @returns The absolute path to the specified file or directory within the `collections` directory.
562
+ */
563
+ export function collectionsPath(path?: string): string {
564
+ return corePath(`collections/${path || ''}`)
565
+ }
566
+
567
+ /**
568
+ * Returns the path to the `Commands` directory within the app directory.
569
+ *
570
+ * @param path - The relative path to the file or directory within the `Commands` directory.
571
+ * @returns The absolute path to the specified file or directory within the `Commands` directory.
572
+ */
573
+ export function commandsPath(path?: string): string {
574
+ return appPath(`Commands/${path || ''}`)
575
+ }
576
+
577
+ /**
578
+ * Returns the path to the `components` directory within the `resources` directory.
579
+ *
580
+ * @param path - The relative path to the file or directory within the `components` directory.
581
+ * @returns The absolute path to the specified file or directory within the `components` directory.
582
+ */
583
+ export function componentsPath(path?: string): string {
584
+ // Root-level `components/` wins when present, else `resources/components`
585
+ // (stacksjs/stacks#929).
586
+ return `${resolveUserLibBase(projectPath('components'), resourcesPath('components'))}/${path || ''}`
587
+ }
588
+
589
+ /**
590
+ * Returns the path to the `config` directory within the core directory.
591
+ *
592
+ * @param path - The relative path to the file or directory within the config directory.
593
+ * @returns The absolute path to the specified file or directory within the config directory.
594
+ */
595
+ export function configPath(path?: string): string {
596
+ return corePath(`config/${path || ''}`)
597
+ }
598
+
599
+ /**
600
+ * Returns the path to the `core` directory within the framework directory.
601
+ *
602
+ * @param path - The relative path to the file or directory within the core directory.
603
+ * @returns The absolute path to the specified file or directory within the core directory.
604
+ */
605
+ export function corePath(path?: string): string {
606
+ return frameworkPath(`core/${path || ''}`)
607
+ }
608
+
609
+ /**
610
+ * Returns the absolute path to the `custom-elements.json` file within the core directory.
611
+ *
612
+ * @returns The absolute path to the `custom-elements.json` file.
613
+ */
614
+ export function customElementsDataPath(): string {
615
+ return frameworkPath('core/custom-elements.json')
616
+ }
617
+
618
+ /**
619
+ * Returns the path to the `database` directory within the core directory.
620
+ *
621
+ * @param path - The relative path to the file or directory within the database directory.
622
+ * @returns The absolute path to the specified file or directory within the database directory.
623
+ */
624
+ export function databasePath(path?: string): string {
625
+ return corePath(`database/${path || ''}`)
626
+ }
627
+
628
+ /**
629
+ * Returns the path to the `datetime` directory within the core directory.
630
+ *
631
+ * @param path - The relative path to the file or directory within the datetime directory.
632
+ * @returns The absolute path to the specified file or directory within the datetime directory.
633
+ */
634
+ export function datetimePath(path?: string): string {
635
+ return corePath(`datetime/${path || ''}`)
636
+ }
637
+
638
+ /**
639
+ * Returns the path to the `development` directory within the core directory.
640
+ *
641
+ * @param path - The relative path to the file or directory within the development directory.
642
+ * @returns The absolute path to the specified file or directory within the development directory.
643
+ */
644
+ export function developmentPath(path?: string): string {
645
+ return corePath(`development/${path || ''}`)
646
+ }
647
+
648
+ /**
649
+ * Returns the path to the `desktop` directory within the core directory.
650
+ *
651
+ * @param path - The relative path to the file or directory within the desktop directory.
652
+ * @returns The absolute path to the specified file or directory within the desktop directory.
653
+ */
654
+ export function desktopPath(path?: string): string {
655
+ return corePath(`desktop/${path || ''}`)
656
+ }
657
+
658
+ /**
659
+ * Returns the path to the `docs` directory within the core directory.
660
+ *
661
+ * @param path - The relative path to the file or directory within the `docs` directory.
662
+ * @returns The absolute path to the specified file or directory within the `docs` directory.
663
+ */
664
+ export function docsPath(path?: string): string {
665
+ return corePath(`docs/${path || ''}`)
666
+ }
667
+
668
+ /**
669
+ * Returns the path to the `domains` directory within the core directory.
670
+ *
671
+ * @param path - The relative path to the file or directory within the `domains` directory.
672
+ * @returns The absolute path to the specified file or directory within the `domains` directory.
673
+ */
674
+ export function dnsPath(path?: string): string {
675
+ return corePath(`domains/${path || ''}`)
676
+ }
677
+
678
+ /**
679
+ * Returns the path to the `email` directory within the `notifications` directory.
680
+ *
681
+ * @param path - The relative path to the file or directory within the email directory.
682
+ * @returns The absolute path to the specified file or directory within the email directory.
683
+ */
684
+ export function emailPath(path?: string): string {
685
+ return notificationsPath(`email/${path || ''}`)
686
+ }
687
+
688
+ /**
689
+ * Returns the path to the `enums` directory within the core directory.
690
+ *
691
+ * @param path - The relative path to the file or directory within the `enums` directory.
692
+ * @returns The absolute path to the specified file or directory within the `enums` directory.
693
+ */
694
+ export function enumsPath(path?: string): string {
695
+ return corePath(`enums/${path || ''}`)
696
+ }
697
+
698
+ /**
699
+ * Returns the path to the `eslint-plugin` directory within the core directory.
700
+ *
701
+ * @param path - The relative path to the file or directory within the eslint-plugin directory.
702
+ * @returns The absolute path to the specified file or directory within the eslint-plugin directory.
703
+ */
704
+ export function eslintPluginPath(path?: string): string {
705
+ return corePath(`eslint-plugin/${path || ''}`)
706
+ }
707
+
708
+ /**
709
+ * Returns the path to the `error-handling` directory within the core directory.
710
+ *
711
+ * @param path - The relative path to the file or directory within the error-handling directory.
712
+ * @returns The absolute path to the specified file or directory within the error-handling directory.
713
+ */
714
+ export function errorHandlingPath(path?: string): string {
715
+ return corePath(`error-handling/${path || ''}`)
716
+ }
717
+
718
+ /**
719
+ * Returns the path to the `events` directory within the core directory.
720
+ *
721
+ * @param path - The relative path to the file or directory within the `events` directory.
722
+ * @returns The absolute path to the specified file or directory within the `events` directory.
723
+ */
724
+ export function eventsPath(path?: string): string {
725
+ return corePath(`events/${path || ''}`)
726
+ }
727
+
728
+ /**
729
+ * Returns the path to the `env` directory within the core directory.
730
+ *
731
+ * @param path - The relative path to the file or directory within the env directory.
732
+ * @returns The absolute path to the specified file or directory within the env directory.
733
+ */
734
+ export function coreEnvPath(path?: string): string {
735
+ return corePath(`env/${path || ''}`)
736
+ }
737
+
738
+ /**
739
+ * Returns the path to the `examples` directory within the framework directory, filtered by type.
740
+ *
741
+ * @param type - The type of examples to filter by ('web-components').
742
+ * @returns The absolute path to the specified type of examples within the `examples` directory.
743
+ */
744
+ export function examplesPath(type?: 'web-components'): string {
745
+ return frameworkPath(`examples/${type || ''}`)
746
+ }
747
+
748
+ /**
749
+ * Returns the path to the `faker` directory within the core directory.
750
+ *
751
+ * @param path - The relative path to the file or directory within the faker directory.
752
+ * @returns The absolute path to the specified file or directory within the faker directory.
753
+ */
754
+ export function fakerPath(path?: string): string {
755
+ return corePath(`faker/${path || ''}`)
756
+ }
757
+
758
+ /**
759
+ * Returns the path to the framework directory, optionally relative to the current working directory.
760
+ *
761
+ * @param path - The relative path to the file or directory within the framework directory.
762
+ * @param options - Optional. An object containing configuration settings.
763
+ * @param options.relative - If true, returns the path relative to the current working directory.
764
+ * @param options.cwd - Specifies a custom working directory.
765
+ * @returns The absolute or relative path to the specified file or directory within the framework directory.
766
+ */
767
+ export function frameworkPath(path?: string, options?: { relative?: boolean, cwd?: string }): string {
768
+ const absolutePath = storagePath(`framework/${path || ''}`)
769
+
770
+ if (options?.relative)
771
+ return relative(options.cwd || process.cwd(), absolutePath)
772
+
773
+ return absolutePath
774
+ }
775
+
776
+ /**
777
+ * Returns the path to the `frontend` directory within the core directory.
778
+ *
779
+ * @param path - The relative path to the file or directory within the health directory.
780
+ * @returns The absolute path to the specified file or directory within the health directory.
781
+ */
782
+ export function browserPath(path?: string): string {
783
+ return corePath(`browser/${path || ''}`)
784
+ }
785
+
786
+ /**
787
+ * Returns the path to the `health` directory within the core directory.
788
+ *
789
+ * @param path - The relative path to the file or directory within the health directory.
790
+ * @returns The absolute path to the specified file or directory within the health directory.
791
+ */
792
+ export function healthPath(path?: string): string {
793
+ return corePath(`health/${path || ''}`)
794
+ }
795
+
796
+ /**
797
+ * Returns the path to the `functions` directory within the `resources` directory.
798
+ *
799
+ * @param path - The relative path to the file or directory within the `functions` directory.
800
+ * @returns The absolute path to the specified file or directory within the `functions` directory.
801
+ */
802
+ export function functionsPath(path?: string): string {
803
+ // Root-level `functions/` wins when present, else `resources/functions`
804
+ // (stacksjs/stacks#929).
805
+ return `${resolveUserLibBase(projectPath('functions'), resourcesPath('functions'))}/${path || ''}`
806
+ }
807
+
808
+ /**
809
+ * Returns the path to the `git` directory within the core directory.
810
+ *
811
+ * @param path - The relative path to the file or directory within the git directory.
812
+ * @returns The absolute path to the specified file or directory within the git directory.
813
+ */
814
+ export function gitPath(path?: string): string {
815
+ return corePath(`git/${path || ''}`)
816
+ }
817
+
818
+ /**
819
+ * Returns the path to the `lang` directory, optionally relative to the project directory.
820
+ *
821
+ * @param path - The relative path to the file or directory within the lang directory.
822
+ * @returns The absolute path to the specified file or directory within the lang directory.
823
+ */
824
+ export function langPath(path?: string): string {
825
+ return resourcesPath(`lang/${path || ''}`)
826
+ }
827
+
828
+ /**
829
+ * Returns the path to the `layouts` directory within the `resources` directory, optionally relative to the current working directory.
830
+ *
831
+ * @param path - The relative path to the file or directory within the `layouts` directory.
832
+ * @param options - Optional. An object containing configuration settings.
833
+ * @param options.relative - If true, returns the path relative to the current working directory.
834
+ * @param options.defaults - If true, returns the path to the `defaults/layouts` directory.
835
+ * @returns The absolute or relative path to the specified file or directory within the `layouts` directory.
836
+ */
837
+ export function layoutsPath(path?: string, options?: { relative?: boolean, defaults?: boolean }): string {
838
+ let absolutePath
839
+ if (options?.defaults)
840
+ absolutePath = frameworkPath(`defaults/resources/layouts/${path || ''}`)
841
+ else
842
+ absolutePath = resourcesPath(`layouts/${path || ''}`)
843
+
844
+ if (options?.relative)
845
+ return relative(process.cwd(), absolutePath)
846
+
847
+ return absolutePath
848
+ }
849
+
850
+ /**
851
+ * Returns the path to the library entry file, filtered by library type.
852
+ *
853
+ * @param type - The type of library ('web-components', or 'functions').
854
+ * @returns The absolute path to the specified library entry file.
855
+ */
856
+ export type LibraryType = 'web-components' | 'functions'
857
+ export function libraryEntryPath(type: LibraryType): string {
858
+ return libsEntriesPath(`${type}.ts`)
859
+ }
860
+
861
+ /**
862
+ * Returns the path to the `lint` directory within the core directory.
863
+ *
864
+ * @param path - The relative path to the file or directory within the lint directory.
865
+ * @returns The absolute path to the specified file or directory within the lint directory.
866
+ */
867
+ export function lintPath(path?: string): string {
868
+ return corePath(`lint/${path || ''}`)
869
+ }
870
+
871
+ /**
872
+ * Returns the path to the `listeners` directory within the app directory.
873
+ *
874
+ * @param path - The relative path to the file or directory within the `listeners` directory.
875
+ * @returns The absolute path to the specified file or directory within the `listeners` directory.
876
+ */
877
+ export function listenersPath(path?: string): string {
878
+ return appPath(`Listeners/${path || ''}`)
879
+ }
880
+
881
+ /**
882
+ * Returns the path to the `jobs` directory within the app directory.
883
+ *
884
+ * @param path - The relative path to the file or directory within the `jobs` directory.
885
+ * @returns The absolute path to the specified file or directory within the `jobs` directory.
886
+ */
887
+ export function jobsPath(path?: string): string {
888
+ return appPath(`Jobs/${path || ''}`)
889
+ }
890
+
891
+ /**
892
+ * Returns the path to the `logging` directory within the core directory.
893
+ *
894
+ * @param path - The relative path to the file or directory within the logging directory.
895
+ * @returns The absolute path to the specified file or directory within the logging directory.
896
+ */
897
+ export function loggingPath(path?: string): string {
898
+ return corePath(`logging/${path || ''}`)
899
+ }
900
+
901
+ /**
902
+ * Returns the path to the `logs` directory within the project storage directory.
903
+ *
904
+ * @param path - The relative path to the file or directory within the `logs` directory.
905
+ * @returns The absolute path to the specified file or directory within the `logs` directory.
906
+ */
907
+ export function logsPath(path?: string): string {
908
+ return storagePath(`logs/${path || ''}`)
909
+ }
910
+
911
+ /**
912
+ * Returns the path to the `models` directory within the app directory.
913
+ *
914
+ * @param path - The relative path to the file or directory within the `models` directory.
915
+ * @returns The absolute path to the specified file or directory within the `models` directory.
916
+ */
917
+ export function modelsPath(path?: string): string {
918
+ return appPath(`models/${path || ''}`)
919
+ }
920
+
921
+ /**
922
+ * Returns the path to the `modules` directory within the `resources` directory.
923
+ *
924
+ * @param path - The relative path to the file or directory within the `modules` directory.
925
+ * @returns The absolute path to the specified file or directory within the `modules` directory.
926
+ */
927
+ export function modulesPath(path?: string): string {
928
+ return resourcesPath(`modules/${path || ''}`)
929
+ }
930
+
931
+ /**
932
+ * Returns the path to the `notifications` directory within the core directory.
933
+ *
934
+ * @param path - The relative path to the file or directory within the `notifications` directory.
935
+ * @returns The absolute path to the specified file or directory within the `notifications` directory.
936
+ */
937
+ export function notificationsPath(path?: string): string {
938
+ return corePath(`notifications/${path || ''}`)
939
+ }
940
+
941
+ /**
942
+ * Returns the path to the `newsletter` directory within the core directory.
943
+ *
944
+ * @param path - The relative path to the file or directory within the `newsletter` directory.
945
+ * @returns The absolute path to the specified file or directory within the `newsletter` directory.
946
+ */
947
+ export function newsletterPath(path?: string): string {
948
+ return corePath(`newsletter/${path || ''}`)
949
+ }
950
+
951
+ /**
952
+ * Returns the path to the `orm` directory within the core directory.
953
+ *
954
+ * @param path - The relative path to the file or directory within the orm directory.
955
+ * @returns The absolute path to the specified file or directory within the orm directory.
956
+ */
957
+ export function ormPath(path?: string): string {
958
+ return corePath(`orm/${path || ''}`)
959
+ }
960
+
961
+ /**
962
+ * Returns the path to the `objects` directory within the core directory.
963
+ *
964
+ * @param path - The relative path to the file or directory within the `objects` directory.
965
+ * @returns The absolute path to the specified file or directory within the `objects` directory.
966
+ */
967
+ export function objectsPath(path?: string): string {
968
+ return corePath(`objects/${path || ''}`)
969
+ }
970
+
971
+ /**
972
+ * Returns the default path to the onboarding views within the project directory, or a specified path.
973
+ *
974
+ * @param path - The relative path to the file or directory within the project directory. Defaults to 'views/dashboard/onboarding'.
975
+ * @returns The absolute path to the specified file or directory within the project directory.
976
+ */
977
+ export function onboardingPath(path?: string): string {
978
+ return projectPath(`${path || 'views/dashboard/onboarding'}`)
979
+ }
980
+
981
+ /**
982
+ * Returns the path to the `package.json` file of a specified library type within the framework directory.
983
+ *
984
+ * @param type - The type of the library ('web-components', or 'functions') for which to return the package.json path.
985
+ * @returns The absolute path to the specified package.json file within the framework directory.
986
+ */
987
+ export function packageJsonPath(type: LibraryType): string {
988
+ if (type === 'web-components')
989
+ return frameworkPath('libs/components/web/package.json')
990
+
991
+ return frameworkPath(`libs/${type}/package.json`)
992
+ }
993
+
994
+ /**
995
+ * Returns the path to the `views` directory within the `resources` directory.
996
+ *
997
+ * @param path - The relative path to the file or directory within the `views` directory.
998
+ * @returns The absolute path to the specified file or directory within the `views` directory.
999
+ */
1000
+ export function viewsPath(path?: string): string {
1001
+ return resourcesPath(`views/${path || ''}`)
1002
+ }
1003
+
1004
+ /**
1005
+ * Returns the path to the `path` directory within the core directory.
1006
+ *
1007
+ * @param path - The relative path to the file or directory within the path directory.
1008
+ * @returns The absolute path to the specified file or directory within the path directory.
1009
+ */
1010
+ export function pathPath(path?: string): string {
1011
+ return corePath(`path/${path || ''}`)
1012
+ }
1013
+
1014
+ /**
1015
+ * Returns the path to the `payments` directory within the core directory.
1016
+ *
1017
+ * @param path - The relative path to the file or directory within the `payments` directory.
1018
+ * @returns The absolute path to the specified file or directory within the `payments` directory.
1019
+ */
1020
+ export function paymentsPath(path?: string): string {
1021
+ return corePath(`payments/${path || ''}`)
1022
+ }
1023
+
1024
+ /**
1025
+ * Returns the project path, resolving from the current working directory and moving up until the storage directory is no longer part of the path.
1026
+ *
1027
+ * @param filePath - The relative path to append to the project path. Defaults to an empty string.
1028
+ * @returns The absolute path to the specified file or directory within the project directory.
1029
+ */
1030
+ export function projectPath(filePath = '', options?: { relative: boolean }): string {
1031
+ let path = process.cwd()
1032
+
1033
+ while (path.includes('storage')) {
1034
+ const parent = resolve(path, '..')
1035
+ if (parent === path) break
1036
+ path = parent
1037
+ }
1038
+
1039
+ const finalPath = resolve(path, filePath)
1040
+
1041
+ // If the `relative` option is true, return the path relative to the current working directory
1042
+ if (options?.relative)
1043
+ return relative(process.cwd(), finalPath)
1044
+
1045
+ return finalPath
1046
+ }
1047
+
1048
+ /**
1049
+ * Finds and returns the absolute path of a specified project by name.
1050
+ *
1051
+ * @param project - The name of the project to find.
1052
+ * @returns The absolute path to the specified project.
1053
+ * @throws Error if the project with the specified name cannot be found.
1054
+ */
1055
+ export async function findProjectPath(project: string): Promise<string> {
1056
+ const projectList = Bun.spawnSync(['buddy', 'projects:list', '--quiet']).stdout.toString()
1057
+ await debugLog(`ProjectList in findProjectPath ${projectList}`)
1058
+
1059
+ // get the list of all Stacks project paths (on the system)
1060
+ const projects = projectList
1061
+ .split('\n')
1062
+ .filter((line: string) => line.startsWith(' - '))
1063
+ .map((line: string) => line.trim().substring(4))
1064
+
1065
+ await debugLog(`Projects in findProjectPath ${projects}`)
1066
+
1067
+ // since we are targeting a specific project, find its path
1068
+ const projectPath = projects.find((proj: string) => proj.includes(project))
1069
+
1070
+ if (!projectPath)
1071
+ throw new Error(`Could not find project with name: ${project}`)
1072
+
1073
+ return projectPath.startsWith('/') ? projectPath : `/${projectPath}`
1074
+ }
1075
+
1076
+ /**
1077
+ * Returns the path to the `config` directory within the project directory.
1078
+ *
1079
+ * @param path - The relative path to the file or directory within the config directory.
1080
+ * @returns The absolute path to the specified file or directory within the config directory.
1081
+ */
1082
+ export function projectConfigPath(path?: string): string {
1083
+ return projectPath(`config/${path || ''}`)
1084
+ }
1085
+
1086
+ /**
1087
+ * Returns the path to the `storage` directory within the project directory.
1088
+ *
1089
+ * @param path - The relative path to the file or directory within the storage directory.
1090
+ * @returns The absolute path to the specified file or directory within the storage directory.
1091
+ */
1092
+ export function storagePath(path?: string): string {
1093
+ return projectPath(`storage/${path || ''}`)
1094
+ }
1095
+
1096
+ /**
1097
+ * Returns the path to the `public` directory within the project directory.
1098
+ *
1099
+ * @param path - The relative path to the file or directory within the public directory.
1100
+ * @returns The absolute path to the specified file or directory within the public directory.
1101
+ */
1102
+ export function publicPath(path?: string): string {
1103
+ return projectPath(`public/${path || ''}`)
1104
+ }
1105
+
1106
+ /**
1107
+ * Returns the path to the `push` directory within the `notifications` directory.
1108
+ *
1109
+ * @param path - The relative path to the file or directory within the push directory.
1110
+ * @returns The absolute path to the specified file or directory within the push directory.
1111
+ */
1112
+ export function pushPath(path?: string): string {
1113
+ return notificationsPath(`push/${path || ''}`)
1114
+ }
1115
+
1116
+ /**
1117
+ * Returns the path to the `query-builder` directory within the core directory.
1118
+ *
1119
+ * @param path - The relative path to the file or directory within the query-builder directory.
1120
+ * @returns The absolute path to the specified file or directory within the query-builder directory.
1121
+ */
1122
+ export function queryBuilderPath(path?: string): string {
1123
+ return corePath(`query-builder/${path || ''}`)
1124
+ }
1125
+
1126
+ /**
1127
+ * Returns the path to the `queue` directory within the core directory.
1128
+ *
1129
+ * @param path - The relative path to the file or directory within the queue directory.
1130
+ * @returns The absolute path to the specified file or directory within the queue directory.
1131
+ */
1132
+ export function queuePath(path?: string): string {
1133
+ return corePath(`queue/${path || ''}`)
1134
+ }
1135
+
1136
+ /**
1137
+ * Returns the path to the `realtime` directory within the core directory.
1138
+ *
1139
+ * @param path - The relative path to the file or directory within the realtime directory.
1140
+ * @returns The absolute path to the specified file or directory within the realtime directory.
1141
+ */
1142
+ export function realtimePath(path?: string): string {
1143
+ return corePath(`realtime/${path || ''}`)
1144
+ }
1145
+
1146
+ /**
1147
+ * Returns the path to the `resources` directory within the project storage directory, with an option for relative paths.
1148
+ *
1149
+ * @param path - The relative path to the file or directory within the `resources` directory.
1150
+ * @param options - Optional. An object containing configuration settings.
1151
+ * @param options.relative - If true, returns the path relative to the current working directory.
1152
+ * @returns The absolute or relative path to the specified file or directory within the `resources` directory.
1153
+ */
1154
+ export function resourcesPath(path?: string, options?: { relative?: boolean }): string {
1155
+ if (options?.relative) {
1156
+ const absolutePath = projectPath(`resources/${path || ''}`)
1157
+ return relative(process.cwd(), absolutePath)
1158
+ }
1159
+
1160
+ return projectPath(`resources/${path || ''}`)
1161
+ }
1162
+
1163
+ /**
1164
+ * Returns the path to the `repl` directory within the core directory.
1165
+ *
1166
+ * @param path - The relative path to the file or directory within the repl directory.
1167
+ * @returns The absolute path to the specified file or directory within the repl directory.
1168
+ */
1169
+ export function replPath(path?: string): string {
1170
+ return corePath(`repl/${path || ''}`)
1171
+ }
1172
+
1173
+ /**
1174
+ * Returns the path to the `router` directory within the core directory.
1175
+ *
1176
+ * @param path - The relative path to the file or directory within the router directory.
1177
+ * @returns The absolute path to the specified file or directory within the router directory.
1178
+ */
1179
+ export function routerPath(path?: string): string {
1180
+ return corePath(`router/${path || ''}`)
1181
+ }
1182
+
1183
+ /**
1184
+ * Returns the path to the `routes` directory within the `resources` directory, with an option for relative paths.
1185
+ *
1186
+ * @param path - The relative path to the file or directory within the `routes` directory.
1187
+ * @param options - Optional. An object containing configuration settings.
1188
+ * @param options.relative - If true, returns the path relative to the current working directory.
1189
+ * @returns The absolute or relative path to the specified file or directory within the `routes` directory.
1190
+ */
1191
+ export function routesPath(path?: string, options?: { relative?: boolean }): string {
1192
+ const absolutePath = resourcesPath(`routes/${path || ''}`)
1193
+
1194
+ if (options?.relative)
1195
+ return relative(process.cwd(), absolutePath)
1196
+
1197
+ return projectPath(`routes/${path || ''}`)
1198
+ }
1199
+
1200
+ /**
1201
+ * Returns the path to the `search-engine` directory within the core directory.
1202
+ *
1203
+ * @param path - The relative path to the file or directory within the search-engine directory.
1204
+ * @returns The absolute path to the specified file or directory within the search-engine directory.
1205
+ */
1206
+ export function searchEnginePath(path?: string): string {
1207
+ return corePath(`search-engine/${path || ''}`)
1208
+ }
1209
+
1210
+ /**
1211
+ * Returns the path to the `settings` directory within the project directory, defaulting to the views/dashboard/settings directory.
1212
+ *
1213
+ * @param path - The relative path to the file or directory within the `settings` directory.
1214
+ * @returns The absolute path to the specified file or directory within the `settings` directory.
1215
+ */
1216
+ export function settingsPath(path?: string): string {
1217
+ return projectPath(`${path || 'views/dashboard/settings'}`)
1218
+ }
1219
+
1220
+ /**
1221
+ * Returns the path to the `scripts` directory within the framework directory.
1222
+ *
1223
+ * @param path - The relative path to the file or directory within the `scripts` directory.
1224
+ * @returns The absolute path to the specified file or directory within the `scripts` directory.
1225
+ */
1226
+ export function scriptsPath(path?: string): string {
1227
+ return frameworkPath(`scripts/${path || ''}`)
1228
+ }
1229
+
1230
+ /**
1231
+ * Returns the path to the `scheduler` directory within the core directory.
1232
+ *
1233
+ * @param path - The relative path to the file or directory within the scheduler directory.
1234
+ * @returns The absolute path to the specified file or directory within the scheduler directory.
1235
+ */
1236
+ export function schedulerPath(path?: string): string {
1237
+ return corePath(`scheduler/${path || ''}`)
1238
+ }
1239
+
1240
+ /**
1241
+ * Returns the path to the `slug` directory within the core directory.
1242
+ *
1243
+ * @param path - The relative path to the file or directory within the slug directory.
1244
+ * @returns The absolute path to the specified file or directory within the slug directory.
1245
+ */
1246
+ export function slugPath(path?: string): string {
1247
+ return corePath(`slug/${path || ''}`)
1248
+ }
1249
+
1250
+ /**
1251
+ * Returns the path to the `sms` directory within the `notifications` directory.
1252
+ *
1253
+ * @param path - The relative path to the file or directory within the `sms` directory.
1254
+ * @returns The absolute path to the specified file or directory within the `sms` directory.
1255
+ */
1256
+ export function smsPath(path?: string): string {
1257
+ return notificationsPath(`sms/${path || ''}`)
1258
+ }
1259
+
1260
+ /**
1261
+ * Returns the path to the `storage` directory within the core directory.
1262
+ *
1263
+ * @param path - The relative path to the file or directory within the storage directory.
1264
+ * @returns The absolute path to the specified file or directory within the storage directory.
1265
+ */
1266
+ export function coreStoragePath(path?: string): string {
1267
+ return corePath(`storage/${path || ''}`)
1268
+ }
1269
+
1270
+ /**
1271
+ * Returns the path to the `stores` directory within the `resources` directory.
1272
+ *
1273
+ * @param path - The relative path to the file or directory within the `stores` directory.
1274
+ * @returns The absolute path to the specified file or directory within the `stores` directory.
1275
+ */
1276
+ export function storesPath(path?: string): string {
1277
+ return resourcesPath(`stores/${path || ''}`)
1278
+ }
1279
+
1280
+ /**
1281
+ * Returns the path to the `security` directory within the core directory.
1282
+ *
1283
+ * @param path - The relative path to the file or directory within the security directory.
1284
+ * @returns The absolute path to the specified file or directory within the security directory.
1285
+ */
1286
+ export function securityPath(path?: string): string {
1287
+ return corePath(`security/${path || ''}`)
1288
+ }
1289
+
1290
+ /**
1291
+ * Returns the path to the `server` directory within the core directory.
1292
+ *
1293
+ * @param path - The relative path to the file or directory within the server directory.
1294
+ * @returns The absolute path to the specified file or directory within the server directory.
1295
+ */
1296
+ export function serverPath(path?: string): string {
1297
+ return corePath(`server/${path || ''}`)
1298
+ }
1299
+
1300
+ export function userServerPath(path?: string): string {
1301
+ return frameworkPath(`server/${path || ''}`)
1302
+ }
1303
+
1304
+ /**
1305
+ * Returns the path to the `serverless` directory within the core directory.
1306
+ *
1307
+ * @param path - The relative path to the file or directory within the `serverless` directory.
1308
+ * @returns The absolute path to the specified file or directory within the `serverless` directory.
1309
+ */
1310
+ export function serverlessPath(path?: string): string {
1311
+ return corePath(`serverless/${path || ''}`)
1312
+ }
1313
+
1314
+ /**
1315
+ * Returns the path to the specified directory or file within the framework's `src` directory.
1316
+ *
1317
+ * @param path - The relative path to the file or directory within the framework's `src` directory.
1318
+ * @returns The absolute path to the specified file or directory within the framework's `src` directory.
1319
+ */
1320
+ export function stacksPath(path?: string): string {
1321
+ return frameworkPath(`src/${path || ''}`)
1322
+ }
1323
+
1324
+ export function stacksLockPath(): string {
1325
+ return storagePath('framework/stacks.lock.json')
1326
+ }
1327
+
1328
+ export function stacksBackupPath(stackName?: string): string {
1329
+ return storagePath(`framework/stacks/backups/${stackName || ''}`)
1330
+ }
1331
+
1332
+ /**
1333
+ * Returns the path to the `shell` directory within the core directory.
1334
+ *
1335
+ * @param path - The relative path to the file or directory within the shell directory.
1336
+ * @returns The absolute path to the specified file or directory within the shell directory.
1337
+ */
1338
+ export function shellPath(path?: string): string {
1339
+ return corePath(`shell/${path || ''}`)
1340
+ }
1341
+
1342
+ /**
1343
+ * Returns the path to the `strings` directory within the core directory.
1344
+ *
1345
+ * @param path - The relative path to the file or directory within the `strings` directory.
1346
+ * @returns The absolute path to the specified file or directory within the `strings` directory.
1347
+ */
1348
+ export function stringsPath(path?: string): string {
1349
+ return corePath(`strings/${path || ''}`)
1350
+ }
1351
+
1352
+ /**
1353
+ * Returns the path to the `testing` directory within the core directory.
1354
+ *
1355
+ * @param path - The relative path to the file or directory within the testing directory.
1356
+ * @returns The absolute path to the specified file or directory within the testing directory.
1357
+ */
1358
+ export function testingPath(path?: string): string {
1359
+ return corePath(`testing/${path || ''}`)
1360
+ }
1361
+
1362
+ /**
1363
+ * Returns the path to the `tinker` directory within the core directory.
1364
+ *
1365
+ * @param path - The relative path to the file or directory within the tinker directory.
1366
+ * @returns The absolute path to the specified file or directory within the tinker directory.
1367
+ */
1368
+ export function tinkerPath(path?: string): string {
1369
+ return corePath(`tinker/${path || ''}`)
1370
+ }
1371
+
1372
+ /**
1373
+ * Returns the path to the `tests` directory within the framework directory.
1374
+ *
1375
+ * @param path - The relative path to the file or directory within the `tests` directory.
1376
+ * @returns The absolute path to the specified file or directory within the `tests` directory.
1377
+ */
1378
+ export function testsPath(path?: string): string {
1379
+ return frameworkPath(`tests/${path || ''}`)
1380
+ }
1381
+
1382
+ /**
1383
+ * Returns the path to the `types` directory within the core directory.
1384
+ *
1385
+ * @param path - The relative path to the file or directory within the `types` directory.
1386
+ * @returns The absolute path to the specified file or directory within the `types` directory.
1387
+ */
1388
+ export function typesPath(path?: string): string {
1389
+ return corePath(`types/${path || ''}`)
1390
+ }
1391
+
1392
+ /**
1393
+ * Returns the path to the `ui` directory within the core directory.
1394
+ *
1395
+ * @param path - The relative path to the file or directory within the ui directory.
1396
+ * @returns The absolute path to the specified file or directory within the ui directory.
1397
+ */
1398
+ export function uiPath(path?: string, options?: { relative?: boolean }): string {
1399
+ const absolutePath = corePath(`ui/${path || ''}`)
1400
+
1401
+ if (options?.relative)
1402
+ return relative(process.cwd(), absolutePath)
1403
+
1404
+ return absolutePath
1405
+ }
1406
+
1407
+ /**
1408
+ * Returns the path to the `utils` directory within the core directory.
1409
+ *
1410
+ * @param path - The relative path to the file or directory within the `utils` directory.
1411
+ * @returns The absolute path to the specified file or directory within the `utils` directory.
1412
+ */
1413
+ export function utilsPath(path?: string): string {
1414
+ return corePath(`utils/${path || ''}`)
1415
+ }
1416
+
1417
+ /**
1418
+ * Returns the path to the `validation` directory within the core directory.
1419
+ *
1420
+ * @param path - The relative path to the file or directory within the validation directory.
1421
+ * @returns The absolute path to the specified file or directory within the validation directory.
1422
+ */
1423
+ export function validationPath(path?: string): string {
1424
+ return corePath(`validation/${path || ''}`)
1425
+ }
1426
+
1427
+ /**
1428
+ * Returns the path to the `validation` directory within the core directory.
1429
+ *
1430
+ * @param path - The relative path to the file or directory within the validation directory.
1431
+ * @returns The absolute path to the specified file or directory within the validation directory.
1432
+ */
1433
+ export function socialsPath(path?: string): string {
1434
+ return corePath(`socials/${path || ''}`)
1435
+ }
1436
+
1437
+
1438
+ /**
1439
+ * Returns the path to the `x-ray` directory within the `stacks` directory of the framework.
1440
+ *
1441
+ * @param path - The relative path to the file or directory within the x-ray directory.
1442
+ * @returns The absolute path to the specified file or directory within the x-ray directory.
1443
+ */
1444
+ export function xRayPath(path?: string): string {
1445
+ return frameworkPath(`stacks/x-ray/${path || ''}`)
1446
+ }
1447
+
1448
+ /**
1449
+ * Returns the path to the home directory, optionally appending a given path.
1450
+ *
1451
+ * @param path - The relative path to append to the home directory path.
1452
+ * @returns The absolute path to the specified file or directory within the home directory.
1453
+ */
1454
+ export function homeDir(path?: string): string {
1455
+ return os.homedir() + (path ? (path.startsWith('/') ? '' : '/') + path : '~')
1456
+ }
1457
+
1458
+ export interface Path {
1459
+ actionsPath: (path?: string) => string
1460
+ userActionsPath: (path?: string) => string
1461
+ builtUserActionsPath: (path?: string, option?: { relative: boolean }) => string
1462
+ userComponentsPath: (path?: string) => string
1463
+ userViewsPath: (path?: string) => string
1464
+ userFunctionsPath: (path?: string) => string
1465
+ aiPath: (path?: string) => string
1466
+ assetsPath: (path?: string) => string
1467
+ relativeActionsPath: (path?: string) => string
1468
+ aliasPath: (path?: string) => string
1469
+ analyticsPath: (path?: string) => string
1470
+ arraysPath: (path?: string) => string
1471
+ appPath: (path?: string) => string
1472
+ defaultsAppPath: (path?: string) => string
1473
+ defaultsResourcesPath: (path?: string) => string
1474
+ authPath: (path?: string) => string
1475
+ coreApiPath: (path?: string) => string
1476
+ buddyPath: (path?: string) => string
1477
+ buildEnginePath: (path?: string) => string
1478
+ libsEntriesPath: (path?: string) => string
1479
+ buildPath: (path?: string) => string
1480
+ cachePath: (path?: string) => string
1481
+ chartsPath: (path?: string) => string
1482
+ chatPath: (path?: string) => string
1483
+ cliPath: (path?: string) => string
1484
+ cloudPath: (path?: string) => string
1485
+ frameworkCloudPath: (path?: string) => string
1486
+ collectionsPath: (path?: string) => string
1487
+ commandsPath: (path?: string) => string
1488
+ componentsPath: (path?: string) => string
1489
+ configPath: (path?: string) => string
1490
+ projectConfigPath: (path?: string) => string
1491
+ corePath: (path?: string) => string
1492
+ customElementsDataPath: (path?: string) => string
1493
+ databasePath: (path?: string) => string
1494
+ datetimePath: (path?: string) => string
1495
+ developmentPath: (path?: string) => string
1496
+ desktopPath: (path?: string) => string
1497
+ docsPath: (path?: string) => string
1498
+ dnsPath: (path?: string) => string
1499
+ emailPath: (path?: string) => string
1500
+ enumsPath: (path?: string) => string
1501
+ eslintPluginPath: (path?: string) => string
1502
+ errorHandlingPath: (path?: string) => string
1503
+ eventsPath: (path?: string) => string
1504
+ coreEnvPath: (path?: string) => string
1505
+ healthPath: (path?: string) => string
1506
+ examplesPath: (type?: 'web-components') => string
1507
+ fakerPath: (path?: string) => string
1508
+ frameworkPath: (path?: string) => string
1509
+ browserPath: (path?: string) => string
1510
+ storagePath: (path?: string) => string
1511
+ functionsPath: (path?: string) => string
1512
+ gitPath: (path?: string) => string
1513
+ langPath: (path?: string) => string
1514
+ layoutsPath: (path?: string, options?: { relative?: boolean }) => string
1515
+ libsPath: (path?: string) => string
1516
+ userLibsPath: (path?: string) => string
1517
+ libraryEntryPath: (type: LibraryType) => string
1518
+ lintPath: (path?: string) => string
1519
+ listenersPath: (path?: string) => string
1520
+ loggingPath: (path?: string) => string
1521
+ logsPath: (path?: string) => string
1522
+ jobsPath: (path?: string) => string
1523
+ modulesPath: (path?: string) => string
1524
+ ormPath: (path?: string) => string
1525
+ objectsPath: (path?: string) => string
1526
+ onboardingPath: (path?: string) => string
1527
+ notificationsPath: (path?: string) => string
1528
+ newsletterPath: (path?: string) => string
1529
+ packageJsonPath: (type: LibraryType) => string
1530
+ viewsPath: (path?: string) => string
1531
+ pathPath: (path?: string) => string
1532
+ paymentsPath: (path?: string) => string
1533
+ projectPath: (path?: string) => string
1534
+ findProjectPath: (project: string) => Promise<string>
1535
+ coreStoragePath: (path?: string) => string
1536
+ publicPath: (path?: string) => string
1537
+ pushPath: (path?: string) => string
1538
+ queryBuilderPath: (path?: string) => string
1539
+ queuePath: (path?: string) => string
1540
+ realtimePath: (path?: string) => string
1541
+ resourcesPath: (path?: string) => string
1542
+ replPath: (path?: string) => string
1543
+ routerPath: (path?: string) => string
1544
+ routesPath: (path?: string) => string
1545
+ runtimePath: (path?: string) => string
1546
+ searchEnginePath: (path?: string) => string
1547
+ schedulerPath: (path?: string) => string
1548
+ settingsPath: (path?: string) => string
1549
+ smsPath: (path?: string) => string
1550
+ slugPath: (path?: string) => string
1551
+ scriptsPath: (path?: string) => string
1552
+ securityPath: (path?: string) => string
1553
+ serverPath: (path?: string) => string
1554
+ userServerPath: (path?: string) => string
1555
+ serverlessPath: (path?: string) => string
1556
+ stacksPath: (path?: string) => string
1557
+ stacksLockPath: () => string
1558
+ stacksBackupPath: (stackName?: string) => string
1559
+ stringsPath: (path?: string) => string
1560
+ shellPath: (path?: string) => string
1561
+ storesPath: (path?: string) => string
1562
+ socialsPath: (path?: string) => string
1563
+ testingPath: (path?: string) => string
1564
+ testsPath: (path?: string) => string
1565
+ tinkerPath: (path?: string) => string
1566
+ typesPath: (path?: string) => string
1567
+ uiPath: (path?: string, options?: { relative?: boolean }) => string
1568
+ userDatabasePath: (path?: string) => string
1569
+ userMigrationsPath: (path?: string) => string
1570
+ userEventsPath: (path?: string) => string
1571
+ userJobsPath: (path?: string) => string
1572
+ userControllersPath: (path?: string) => string
1573
+ userListenersPath: (path?: string) => string
1574
+ userMiddlewarePath: (path?: string) => string
1575
+ userModelsPath: (path?: string) => string
1576
+ userNotificationsPath: (path?: string) => string
1577
+ userMailPath: (path?: string) => string
1578
+ userEmailsPath: (path?: string) => string
1579
+ utilsPath: (path?: string) => string
1580
+ validationPath: (path?: string) => string
1581
+ xRayPath: (path?: string) => string
1582
+ homeDir: (path?: string) => string
1583
+ basename: (path: string) => string
1584
+ delimiter: () => ';' | ':'
1585
+ dirname: (path: string) => string
1586
+ extname: (path: string) => string
1587
+ isAbsolute: (path: string) => boolean
1588
+ join: (...paths: string[]) => string
1589
+ normalize: (path: string) => string
1590
+ relative: (from: string, to: string) => string
1591
+ resolve: (...paths: string[]) => string
1592
+ parse: (path: string) => ParsedPath
1593
+ sep: () => '/' | '\\'
1594
+ toNamespacedPath: (path: string) => string
1595
+ }
1596
+
1597
+ export const path: Path = {
1598
+ actionsPath,
1599
+ userActionsPath,
1600
+ builtUserActionsPath,
1601
+ userComponentsPath,
1602
+ userViewsPath,
1603
+ userFunctionsPath,
1604
+ aiPath,
1605
+ assetsPath,
1606
+ relativeActionsPath,
1607
+ aliasPath,
1608
+ analyticsPath,
1609
+ arraysPath,
1610
+ appPath,
1611
+ defaultsAppPath,
1612
+ defaultsResourcesPath,
1613
+ authPath,
1614
+ coreApiPath,
1615
+ buddyPath,
1616
+ buildEnginePath,
1617
+ libsEntriesPath,
1618
+ buildPath,
1619
+ cachePath,
1620
+ chartsPath,
1621
+ chatPath,
1622
+ cliPath,
1623
+ cloudPath,
1624
+ frameworkCloudPath,
1625
+ collectionsPath,
1626
+ commandsPath,
1627
+ componentsPath,
1628
+ configPath,
1629
+ projectConfigPath,
1630
+ corePath,
1631
+ customElementsDataPath,
1632
+ databasePath,
1633
+ datetimePath,
1634
+ developmentPath,
1635
+ desktopPath,
1636
+ docsPath,
1637
+ dnsPath,
1638
+ emailPath,
1639
+ enumsPath,
1640
+ eslintPluginPath,
1641
+ errorHandlingPath,
1642
+ eventsPath,
1643
+ coreEnvPath,
1644
+ healthPath,
1645
+ examplesPath,
1646
+ fakerPath,
1647
+ frameworkPath,
1648
+ browserPath,
1649
+ storagePath,
1650
+ functionsPath,
1651
+ gitPath,
1652
+ langPath,
1653
+ layoutsPath,
1654
+ libsPath,
1655
+ userLibsPath,
1656
+ libraryEntryPath,
1657
+ lintPath,
1658
+ listenersPath,
1659
+ loggingPath,
1660
+ logsPath,
1661
+ jobsPath,
1662
+ modulesPath,
1663
+ ormPath,
1664
+ objectsPath,
1665
+ onboardingPath,
1666
+ notificationsPath,
1667
+ newsletterPath,
1668
+ packageJsonPath,
1669
+ viewsPath,
1670
+ pathPath,
1671
+ paymentsPath,
1672
+ projectPath,
1673
+ findProjectPath,
1674
+ coreStoragePath,
1675
+ publicPath,
1676
+ pushPath,
1677
+ queryBuilderPath,
1678
+ queuePath,
1679
+ realtimePath,
1680
+ resourcesPath,
1681
+ replPath,
1682
+ routerPath,
1683
+ routesPath,
1684
+ runtimePath,
1685
+ searchEnginePath,
1686
+ schedulerPath,
1687
+ settingsPath,
1688
+ smsPath,
1689
+ slugPath,
1690
+ scriptsPath,
1691
+ securityPath,
1692
+ serverPath,
1693
+ userServerPath,
1694
+ serverlessPath,
1695
+ stacksPath,
1696
+ stacksLockPath,
1697
+ stacksBackupPath,
1698
+ stringsPath,
1699
+ shellPath,
1700
+ socialsPath,
1701
+ storesPath,
1702
+ testingPath,
1703
+ testsPath,
1704
+ tinkerPath,
1705
+ typesPath,
1706
+ uiPath,
1707
+ userDatabasePath,
1708
+ userMigrationsPath,
1709
+ userEventsPath,
1710
+ userJobsPath,
1711
+ userControllersPath,
1712
+ userListenersPath,
1713
+ userMiddlewarePath,
1714
+ userModelsPath,
1715
+ userNotificationsPath,
1716
+ userMailPath,
1717
+ userEmailsPath,
1718
+ utilsPath,
1719
+ validationPath,
1720
+ xRayPath,
1721
+ homeDir,
1722
+
1723
+ // path utils
1724
+ basename,
1725
+ delimiter: () => delimiter,
1726
+ dirname,
1727
+ extname,
1728
+ isAbsolute,
1729
+ join,
1730
+ normalize,
1731
+ relative,
1732
+ resolve,
1733
+ parse,
1734
+ sep: () => sep,
1735
+ toNamespacedPath,
1736
+ }
1737
+
1738
+ export { basename, delimiter, dirname, extname, isAbsolute, join, normalize, relative, resolve, sep, toNamespacedPath }