//#region src/lib/options/append.d.ts interface AppendOption { /** * File paths to read in and append to the bottom of the generated license file * * This is useful for content that's included via a CDN or for other types * of content that are not included in the project's package.json * like images or fonts * * @example ["./licenses/some-image.txt", "./licenses/some-font.txt"] */ append?: string[]; } //#endregion //#region src/lib/options/exclude.d.ts interface ExcludeOption { /** * Packages to exclude from the generated license file * * Packages need to be specified with an exact version * * This is useful for when you're confident that a package * is not actually used in your project and you want to * exclude it from the generated license file * * @example ["react@16.13.1"] */ exclude?: string[]; } //#endregion //#region src/lib/lineEndings.d.ts declare const lineEndings: readonly ["crlf", "lf"]; /** * Used to specify which line endings to use in the generated file. * * Possible values are: * * `crlf` (`\r\n`) * * `lf` (`\n`) */ type LineEnding = (typeof lineEndings)[number]; //#endregion //#region src/lib/options/lineEnding.d.ts type LineEndingOption = { /** * Specify the line ending to use in the generated license file: either "lf" or "crlf" * * If you don't specify a line ending then line ending of the operating * system will be used * * This is useful if different operating systems are used by different * people who are working of the same project */ lineEnding?: LineEnding; }; //#endregion //#region src/lib/options/omitVersions.d.ts interface OmitVersionsOption { /** * Option to omit the package version numbers in the output * * This is useful when you want to generate a license file that only * includes the package name without a specific version number. * * @example true */ omitVersions?: boolean; } //#endregion //#region src/lib/options/optionsExpander.d.ts /** * This type takes an intersection type and expands each intersected type into a new single type. * * Think of it like the following but for types rather than instances: * ```ts * const a = { a: 1 }; * const b = { b: 2 }; * const intersection = { ...a, ...b }; * ``` * a.k.a * ```ts * type A = { a: number }; * type B = { b: number }; * type Intersection = IntersectionExpander; * ``` * * This is really useful because it means that IDE tooltips * show all the fields from the intersected types rather than * just the intersection itself * * If you simply use: * ```ts * type Intersection = A & B; * ``` * * Then an IDE tooltip will show: * ```ts * type Intersection = A & B; * ``` * * But if you use * ```ts * type Intersection = IntersectionExpander; * ``` * * Then an IDE tooltip will show: * ```ts * type Intersection = { * a: number; * b: number; * } * ``` * * This means we can use the `IntersectionExpander` type to * compose options interfaces together and have the IDE * show all the fields within each option interface. * * The composition of options interfaces is important because * it means we only need to write the JSdoc for each option once. * * @link https://stackoverflow.com/a/69288824/3075190 */ type IntersectionExpander = T extends ((...args: infer A) => infer R) ? (...args: IntersectionExpander) => IntersectionExpander : T extends (infer O) ? { [K in keyof O]: O[K]; } : never; //#endregion //#region src/lib/options/replace.d.ts interface ReplaceOption { /** * A map of packages-to-file-paths containing content * that should be used instead of the package's license content * * Packages can be specified with or without exact versions, * though using versions is recommended to avoid uncertainty. * * This is useful for when a package is dual licensed and you * want to use one of the licenses instead of the other * * @example { * "react@16.13.1": "./licenses/react.txt", * "lodash": "./node_modules/lodash/LICENSE.md", * } */ replace?: Record; } //#endregion //#region src/lib/generateLicenseFile.d.ts type GenerateLicenseFileOptions = IntersectionExpander; /** * Scans the project found at the given path and creates a license file at the given output location * @param pathToPackageJson A path to the package.json for the project. The file must be named package.json * @param outputPath A file path for the resulting license file * @param options Additional options for the license file generation */ declare function generateLicenseFile(pathToPackageJson: string, outputPath: string, options?: GenerateLicenseFileOptions): Promise; /** * Scans the projects found at the given paths and creates a license file at the given output location * @param pathsToPackageJsons Paths to the package.jsons for the projects. Each file must be named package.json * @param outputPath A file path for the resulting license file * @param options Additional options for the license file generation */ declare function generateLicenseFile(pathsToPackageJsons: string[], outputPath: string, options?: GenerateLicenseFileOptions): Promise; //#endregion //#region src/lib/getLicenseFileText.d.ts type GetLicenseFileTextOptions = IntersectionExpander; /** * Scans the project found at the given path and returns a string containing the licenses for all of the dependencies * @param pathToPackageJson A path to the package.json for the project. The file must be named package.json * @param options Additional options for the license text generation * @returns A promise that resolves to the license file text */ declare function getLicenseFileText(pathToPackageJson: string, options?: GetLicenseFileTextOptions): Promise; /** * Scans the projects found at the given paths and returns a string containing the licenses for all the dependencies across all the projects * @param pathsToPackageJsons Paths to the package.jsons for the projects. Each file must be named package.json * @param options Additional options for the license text generation * @returns A promise that resolves to the license file text */ declare function getLicenseFileText(pathsToPackageJsons: string[], options?: GetLicenseFileTextOptions): Promise; //#endregion //#region src/lib/models/license.d.ts /** * ILicense contains the content of a given license and the list of dependencies it pertains to. */ interface ILicense { /** * Body of the license. */ content: string; /** * Notices for the license. */ notices: string[]; /** * List of node packages that this license applies to. */ dependencies: string[]; } //#endregion //#region src/lib/getProjectLicenses.d.ts type GetProjectLicensesOptions = IntersectionExpander; /** * Scans the project found at the given path and returns an array of objects each * containing the details of an identified license and the dependencies it pertains to. * @param pathToPackageJson A path to the package.json for the project. The file must be named package.json * @param options Additional options for the license discovery * @returns Array of `ILicense`s each containing the license content and respective dependencies */ declare function getProjectLicenses(pathToPackageJson: string, options?: GetProjectLicensesOptions): Promise; //#endregion export { type GenerateLicenseFileOptions, type GetLicenseFileTextOptions, type GetProjectLicensesOptions, type ILicense, type LineEnding, generateLicenseFile, getLicenseFileText, getProjectLicenses };