Skip to content

Commit b5ffe42

Browse files
committed
chore: add placeholder example
chore: adjust example 9
1 parent b28c856 commit b5ffe42

File tree

2 files changed

+158
-0
lines changed

2 files changed

+158
-0
lines changed

fixtures/input/example/0009.ts

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
import os from 'node:os'
2+
import {
3+
basename,
4+
delimiter,
5+
dirname,
6+
extname,
7+
isAbsolute,
8+
join,
9+
normalize,
10+
type ParsedPath,
11+
relative,
12+
resolve,
13+
sep,
14+
toNamespacedPath,
15+
} from 'node:path'
16+
import process from 'node:process'
17+
18+
/**
19+
* Returns the path to the `actions` directory. The `actions` directory
20+
* contains the core Stacks' actions.
21+
*
22+
* @param path - The relative path to the file or directory.
23+
* @returns The absolute path to the file or directory.
24+
* @example
25+
* ```ts
26+
* import { actionsPath } from '@stacksjs/path'
27+
*
28+
* console.log(actionsPath('path/to/action.ts')) // Outputs the absolute path to 'path/to/action.ts' within the `actions` directory
29+
* ```
30+
*/
31+
export function actionsPath(path?: string): string {
32+
return corePath(`actions/${path || ''}`)
33+
}
34+
35+
36+
export function corePath(path?: string): string {
37+
return frameworkPath(`core/${path || ''}`)
38+
}
39+
40+
export function frameworkPath(path?: string, options?: { relative?: boolean, cwd?: string }): string {
41+
const absolutePath = storagePath(`framework/${path || ''}`)
42+
43+
if (options?.relative)
44+
return relative(options.cwd || process.cwd(), absolutePath)
45+
46+
return absolutePath
47+
}
48+
49+
export function storagePath(path?: string): string {
50+
return projectPath(`storage/${path || ''}`)
51+
}
52+
53+
export function projectPath(filePath = '', options?: { relative: boolean }): string {
54+
let path = process.cwd()
55+
56+
while (path.includes('storage')) path = resolve(path, '..')
57+
58+
const finalPath = resolve(path, filePath)
59+
60+
if (options?.relative)
61+
return relative(process.cwd(), finalPath)
62+
63+
return finalPath
64+
}
65+
66+
export function userActionsPath(path?: string, options?: { relative: true }): string {
67+
const absolutePath = appPath(`Actions/${path || ''}`)
68+
69+
if (options?.relative)
70+
return relative(process.cwd(), absolutePath)
71+
72+
return absolutePath
73+
}
74+
75+
export function builtUserActionsPath(path?: string, options?: { relative: boolean }): string {
76+
const absolutePath = frameworkPath(`actions/${path || ''}`)
77+
78+
if (options?.relative)
79+
return relative(process.cwd(), absolutePath)
80+
81+
return absolutePath
82+
}
83+
84+
/**
85+
* Returns the path to the home directory, optionally appending a given path.
86+
*
87+
* @param path - The relative path to append to the home directory path.
88+
* @returns The absolute path to the specified file or directory within the home directory.
89+
*/
90+
export function homeDir(path?: string): string {
91+
return os.homedir() + (path ? (path.startsWith('/') ? '' : '/') + path : '~')
92+
}
93+
94+
/**
95+
* Returns the path to the library entry file, filtered by library type.
96+
*
97+
* @param type - The type of library ('vue-components', 'web-components', or 'functions').
98+
* @returns The absolute path to the specified library entry file.
99+
*/
100+
export type LibraryType = 'vue-components' | 'web-components' | 'functions'
101+
export function libraryEntryPath(type: LibraryType): string {
102+
return libsEntriesPath(`${type}.ts`)
103+
}
104+
105+
/**
106+
* Returns the path to the `examples` directory within the framework directory, filtered by type.
107+
*
108+
* @param type - The type of examples to filter by ('vue-components' or 'web-components').
109+
* @returns The absolute path to the specified type of examples within the `examples` directory.
110+
*/
111+
export function examplesPath(type?: 'vue-components' | 'web-components'): string {
112+
return frameworkPath(`examples/${type || ''}`)
113+
}
114+
115+
export interface Path {
116+
actionsPath: (path?: string) => string
117+
userActionsPath: (path?: string) => string
118+
builtUserActionsPath: (path?: string, option?: { relative: boolean }) => string
119+
examplesPath: (type?: 'vue-components' | 'web-components') => string
120+
libraryEntryPath: (type: LibraryType) => string
121+
homeDir: (path?: string) => string
122+
parse: (path: string) => ParsedPath
123+
sep: () => '/' | '\\'
124+
}
125+
126+
export const path: Path = {
127+
actionsPath,
128+
userActionsPath,
129+
builtUserActionsPath,
130+
homeDir,
131+
132+
// some comment
133+
libraryEntryPath,
134+
examplesPath,
135+
parse,
136+
sep: () => sep,
137+
}
138+
139+
export { basename, delimiter, dirname, extname, isAbsolute, join, normalize, relative, resolve, sep, toNamespacedPath }

fixtures/output/0009.d.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { actionsPath } from '@stacksjs/path';
2+
3+
export { basename, delimiter, dirname, extname, isAbsolute, join, normalize, relative, resolve, sep, toNamespacedPath }
4+
declare type ParsedPath,
5+
relative,
6+
resolve,
7+
sep,
8+
toNamespacedPath,
9+
} from 'node:path'
10+
export declare function actionsPath(path?: string): string;
11+
export declare function corePath(path?: string): string;
12+
export declare function frameworkPath(path?: string, options?: { relative?: , boolean, cwd?: , string }): string;
13+
export declare function storagePath(path?: string): string;
14+
export declare function projectPath(filePath, options?: { relative: , boolean }): string;
15+
export declare function userActionsPath(path?: string, options?: { relative: , true }): string;
16+
export declare function builtUserActionsPath(path?: string, options?: { relative: , boolean }): string;
17+
export declare function homeDir(path?: string): string;
18+
export declare function libraryEntryPath(type: LibraryType): string;
19+
export declare function examplesPath(type?: 'vue-components' | 'web-components'): string;

0 commit comments

Comments
 (0)