Skip to content

Commit

Permalink
feat: provide ext configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub committed Jan 30, 2024
1 parent 125f244 commit 4a7eec8
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 15 deletions.
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
9 changes: 8 additions & 1 deletion src/main/ts/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ const cli = meow(
--cwd, working dir path
--tsconfig
--customTypings, attach custom libdefs to d.ts bundle
--entry, alias entry (<pkgName>/target/es5/index by default)
--entry, pkg entry point (<pkgName>/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)
`,
Expand All @@ -38,6 +39,12 @@ const cli = meow(
cache: {
type: 'string',
},
entry: {
type: 'string',
},
ext: {
type: 'string',
},
},
},
)
Expand Down
7 changes: 5 additions & 2 deletions src/main/ts/dts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const generate = (
name: string,
cwd: string,
entryPoints: Record<string, string> = {},
ext: string,
): string => {
const cfg = populateSync(fse.readJsonSync(tsconfig), {
merge: {
Expand All @@ -40,7 +41,7 @@ export const generate = (
outDir,
entryPoints,
conceal: false,
ext: '.js',
ext,
cwd
})['bundle.d.ts']
}
Expand All @@ -55,6 +56,7 @@ export const pipe: IExecPipe = (ctx): IContext => {
const {
name,
entry,
ext,
tsconfig = [],
customTypings = [],
dtsOut,
Expand All @@ -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')

Expand Down
2 changes: 2 additions & 0 deletions src/main/ts/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export type ICmdInvokeOptions = {
export type ICliFlags = {
cwd?: string
entry?: string
ext?: string
dtsOut?: string
flowOut?: string
tsconfig?: string[]
Expand All @@ -27,6 +28,7 @@ export type IContext = ICliFlags & {
cwd: string
name: string
entry: string
ext: string
dtsOut: string
flowOut: string
} & TFlags
Expand Down
3 changes: 2 additions & 1 deletion src/main/ts/libdefkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ 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')
const flowOut = flags.flowOut === 'false'
? 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) => {
Expand Down
5 changes: 4 additions & 1 deletion src/test/ts/libdefkit.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand All @@ -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;
Expand All @@ -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, string>) => string;
export const generate: (tsconfig: string, name: string, cwd: string, entryPoints: Record<string, string>, ext: string) => string;
export const mixFiles: (files: string[], memo?: string) => string;
export const pipe: IExecPipe;
}
Expand All @@ -83,6 +85,7 @@ declare module '@qiwi/libdefkitfake' {
",
"dtsOut": "<cwd>/src/test/temp/index.d.ts",
"entry": "./index.ts",
"ext": ".js",
"flowOut": "<cwd>/src/test/temp/index.flow.js",
"name": "@qiwi/libdefkit",
"tsconfig": [
Expand Down

0 comments on commit 4a7eec8

Please sign in to comment.