-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibdefkit.ts
36 lines (28 loc) · 1.15 KB
/
libdefkit.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/** @module @qiwi/libdefkit */
/** */
import fs from 'fs-extra'
import { join } from 'path'
import tempy from 'tempy'
import { pipe as dtsgen } from './dts'
import { ICliFlags, IContext, IExecPipe } from './interface'
import { invoke } from './util'
export const normalize: IExecPipe = (flags: ICliFlags): IContext => {
const cwd = flags.cwd || process.cwd()
const cache = tempy.directory()
const name = fs.readJsonSync(join(cwd, 'package.json')).name
const entry = flags.entry ?? `${name}/target/es6`
const dtsOut = flags.dtsOut ?? join(cwd, 'typings', 'index.d.ts')
const flowOut = flags.flowOut ?? join(cwd, 'flow-typed', 'index.flow.js')
return { cache, ...flags, cwd, name, entry, dtsOut, flowOut }
}
export const clear: IExecPipe = (ctx) => {
fs.emptyDirSync(ctx.cache)
}
export const flowgen: IExecPipe = ({ dtsOut, flowOut }): void => {
if (dtsOut && flowOut) {
invoke({ cmd: 'flowgen', args: [dtsOut, '--output-file', flowOut] })
}
}
export const pipeline: IExecPipe[] = [normalize, clear, dtsgen, flowgen]
export const execute = (flags: ICliFlags): IContext =>
pipeline.reduce((ctx, pipe) => pipe(ctx) || ctx, flags as IContext)