1+ import pak from '../package.json' ;
12import fs from 'fs-extra' ;
23import kleur from 'kleur' ;
34import ora from 'ora' ;
45import path from 'path' ;
5- import yargs from 'yargs' ;
66import {
77 FALLBACK_BOB_VERSION ,
88 FALLBACK_NITRO_MODULES_VERSION ,
@@ -11,50 +11,24 @@ import {
1111import { alignDependencyVersionsWithExampleApp } from './exampleApp/dependencies' ;
1212import generateExampleApp from './exampleApp/generateExampleApp' ;
1313import {
14- printErrorHelp ,
1514 printLocalLibNextSteps ,
1615 printNonLocalLibNextSteps ,
1716 printUsedRNVersion ,
1817} from './inform' ;
19- import {
20- acceptedArgs ,
21- createMetadata ,
22- createQuestions ,
23- type Answers ,
24- } from './input' ;
18+ import { prompt } from './prompt' ;
2519import { applyTemplates , generateTemplateConfiguration } from './template' ;
2620import { assertNpxExists } from './utils/assert' ;
21+ import { configureTools } from './utils/configureTools' ;
2722import { createInitialGitCommit } from './utils/initialCommit' ;
2823import {
2924 addNitroDependencyToLocalLibrary ,
3025 linkLocalLibrary ,
3126} from './utils/local' ;
3227import { determinePackageManager } from './utils/packageManager' ;
33- import { prompt } from './utils/prompt' ;
3428import { resolveNpmPackageVersion } from './utils/resolveNpmPackageVersion' ;
35- import { hideBin } from 'yargs/helpers' ;
36- import { configureTools } from './utils/configureTools' ;
37-
38- type Args = Partial < Answers > & {
39- $0 : string ;
40- [ key : string ] : unknown ;
41- } ;
42-
43- void yargs ( hideBin ( process . argv ) )
44- . command ( '$0 [name]' , 'create a react native library' , acceptedArgs , create )
45- . demandCommand ( )
46- . recommendCommands ( )
47- . fail ( printErrorHelp )
48- . parserConfiguration ( {
49- // don't pass kebab-case args to handler.
50- 'strip-dashed' : true ,
51- } )
52- . parse ( ) ;
53-
54- async function create ( _argv : Args ) {
55- // eslint-disable-next-line @typescript-eslint/no-unused-vars
56- const { _, $0, ...argv } = _argv ;
29+ import { createMetadata } from './utils/createMetadata' ;
5730
31+ async function create ( ) {
5832 // Prefetch bob version in background while asking questions
5933 const bobVersionPromise = resolveNpmPackageVersion (
6034 'react-native-builder-bob' ,
@@ -67,12 +41,18 @@ async function create(_argv: Args) {
6741
6842 await assertNpxExists ( ) ;
6943
70- const questions = await createQuestions ( argv ) ;
71-
72- const answers = await prompt < Answers , typeof argv > ( questions , argv , {
73- interactive : argv . interactive ,
44+ const answers = await prompt . show ( {
45+ name : pak . name ,
46+ version : pak . version ,
47+ description : pak . description ,
7448 } ) ;
7549
50+ if ( answers == null ) {
51+ process . exit ( 0 ) ;
52+ }
53+
54+ console . log ( '\n' ) ;
55+
7656 const bobVersion = await bobVersionPromise ;
7757 const nitroModulesVersion =
7858 answers . type === 'nitro-module' || answers . type === 'nitro-view'
@@ -101,7 +81,7 @@ async function create(_argv: Args) {
10181
10282 const spinner = ora ( ) . start ( ) ;
10383
104- if ( config . example !== 'none' ) {
84+ if ( config . example != null ) {
10585 spinner . text = 'Generating example app' ;
10686
10787 await generateExampleApp ( {
@@ -117,7 +97,7 @@ async function create(_argv: Args) {
11797
11898 const rootPackageJson = await fs . readJson ( path . join ( folder , 'package.json' ) ) ;
11999
120- if ( config . example !== 'none' ) {
100+ if ( config . example != null ) {
121101 await alignDependencyVersionsWithExampleApp ( rootPackageJson , folder ) ;
122102 }
123103
@@ -200,3 +180,11 @@ async function create(_argv: Args) {
200180 printNonLocalLibNextSteps ( config ) ;
201181 }
202182}
183+
184+ create ( ) . catch ( ( e : unknown ) => {
185+ console . log ( '\n' ) ;
186+ console . log ( kleur . red ( '× An error occurred while creating the project.\n' ) ) ;
187+ console . error ( e ) ;
188+
189+ process . exit ( 1 ) ;
190+ } ) ;
0 commit comments