@timeax/scaffold 0.0.5 → 0.0.6
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.
- package/.idea/dictionaries/project.xml +7 -0
- package/.idea/modules.xml +8 -0
- package/.idea/php.xml +34 -0
- package/.idea/scaffold.iml +8 -0
- package/.idea/vcs.xml +6 -0
- package/dist/ast.d.cts +4 -2
- package/dist/ast.d.ts +4 -2
- package/dist/cli.cjs +1673 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.mjs +1662 -0
- package/dist/cli.mjs.map +1 -0
- package/dist/config-C0067l3c.d.cts +383 -0
- package/dist/config-C0067l3c.d.ts +383 -0
- package/dist/index.cjs +1311 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +8 -347
- package/dist/index.d.ts +8 -347
- package/dist/index.mjs +1295 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +1 -1
- package/src/cli/main.ts +3 -1
- package/tsup.config.ts +24 -60
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Common options that can be applied to both files and directories
|
|
3
|
+
* in the scaffold structure.
|
|
4
|
+
*
|
|
5
|
+
* These options are *declarative* — they do not enforce behavior by
|
|
6
|
+
* themselves; they are consumed by the core engine.
|
|
7
|
+
*/
|
|
8
|
+
interface BaseEntryOptions {
|
|
9
|
+
/**
|
|
10
|
+
* Glob patterns relative to the group root or project root
|
|
11
|
+
* (depending on how the engine is called).
|
|
12
|
+
*
|
|
13
|
+
* If provided, at least one pattern must match the entry path
|
|
14
|
+
* for the entry to be considered.
|
|
15
|
+
*/
|
|
16
|
+
include?: string[];
|
|
17
|
+
/**
|
|
18
|
+
* Glob patterns relative to the group root or project root.
|
|
19
|
+
*
|
|
20
|
+
* If any pattern matches the entry path, the entry will be ignored.
|
|
21
|
+
*/
|
|
22
|
+
exclude?: string[];
|
|
23
|
+
/**
|
|
24
|
+
* Name of the stub to use when creating this file or directory’s
|
|
25
|
+
* content. For directories, this can act as an “inherited” stub
|
|
26
|
+
* for child files if the engine chooses to support that behavior.
|
|
27
|
+
*/
|
|
28
|
+
stub?: string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* A single file entry in the structure tree.
|
|
32
|
+
*
|
|
33
|
+
* Paths are always stored as POSIX-style forward-slash paths
|
|
34
|
+
* relative to the group root / project root.
|
|
35
|
+
*/
|
|
36
|
+
interface FileEntry extends BaseEntryOptions {
|
|
37
|
+
type: 'file';
|
|
38
|
+
/**
|
|
39
|
+
* File path (e.g. "src/index.ts", "Models/User.php").
|
|
40
|
+
* Paths should never end with a trailing slash.
|
|
41
|
+
*/
|
|
42
|
+
path: string;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* A directory entry in the structure tree.
|
|
46
|
+
*
|
|
47
|
+
* Paths should *logically* represent directories and may end
|
|
48
|
+
* with a trailing slash for readability (the engine can normalize).
|
|
49
|
+
*/
|
|
50
|
+
interface DirEntry extends BaseEntryOptions {
|
|
51
|
+
type: 'dir';
|
|
52
|
+
/**
|
|
53
|
+
* Directory path (e.g. "src/", "src/schema/", "Models/").
|
|
54
|
+
* It is recommended (but not strictly required) that directory
|
|
55
|
+
* paths end with a trailing slash.
|
|
56
|
+
*/
|
|
57
|
+
path: string;
|
|
58
|
+
/**
|
|
59
|
+
* Nested structure entries for files and subdirectories.
|
|
60
|
+
*/
|
|
61
|
+
children?: StructureEntry[];
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* A single node in the structure tree:
|
|
65
|
+
* either a file or a directory.
|
|
66
|
+
*/
|
|
67
|
+
type StructureEntry = FileEntry | DirEntry;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Lifecycle stages for non-stub (regular) hooks.
|
|
71
|
+
*
|
|
72
|
+
* These hooks are called around file operations (create/delete).
|
|
73
|
+
*/
|
|
74
|
+
type RegularHookKind = 'preCreateFile' | 'postCreateFile' | 'preDeleteFile' | 'postDeleteFile';
|
|
75
|
+
/**
|
|
76
|
+
* Lifecycle stages for stub-related hooks.
|
|
77
|
+
*
|
|
78
|
+
* These hooks are called around stub resolution for file content.
|
|
79
|
+
*/
|
|
80
|
+
type StubHookKind = 'preStub' | 'postStub';
|
|
81
|
+
/**
|
|
82
|
+
* Context object passed to all hooks (both regular and stub).
|
|
83
|
+
*/
|
|
84
|
+
interface HookContext {
|
|
85
|
+
/**
|
|
86
|
+
* Absolute path to the group root / project root that this
|
|
87
|
+
* scaffold run is targeting.
|
|
88
|
+
*/
|
|
89
|
+
projectRoot: string;
|
|
90
|
+
/**
|
|
91
|
+
* Path of the file or directory relative to the project root
|
|
92
|
+
* used for this run (or group root, if grouped).
|
|
93
|
+
*
|
|
94
|
+
* Example: "src/index.ts", "Http/Controllers/Controller.php".
|
|
95
|
+
*/
|
|
96
|
+
targetPath: string;
|
|
97
|
+
/**
|
|
98
|
+
* Absolute path to the file or directory on disk.
|
|
99
|
+
*/
|
|
100
|
+
absolutePath: string;
|
|
101
|
+
/**
|
|
102
|
+
* Whether the target is a directory.
|
|
103
|
+
* (For now, most hooks will be for files, but this is future-proofing.)
|
|
104
|
+
*/
|
|
105
|
+
isDirectory: boolean;
|
|
106
|
+
/**
|
|
107
|
+
* The stub name associated with the file (if any).
|
|
108
|
+
*
|
|
109
|
+
* For regular hooks, this can be used to detect which stub
|
|
110
|
+
* produced a given file.
|
|
111
|
+
*/
|
|
112
|
+
stubName?: string;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Common filter options used by both regular and stub hooks.
|
|
116
|
+
*
|
|
117
|
+
* Filters are evaluated against the `targetPath`.
|
|
118
|
+
*/
|
|
119
|
+
interface HookFilter {
|
|
120
|
+
/**
|
|
121
|
+
* Glob patterns which must match for the hook to run.
|
|
122
|
+
* If provided, at least one pattern must match.
|
|
123
|
+
*/
|
|
124
|
+
include?: string[];
|
|
125
|
+
/**
|
|
126
|
+
* Glob patterns which, if any match, will prevent the hook
|
|
127
|
+
* from running.
|
|
128
|
+
*/
|
|
129
|
+
exclude?: string[];
|
|
130
|
+
/**
|
|
131
|
+
* Additional patterns or explicit file paths, treated similarly
|
|
132
|
+
* to `include` — mainly a convenience alias.
|
|
133
|
+
*/
|
|
134
|
+
files?: string[];
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Function signature for regular hooks.
|
|
138
|
+
*/
|
|
139
|
+
type RegularHookFn = (ctx: HookContext) => void | Promise<void>;
|
|
140
|
+
/**
|
|
141
|
+
* Function signature for stub hooks.
|
|
142
|
+
*/
|
|
143
|
+
type StubHookFn = (ctx: HookContext) => void | Promise<void>;
|
|
144
|
+
/**
|
|
145
|
+
* Configuration for a regular hook instance.
|
|
146
|
+
*
|
|
147
|
+
* Each hook category (e.g. `preCreateFile`) can have an array
|
|
148
|
+
* of these, each with its own filter.
|
|
149
|
+
*/
|
|
150
|
+
interface RegularHookConfig extends HookFilter {
|
|
151
|
+
fn: RegularHookFn;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Configuration for a stub hook instance.
|
|
155
|
+
*
|
|
156
|
+
* Each stub can have its own `preStub` / `postStub` hook arrays,
|
|
157
|
+
* each with independent filters.
|
|
158
|
+
*/
|
|
159
|
+
interface StubHookConfig extends HookFilter {
|
|
160
|
+
fn: StubHookFn;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Stub configuration, defining how file content is generated
|
|
164
|
+
* and which stub-specific hooks apply.
|
|
165
|
+
*/
|
|
166
|
+
interface StubConfig {
|
|
167
|
+
/**
|
|
168
|
+
* Unique name of this stub within the config.
|
|
169
|
+
* This is referenced from structure entries via `stub: name`.
|
|
170
|
+
*/
|
|
171
|
+
name: string;
|
|
172
|
+
/**
|
|
173
|
+
* Content generator for files that use this stub.
|
|
174
|
+
*
|
|
175
|
+
* If omitted, the scaffold engine may default to an empty file.
|
|
176
|
+
*/
|
|
177
|
+
getContent?: (ctx: HookContext) => string | Promise<string>;
|
|
178
|
+
/**
|
|
179
|
+
* Stub-specific hooks called for files that reference this stub.
|
|
180
|
+
*/
|
|
181
|
+
hooks?: {
|
|
182
|
+
preStub?: StubHookConfig[];
|
|
183
|
+
postStub?: StubHookConfig[];
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
type FormatMode = 'strict' | 'loose';
|
|
188
|
+
interface FormatConfig {
|
|
189
|
+
/**
|
|
190
|
+
* Enable CLI-driven formatting.
|
|
191
|
+
*
|
|
192
|
+
* If false or omitted, formatting is only run when the user explicitly
|
|
193
|
+
* passes `--format` on the CLI.
|
|
194
|
+
*/
|
|
195
|
+
enabled?: boolean;
|
|
196
|
+
/**
|
|
197
|
+
* Default indent step for formatting.
|
|
198
|
+
* Falls back to top-level `indentStep` or 2 if undefined.
|
|
199
|
+
*/
|
|
200
|
+
indentStep?: number;
|
|
201
|
+
/**
|
|
202
|
+
* AST mode used by the formatter.
|
|
203
|
+
* - 'loose' (default): try to repair mild indentation issues.
|
|
204
|
+
* - 'strict': keep lines as-is and only normalize cosmetic whitespace.
|
|
205
|
+
*/
|
|
206
|
+
mode?: FormatMode;
|
|
207
|
+
/**
|
|
208
|
+
* Sort non-comment entries lexicographically within their parent block.
|
|
209
|
+
* Matches the simple "sortEntries" behaviour you already had.
|
|
210
|
+
*/
|
|
211
|
+
sortEntries?: boolean;
|
|
212
|
+
/**
|
|
213
|
+
* When running `scaffold --watch`, if true then any changed structure file
|
|
214
|
+
* is formatted after save and before the scaffold run.
|
|
215
|
+
*/
|
|
216
|
+
formatOnWatch?: boolean;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Configuration for a single structure group.
|
|
220
|
+
*
|
|
221
|
+
* Groups allow you to clearly separate different roots in a project,
|
|
222
|
+
* such as "app", "routes", "resources/js", etc., each with its own
|
|
223
|
+
* structure definition.
|
|
224
|
+
*/
|
|
225
|
+
interface StructureGroupConfig {
|
|
226
|
+
/**
|
|
227
|
+
* Human-readable identifier for the group (e.g. "app", "routes", "frontend").
|
|
228
|
+
* Used mainly for logging and, optionally, cache metadata.
|
|
229
|
+
*/
|
|
230
|
+
name: string;
|
|
231
|
+
/**
|
|
232
|
+
* Root directory for this group, relative to the overall project root.
|
|
233
|
+
*
|
|
234
|
+
* Example: "app", "routes", "resources/js".
|
|
235
|
+
*
|
|
236
|
+
* All paths produced from this group's structure are resolved
|
|
237
|
+
* relative to this directory.
|
|
238
|
+
*/
|
|
239
|
+
root: string;
|
|
240
|
+
/**
|
|
241
|
+
* Optional inline structure entries for this group.
|
|
242
|
+
* If present and non-empty, these take precedence over `structureFile`.
|
|
243
|
+
*/
|
|
244
|
+
structure?: StructureEntry[];
|
|
245
|
+
/**
|
|
246
|
+
* Name of the structure file inside the scaffold directory for this group.
|
|
247
|
+
*
|
|
248
|
+
* Example: "app.txt", "routes.txt".
|
|
249
|
+
*
|
|
250
|
+
* If omitted, the default is `<name>.txt` within the scaffold directory.
|
|
251
|
+
*/
|
|
252
|
+
structureFile?: string;
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Root configuration object for @timeax/scaffold.
|
|
256
|
+
*
|
|
257
|
+
* This is what you export from `scaffold/config.ts` in a consuming
|
|
258
|
+
* project, or from any programmatic usage of the library.
|
|
259
|
+
*/
|
|
260
|
+
interface ScaffoldConfig {
|
|
261
|
+
/**
|
|
262
|
+
* Absolute or relative project root (where files are created).
|
|
263
|
+
*
|
|
264
|
+
* If omitted, the engine will treat `process.cwd()` as the root.
|
|
265
|
+
*/
|
|
266
|
+
root?: string;
|
|
267
|
+
/**
|
|
268
|
+
* Base directory where structures are applied and files/folders
|
|
269
|
+
* are actually created.
|
|
270
|
+
*
|
|
271
|
+
* This is resolved relative to `root` (not CWD).
|
|
272
|
+
*
|
|
273
|
+
* Default: same as `root`.
|
|
274
|
+
*
|
|
275
|
+
* Examples:
|
|
276
|
+
* - base: '.' with root: '.' → apply to <cwd>
|
|
277
|
+
* - base: 'src' with root: '.' → apply to <cwd>/src
|
|
278
|
+
* - base: '..' with root: 'tools' → apply to <cwd>/tools/..
|
|
279
|
+
*/
|
|
280
|
+
base?: string;
|
|
281
|
+
/**
|
|
282
|
+
* Path to the scaffold cache file, relative to `root`.
|
|
283
|
+
*
|
|
284
|
+
* Default: ".scaffold-cache.json"
|
|
285
|
+
*/
|
|
286
|
+
cacheFile?: string;
|
|
287
|
+
/**
|
|
288
|
+
* File size threshold (in bytes) above which deletions become
|
|
289
|
+
* interactive (e.g. ask "are you sure?").
|
|
290
|
+
*
|
|
291
|
+
* Default is determined by the core engine (e.g. 128 KB).
|
|
292
|
+
*/
|
|
293
|
+
sizePromptThreshold?: number;
|
|
294
|
+
/**
|
|
295
|
+
* Optional single-root structure (legacy or simple mode).
|
|
296
|
+
*
|
|
297
|
+
* If `groups` is defined and non-empty, this is ignored.
|
|
298
|
+
* Paths are relative to `root` in this mode.
|
|
299
|
+
*/
|
|
300
|
+
structure?: StructureEntry[];
|
|
301
|
+
/**
|
|
302
|
+
* Name of the single structure file in the scaffold directory
|
|
303
|
+
* for legacy mode.
|
|
304
|
+
*
|
|
305
|
+
* If `groups` is empty and `structure` is not provided, this
|
|
306
|
+
* file name is used (default: "structure.txt").
|
|
307
|
+
*/
|
|
308
|
+
structureFile?: string;
|
|
309
|
+
/**
|
|
310
|
+
* Multiple structure groups (recommended).
|
|
311
|
+
*
|
|
312
|
+
* When provided and non-empty, the engine will iterate over each
|
|
313
|
+
* group and apply its structure relative to each group's `root`.
|
|
314
|
+
*/
|
|
315
|
+
groups?: StructureGroupConfig[];
|
|
316
|
+
/**
|
|
317
|
+
* Hook configuration for file lifecycle events.
|
|
318
|
+
*
|
|
319
|
+
* Each category (e.g. "preCreateFile") is an array of hook configs,
|
|
320
|
+
* each with its own `include` / `exclude` / `files` filters.
|
|
321
|
+
*/
|
|
322
|
+
hooks?: {
|
|
323
|
+
[K in RegularHookKind]?: RegularHookConfig[];
|
|
324
|
+
};
|
|
325
|
+
/**
|
|
326
|
+
* Stub definitions keyed by stub name.
|
|
327
|
+
*
|
|
328
|
+
* These are referenced from structure entries by `stub: name`.
|
|
329
|
+
*/
|
|
330
|
+
stubs?: Record<string, StubConfig>;
|
|
331
|
+
/**
|
|
332
|
+
* When true, the CLI or consuming code may choose to start scaffold
|
|
333
|
+
* in watch mode by default (implementation-specific).
|
|
334
|
+
*
|
|
335
|
+
* This flag itself does not start watch mode; it is a hint to the
|
|
336
|
+
* runner / CLI.
|
|
337
|
+
*/
|
|
338
|
+
watch?: boolean;
|
|
339
|
+
/**
|
|
340
|
+
* Number of spaces per indent level in structure files.
|
|
341
|
+
* Default: 2.
|
|
342
|
+
*
|
|
343
|
+
* Examples:
|
|
344
|
+
* - 2 → "··entry"
|
|
345
|
+
* - 4 → "····entry"
|
|
346
|
+
*/
|
|
347
|
+
indentStep?: number;
|
|
348
|
+
/**
|
|
349
|
+
* Formatting configuration for structure files.
|
|
350
|
+
*/
|
|
351
|
+
format?: FormatConfig;
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* Options when scanning an existing directory into a structure.txt tree.
|
|
355
|
+
*/
|
|
356
|
+
interface ScanStructureOptions {
|
|
357
|
+
/**
|
|
358
|
+
* Glob patterns (relative to the scanned root) to ignore.
|
|
359
|
+
*/
|
|
360
|
+
ignore?: string[];
|
|
361
|
+
/**
|
|
362
|
+
* Maximum depth to traverse (0 = only that dir).
|
|
363
|
+
* Default: Infinity (no limit).
|
|
364
|
+
*/
|
|
365
|
+
maxDepth?: number;
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Options when scanning based on the scaffold config/groups.
|
|
369
|
+
*/
|
|
370
|
+
interface ScanFromConfigOptions extends ScanStructureOptions {
|
|
371
|
+
/**
|
|
372
|
+
* If provided, only scan these group names (by `StructureGroupConfig.name`).
|
|
373
|
+
* If omitted, all groups are scanned (or single-root mode).
|
|
374
|
+
*/
|
|
375
|
+
groups?: string[];
|
|
376
|
+
/**
|
|
377
|
+
* Optional override for scaffold directory; normally you can let
|
|
378
|
+
* loadScaffoldConfig resolve this from "<cwd>/scaffold".
|
|
379
|
+
*/
|
|
380
|
+
scaffoldDir?: string;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
export type { BaseEntryOptions as B, DirEntry as D, FileEntry as F, HookContext as H, RegularHookKind as R, ScaffoldConfig as S, ScanStructureOptions as a, ScanFromConfigOptions as b, StructureEntry as c, StubHookKind as d, HookFilter as e, RegularHookFn as f, StubHookFn as g, RegularHookConfig as h, StubHookConfig as i, StubConfig as j, FormatMode as k, FormatConfig as l, StructureGroupConfig as m };
|