Skip to content

Latest commit

 

History

History
51 lines (36 loc) · 1.47 KB

README.md

File metadata and controls

51 lines (36 loc) · 1.47 KB

Build a declaration file for Astro Integrations

This utility function is used to build a declaration file for use with Astro's injectTypes function added in the astro:config:done Integration Hook in Astro 4.14.0. This function is useful for generating TypeScript declaration files for Astro Integrations.

Example Usage

// Import and use the function
import buildDeclarationFile from '@matthiesenxyz/astrodtsbuilder';
const dts = buildDeclarationFile();

// Add a note to the file
dts.addSingleLineNote(`This file was generated by '@my-example/module'`);

// Add a Multi-line Note to the file
dts.addMultiLineNote(['It does some cool and helpful stuff', 'It also does some other cool stuff']);

// Add a module with a default export and single line description
dts.addModule("example:module", {
  defaultExport: {
    typeDef: "import('@my-example/module').ExampleModule",
    singleLineDescription: "This is the default Module",
  }
});

// Write the file
const dtsFile = dts.makeFile();

// Output the file
console.log(dtsFile);

Example Output

// This file was generated by '@my-example/module'

// It does some cool and helpful stuff
// It also does some other cool stuff

declare module 'example:module' {
    //** This is the default Module * /
    const defaultExport: import('@my-example/module').ExampleModule;
    export default defaultExport;

}

Licensing

MIT Licensed. Made with ❤️ by Adam Matthiesen.