@@ -793,14 +793,13 @@ async function create(_argv: yargs.Arguments<any>) {
793
793
}
794
794
}
795
795
796
+ const rootPackageJson = await fs . readJson ( path . join ( folder , 'package.json' ) ) ;
797
+
796
798
if ( example !== 'none' ) {
797
799
// Set `react` and `react-native` versions of root `package.json` from example `package.json`
798
800
const examplePackageJson = await fs . readJSON (
799
801
path . join ( folder , 'example' , 'package.json' )
800
802
) ;
801
- const rootPackageJson = await fs . readJSON (
802
- path . join ( folder , 'package.json' )
803
- ) ;
804
803
805
804
if ( ! rootPackageJson . devDependencies ) {
806
805
rootPackageJson . devDependencies = { } ;
@@ -810,34 +809,6 @@ async function create(_argv: yargs.Arguments<any>) {
810
809
examplePackageJson . dependencies . react ;
811
810
rootPackageJson . devDependencies [ 'react-native' ] =
812
811
examplePackageJson . dependencies [ 'react-native' ] ;
813
-
814
- await fs . writeJSON ( path . join ( folder , 'package.json' ) , rootPackageJson , {
815
- spaces : 2 ,
816
- } ) ;
817
- }
818
-
819
- if ( ! local ) {
820
- let isInGitRepo = false ;
821
-
822
- try {
823
- isInGitRepo =
824
- ( await spawn ( 'git' , [ 'rev-parse' , '--is-inside-work-tree' ] ) ) === 'true' ;
825
- } catch ( e ) {
826
- // Ignore error
827
- }
828
-
829
- if ( ! isInGitRepo ) {
830
- try {
831
- await spawn ( 'git' , [ 'init' ] , { cwd : folder } ) ;
832
- await spawn ( 'git' , [ 'branch' , '-M' , 'main' ] , { cwd : folder } ) ;
833
- await spawn ( 'git' , [ 'add' , '.' ] , { cwd : folder } ) ;
834
- await spawn ( 'git' , [ 'commit' , '-m' , 'chore: initial commit' ] , {
835
- cwd : folder ,
836
- } ) ;
837
- } catch ( e ) {
838
- // Ignore error
839
- }
840
- }
841
812
}
842
813
843
814
// Some of the passed args can already be derived from the generated package.json file.
@@ -864,16 +835,38 @@ async function create(_argv: yargs.Arguments<any>) {
864
835
( [ answer ] ) => ! ignoredAnswers . includes ( answer )
865
836
)
866
837
) ;
838
+
867
839
libraryMetadata . version = version ;
840
+ rootPackageJson [ 'create-react-native-library' ] = libraryMetadata ;
868
841
869
- const libraryPackageJson = await fs . readJson (
870
- path . join ( folder , 'package.json' )
871
- ) ;
872
- libraryPackageJson [ 'create-react-native-library' ] = libraryMetadata ;
873
- await fs . writeJson ( path . join ( folder , 'package.json' ) , libraryPackageJson , {
842
+ await fs . writeJson ( path . join ( folder , 'package.json' ) , rootPackageJson , {
874
843
spaces : 2 ,
875
844
} ) ;
876
845
846
+ if ( ! local ) {
847
+ let isInGitRepo = false ;
848
+
849
+ try {
850
+ isInGitRepo =
851
+ ( await spawn ( 'git' , [ 'rev-parse' , '--is-inside-work-tree' ] ) ) === 'true' ;
852
+ } catch ( e ) {
853
+ // Ignore error
854
+ }
855
+
856
+ if ( ! isInGitRepo ) {
857
+ try {
858
+ await spawn ( 'git' , [ 'init' ] , { cwd : folder } ) ;
859
+ await spawn ( 'git' , [ 'branch' , '-M' , 'main' ] , { cwd : folder } ) ;
860
+ await spawn ( 'git' , [ 'add' , '.' ] , { cwd : folder } ) ;
861
+ await spawn ( 'git' , [ 'commit' , '-m' , 'chore: initial commit' ] , {
862
+ cwd : folder ,
863
+ } ) ;
864
+ } catch ( e ) {
865
+ // Ignore error
866
+ }
867
+ }
868
+ }
869
+
877
870
spinner . succeed (
878
871
`Project created successfully at ${ kleur . yellow (
879
872
path . relative ( process . cwd ( ) , folder )
0 commit comments