Skip to content

Commit

Permalink
feat(napi): add pipe flag to pipe the generated files into custom com…
Browse files Browse the repository at this point in the history
…mand
  • Loading branch information
Brooooooklyn committed Nov 16, 2021
1 parent 41037ec commit e37c3fd
Showing 1 changed file with 40 additions and 7 deletions.
47 changes: 40 additions & 7 deletions cli/src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ export class BuildCommand extends Command {
)} file`,
})

pipe?: string = Option.String('--pipe', {
description: `Pipe [${chalk.green(
'.js/.ts',
)}] files to this command, eg ${chalk.green('prettier -w')}`,
})

destDir = Option.String({
required: false,
})
Expand Down Expand Up @@ -234,18 +240,45 @@ export class BuildCommand extends Command {
debug(`Write binary content to [${chalk.yellowBright(distModulePath)}]`)
await copyFileAsync(sourcePath, distModulePath)

const dtsFilePath = join(
process.cwd(),
this.destDir ?? '.',
this.dts ?? 'index.d.ts',
)

const idents = await processIntermediateTypeFile(
intermediateTypeFile,
join(this.destDir ?? '.', this.dts ?? 'index.d.ts'),
dtsFilePath,
)
await writeJsBinding(
binaryName,
packageName,
if (this.pipe) {
const pipeCommand = `${this.pipe} ${dtsFilePath}`
console.info(`Run ${chalk.green(pipeCommand)}`)
try {
execSync(pipeCommand, { stdio: 'inherit', env: process.env })
} catch (e) {
console.warn(
chalk.bgYellowBright('Pipe the dts file to command failed'),
e,
)
}
}
const jsBindingFilePath =
this.jsBinding && this.jsBinding !== 'false'
? join(process.cwd(), this.jsBinding)
: null,
idents,
)
: null
await writeJsBinding(binaryName, packageName, jsBindingFilePath, idents)
if (this.pipe && jsBindingFilePath) {
const pipeCommand = `${this.pipe} ${jsBindingFilePath}`
console.info(`Run ${chalk.green(pipeCommand)}`)
try {
execSync(pipeCommand, { stdio: 'inherit', env: process.env })
} catch (e) {
console.warn(
chalk.bgYellowBright('Pipe the js binding file to command failed'),
e,
)
}
}
}
}

Expand Down

0 comments on commit e37c3fd

Please sign in to comment.