Skip to content

Commit 369575c

Browse files
committed
refactor: extract assert npx
1 parent b234c3f commit 369575c

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

packages/create-react-native-library/src/index.ts

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { spawn } from './utils/spawn';
1616
import { version } from '../package.json';
1717
import { addCodegenBuildScript } from './utils/addCodegenBuildScript';
1818
import { createInitialGitCommit } from './utils/initialCommit';
19+
import { assertNpx } from './utils/assert';
1920

2021
const FALLBACK_BOB_VERSION = '0.29.0';
2122

@@ -342,22 +343,7 @@ async function create(_argv: yargs.Arguments<any>) {
342343
process.exit(1);
343344
}
344345

345-
try {
346-
await spawn('npx', ['--help']);
347-
} catch (error) {
348-
// @ts-expect-error: TS doesn't know about `code`
349-
if (error != null && error.code === 'ENOENT') {
350-
console.log(
351-
`Couldn't find ${kleur.blue(
352-
'npx'
353-
)}! Please install it by running ${kleur.blue('npm install -g npx')}`
354-
);
355-
356-
process.exit(1);
357-
} else {
358-
throw error;
359-
}
360-
}
346+
await assertNpx();
361347

362348
let name, email;
363349

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import kleur from 'kleur';
2+
import { spawn } from './spawn';
3+
4+
export async function assertNpx() {
5+
try {
6+
await spawn('npx', ['--help']);
7+
} catch (error) {
8+
// @ts-expect-error: TS doesn't know about `code`
9+
if (error != null && error.code === 'ENOENT') {
10+
console.log(
11+
`Couldn't find ${kleur.blue(
12+
'npx'
13+
)}! Please install it by running ${kleur.blue('npm install -g npx')}`
14+
);
15+
16+
process.exit(1);
17+
} else {
18+
throw error;
19+
}
20+
}
21+
}

0 commit comments

Comments
 (0)