|
| 1 | +import process from 'node:process' |
| 2 | +import type { DtsGenerationConfig } from '@stacksjs/dtsx' |
| 3 | + |
| 4 | +/** |
| 5 | + * Example of const declaration |
| 6 | + */ |
| 7 | +export const conf: { [key: string]: string } = { |
| 8 | + apiUrl: 'https://api.stacksjs.org', |
| 9 | + timeout: '5000', // as string |
| 10 | +} |
| 11 | + |
| 12 | +export let test = 'test' |
| 13 | + |
| 14 | +export var helloWorld = 'Hello World' |
| 15 | + |
| 16 | +export const someObject = { |
| 17 | + someString: 'Stacks', |
| 18 | + someNumber: 1000, |
| 19 | + someBoolean: true, |
| 20 | + someFalse: false, |
| 21 | + someFunction: () => { console.log('hello world') }, |
| 22 | + anotherOne: () => { |
| 23 | + // some comment |
| 24 | + /* some other comment */ |
| 25 | + return some.object ?? 'default' |
| 26 | + }, |
| 27 | + someArray: [1, 2, 3], |
| 28 | + someNestedArray: [ |
| 29 | + [1, 2, 3], |
| 30 | + [4, 5, 6, 7, 8, 9, 10], |
| 31 | + ], |
| 32 | + someNestedArray2: [ |
| 33 | + [1, 2, 3], |
| 34 | + [4, 5, 6, 7, 8, 9, 10], |
| 35 | + 'dummy value', |
| 36 | + ], |
| 37 | + someNestedArray3: [ |
| 38 | + [1, 2, 3], |
| 39 | + [4, 5, 6, 7, 8, 9, 10], |
| 40 | + 'dummy value', |
| 41 | + [11, 12, 13], |
| 42 | + ], |
| 43 | + someOtherNestedArray: [ |
| 44 | + [ |
| 45 | + 'some text', |
| 46 | + 2, |
| 47 | + console.log, |
| 48 | + () => console.log('hello world'), |
| 49 | + helloWorld, |
| 50 | + ], |
| 51 | + [4, 5, 6, 7, 8, 9, 10], |
| 52 | + ], |
| 53 | + someComplexArray: [ |
| 54 | + [ |
| 55 | + { key: 'value' }, |
| 56 | + ], |
| 57 | + [ |
| 58 | + { key2: 'value2' }, |
| 59 | + 'test', |
| 60 | + 1000, |
| 61 | + ], |
| 62 | + [ |
| 63 | + 'some string', |
| 64 | + console.log, |
| 65 | + someFunction(), |
| 66 | + ] |
| 67 | + ], |
| 68 | + someObject: { key: 'value' }, |
| 69 | + someNestedObject: { |
| 70 | + key: { |
| 71 | + nestedKey: 'value', |
| 72 | + }, |
| 73 | + otherKey: { |
| 74 | + nestedKey: process.cwd(), |
| 75 | + nestedKey2: () => { console.log('hello world') }, |
| 76 | + } |
| 77 | + }, |
| 78 | + someNestedObjectArray: [ |
| 79 | + { key: 'value' }, |
| 80 | + { key2: 'value2' }, |
| 81 | + ], |
| 82 | + someOtherObject: some.deep.object, |
| 83 | + someInlineCall2: console.log, |
| 84 | + someInlineCall3: console.log(), |
| 85 | +} |
| 86 | + |
| 87 | +/** |
| 88 | + * Example of another const declaration |
| 89 | + * |
| 90 | +* with multiple empty lines, including being poorly formatted |
| 91 | + */ |
| 92 | +const settings: { [key: string]: any } = { |
| 93 | + theme: 'dark', |
| 94 | + language: 'en', |
| 95 | +} |
| 96 | + |
| 97 | +export const defaultHeaders = { |
| 98 | + 'Content-Type': 'application/json', |
| 99 | +} |
| 100 | + |
| 101 | +// eslint-disable-next-line antfu/no-top-level-await |
| 102 | +const dtsConfig: DtsGenerationConfig = await loadConfig({ |
| 103 | + name: 'dts', |
| 104 | + cwd: process.cwd(), |
| 105 | + defaultConfig: { |
| 106 | + cwd: process.cwd(), |
| 107 | + root: './src', |
| 108 | + entrypoints: ['**/*.ts'], |
| 109 | + outdir: './dist', |
| 110 | + keepComments: true, |
| 111 | + clean: true, |
| 112 | + tsconfigPath: './tsconfig.json', |
| 113 | + }, |
| 114 | +}) |
| 115 | + |
| 116 | +// Complex Arrays and Tuples |
| 117 | +export const complexArrays = { |
| 118 | + matrix: [ |
| 119 | + [1, 2, [3, 4, [5, 6]]], |
| 120 | + ['a', 'b', ['c', 'd']], |
| 121 | + [true, [false, [true]]], |
| 122 | + ], |
| 123 | + tuples: [ |
| 124 | + [1, 'string', true] as const, |
| 125 | + ['literal', 42, false] as const, |
| 126 | + ], |
| 127 | + // TODO: get this part to generate correctly |
| 128 | + // mixedArrays: [ |
| 129 | + // new Date(), |
| 130 | + // Promise.resolve('async'), |
| 131 | + // async () => 'result', |
| 132 | + // function* generator() { yield 42 }, |
| 133 | + // ] |
| 134 | +} |
| 135 | + |
| 136 | +// TODO: Nested Object Types with Methods |
| 137 | +// export const complexObject = { |
| 138 | +// handlers: { |
| 139 | +// async onSuccess<T>(data: T): Promise<void> { |
| 140 | +// console.log(data) |
| 141 | +// }, |
| 142 | +// onError(error: Error & { code?: number }): never { |
| 143 | +// throw error |
| 144 | +// } |
| 145 | +// }, |
| 146 | +// utils: { |
| 147 | +// formatters: { |
| 148 | +// date: (input: Date) => input.toISOString(), |
| 149 | +// currency: (amount: number, currency = 'USD') => |
| 150 | +// new Intl.NumberFormat('en-US', { style: 'currency', currency }).format(amount) |
| 151 | +// } |
| 152 | +// } |
| 153 | +// } |
| 154 | + |
| 155 | +// TODO: Method Decorators and Metadata |
| 156 | +// export const methodDecorator = ( |
| 157 | +// target: any, |
| 158 | +// propertyKey: string, |
| 159 | +// descriptor: PropertyDescriptor |
| 160 | +// ) => { |
| 161 | +// return { |
| 162 | +// ...descriptor, |
| 163 | +// enumerable: true, |
| 164 | +// } |
| 165 | +// } |
| 166 | + |
| 167 | +// TODO: Complex Constants with Type Inference |
| 168 | +// export const CONFIG_MAP = { |
| 169 | +// development: { |
| 170 | +// features: { |
| 171 | +// auth: { |
| 172 | +// providers: ['google', 'github'] as const, |
| 173 | +// settings: { timeout: 5000, retries: 3 } |
| 174 | +// } |
| 175 | +// } |
| 176 | +// }, |
| 177 | +// production: { |
| 178 | +// features: { |
| 179 | +// auth: { |
| 180 | +// providers: ['google', 'github', 'microsoft'] as const, |
| 181 | +// settings: { timeout: 3000, retries: 5 } |
| 182 | +// } |
| 183 | +// } |
| 184 | +// } |
| 185 | +// } as const |
0 commit comments