Skip to content

Commit 5b2503a

Browse files
committed
fix: ask to publish flow defs only if pragma is present
1 parent c0cb4d2 commit 5b2503a

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/cli.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ const { name } = require('../package.json');
1515
const root = process.cwd();
1616
const explorer = cosmiconfig(name);
1717

18+
const FLOW_PRGAMA_REGEX = /\*?\s*@(flow)\b/m;
19+
1820
yargs
1921
.command('init', 'configure the package to use bob', {}, async () => {
2022
const pak = path.join(root, 'package.json');
@@ -64,7 +66,7 @@ yargs
6466
}
6567

6668
const pkg = JSON.parse(await fs.readFile(pak, 'utf-8'));
67-
const { output, targets, flow } = await inquirer.prompt([
69+
const questions: inquirer.Question[] = [
6870
{
6971
type: 'input',
7072
name: 'output',
@@ -79,13 +81,23 @@ yargs
7981
choices: ['commonjs', 'module', 'typescript'],
8082
validate: input => Boolean(input.length),
8183
},
82-
{
84+
];
85+
86+
if (
87+
entryFile.endsWith('.js') &&
88+
FLOW_PRGAMA_REGEX.test(
89+
await fs.readFile(path.join(root, source, entryFile), 'utf-8')
90+
)
91+
) {
92+
questions.push({
8393
type: 'confirm',
8494
name: 'flow',
8595
message: 'Do you want to publish definitions for flow?',
8696
default: Object.keys(pkg.devDependencies || {}).includes('flow-bin'),
87-
},
88-
]);
97+
});
98+
}
99+
100+
const { output, targets, flow } = await inquirer.prompt(questions);
89101

90102
const target =
91103
targets[0] === 'commonjs' || targets[0] === 'module'

0 commit comments

Comments
 (0)