Code Monkey home page Code Monkey logo

make-react-native-package's Introduction

make-react-native-package

npm version CircleCI js-standard-style Dependency Status devDependencies Status npm

CLI tool for bootstrapping react-native packages with Kotlin & Swift & Typescript

About

  • CLI tool:
    • single command to scaffold a monorepo with package itself and ready-to-run example app
    • can create any amount of dummy native components and modules inside same package
    • has multiple component templates
    • versioning doesn't follow 'semver', major and minor numbers match the ones from specific version of react‑native whose project template is used by MRNP
  • Bootstrapped package:
    • supports iOS & Android & react-native ">= 0.60.0"
    • contains (absolutely optional) basic CI setup: CircleCI -> lint & build -> npm
    • has setup instructions for package end-users in generated README.md files
    • includes a Dockerfile for creating a release example .apk in 'neutral' environment

Getting started

$ npx make-react-native-package -p react-native-cool-component --githubUsername cool-github-user

Usage guide

$ npx make-react-native-package --help
Usage

  $ make-react-native-package <--packageName name> <--githubUsername user> ...

Required options

  -p, --packageName string      The name of project folder, github repo and npm package
  -g, --githubUsername string   Your github username

Options

  -h, --help                   Print this usage guide
  -a, --appName string         Example app name
  -o, --objcPrefix string      Objective-C file prefix
  -c, --components string[]    List of space-separated native component names
  -m, --modules string[]       List of space-separated native module names
  -d, --description string     Package description
  -n, --npmUsername string     Your npm username
  -e, --email string           Your npm email
  -w, --withoutConfirmation    Skip confirmation prompt
  -s, --skipInstall            Skip dependency installation
  -t, --templates string[]     List of space-separated component templates:
                               ios:default - default Swift template
                               android:default - default Kotlin template
                               ios:swift-ui - SwiftUI component template
                               android:jetpack-compose - Jetpack Compose component template
                               ios:component-kit - ComponentKit Objective-C++ component template
                               android:litho - Litho Kotlin component template

Example

  $ make-react-native-package --packageName react-native-cool-component
    --githubUsername octocat --appName CoolExample --objcPrefix RNCC
    --description "Cool description" --npmUsername wombat --email [email protected]
    --templates ios:swift-ui android:jetpack-compose

Workflow

Installation

Usually no additional steps required after bootstrapping a package. However, if you have skipped dependency installation with --skipInstall option you can setup everything later by running npm run init:package from package root folder.

Development

Generated folder contains the package itself in the root and the sample app inside ./example folder. Example app imports package dependency locally as a file:.. symlink, so all changes inside the root folder will be available for a running app and editors/IDEs immediately.

To watch on Typescript sources changes you have to run npm run watch commands from both root and ./example folders. Most of 'development' commands are located in ./example/package.json scripts section, and watch script from ./package.json probably is the only common 'development' command in the root folder.

To open a project in Xcode go to ./example/ios folder and open .xcworkspace file, package Swift sources should be found inside Pods > Development Pods > {{packageName}} group in project navigator.

To open a project from Android Studio 'welcome to' window press Import project and open ./example/android folder, after gradle sync task completes package Kotlin sources should be found inside {{packageName}} > java group in project tool window.

To build native code and run sample app on device/simulator just use standard react-native 'run' commands or 'run' buttons from Xcode/Android Studio.

Publishing

There are two options: publishing from local machine or publishing from CircleCI.

To publish from a local machine just run npm version <your_package_next_version> && npm publish from package root folder. It will run linters and build Typescript sources in preversion hook and push changes and git tags to a remote repo in postversion hook. Then if everything succeed, the package will be published to npm.

If you have an account on CircleCI you can use it for publishing a package when git tags are being pushed to a remote repo. Note that before enabling your package in CircleCI dashboard you should either ask their support for macOS plan (it is free for open-source projects) or remove test-ios job related code from .circleci/config.yml file. Also you have to set NPM_TOKEN environment variable in CircleCI dashboard project settings - this token can be created directly on npmjs.com or imported from your other CircleCI project. When everything is ready run npm version <your_package_next_version> -m "%s [skip ci]" to initiate just publish job on CircleCI without triggering surplus test-ios & test-android jobs because of master branch changes. It won't only lint sources and build Typescript, but also will check that native code compiles (this can take some time). After both test-ios and test-android jobs succeed the publish job will be triggered.

Created with MRNP

Packages that were bootstrapped with MRNP most likely will contain Bootstrapped with make-react-native-package string marker in their README.md files, so they could be easily found with Github search.

Credits

  • SwiftUI component template is based on this approach by @Kureev

make-react-native-package's People

Contributors

dependabot[bot] avatar iyegoroff avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

make-react-native-package's Issues

Problems with project.pbxproj

Hi, first of all thanks for creating this tool! I was looking everywhere for a tool that could create an RN library that uses Swift.

I forked the project to remove the github links, since I'm using gitlab for this project. When trying to load xcode I get the error:
The project ´...’ is damaged and cannot be opened due to a parse error. Examine the project file for invalid edits or unresolved source control conflicts.

Upon closer examination project.pbxproj is empty. Is this intended?

Perhaps you could look at my fork. In general I think it might be good to make github optional, since not everyone will need this feature.

Thanks for your all your efforts! :)

iOS example first run crash

Hello, how to fix this?

xcode 11.3.1

  1. npx make-react-native-package -p react-native-add-to-wallet -g MikePodgorniy -m "AddToWallet"
  2. open ReactNativeAddToWalletExample.xcworkspace
  3. run

Снимок экрана 2020-02-05 в 10 32 53

Exception 'Modifications to the layout engine must not be performed from a background thread after it has been accessed from the main thread.' was thrown while invoking show on target RNATWAddToWallet with params (
AddToWallet
)
callstack: (
0 CoreFoundation 0x00007fff23c7127e __exceptionPreprocess + 350
1 libobjc.A.dylib 0x00007fff513fbb20 objc_exception_throw + 48
2 Foundation 0x00007fff258d7b64 -[NSISEngine tryToOptimizeReturningMutuallyExclusiveConstraints] + 0
3 Foundation 0x00007fff258d8228 -[NSISEngine withBehaviors:performModifications:] + 25
4 UIKitCore 0x00007fff4849068a -[UIView(UIConstraintBasedLayout) _calculatedSystemLayoutSizeFittingSize:withHorizontalFittingPriority:verticalFittingPriority:hasIntentionallyCollapsedHeight:] + 1198
5 UIKitCore 0x00007fff48491b1b -[UIView(AdditionalLayoutSupport) _systemLayoutSizeFittingSize:withHorizontalFittingPriority:verticalFittingPriority:hasIntentionallyCollapsedHeight:] + 694
6 UIKitCore 0x00007fff47650745 -[_UIAlertControllerView _minimumSizeForAllActions] + 593
7 UIKitCore 0x00007fff4764bd23 -[_UIAlertControllerView _itemSizeForHorizontalLayout:visualStyleRequiresActionRepresentationToFitItemSize:] + 36
8 UIKitCore 0x00007fff4764c2b0 -[_UIAlertControllerView _actionLayoutDirectionChanged] + 109
9 UIKitCore 0x00007fff47650f07 -[_UIAlertControllerView _updateStyleForIdiomChange:] + 224
10 UIKitCore 0x00007fff47650d8a -[_UIAlertControllerView _setVisualStyle:] + 282
11 UIKitCore 0x00007fff47631df9 -[UIAlertController loadView] + 397
12 UIKitCore 0x00007fff47a13aca -[UIViewController loadViewIfRequired] + 172
13 UIKitCore 0x00007fff47a14277 -[UIViewController view] + 27
14 UIKitCore 0x00007fff47a2b52e -[UIViewController _setPresentationController:] + 100
15 UIKitCore 0x00007fff47a23d25 -[UIViewController _presentViewController:modalSourceViewController:presentationController:animationController:interactionController:completion:] + 1318
16 UIKitCore 0x00007fff47a25798 -[UIViewController _presentViewController:withAnimationController:completion:] + 4349
17 UIKitCore 0x00007fff47a2801b __63-[UIViewController _presentViewController:animated:completion:]_block_invoke + 98
18 UIKitCore 0x00007fff47a28533 -[UIViewController _performCoordinatedPresentOrDismiss:animated:] + 511
19 UIKitCore 0x00007fff47a27f79 -[UIViewController presentViewController:animated:completion:] + 187
20 UIKitCore 0x00007fff47a281e0 -[UIViewController presentViewController:animated:completion:] + 150
21 ReactNativeAddToWalletExample 0x000000010505c6fa $s26react_native_add_to_wallet11AddToWalletC4showyySSF + 426
22 ReactNativeAddToWalletExample 0x000000010505cb83 $s26react_native_add_to_wallet11AddToWalletC4showyySSFTo + 83
23 CoreFoundation 0x00007fff23c7820c invoking
+ 140
24 CoreFoundation 0x00007fff23c753af -[NSInvocation invoke] + 319
25 CoreFoundation 0x00007fff23c75684 -[NSInvocation invokeWithTarget:] + 68
26 ReactNativeAddToWalletExample 0x0000000104e92b62 -[RCTModuleMethod invokeWithBridge:module:arguments:] + 2658
27 ReactNativeAddToWalletExample 0x0000000104e96c97 _ZN8facebook5reactL11invokeInnerEP9RCTBridgeP13RCTModuleDatajRKN5folly7dynamicE + 791
28 ReactNativeAddToWalletExample 0x0000000104e967a3 _ZZN8facebook5react15RCTNativeModule6invokeEjON5folly7dynamicEiENK3$_0clEv + 131
29 ReactNativeAddToWalletExample 0x0000000104e96719 ___ZN8facebook5react15RCTNativeModule6invokeEjON5folly7dynamicEi_block_invoke + 25
30 libdispatch.dylib 0x000000010655ddd4 _dispatch_call_block_and_release + 12
31 libdispatch.dylib 0x000000010655ed48 _dispatch_client_callout + 8
32 libdispatch.dylib 0x00000001065655ef _dispatch_lane_serial_drain + 788
33 libdispatch.dylib 0x000000010656617f _dispatch_lane_invoke + 422
34 libdispatch.dylib 0x0000000106571a4e _dispatch_workloop_worker_thread + 719
35 libsystem_pthread.dylib 0x00007fff524636fc _pthread_wqthread + 290
36 libsystem_pthread.dylib 0x00007fff52462827 start_wqthread + 15
)

RCTFatal
facebook::react::invokeInner(RCTBridge*, RCTModuleData*, unsigned int, folly::dynamic const&)
facebook::react::RCTNativeModule::invoke(unsigned int, folly::dynamic&&, int)::$_0::operator()() const
invocation function for block in facebook::react::RCTNativeModule::invoke(unsigned int, folly::dynamic&&, int)
_dispatch_call_block_and_release
_dispatch_client_callout
_dispatch_lane_serial_drain
_dispatch_lane_invoke
_dispatch_workloop_worker_thread
_pthread_wqthread
start_wqthread

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.