UNPKG

26 kBTypeScriptView Raw
1/// <reference types="node" />
2
3import { Stats } from 'fs';
4import { Mode } from 'stat-mode';
5import { Debugger as DebugDebugger } from 'debug';
6import { GrayMatterFile } from 'gray-matter';
7import { WatchOptions } from 'chokidar';
8import micromatch = require('micromatch');
9declare class Metalsmith {
10 /**
11 * Initialize a new `Metalsmith` builder with a working `directory`.
12 **/
13 constructor(directory:string)
14 /**
15 *
16 */
17 matter: {
18 /**
19 * Return matter options to use for parsing & stringification
20 * [API Docs](https://metalsmith.io/api/#Metalsmith+matter+options) | [Source code](https://github.com/metalsmith/metalsmith/blob/v2.6.0/lib/matter.js#L27)
21 */
22 options(): Metalsmith.MatterOptions
23 /**
24 * Set matter options to use for parsing & stringification
25 * [API Docs](https://metalsmith.io/api/#Metalsmith+matter+options) | [Source code](https://github.com/metalsmith/metalsmith/blob/v2.6.0/lib/matter.js#L27)
26 */
27 options(options: Metalsmith.MatterOptions): void
28 /**
29 * Parse a string or buffer for front matter and return it as a {@linkcode Metalsmith.File} object.
30 * [API Docs](https://metalsmith.io/api/#Metalsmith+matter+parse) | [Source code](https://github.com/metalsmith/metalsmith/blob/v2.6.0/lib/matter.js#L37)
31 * @example
32 * metalsmith.matter.parse(Buffer.from('---\ntitle: Hello World\n---\nIntro\n---'))
33 * === {
34 * contents: Buffer<'Hello world'>,
35 * title: 'Hello World',
36 * excerpt: 'Intro'
37 * }
38 */
39 parse(contents: Buffer|string): Metalsmith.File,
40 /**
41 * Stringify a {@linkcode Metalsmith.File} object to a string with frontmatter and contents
42 * [API Docs](https://metalsmith.io/api/#Metalsmith+matter+stringify) | [Source code](https://github.com/metalsmith/metalsmith/blob/v2.6.0/lib/matter.js#L59)
43 * @example
44 * metalsmith.matter.stringify({
45 * contents: Buffer.from('body'),
46 * title: 'Hello World',
47 * excerpt: 'Intro'
48 * }) === `
49 * title: Hello World
50 * excerpt: Intro
51 * ---
52 * body
53 * `
54 */
55 stringify(file: Metalsmith.File): string
56 /**
57 * Wrap stringified front-matter-compatible data with the matter delimiters
58 * [API Docs](https://metalsmith.io/api/#Metalsmith+matter+wrap) | [Source code](https://github.com/metalsmith/metalsmith/blob/v2.6.0/lib/matter.js#L69)
59 */
60 wrap(stringifiedData: Buffer|string): string
61 }
62 /**
63 * Set the working `directory`. Relative paths resolve to `process.cwd()`
64 * [API Docs](https://metalsmith.io/api/#Metalsmith+directory) | [Source code](https://github.com/metalsmith/metalsmith/blob/v2.6.0/lib/index.js#L181)
65 * @example
66 * new Metalsmith(__dirname) // set the path of the working directory through the constructor
67 * metalsmith.directory('./other/path') // set the path of the working directory
68 */
69 directory(directory: string): Metalsmith;
70 /**
71 * Get the absolute path of the working directory.
72 * [API Docs](https://metalsmith.io/api/#Metalsmith+directory) | [Source code](https://github.com/metalsmith/metalsmith/blob/v2.6.0/lib/index.js#L181)
73 * @example
74 * const msdir = metalsmith.directory();
75 */
76 directory(): string;
77 /**
78 * Set the path of the `source` directory, relative to `metalsmith.directory()`
79 * [API Docs](https://metalsmith.io/api/#Metalsmith+source) | [Source code](https://github.com/metalsmith/metalsmith/blob/v2.6.0/lib/index.js#L217)
80 * @default 'src'
81 * @example
82 * metalsmith.source('src');
83 */
84 source(path: string): Metalsmith;
85 /**
86 * Get the absolute path of the `source` directory.
87 * [API](https://metalsmith.io/api/#Metalsmith+source) | [Source code](https://github.com/metalsmith/metalsmith/blob/v2.6.0/lib/index.js#L217)
88 * @example
89 * const src = metalsmith.source();
90 */
91 source(): string;
92 /**
93 * Set the path of the `destination` directory.
94 * [API Docs](https://metalsmith.io/api/#Metalsmith+destination) | [Source code](https://github.com/metalsmith/metalsmith/blob/v2.6.0/lib/index.js#L235)
95 * @default 'build'
96 * @example
97 * metalsmith.destination('build');
98 */
99 destination(
100 /** Relative or absolute `destination` directory path. */
101 path: string
102 ): Metalsmith;
103 /**
104 * Get the absolute path of the `destination` directory.
105 * [API Docs](https://metalsmith.io/api/#Metalsmith+destination) | [Source code](https://github.com/metalsmith/metalsmith/blob/v2.6.0/lib/index.js#L235)
106 * @example
107 * const dest = metalsmith.destination()
108 */
109 destination(): string;
110 /**
111 * Set the `max` number of files to open at once. Useful if you encounter `EMFILE` errors, see [Node.js docs](https://nodejs.org/api/errors.html#errors_common_system_errors)
112 * [API Docs](https://metalsmith.io/api/#Metalsmith+concurrency) | [Source code](https://github.com/metalsmith/metalsmith/blob/v2.6.0/lib/index.js#L253)
113 * @default Infinity
114 * @example
115 * metalsmith.concurrency(50)
116 */
117 concurrency(
118 /** Maximum number of file descriptors to open simultaneously. Defaults to `Infinity` */
119 max: number
120 ): Metalsmith;
121 /**
122 * Get the `max` number of files to open at once.
123 * [API](https://metalsmith.io/api/#Metalsmith+concurrency) | [Source](https://github.com/metalsmith/metalsmith/blob/v2.6.0/lib/index.js#L253)
124 * @example
125 * const max = metalsmith.concurrency()
126 */
127 concurrency(): number;
128 /**
129 * Set whether {@linkcode Metalsmith.directory} will be `cleaned` before writing. Defaults to `true`.
130 * [API Docs](https://metalsmith.io/api/#Metalsmith+clean) | [Source code](https://github.com/metalsmith/metalsmith/blob/v2.6.0/lib/index.js#L270)
131 * @default true
132 * @example
133 * metalsmith.clean(false)
134 */
135 clean(clean: boolean): Metalsmith;
136 /**
137 * Get whether the destination directory will be `cleaned` before writing.
138 * [API Docs](https://metalsmith.io/api/#Metalsmith+clean) | [Source code](https://github.com/metalsmith/metalsmith/blob/v2.6.0/lib/index.js#L270)
139 * @example
140 * const clean = metalsmith.clean()
141 */
142 clean(): boolean;
143 /**
144 * Set the flag on whether to parse YAML `frontmatter`
145 * [API Docs](https://metalsmith.io/api/#Metalsmith+frontmatter) | [Source code](https://github.com/metalsmith/metalsmith/blob/v2.6.0/lib/index.js#L291)
146 * @default true
147 * @example
148 * metalsmith.frontmatter(false);
149 */
150 frontmatter(frontmatter?: boolean | {}): Metalsmith;
151 /**
152 * Get the flag on whether to parse YAML `frontmatter`
153 * [API Docs](https://metalsmith.io/api/#Metalsmith+frontmatter) | [Source code](https://github.com/metalsmith/metalsmith/blob/v2.6.0/lib/index.js#L291)
154 * @example
155 * const on = metalsmith.frontmatter() // true or false
156 */
157 frontmatter(): boolean;
158 /** Consult [chokidar.watchOptions](https://github.com/paulmillr/chokidar#api) in use by `metalsmith.watch`.
159 * [API Docs](https://metalsmith.io/api/#Metalsmith+watch) | [Source code](https://github.com/metalsmith/metalsmith/blob/v2.6.0/lib/index.js#L510)
160 * @example
161 * metalsmith.watch()
162 * // {
163 * // paths: [metalsmith.source()],
164 * // ignoreInitial: true,
165 * // awaitWriteFinish: false,
166 * // ignore: metalsmith.ignore(),
167 * // alwaysStat: false
168 * // }
169 */
170 watch(): false|WatchOptions
171 /**
172 * Set the list of paths to watch and trigger rebuilds on. The watch method will skip files ignored with {@linkcode Metalsmith.ignore}
173 * and will do partial (true) or full (false) rebuilds depending on the {@linkcode Metalsmith.clean} setting.
174 * It can be used both for rebuilding in-memory with {@linkcode Metalsmith.process} or writing to file system with {@linkcode Metalsmith.build}.
175 * [API Docs](https://metalsmith.io/api/#Metalsmith+watch) | [Source code](https://github.com/metalsmith/metalsmith/blob/v2.6.0/lib/index.js#L510)
176 * @default false
177 * @example
178 * metalsmith
179 * .ignore(['wont-be-watched']) // ignored
180 * .clean(false) // do partial rebuilds
181 * .watch(true) // watch all files in metalsmith.source()
182 * .watch(['lib','src']) // or watch files in directories 'lib' and 'src'
183 */
184 watch(
185 /** `true` or `false` to watch {@linkcode Metalsmith.source}, or one or more paths/ globs, or a subset of chokidar watchOptions */
186 watch: boolean|string|string[]|Omit<WatchOptions, 'ignoreInitial'|'ignored'|'alwaysStat'|'cwd'>
187 ): Metalsmith;
188 /**
189 * Get a single metalsmith environment variable. Metalsmith env vars are case-insensitive.
190 * [API Docs](https://metalsmith.io/api/#Metalsmith+env) | [Source code](https://github.com/metalsmith/metalsmith/blob/v2.6.0/lib/index.js#L372)
191 * @example
192 * const env = metalsmith.env('NODE_ENV')
193 * if (env === 'development') { ... }
194 */
195 env(name:string): number|boolean|string|null;
196 /**
197 * Get all metalsmith environment variables. Metalsmith env vars are returned in capital-case.
198 * [API Docs](https://metalsmith.io/api/#Metalsmith+env) | [Source code](https://github.com/metalsmith/metalsmith/blob/v2.6.0/lib/index.js#L372)
199 * @example
200 * const env = metalsmith.env();
201 * console.log(env) // { NODE_ENV: 'development' }
202 */
203 env(): Object;
204 /**
205 * Set a single metalsmith environment variable (chainable). Metalsmith env vars are case-insensitive.
206 * [API Docs](https://metalsmith.io/api/#Metalsmith+env) | [Source code](https://github.com/metalsmith/metalsmith/blob/v2.6.0/lib/index.js#L372)
207 * @example
208 * metalsmith
209 * .env('NODE_ENV', process.env.NODE_ENV)
210 * .env('DEBUG', '@metalsmith/*')
211 */
212 env(name:string, value: number|boolean|string|null): Metalsmith;
213 /**
214 * Add multiple metalsmith environment variables at once (chainable). Metalsmith env vars are case-insensitive.
215 * This signature will overwrite but not remove existing metalsmith environment variables
216 * [API Docs](https://metalsmith.io/api/#Metalsmith+env) | [Source code](https://github.com/metalsmith/metalsmith/blob/v2.6.0/lib/index.js#L372)
217 * @example
218 * metalsmith.env({
219 * NODE_ENV: process.env.NODE_ENV,
220 * DEBUG: '@metalsmith/*'
221 * })
222 */
223 env(env: {[key:string]: (number|boolean|string|null)}): Metalsmith;
224 /**
225 * Assign values to the global `metadata` object.
226 * [API Docs](https://metalsmith.io/api/#Metalsmith+metadata) | [Source code](https://github.com/metalsmith/metalsmith/blob/v2.6.0/lib/index.js#L199)
227 * @example
228 * metalsmith.metadata({
229 * sitename: "My Static Site",
230 * baseurl: process.env.NODE_ENV === 'development' ? 'http://localhost:8080' : 'https://johndoe.com'
231 * });
232 */
233 metadata(metadata: object): Metalsmith;
234 /**
235 * Get the global `metadata` object.
236 * [API Docs](https://metalsmith.io/api/#Metalsmith+metadata) | [Source code](https://github.com/metalsmith/metalsmith/blob/v2.6.0/lib/index.js#L199)
237 * @example
238 * const metadata = metalsmith.metadata();
239 */
240 metadata(): object;
241 /**
242 * Add a `plugin` function to the stack.
243 * [API Docs](https://metalsmith.io/api/#Metalsmith+use) | [Source code](https://github.com/metalsmith/metalsmith/blob/v2.6.0/lib/index.js#L164)
244 * @example
245 * import markdown from '@metalsmith/markdown'
246 * metalsmith.use(markdown({ gfm: true }))
247 */
248 use(plugin: Metalsmith.Plugin | Metalsmith.Plugin[]): Metalsmith;
249 /**
250 * Set the {@linkcode Metalsmith.ignores} files/paths to ignore loading into Metalsmith.
251 * [API Docs](https://metalsmith.io/api/#Metalsmith+ignore) | [Source code](https://github.com/metalsmith/metalsmith/blob/v2.6.0/lib/index.js#L316)
252 * @example
253 * metalsmith.ignore("corrupted.html");
254 * metalsmith.ignore(function (filepath: string, stats: Stats) {
255 * return stats.isDirectory() && path.basename(filepath) === 'nested';
256 * });
257 */
258 ignore(files: string | string[] | Metalsmith.Ignore | Metalsmith.Ignore[]): Metalsmith;
259 /**
260 * Get the array of {@linkcode Metalsmith.ignores} files/paths.
261 * [API Docs](https://metalsmith.io/api/#Metalsmith+ignore) | [Source code](https://github.com/metalsmith/metalsmith/blob/v2.6.0/lib/index.js#L316)
262 * @example
263 * const ignored = metalsmith.ignore();
264 */
265 ignore(): string[];
266 /**
267 * Match filepaths in the source directory by [glob](https://en.wikipedia.org/wiki/Glob_(programming)) pattern.
268 * If `input` is not specified, patterns are matched against `Object.keys(files)`
269 * [API Docs](https://metalsmith.io/api/#Metalsmith+match) | [Source code](https://github.com/metalsmith/metalsmith/blob/v2.6.0/lib/index.js#L346)
270 * @example
271 * // match all .html files at the source dir root but omit files starting with a dot:
272 * metalsmith.match('*.html', Object.keys(files), { dot: false })
273 */
274 match(pattern:string|string[], input?:string[], options?:Omit<micromatch.Options, 'format'>): string[];
275 /**
276 * Resolve `paths` relative to the root directory.
277 * [API Docs](https://metalsmith.io/api/#Metalsmith+path) | [Source code](https://github.com/metalsmith/metalsmith/blob/v2.6.0/lib/index.js#L332)
278 * @example
279 * const path = metalsmith.path("./dist", "assets");
280 */
281 path(...paths: string[]): string;
282 /**
283 * Perform the build with the current settings outputting to {@linkcode Metalsmith.destination}.
284 * [API Docs](https://metalsmith.io/api/#Metalsmith+build) | [Source code](https://github.com/metalsmith/metalsmith/blob/v2.6.0/lib/index.js#L407)
285 * @example
286 * metalsmith.build()
287 * .then(files => console.log(`Build success. Processed ${files.length}`))
288 * .catch(err => { throw err })
289 */
290 build(): Promise<Metalsmith.Files>;
291 /**
292 * Perform the build with the current settings outputting to {@linkcode Metalsmith.destination}.
293 * [API Docs](https://metalsmith.io/api/#Metalsmith+build) | [Source code](https://github.com/metalsmith/metalsmith/blob/v2.6.0/lib/index.js#L407)
294 * @example
295 * metalsmith.build((err, files) => {
296 * if (err) throw err
297 * console.log(`Build success. Processed ${files.length}`)
298 * });
299 */
300 build(callback: Metalsmith.Callback): void;
301 /**
302 * Process files through {@linkcode Metalsmith.plugins} without writing out files.
303 * [API Docs](https://metalsmith.io/api/#Metalsmith+process) | [Source code](https://github.com/metalsmith/metalsmith/blob/v2.6.0/lib/index.js#L549)
304 * @example
305 * metalsmith.process()
306 * .then(files => console.log(`Done processing ${files.length} files.`))
307 * .catch(err => { throw err })
308 */
309 process(): Promise<Metalsmith.Files>;
310 /**
311 * Process files through {@linkcode Metalsmith.plugins} without writing out files.
312 * [API Docs](https://metalsmith.io/api/#Metalsmith+process) | [Source code](https://github.com/metalsmith/metalsmith/blob/v2.6.0/lib/index.js#L549)
313 * @example
314 * metalsmith.process((err, files) => {
315 * if (err) throw err
316 * console.log(`Done processing ${files.length} files.`))
317 * })
318 */
319 process(callback: Metalsmith.Callback): void;
320 /**
321 * Run a set of files through the plugins stack.
322 * [API Docs](https://metalsmith.io/api/#Metalsmith+run) | [Source code](https://github.com/metalsmith/metalsmith/blob/v2.6.0/lib/index.js#L581)
323 * @example
324 * const file = { contents: Buffer.from('contents') }
325 * metalsmith.run({ 'index.html': file } , (err, files) => { if (err) {throw err;}});
326 */
327 run(
328 files: Metalsmith.Files,
329 callback: Metalsmith.Callback
330 ): void;
331 /**
332 * `Run` a set of files through the plugins stack.
333 * [API Docs](https://metalsmith.io/api/#Metalsmith+run) | [Source code](https://github.com/metalsmith/metalsmith/blob/v2.6.0/lib/index.js#L581)
334 * @example
335 * const file = { contents: Buffer.from('contents') }
336 * metalsmith.run({ 'index.html': file }, metalsmith.plugins, (err, files) => { if (err) {throw err;}});
337 */
338 run(
339 files: Metalsmith.Files,
340 /** Defaults to {@linkcode Metalsmith.plugins} */
341 plugins: Metalsmith.Plugin[],
342 callback: Metalsmith.Callback
343 ): void;
344 /**
345 * `Run` a set of files through the plugins stack.
346 * [API Docs](https://metalsmith.io/api/#Metalsmith+run) | [Source code](https://github.com/metalsmith/metalsmith/blob/v2.6.0/lib/index.js#L581)
347 * @example
348 * const file = { contents: Buffer.from('contents') }
349 * metalsmith.run({ 'index.html': file }, metalsmith.plugins)
350 * .then(files => {})
351 * .catch(err => { if (err) {throw err;}});
352 */
353 run(
354 files: Metalsmith.Files,
355 /** Defaults to {@linkcode Metalsmith.plugins} */
356 plugins?: Metalsmith.Plugin[]
357 ): Promise<Metalsmith.Files>;
358 /**
359 * Read a dictionary of files from a `dir`, parsing frontmatter *(promise variant)*.
360 * If no directory is provided, it will default to {@linkcode Metalsmith.source}.
361 * [API Docs](https://metalsmith.io/api/#Metalsmith+read) | [Source code](https://github.com/metalsmith/metalsmith/blob/v2.6.0/lib/index.js#L625)
362 * @example
363 * metalsmith.read('relative/to/msdir')
364 * .then(files => console.log(files))
365 * .catch(err => { throw err })
366 */
367 read(
368 /** Directory to read. Defaults to {@linkcode Metalsmith.source} */
369 dir?: string
370 ): Promise<Metalsmith.Files>;
371 /**
372 * Read a dictionary of files from a `dir`, parsing frontmatter.
373 * If no directory is provided, it will default to {@linkcode Metalsmith.source}.
374 * [API Docs](https://metalsmith.io/api/#Metalsmith+read) | [Source code](https://github.com/metalsmith/metalsmith/blob/v2.6.0/lib/index.js#L625)
375 * @example
376 * metalsmith.read('relative/to/msdir', (err, files) => {
377 * if (err) throw err
378 * console.log(files)
379 * });
380 */
381 read(
382 /** Directory to read. Defaults to {@linkcode Metalsmith.source} */
383 dir: string,
384 callback: Metalsmith.Callback
385 ): void
386 /**
387 * Read a `file` by path. Relative paths resolve to {@linkcode Metalsmith.source}.
388 * [API Docs](https://metalsmith.io/api/#Metalsmith+readFile) | [Source code](https://github.com/metalsmith/metalsmith/blob/v2.6.0/lib/index.js#L663)
389 * @example
390 * metalsmith.readFile('index.md')
391 * .then(file => {
392 * const { contents, stat, mode, ...metadata } = file
393 * })
394 * .catch(err => { throw err });
395 */
396 readFile(file: string): Promise<Metalsmith.File>;
397 /**
398 * Read a `file` by path. Relative paths resolve to {@linkcode Metalsmith.source}.
399 * [API Docs](https://metalsmith.io/api/#Metalsmith+readFile) | [Source code](https://github.com/metalsmith/metalsmith/blob/v2.6.0/lib/index.js#L663)
400 * @example
401 * metalsmith.readFile("a.html", (err, file) => {
402 * if (err) throw err
403 * const { contents, stat, mode, ...metadata } = file
404 * });
405 */
406 readFile(file: string, callback: (err:Error|null, file?:Metalsmith.File) => void): void;
407 /**
408 * Write an object of {@linkcode Metalsmith.Files} to a destination `dir`. Relative paths resolve to {@linkcode Metalsmith.destination}.
409 * [API Docs](https://metalsmith.io/api/#Metalsmith+write) | [Source code](https://github.com/metalsmith/metalsmith/blob/v2.6.0/lib/index.js#L719)
410 * @example
411 * const files = {
412 * 'index.html': { contents: Buffer.from('...') }
413 * }
414 * metalsmith.write(files, metalsmith.path("./dist"));
415 */
416 write(files: Metalsmith.Files, dir: string, callback: Metalsmith.Callback): void;
417 /**
418 * Write an object of {@linkcode Metalsmith.Files} to a destination `dir`. Relative paths resolve to {@linkcode Metalsmith.destination}.
419 * [API Docs](https://metalsmith.io/api/#Metalsmith+write) | [Source code](https://github.com/metalsmith/metalsmith/blob/v2.6.0/lib/index.js#L719)
420 * @example
421 * metalsmith.write({fileA: "a.html"} , metalsmith.path("./dist"));
422 */
423 write(files: Metalsmith.Files, callback: Metalsmith.Callback): void;
424 /**
425 * Write an object of {@linkcode Metalsmith.Files} to a destination `dir`. Relative paths resolve to {@linkcode Metalsmith.destination}.
426 * [API Docs](https://metalsmith.io/api/#Metalsmith+write) | [Source code](https://github.com/metalsmith/metalsmith/blob/v2.6.0/lib/index.js#L719)
427 * @example
428 * const file = { contents: Buffer.from('...')
429 * metalsmith.write({ 'index.html': file })
430 * .then(() => console.log('Files written'))
431 * .catch(err => { throw err })
432 */
433 write(files: Metalsmith.Files, dir?:string): Promise<void>;
434 /**
435 * Write {@linkcode Metalsmith.File|data} to `filepath`. Relative paths resolve to {@linkcode Metalsmith.destination}.
436 * [API Docs](https://metalsmith.io/api/#Metalsmith+writeFile) | [Source code](https://github.com/metalsmith/metalsmith/blob/v2.6.0/lib/index.js#L650)
437 * @example
438 * const file = { contents: Buffer.from('File Contents') }
439 * metalsmith.writeFile("test.html", file)
440 * .then(() => console.log('File written'))
441 * .catch(err => { throw err })
442 */
443 writeFile(filepath: string, data: Metalsmith.File): Promise<void>;
444 /**
445 * Write {@linkcode Metalsmith.File|data} to `filepath`. Relative paths resolve to {@linkcode Metalsmith.destination}.
446 * [API Docs](https://metalsmith.io/api/#Metalsmith+writeFile) | [Source code](https://github.com/metalsmith/metalsmith/blob/v2.6.0/lib/index.js#L650)
447 * @example
448 * const file = { contents: Buffer.from('File Contents') }
449 * metalsmith.writeFile("test.html", file, (err) => {
450 * if (err) throw err
451 * console.log('File written')
452 * })
453 */
454 writeFile(filepath: string, data: Metalsmith.File, callback:(error:Error|null) => void): void;
455
456 /**
457 * Initialize a plugin {@linkcode Metalsmith.Debugger}
458 * [API Docs](https://metalsmith.io/api/#Metalsmith+debug) | [Source code](https://github.com/metalsmith/metalsmith/blob/v2.6.0/lib/debug.js)
459 * @example
460 * const debugger = metalsmith.debug('metalsmith-myplugin')
461 *
462 * debug('a log') // logs 'metalsmith-myplugin a log'
463 * debug.info('an info') // logs 'metalsmith-myplugin:info an info'
464 * debug.warn('a warning') // logs 'metalsmith-myplugin:warn a warning'
465 * debug.error('an error') // logs 'metalsmith-myplugin:error an error'
466 */
467 debug: {
468 (
469 /** A metalsmith plugin debug namespace */
470 namespace:string
471 ): Metalsmith.Debugger;
472
473 enable(namespaces:string): void;
474 disable(): void;
475 handle(...args:any[]): void;
476 colors: boolean;
477 enabled: boolean;
478 }
479
480 /**
481 * The (read-only) list of plugins `use`'d by the current metalsmith instance.
482 * When read from inside a plugin, the list is guaranteed to be complete
483 */
484 readonly plugins: Metalsmith.Plugin[];
485
486 /**
487 * The (read-only) list of ignores of the current metalsmith instance
488 */
489 readonly ignores: string[];
490}
491
492/**
493 * Initialize a new `Metalsmith` builder with a working `directory`.
494 * [API Docs](https://metalsmith.io/api/#Metalsmith) | [Source code](https://github.com/metalsmith/metalsmith/blob/v2.6.0/lib/index.js#L119)
495 * @example
496 * import { fileURLToPath } from 'url'
497 * import { dirname } from 'path'
498 * import Metalsmith from 'metalsmith'
499 *
500 * const __dirname = dirname(fileURLToPath(import.meta.url))
501 * const metalsmith = Metalsmith(__dirname)
502 */
503declare function Metalsmith(directory: string): Metalsmith;
504
505declare namespace Metalsmith {
506 /**
507 * A Metalsmith plugin is a function that is passed the file list, the metalsmith instance, and a `done` callback.
508 * Calling the callback is required for asynchronous plugins, and optional for synchronous plugins.
509 */
510 type Plugin = (files: Files, metalsmith: Metalsmith, callback: DoneCallback) => void|Promise<void>;
511 type DoneCallback = (err?: Error) => void;
512 type Callback = (err: Error | null, files: Files) => void;
513 type Ignore = (path: string, stat: Stats) => void;
514
515 /**
516 * Metalsmith representation of a file
517 */
518 type File<AdditionalProperties extends Record<string, unknown> = Record<string, unknown>> = {
519 /** A Node {@linkcode Buffer} that can be `.toString`'ed to obtain its human-readable contents */
520 contents: Buffer;
521 /** A Node {@linkcode Stats} object with extra filesystem metadata and methods (like {@linkcode Stats.isFile}) */
522 stats?: Stats;
523 /** Octal permission {@linkcode Mode} of a file */
524 mode?: string;
525 } & AdditionalProperties
526
527 /**
528 * Metalsmith representation of the files in {@linkcode Metalsmith.source}.
529 * The keys represent the file paths and the values are {@linkcode Metalsmith.File} objects
530 */
531 interface Files {
532 [filepath: string]: File;
533 }
534 /** Metalsmith debugger */
535 interface Debugger extends DebugDebugger {
536 info: DebugDebugger;
537 warn: DebugDebugger;
538 error: DebugDebugger;
539 }
540
541 interface MatterOptions {
542 language?: string
543 excerpt?: boolean | ((file:GrayMatterFile<string>, options: Metalsmith.MatterOptions) => {})
544 excerpt_separator?: string
545 delimiters?: string | string[]
546 engines?: {
547 [engine:string]: ((file:string) => any) | {
548 parse: (file:string) => any
549 stringify?: (data:any) => string
550 }
551 }
552 }
553}
554
555export = Metalsmith;