diff --git a/README.md b/README.md index 3effee8..768b7df 100644 --- a/README.md +++ b/README.md @@ -23,16 +23,17 @@ Insert script to `package.json` ``` ## CLI -| Flag | Description | Default | -|-------------------|---------------------------------------|----------------------------| -| `--help` | Display usage hints | | -| `--cwd` | Set current working dir | `process.cwd()` | -| `--entry` | Define pkg entry point | `./index.ts` | -| `--tsconfig` | Define path(s) to project's TS config | | -| `--customTypings` | Attach custom libdefs to d.ts bundle | | -| `--cache` | Dir for temporary assets | `tempy.directory()` | -| `--dtsOut` | **TS** typings output | `typings/index.d.ts` | -| `--flowOut` | **Flow** libdef output | `flow-typed/index.flow.js` | +| Flag | Description | Default | +|-------------------|-------------------------------------------------------------|----------------------------| +| `--help` | Display usage hints | | +| `--cwd` | Set current working dir | `process.cwd()` | +| `--entry` | Define pkg entry point | `./index.ts` | +| `--ext` | Extension to use in module declarations. `''` to unset any. | `.js` | +| `--tsconfig` | Define path(s) to project's TS config | | +| `--customTypings` | Attach custom libdefs to d.ts bundle | | +| `--cache` | Dir for temporary assets | `tempy.directory()` | +| `--dtsOut` | **TS** typings output | `typings/index.d.ts` | +| `--flowOut` | **Flow** libdef output | `flow-typed/index.flow.js` | ## License [MIT](./LICENSE) diff --git a/src/main/ts/cli.ts b/src/main/ts/cli.ts index ea3d2c0..cc15505 100644 --- a/src/main/ts/cli.ts +++ b/src/main/ts/cli.ts @@ -11,7 +11,8 @@ const cli = meow( --cwd, working dir path --tsconfig --customTypings, attach custom libdefs to d.ts bundle - --entry, alias entry (/target/es5/index by default) + --entry, pkg entry point (/index by default) + --ext, extension to use in module declarations (default: .js) --dtsOut, dts output (typings/index.d.ts by default) --flowOut, flow output (flow-typed/index.flow.js by default) `, @@ -38,6 +39,12 @@ const cli = meow( cache: { type: 'string', }, + entry: { + type: 'string', + }, + ext: { + type: 'string', + }, }, }, ) diff --git a/src/main/ts/dts.ts b/src/main/ts/dts.ts index 747042c..24c0e97 100644 --- a/src/main/ts/dts.ts +++ b/src/main/ts/dts.ts @@ -14,6 +14,7 @@ export const generate = ( name: string, cwd: string, entryPoints: Record = {}, + ext: string, ): string => { const cfg = populateSync(fse.readJsonSync(tsconfig), { merge: { @@ -40,7 +41,7 @@ export const generate = ( outDir, entryPoints, conceal: false, - ext: '.js', + ext, cwd })['bundle.d.ts'] } @@ -55,6 +56,7 @@ export const pipe: IExecPipe = (ctx): IContext => { const { name, entry, + ext, tsconfig = [], customTypings = [], dtsOut, @@ -66,7 +68,8 @@ export const pipe: IExecPipe = (ctx): IContext => { cfg, name, cwd, - i === 0 ? {'.': entry ?? './index.ts'} : {} + i === 0 ? {'.': entry ?? './index.ts'} : {}, + ext ), ).join('\n\n') diff --git a/src/main/ts/interface.ts b/src/main/ts/interface.ts index 77a3d05..3631976 100644 --- a/src/main/ts/interface.ts +++ b/src/main/ts/interface.ts @@ -15,6 +15,7 @@ export type ICmdInvokeOptions = { export type ICliFlags = { cwd?: string entry?: string + ext?: string dtsOut?: string flowOut?: string tsconfig?: string[] @@ -27,6 +28,7 @@ export type IContext = ICliFlags & { cwd: string name: string entry: string + ext: string dtsOut: string flowOut: string } & TFlags diff --git a/src/main/ts/libdefkit.ts b/src/main/ts/libdefkit.ts index 8087f73..0eae313 100644 --- a/src/main/ts/libdefkit.ts +++ b/src/main/ts/libdefkit.ts @@ -16,6 +16,7 @@ export const normalize: IExecPipe = (flags: ICliFlags): IContext => { const temp = temporaryDirectory() const name = fs.readJsonSync(join(cwd, 'package.json')).name const entry = flags.entry ?? `./index.ts` + const ext = flags.ext ?? '.js' const dtsOut = flags.dtsOut === 'false' ? join(temp, 'index.d.ts') : flags.dtsOut ?? join(cwd, 'typings', 'index.d.ts') @@ -23,7 +24,7 @@ export const normalize: IExecPipe = (flags: ICliFlags): IContext => { ? join(temp, 'index.flow.js') : flags.flowOut ?? join(cwd, 'flow-typed', 'index.flow.js') - return { cache, ...flags, cwd, name, entry, dtsOut, flowOut } + return { cache, ...flags, cwd, name, entry, ext, dtsOut, flowOut } } export const clear: IExecPipe = (ctx) => { diff --git a/src/test/ts/libdefkit.ts.snap b/src/test/ts/libdefkit.ts.snap index 4c20a99..1c5d424 100644 --- a/src/test/ts/libdefkit.ts.snap +++ b/src/test/ts/libdefkit.ts.snap @@ -23,6 +23,7 @@ declare module "@qiwi/libdefkit/target/es6/interface.js" { export type ICliFlags = { cwd?: string; entry?: string; + ext?: string; dtsOut?: string; flowOut?: string; tsconfig?: string[]; @@ -34,6 +35,7 @@ declare module "@qiwi/libdefkit/target/es6/interface.js" { cwd: string; name: string; entry: string; + ext: string; dtsOut: string; flowOut: string; } & TFlags; @@ -57,7 +59,7 @@ declare module "@qiwi/libdefkit/target/es6/util.js" { } declare module "@qiwi/libdefkit/target/es6/dts.js" { import { IExecPipe } from "@qiwi/libdefkit/target/es6/interface.js"; - export const generate: (tsconfig: string, name: string, cwd: string, entryPoints?: Record) => string; + export const generate: (tsconfig: string, name: string, cwd: string, entryPoints: Record, ext: string) => string; export const mixFiles: (files: string[], memo?: string) => string; export const pipe: IExecPipe; } @@ -83,6 +85,7 @@ declare module '@qiwi/libdefkitfake' { ", "dtsOut": "/src/test/temp/index.d.ts", "entry": "./index.ts", + "ext": ".js", "flowOut": "/src/test/temp/index.flow.js", "name": "@qiwi/libdefkit", "tsconfig": [