Skip to content

Commit

Permalink
fix: use the correct entry file
Browse files Browse the repository at this point in the history
  • Loading branch information
satya164 committed Apr 2, 2019
1 parent 15da7ce commit 851470e
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ yargs
`Couldn't find a 'package.json' file in '${root}'. Are you in a project folder?`
);
}

const { source } = await inquirer.prompt({
type: 'input',
name: 'source',
Expand All @@ -44,16 +45,21 @@ yargs
validate: input => Boolean(input),
});

if (
!(
(await fs.pathExists(path.join(root, source, 'index.js'))) ||
(await fs.pathExists(path.join(root, source, 'index.ts'))) ||
(await fs.pathExists(path.join(root, source, 'index.tsx')))
)
) {
let entryFile;

if (await fs.pathExists(path.join(root, source, 'index.js'))) {
entryFile = 'index.js';
} else if (await fs.pathExists(path.join(root, source, 'index.ts'))) {
entryFile = 'index.ts';
} else if (await fs.pathExists(path.join(root, source, 'index.tsx'))) {
entryFile = 'index.tsx';
}

if (!entryFile) {
logger.exit(
`Couldn't find a 'index.js'. 'index.ts' or 'index.tsx' file under '${source}'. Please re-run the CLI after creating it.`
);
return;
}

const pkg = JSON.parse(await fs.readFile(pak, 'utf-8'));
Expand Down Expand Up @@ -88,8 +94,8 @@ yargs
const entries: { [key: string]: string } = {
main: target
? path.join(output, target, 'index.js')
: path.join(source, 'index.js'),
'react-native': path.join(source, 'index.js'),
: path.join(source, entryFile),
'react-native': path.join(source, entryFile),
};

if (targets.includes('module')) {
Expand Down

0 comments on commit 851470e

Please sign in to comment.