sync-npm-packages
Version:
Sync released npm packages to a mirror site.
135 lines (131 loc) • 3.21 kB
text/typescript
interface DetectOptions {
/**
* Current working directory for glob
*
* @default process.cwd()
*/
cwd?: string;
/**
* Use built-in default ignore patterns
*
* @default true
*/
defaultIgnore?: boolean;
/**
* Exclude packages from being synced
*
* @default []
*/
exclude?: string | string[];
/**
* Ignore package.json glob pattern
*
* @default []
*/
ignore?: string | string[];
/**
* Additional packages to sync
*
* @default []
*/
include?: string | string[];
/**
* With `optionalDependencies` in `package.json`
*
* @default false
*/
withOptional?: boolean;
}
interface SyncOptions {
/**
* Target mirror site to sync
*
* @requires
*/
target: 'npmmirror';
/**
* Enable debug mode
*
* @default false
*/
debug?: boolean;
}
/**
* options
*/
type Options = DetectOptions & SyncOptions & {
/**
* Dry run
*
* @default false
*/
dry?: boolean;
};
/**
* All property is optional
*/
type OptionalOptions = Partial<Options>;
/**
* partial of package.json type
*/
interface PackageJson {
name: string;
version: string;
optionalDependencies?: Record<string, string>;
private?: boolean;
}
/**
* Sync npm packages release to a mirror site
*
* @param input - package names
* @param options - sync options {@link SyncOptions}
* @returns a Promise with no resolved value
*
* @example
*
* ```ts
* import { syncNpmPackages } from 'sync-npm-packages'
*
* // single package
* await syncNpmPackages('package-foobar', { target: 'npmmirror' })
*
* // multiple packages
* await syncNpmPackages(['package-foo', 'package-bar'], { target: 'npmmirror' })
* ```
*/
declare function syncNpmPackages(input: string | string[], options: SyncOptions): Promise<void[]>;
/**
* Get valid package names from all package.json files
*
* @param options - detect options {@link DetectOptions}
* @returns a promise resolves valid package names
*/
declare function getValidPackageNames(options?: DetectOptions): Promise<string[]>;
/**
* Auto detect and sync npm packages release to a mirror site
* @param options - detect options {@link DetectOptions} and sync options {@link SyncOptions }
*
* @example
*
* ```ts
* import { syncNpmPackagesAuto } from 'sync-npm-packages'
*
* await syncNpmPackagesAuto({ target: 'npmmirror' })
* ```
*/
declare function syncNpmPackagesAuto(options: DetectOptions & SyncOptions): Promise<void[]>;
/**
* Define config for cli and NodeJS api
*
* @param config - user defined config
* @returns config
*/
declare function defineConfig(config?: OptionalOptions): OptionalOptions;
/**
* Resolve user definedConfig based on cli config and config file
*
* @param cliConfig - cli config
* @returns merged config
*/
declare function resolveConfig<T extends OptionalOptions = {}>(cliConfig?: Partial<T>): Promise<Partial<T>>;
export { type DetectOptions, type OptionalOptions, type Options, type PackageJson, type SyncOptions, defineConfig, getValidPackageNames, resolveConfig, syncNpmPackages, syncNpmPackagesAuto };