├── .eslintrc
├── .flowconfig
├── .github
└── FUNDING.yml
├── .gitignore
├── .npmignore
├── CHANGELOG.md
├── LICENSE
├── README.md
├── android
├── build.gradle
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── staltz
│ │ └── reactnativenode
│ │ ├── RNNodeModule.java
│ │ ├── RNNodePackage.java
│ │ ├── RNNodeService.java
│ │ └── RNNodeThread.java
│ └── res
│ └── raw
│ └── bin_node_v710
├── bin.js
├── example
├── .babelrc
├── .buckconfig
├── .flowconfig
├── .gitattributes
├── .gitignore
├── .watchmanconfig
├── README.md
├── android
│ ├── app
│ │ ├── BUCK
│ │ ├── build.gradle
│ │ ├── proguard-rules.pro
│ │ └── src
│ │ │ └── main
│ │ │ ├── AndroidManifest.xml
│ │ │ ├── java
│ │ │ └── com
│ │ │ │ └── example
│ │ │ │ ├── MainActivity.java
│ │ │ │ └── MainApplication.java
│ │ │ └── res
│ │ │ ├── mipmap-hdpi
│ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ └── ic_launcher.png
│ │ │ ├── raw
│ │ │ └── rnnodebundle
│ │ │ └── values
│ │ │ ├── strings.xml
│ │ │ └── styles.xml
│ ├── build.gradle
│ ├── gradle.properties
│ ├── gradle
│ │ └── wrapper
│ │ │ ├── gradle-wrapper.jar
│ │ │ └── gradle-wrapper.properties
│ ├── gradlew
│ ├── gradlew.bat
│ ├── keystores
│ │ ├── BUCK
│ │ └── debug.keystore.properties
│ └── settings.gradle
├── app.json
├── background
│ ├── index.js
│ ├── package.json
│ └── yarn.lock
├── index.android.js
├── jsconfig.json
├── package.json
└── yarn.lock
├── index.js
├── package.json
└── screenshot.png
/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "parser": "babel-eslint",
3 | "ecmaFeatures": {
4 | "jsx": true
5 | },
6 | "env": {
7 | "es6": true,
8 | "jasmine": true,
9 | },
10 | "plugins": [
11 | "react"
12 | ],
13 | // Map from global var to bool specifying if it can be redefined
14 | "globals": {
15 | "__DEV__": true,
16 | "__dirname": false,
17 | "__fbBatchedBridgeConfig": false,
18 | "cancelAnimationFrame": false,
19 | "clearImmediate": true,
20 | "clearInterval": false,
21 | "clearTimeout": false,
22 | "console": false,
23 | "document": false,
24 | "escape": false,
25 | "exports": false,
26 | "fetch": false,
27 | "global": false,
28 | "jest": false,
29 | "Map": true,
30 | "module": false,
31 | "navigator": false,
32 | "process": false,
33 | "Promise": true,
34 | "requestAnimationFrame": true,
35 | "require": false,
36 | "Set": true,
37 | "setImmediate": true,
38 | "setInterval": false,
39 | "setTimeout": false,
40 | "window": false,
41 | "XMLHttpRequest": false,
42 | "pit": false
43 | },
44 | "rules": {
45 | "comma-dangle": 0, // disallow trailing commas in object literals
46 | "no-cond-assign": 1, // disallow assignment in conditional expressions
47 | "no-console": 0, // disallow use of console (off by default in the node environment)
48 | "no-constant-condition": 0, // disallow use of constant expressions in conditions
49 | "no-control-regex": 1, // disallow control characters in regular expressions
50 | "no-debugger": 1, // disallow use of debugger
51 | "no-dupe-keys": 1, // disallow duplicate keys when creating object literals
52 | "no-empty": 0, // disallow empty statements
53 | "no-ex-assign": 1, // disallow assigning to the exception in a catch block
54 | "no-extra-boolean-cast": 1, // disallow double-negation boolean casts in a boolean context
55 | "no-extra-parens": 0, // disallow unnecessary parentheses (off by default)
56 | "no-extra-semi": 1, // disallow unnecessary semicolons
57 | "no-func-assign": 1, // disallow overwriting functions written as function declarations
58 | "no-inner-declarations": 0, // disallow function or variable declarations in nested blocks
59 | "no-invalid-regexp": 1, // disallow invalid regular expression strings in the RegExp constructor
60 | "no-negated-in-lhs": 1, // disallow negation of the left operand of an in expression
61 | "no-obj-calls": 1, // disallow the use of object properties of the global object (Math and JSON) as functions
62 | "no-regex-spaces": 1, // disallow multiple spaces in a regular expression literal
63 | "no-reserved-keys": 0, // disallow reserved words being used as object literal keys (off by default)
64 | "no-sparse-arrays": 1, // disallow sparse arrays
65 | "no-unreachable": 1, // disallow unreachable statements after a return, throw, continue, or break statement
66 | "use-isnan": 1, // disallow comparisons with the value NaN
67 | "valid-jsdoc": 0, // Ensure JSDoc comments are valid (off by default)
68 | "valid-typeof": 1, // Ensure that the results of typeof are compared against a valid string
69 | // Best Practices
70 | // These are rules designed to prevent you from making mistakes. They either prescribe a better way of doing something or help you avoid footguns.
71 | "block-scoped-var": 0, // treat var statements as if they were block scoped (off by default)
72 | "complexity": 0, // specify the maximum cyclomatic complexity allowed in a program (off by default)
73 | "consistent-return": 0, // require return statements to either always or never specify values
74 | "curly": 1, // specify curly brace conventions for all control statements
75 | "default-case": 0, // require default case in switch statements (off by default)
76 | "dot-notation": 1, // encourages use of dot notation whenever possible
77 | "eqeqeq": 1, // require the use of === and !==
78 | "guard-for-in": 0, // make sure for-in loops have an if statement (off by default)
79 | "no-alert": 1, // disallow the use of alert, confirm, and prompt
80 | "no-caller": 1, // disallow use of arguments.caller or arguments.callee
81 | "no-div-regex": 1, // disallow division operators explicitly at beginning of regular expression (off by default)
82 | "no-else-return": 0, // disallow else after a return in an if (off by default)
83 | "no-empty-label": 1, // disallow use of labels for anything other then loops and switches
84 | "no-eq-null": 0, // disallow comparisons to null without a type-checking operator (off by default)
85 | "no-eval": 1, // disallow use of eval()
86 | "no-extend-native": 1, // disallow adding to native types
87 | "no-extra-bind": 1, // disallow unnecessary function binding
88 | "no-fallthrough": 1, // disallow fallthrough of case statements
89 | "no-floating-decimal": 1, // disallow the use of leading or trailing decimal points in numeric literals (off by default)
90 | "no-implied-eval": 1, // disallow use of eval()-like methods
91 | "no-labels": 1, // disallow use of labeled statements
92 | "no-iterator": 1, // disallow usage of __iterator__ property
93 | "no-lone-blocks": 1, // disallow unnecessary nested blocks
94 | "no-loop-func": 0, // disallow creation of functions within loops
95 | "no-multi-str": 0, // disallow use of multiline strings
96 | "no-native-reassign": 0, // disallow reassignments of native objects
97 | "no-new": 1, // disallow use of new operator when not part of the assignment or comparison
98 | "no-new-func": 1, // disallow use of new operator for Function object
99 | "no-new-wrappers": 1, // disallows creating new instances of String,Number, and Boolean
100 | "no-octal": 1, // disallow use of octal literals
101 | "no-octal-escape": 1, // disallow use of octal escape sequences in string literals, such as var foo = "Copyright \251";
102 | "no-proto": 1, // disallow usage of __proto__ property
103 | "no-redeclare": 0, // disallow declaring the same variable more then once
104 | "no-return-assign": 1, // disallow use of assignment in return statement
105 | "no-script-url": 1, // disallow use of javascript: urls.
106 | "no-self-compare": 1, // disallow comparisons where both sides are exactly the same (off by default)
107 | "no-sequences": 1, // disallow use of comma operator
108 | "no-unused-expressions": 0, // disallow usage of expressions in statement position
109 | "no-void": 1, // disallow use of void operator (off by default)
110 | "no-warning-comments": 0, // disallow usage of configurable warning terms in comments": 1, // e.g. TODO or FIXME (off by default)
111 | "no-with": 1, // disallow use of the with statement
112 | "radix": 1, // require use of the second argument for parseInt() (off by default)
113 | "semi-spacing": 1, // require a space after a semi-colon
114 | "vars-on-top": 0, // requires to declare all vars on top of their containing scope (off by default)
115 | "wrap-iife": 0, // require immediate function invocation to be wrapped in parentheses (off by default)
116 | "yoda": 1, // require or disallow Yoda conditions
117 | // Strict Mode
118 | // These rules relate to using strict mode.
119 | "strict": [
120 | 2,
121 | "global"
122 | ], // require or disallow the "use strict" pragma in the global scope (off by default in the node environment)
123 | // Variables
124 | // These rules have to do with variable declarations.
125 | "no-catch-shadow": 1, // disallow the catch clause parameter name being the same as a variable in the outer scope (off by default in the node environment)
126 | "no-delete-var": 1, // disallow deletion of variables
127 | "no-label-var": 1, // disallow labels that share a name with a variable
128 | "no-shadow": 1, // disallow declaration of variables already declared in the outer scope
129 | "no-shadow-restricted-names": 1, // disallow shadowing of names such as arguments
130 | "no-undef": 2, // disallow use of undeclared variables unless mentioned in a /*global */ block
131 | "no-undefined": 0, // disallow use of undefined variable (off by default)
132 | "no-undef-init": 1, // disallow use of undefined when initializing variables
133 | "no-unused-vars": [
134 | 1,
135 | {
136 | "vars": "all",
137 | "args": "none"
138 | }
139 | ], // disallow declaration of variables that are not used in the code
140 | "no-use-before-define": 0, // disallow use of variables before they are defined
141 | // Node.js
142 | // These rules are specific to JavaScript running on Node.js.
143 | "handle-callback-err": 1, // enforces error handling in callbacks (off by default) (on by default in the node environment)
144 | "no-mixed-requires": 1, // disallow mixing regular variable and require declarations (off by default) (on by default in the node environment)
145 | "no-new-require": 1, // disallow use of new operator with the require function (off by default) (on by default in the node environment)
146 | "no-path-concat": 1, // disallow string concatenation with __dirname and __filename (off by default) (on by default in the node environment)
147 | "no-process-exit": 0, // disallow process.exit() (on by default in the node environment)
148 | "no-restricted-modules": 1, // restrict usage of specified node modules (off by default)
149 | "no-sync": 0, // disallow use of synchronous methods (off by default)
150 | // Stylistic Issues
151 | // These rules are purely matters of style and are quite subjective.
152 | "key-spacing": 0,
153 | "comma-spacing": 0,
154 | "no-multi-spaces": 0,
155 | "brace-style": 0, // enforce one true brace style (off by default)
156 | "camelcase": 0, // require camel case names
157 | "consistent-this": [
158 | 1,
159 | "self"
160 | ], // enforces consistent naming when capturing the current execution context (off by default)
161 | "eol-last": 1, // enforce newline at the end of file, with no multiple empty lines
162 | "func-names": 0, // require function expressions to have a name (off by default)
163 | "func-style": 0, // enforces use of function declarations or expressions (off by default)
164 | "new-cap": 0, // require a capital letter for constructors
165 | "new-parens": 1, // disallow the omission of parentheses when invoking a constructor with no arguments
166 | "no-nested-ternary": 0, // disallow nested ternary expressions (off by default)
167 | "no-array-constructor": 1, // disallow use of the Array constructor
168 | "no-lonely-if": 0, // disallow if as the only statement in an else block (off by default)
169 | "no-new-object": 1, // disallow use of the Object constructor
170 | "no-spaced-func": 1, // disallow space between function identifier and application
171 | "no-ternary": 0, // disallow the use of ternary operators (off by default)
172 | "no-trailing-spaces": 1, // disallow trailing whitespace at the end of lines
173 | "no-underscore-dangle": 0, // disallow dangling underscores in identifiers
174 | "no-mixed-spaces-and-tabs": 1, // disallow mixed spaces and tabs for indentation
175 | "quotes": [
176 | 1,
177 | "single",
178 | "avoid-escape"
179 | ], // specify whether double or single quotes should be used
180 | "quote-props": 0, // require quotes around object literal property names (off by default)
181 | "semi": 1, // require or disallow use of semicolons instead of ASI
182 | "sort-vars": 0, // sort variables within the same declaration block (off by default)
183 | "space-after-keywords": 1, // require a space after certain keywords (off by default)
184 | "space-in-brackets": 0, // require or disallow spaces inside brackets (off by default)
185 | "space-in-parens": 0, // require or disallow spaces inside parentheses (off by default)
186 | "space-infix-ops": 1, // require spaces around operators
187 | "space-return-throw-case": 1, // require a space after return, throw, and case
188 | "space-unary-ops": [
189 | 1,
190 | {
191 | "words": true,
192 | "nonwords": false
193 | }
194 | ], // require or disallow spaces before/after unary operators (words on by default, nonwords off by default)
195 | "max-nested-callbacks": 0, // specify the maximum depth callbacks can be nested (off by default)
196 | "one-var": 0, // allow just one var statement per function (off by default)
197 | "wrap-regex": 0, // require regex literals to be wrapped in parentheses (off by default)
198 | // Legacy
199 | // The following rules are included for compatibility with JSHint and JSLint. While the names of the rules may not match up with the JSHint/JSLint counterpart, the functionality is the same.
200 | "max-depth": 0, // specify the maximum depth that blocks can be nested (off by default)
201 | "max-len": 0, // specify the maximum length of a line in your program (off by default)
202 | "max-params": 0, // limits the number of parameters that can be used in the function declaration. (off by default)
203 | "max-statements": 0, // specify the maximum number of statement allowed in a function (off by default)
204 | "no-bitwise": 0, // disallow use of bitwise operators (off by default)
205 | "no-plusplus": 0, // disallow use of unary operators, ++ and -- (off by default)
206 | "react/display-name": 0,
207 | "react/jsx-boolean-value": 0,
208 | "jsx-quotes": [
209 | 2,
210 | "prefer-single"
211 | ],
212 | "react/jsx-no-undef": 1,
213 | "react/jsx-sort-props": 0,
214 | "react/jsx-uses-react": 0,
215 | "react/jsx-uses-vars": 1,
216 | "react/no-did-mount-set-state": [
217 | 1,
218 | "allow-in-func"
219 | ],
220 | "react/no-did-update-set-state": [
221 | 1,
222 | "allow-in-func"
223 | ],
224 | "react/no-multi-comp": 0,
225 | "react/no-unknown-property": 0,
226 | "react/prop-types": 0,
227 | "react/react-in-jsx-scope": 0,
228 | "react/self-closing-comp": 1,
229 | "react/wrap-multilines": 0
230 | }
231 | }
--------------------------------------------------------------------------------
/.flowconfig:
--------------------------------------------------------------------------------
1 | [ignore]
2 |
3 | # We fork some components by platform.
4 | .*/*.web.js
5 | .*/*.android.js
6 |
7 | # Some modules have their own node_modules with overlap
8 | .*/node_modules/node-haste/.*
9 |
10 | # Ugh
11 | .*/node_modules/babel.*
12 | .*/node_modules/babylon.*
13 | .*/node_modules/invariant.*
14 |
15 | # Ignore react and fbjs where there are overlaps, but don't ignore
16 | # anything that react-native relies on
17 | .*/node_modules/fbjs/lib/Map.js
18 | .*/node_modules/fbjs/lib/ErrorUtils.js
19 |
20 | # Flow has a built-in definition for the 'react' module which we prefer to use
21 | # over the currently-untyped source
22 | .*/node_modules/react/react.js
23 | .*/node_modules/react/lib/React.js
24 | .*/node_modules/react/lib/ReactDOM.js
25 |
26 | .*/__mocks__/.*
27 | .*/__tests__/.*
28 |
29 | .*/commoner/test/source/widget/share.js
30 |
31 | # Ignore commoner tests
32 | .*/node_modules/commoner/test/.*
33 |
34 | # See https://github.com/facebook/flow/issues/442
35 | .*/react-tools/node_modules/commoner/lib/reader.js
36 |
37 | # Ignore jest
38 | .*/node_modules/jest-cli/.*
39 |
40 | # Ignore Website
41 | .*/website/.*
42 |
43 | # Ignore generators
44 | .*/local-cli/generator.*
45 |
46 | # Ignore BUCK generated folders
47 | .*\.buckd/
48 |
49 | # Ignore RNPM
50 | .*/local-cli/rnpm/.*
51 |
52 | .*/node_modules/is-my-json-valid/test/.*\.json
53 | .*/node_modules/iconv-lite/encodings/tables/.*\.json
54 | .*/node_modules/y18n/test/.*\.json
55 | .*/node_modules/spdx-license-ids/spdx-license-ids.json
56 | .*/node_modules/spdx-exceptions/index.json
57 | .*/node_modules/resolve/test/subdirs/node_modules/a/b/c/x.json
58 | .*/node_modules/resolve/lib/core.json
59 | .*/node_modules/jsonparse/samplejson/.*\.json
60 | .*/node_modules/json5/test/.*\.json
61 | .*/node_modules/ua-parser-js/test/.*\.json
62 | .*/node_modules/builtin-modules/builtin-modules.json
63 | .*/node_modules/binary-extensions/binary-extensions.json
64 | .*/node_modules/url-regex/tlds.json
65 | .*/node_modules/joi/.*\.json
66 | .*/node_modules/isemail/.*\.json
67 | .*/node_modules/tr46/.*\.json
68 |
69 |
70 | [include]
71 |
72 | [libs]
73 | node_modules/react-native/Libraries/react-native/react-native-interface.js
74 | node_modules/react-native/flow
75 | flow/
76 |
77 | [options]
78 | module.system=haste
79 |
80 | esproposal.class_static_fields=enable
81 | esproposal.class_instance_fields=enable
82 |
83 | munge_underscores=true
84 |
85 | module.name_mapper='^image![a-zA-Z0-9$_-]+$' -> 'GlobalImageStub'
86 | module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> 'RelativeImageStub'
87 |
88 | suppress_type=$FlowIssue
89 | suppress_type=$FlowFixMe
90 | suppress_type=$FixMe
91 |
92 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(2[0-5]\\|1[0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)
93 | suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(2[0-5]\\|1[0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+
94 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy
95 |
96 | [version]
97 | ^0.25.0
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | patreon: andrestaltz
2 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # OSX
2 | #
3 | .DS_Store
4 |
5 | # Xcode
6 | #
7 | build/
8 | *.pbxuser
9 | !default.pbxuser
10 | *.mode1v3
11 | !default.mode1v3
12 | *.mode2v3
13 | !default.mode2v3
14 | *.perspectivev3
15 | !default.perspectivev3
16 | xcuserdata
17 | *.xccheckout
18 | *.moved-aside
19 | DerivedData
20 | *.hmap
21 | *.ipa
22 | *.xcuserstate
23 | project.xcworkspace
24 |
25 | # Android/IJ
26 | #
27 | *.iml
28 | .idea
29 | .gradle
30 | local.properties
31 |
32 | # node.js
33 | #
34 | node_modules/
35 | npm-debug.log
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | # OSX
2 | #
3 | .DS_Store
4 |
5 | # Xcode
6 | #
7 | build/
8 | *.pbxuser
9 | !default.pbxuser
10 | *.mode1v3
11 | !default.mode1v3
12 | *.mode2v3
13 | !default.mode2v3
14 | *.perspectivev3
15 | !default.perspectivev3
16 | xcuserdata
17 | *.xccheckout
18 | *.moved-aside
19 | DerivedData
20 | *.hmap
21 | *.ipa
22 | *.xcuserstate
23 | project.xcworkspace
24 |
25 | # Android/IJ
26 | #
27 | *.iml
28 | .idea
29 | .gradle
30 | local.properties
31 |
32 | # node.js
33 | #
34 | node_modules/
35 | npm-debug.log
36 |
37 | # example project
38 | #
39 | /example
40 | /screenshot.png
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # 3.3.1
2 |
3 | * Fix issue where tar file is updated and should be decompressed. Previously, the updated tar was never decompressed if it already existed. Now, the updated raw resource tar will be decompressed every time its byte size is different to existing tar file.
4 |
5 | # 3.3.0
6 |
7 | * Support `LD_LIBRARY_PATH` env var pointing to the app's library directory
8 | (`getApplicationInfo().nativeLibraryDir)`). The app library directory is
9 | populated with contents from your project's `android/app/src/main/jniLibs`
10 | directory.
11 |
12 | # 3.2.0
13 |
14 | * Support HOME env var pointing to the app's data directory
15 |
16 | # 3.1.1
17 |
18 | * Support `TMPDIR` pointing to an actual directory
19 |
20 | # 3.0.0
21 |
22 | ## Breaking change
23 |
24 | The Android background Service now uses the stickiness level `START_NOT_STICKY`
25 | which makes more sense by default. In future versions we should enable choosing
26 | the stickiness level from the JavaScript API.
27 |
28 | # 2.1.0
29 |
30 | ## Feature / bug fix
31 |
32 | * Displays the stdout and stderr of your node.js process in the Android logcat,
33 | with the tag `nodejs`, as "verbose"
34 |
35 | # 2.0.0
36 |
37 | ## Breaking changes
38 |
39 | * Depends on React Native v0.48, so breaking changes from RN v0.40 to RN v0.48
40 | also apply to this package.
41 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2017-present André Staltz (staltz.com)
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # React Native Node
2 |
3 | *Run a **real** Node.js process in the background, behind a React Native app.*
4 |
5 | **DEPRECATED. Please use [Node.js Mobile](https://code.janeasystems.com/nodejs-mobile/) by Janea Systems instead.** It has the same purpose as this library, but is more updated, and supports iOS. This library still works as documented, but I'm not committed to maintaining it anymore.
6 |
7 | ----------
8 |
9 | Using this package you can: run `http` servers in Android, use Node streams, interface with the filesystem, off load some heavy processing out of the JS thread in React Native, and more! Running the real Node.js in Android, you can do everything that Node.js on desktop can.
10 |
11 | [Example app](./example)
12 |
13 | ## Install
14 |
15 | ```
16 | npm install --save react-native-node
17 | ```
18 |
19 | ```
20 | react-native link react-native-node
21 | ```
22 |
23 | ## Usage
24 |
25 | 1. Develop the background Node.js project under some directory
26 | - e.g. `./background`
27 |
28 | 2. In your React Native JavaScript source files, spawn the background process:
29 |
30 | ```diff
31 | +import RNNode from "react-native-node";
32 |
33 | class MyApp extends Component {
34 | // ...
35 | componentDidMount() {
36 | + RNNode.start();
37 | + // or specify arguments to the process:
38 | + RNNode.start(['--color', 'red', '--port', '3000'])
39 | }
40 |
41 | componentWillUnmount() {
42 | + RNNode.stop();
43 | }
44 | // ...
45 | }
46 | ```
47 |
48 | 3. Bundle and insert the background application into the mobile app using the command
49 |
50 | ```
51 | ./node_modules/.bin/react-native-node insert ./background
52 | ```
53 |
54 | - Compresses your background app into `./android/app/src/main/res/raw/rnnodebundle`
55 | - Updates `AndroidManifest.xml` to include a Service class
56 |
57 | 4. (Re)build the mobile app
58 |
59 | ```
60 | react-native run-android
61 | ```
62 |
63 | ### Tip 1
64 |
65 | If you want to bundle and insert the background app always before building the mobile app, make a `prestart` package.json script (assuming you use the `start` script):
66 |
67 | ```diff
68 | "scripts": {
69 | + "prestart": "react-native-node insert ./background",
70 | "start": "node node_modules/react-native/local-cli/cli.js start",
71 | ```
72 |
73 | ### Tip 2
74 |
75 | You can reduce the size of the bundle file `rnnodebundle` by using a tool like [noderify](https://www.npmjs.com/package/noderify) to create a single js file.
76 |
77 | ### Tip 3
78 |
79 | To debug, use `adb logcat` with the `nodejs` tag. For example with react:
80 |
81 | ```
82 | adb logcat *:S nodejs:V ReactNative:V ReactNativeJS:V
83 | ```
84 |
85 | These additional logging tags are used by `react-native-node`:
86 | - `RNNodeThread` - will tell you if your process has started/terminated/errored
87 | - `RNNodeService` - debug tar/untar, node binary preparation etc.
88 | - `RNNode`
89 |
90 | ## FAQ
91 |
92 | #### How is this possible?
93 |
94 | Node.js v7.1.0 (with V8, not JavaScriptCore) was compiled to a binary `bin_node_v710` following the approach used by ["NodeBase"](https://github.com/dna2github/NodeBase). This binary is prebuilt and included in this library. If you are concerned about security, you shouldn't use the prebuilt binary, but compile it yourself.
95 |
96 | #### What about iOS support?
97 |
98 | We can't run V8 Node.js on iOS since that violates Apple's policy around Just-In-Time compilation, but ChakraCore Node.js can run on iOS. We are depending on [this project by Janea Systems](http://www.janeasystems.com/blog/node-js-meets-ios/) to open source their methods and include a proper open source license.
99 |
100 | #### Does it support packages with native bindings?
101 |
102 | Yes, in theory, but that's the job of individual libraries having native bindings for android. Most packages don't have. I believe sodium-native has. Hint: if you want to compile the native part of packages, I recommend not trying to cross-compile. Instead, install `termux` on an Android device and compile from the phone directly.
103 |
104 | #### Why did you build this?
105 |
106 | I am bringing the [Scuttlebutt](https://www.scuttlebutt.nz/) ecosystem to mobile, and I built the package [react-native-scuttlebot](https://github.com/ssbc/react-native-scuttlebot) which uses this tool as dependency. These are in turn used by the mobile app project [mmmmm](https://github.com/staltz/mmmmm-mobile).
107 |
108 |
--------------------------------------------------------------------------------
/android/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | // Necessary?
4 | buildscript {
5 | repositories {
6 | jcenter()
7 | }
8 |
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:2.3.+'
11 | }
12 | }
13 |
14 | // Necessary?
15 | repositories {
16 | mavenCentral()
17 | }
18 |
19 | android {
20 | compileSdkVersion 23
21 | buildToolsVersion "23.0.1"
22 |
23 | defaultConfig {
24 | minSdkVersion 16
25 | targetSdkVersion 22
26 | versionCode 1
27 | versionName "1.0"
28 | ndk {
29 | abiFilters "armeabi-v7a", "x86"
30 | }
31 | }
32 | }
33 |
34 | dependencies {
35 | compile "com.android.support:appcompat-v7:23.0.1"
36 | compile "org.apache.commons:commons-compress:1.12"
37 | compile "com.facebook.react:react-native:+"
38 | }
39 |
--------------------------------------------------------------------------------
/android/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
--------------------------------------------------------------------------------
/android/src/main/java/com/staltz/reactnativenode/RNNodeModule.java:
--------------------------------------------------------------------------------
1 | package com.staltz.reactnativenode;
2 |
3 | import android.content.Intent;
4 | import android.util.Log;
5 |
6 | import com.facebook.react.bridge.ReactApplicationContext;
7 | import com.facebook.react.bridge.ReactContext;
8 | import com.facebook.react.bridge.ReactContextBaseJavaModule;
9 | import com.facebook.react.bridge.ReactMethod;
10 | import com.facebook.react.bridge.ReadableArray;
11 |
12 | import java.util.ArrayList;
13 |
14 | /**
15 | * The NativeModule acting as a JS API layer for react-native-node.
16 | */
17 | public final class RNNodeModule extends ReactContextBaseJavaModule {
18 | private static final String TAG = "RNNode";
19 | private ReactContext _reactContext;
20 |
21 | public RNNodeModule(ReactApplicationContext reactContext) {
22 | super(reactContext);
23 | _reactContext = reactContext;
24 | }
25 |
26 | @Override
27 | public String getName() {
28 | return TAG;
29 | }
30 |
31 | public ArrayList toStringArrayList(ReadableArray array) {
32 | ArrayList arrayList = new ArrayList<>();
33 | for (int i = 0; i < array.size(); i++) {
34 | arrayList.add(array.getString(i));
35 | }
36 | return arrayList;
37 | }
38 |
39 | @ReactMethod
40 | public void start(ReadableArray args) {
41 | Log.d(TAG, "Launching an intent for RNNodeService...");
42 | Intent intent = new Intent(_reactContext, RNNodeService.class);
43 | intent.putExtra("args", this.toStringArrayList(args));
44 | _reactContext.startService(intent);
45 | }
46 |
47 | @ReactMethod
48 | public void stop() {
49 | Log.d(TAG, "Stopping an intent for RNNodeService...");
50 | Intent intent = new Intent(_reactContext, RNNodeService.class);
51 | _reactContext.stopService(intent);
52 | }
53 | }
--------------------------------------------------------------------------------
/android/src/main/java/com/staltz/reactnativenode/RNNodePackage.java:
--------------------------------------------------------------------------------
1 | package com.staltz.reactnativenode;
2 |
3 | import com.facebook.react.ReactPackage;
4 | import com.facebook.react.bridge.JavaScriptModule;
5 | import com.facebook.react.bridge.NativeModule;
6 | import com.facebook.react.bridge.ReactApplicationContext;
7 | import com.facebook.react.uimanager.ViewManager;
8 |
9 | import java.util.ArrayList;
10 | import java.util.Collections;
11 | import java.util.List;
12 |
13 | public final class RNNodePackage implements ReactPackage {
14 | @Override
15 | public List createNativeModules(ReactApplicationContext reactContext) {
16 | List modules = new ArrayList();
17 | modules.add(new RNNodeModule(reactContext));
18 | return modules;
19 | }
20 |
21 | @Override
22 | public List createViewManagers(ReactApplicationContext reactContext) {
23 | return Collections.emptyList();
24 | }
25 | }
--------------------------------------------------------------------------------
/android/src/main/java/com/staltz/reactnativenode/RNNodeService.java:
--------------------------------------------------------------------------------
1 | package com.staltz.reactnativenode;
2 |
3 | import android.app.Service;
4 | import android.content.Context;
5 | import android.content.Intent;
6 | import android.os.IBinder;
7 | import android.util.Log;
8 |
9 | import org.apache.commons.compress.archivers.ArchiveException;
10 | import org.apache.commons.compress.archivers.ArchiveStreamFactory;
11 | import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
12 | import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
13 | import org.apache.commons.compress.utils.IOUtils;
14 |
15 | import java.io.FileInputStream;
16 | import java.io.FileNotFoundException;
17 | import java.io.FileOutputStream;
18 | import java.io.IOException;
19 | import java.io.InputStream;
20 | import java.io.File;
21 | import java.io.InputStreamReader;
22 | import java.io.OutputStream;
23 | import java.lang.reflect.Array;
24 | import java.util.ArrayList;
25 | import java.util.LinkedList;
26 | import java.util.List;
27 | import java.util.Map;
28 |
29 | public class RNNodeService extends Service {
30 | private static final String TAG = "RNNodeService";
31 | private static final String RAW_BUNDLE_NAME = "rnnodebundle";
32 | private static final String APP_NAME = "rnnodeapp";
33 | private static final String DEFAULT_APP_ENTRY = "index.js";
34 |
35 | private RNNodeThread _thread;
36 |
37 | public RNNodeService() {
38 | }
39 |
40 | @Override
41 | public IBinder onBind(Intent intent) {
42 | throw new UnsupportedOperationException("Not yet implemented");
43 | }
44 |
45 | @Override
46 | public int onStartCommand(Intent intent, int flags, int startId) {
47 | if (intent != null) {
48 | ArrayList args = intent.getStringArrayListExtra("args");
49 | startNode(this.getApplicationInfo().dataDir, args);
50 | }
51 | // running until explicitly stop
52 | return START_NOT_STICKY;
53 | }
54 |
55 | @Override
56 | public void onCreate() {
57 | Log.v(TAG, "Create and prepare");
58 | String dataDir = this.getApplicationInfo().dataDir;
59 | prepareNode(this, dataDir);
60 | File bundleTar = prepareBundle(this, dataDir);
61 | if (bundleTar == null) {
62 | Log.i(TAG, "Skipping untaring of the bundle, because it would be redundant");
63 | return;
64 | }
65 | try {
66 | unTar(bundleTar, new File(dataDir + "/" + APP_NAME));
67 | } catch (Exception e) {
68 | Log.e(TAG, "Cannot uncompress the background app bundle", e);
69 | }
70 | }
71 |
72 | public void prepareNode(Context context, String dataDir) {
73 | InputStream nodeBinary = null;
74 | try {
75 | nodeBinary = context.getResources().openRawResource(R.raw.bin_node_v710);
76 | String nodeFilename = String.format("%s/node", dataDir);
77 | File nodeFile = new File(nodeFilename);
78 | if (nodeFile.exists()) {
79 | return;
80 | }
81 | nodeFile.createNewFile();
82 | InputStreamReader reader = new InputStreamReader(nodeBinary);
83 | FileOutputStream writer = new FileOutputStream(nodeFile);
84 | byte[] binary = new byte[(int)(nodeBinary.available())];
85 | nodeBinary.read(binary);
86 | writer.write(binary);
87 | writer.flush();
88 | writer.close();
89 | nodeFile.setExecutable(true, true);
90 | nodeBinary.close();
91 | } catch (Exception e) {
92 | Log.e(TAG, "Cannot create binary file for \"node\"");
93 | }
94 | }
95 |
96 | public File prepareBundle(Context context, String dataDir) {
97 | InputStream bundleBinary = null;
98 | try {
99 | int rawId = context.getResources().getIdentifier(RAW_BUNDLE_NAME, "raw", context.getPackageName());
100 | bundleBinary = context.getResources().openRawResource(rawId);
101 | String tarFilename = String.format("%s/%s.tgz", dataDir, APP_NAME);
102 | File tarFile = new File(tarFilename);
103 | if (tarFile.exists() && tarFile.length() == bundleBinary.available()) {
104 | return null;
105 | }
106 | tarFile.createNewFile();
107 | InputStreamReader reader = new InputStreamReader(bundleBinary);
108 | FileOutputStream writer = new FileOutputStream(tarFile, false);
109 | byte[] binary = new byte[(int)(bundleBinary.available())];
110 | bundleBinary.read(binary);
111 | writer.write(binary);
112 | writer.flush();
113 | writer.close();
114 | bundleBinary.close();
115 | return tarFile;
116 | } catch (Exception e) {
117 | Log.e(TAG, "Cannot prepare tar file for the bundle. " +
118 | "Are you sure you ran \"react-native-node insert\"?",
119 | e
120 | );
121 | }
122 | return null;
123 | }
124 |
125 | private static List unTar(final File inputFile, final File outputDir) throws FileNotFoundException, IOException, ArchiveException {
126 | Log.i(TAG, String.format("Untaring %s to dir %s", inputFile.getAbsolutePath(), outputDir.getAbsolutePath()));
127 |
128 | if (!outputDir.exists()) {
129 | outputDir.mkdirs();
130 | }
131 | final List untaredFiles = new LinkedList();
132 | final InputStream is = new FileInputStream(inputFile);
133 | final TarArchiveInputStream debInputStream = (TarArchiveInputStream) new ArchiveStreamFactory().createArchiveInputStream("tar", is);
134 | TarArchiveEntry entry = null;
135 | while ((entry = (TarArchiveEntry)debInputStream.getNextEntry()) != null) {
136 | final File outputFile = new File(outputDir, entry.getName());
137 | if (entry.isDirectory()) {
138 | if (!outputFile.exists()) {
139 | if (!outputFile.mkdirs()) {
140 | throw new IllegalStateException(String.format("Couldn't create directory %s.", outputFile.getAbsolutePath()));
141 | }
142 | }
143 | } else {
144 | final OutputStream outputFileStream = new FileOutputStream(outputFile);
145 | IOUtils.copy(debInputStream, outputFileStream);
146 | outputFileStream.close();
147 | }
148 | untaredFiles.add(outputFile);
149 | }
150 | debInputStream.close();
151 |
152 | return untaredFiles;
153 | }
154 |
155 | public void startNode(String dataDir, ArrayList args) {
156 | if (_thread != null) {
157 | return;
158 | }
159 | Log.v(TAG, "Will start RNNodeThread now...");
160 | ArrayList cmd = new ArrayList<>();
161 | cmd.add(String.format("%s/node", dataDir));
162 | cmd.add(String.format("%s/%s/%s", dataDir, APP_NAME, DEFAULT_APP_ENTRY));
163 | if (args != null) {
164 | cmd.addAll(args);
165 | }
166 | try {
167 | ProcessBuilder pb = (new ProcessBuilder(cmd))
168 | .directory(new File(dataDir));
169 | Map env = pb.environment();
170 | env.put("TMPDIR", getCacheDir().getAbsolutePath());
171 | env.put("HOME", dataDir);
172 | env.put("LD_LIBRARY_PATH", this.getApplicationInfo().nativeLibraryDir);
173 | _thread = new RNNodeThread(pb);
174 | _thread.start();
175 | Log.v(TAG, "RNNodeThread started.");
176 | } catch (Exception e) {
177 | Log.e(TAG, "Cannot start \"node\"", e);
178 | }
179 | }
180 |
181 | @Override
182 | public void onDestroy() {
183 | Log.d(TAG, "destroy");
184 | stopNode();
185 | }
186 |
187 | public void stopNode() {
188 | if (_thread != null) {
189 | _thread.kill();
190 | _thread = null;
191 | }
192 | }
193 | }
194 |
--------------------------------------------------------------------------------
/android/src/main/java/com/staltz/reactnativenode/RNNodeThread.java:
--------------------------------------------------------------------------------
1 | package com.staltz.reactnativenode;
2 |
3 | import android.util.Log;
4 |
5 | import java.io.BufferedReader;
6 | import java.io.IOException;
7 | import java.io.InputStream;
8 | import java.io.InputStreamReader;
9 |
10 | public class RNNodeThread extends Thread {
11 | private static final String TAG = "RNNodeThread";
12 | private static final String NODETAG = "nodejs";
13 |
14 | private boolean _running;
15 | private Process _process;
16 | private ProcessBuilder _processBuilder;
17 |
18 | public RNNodeThread(ProcessBuilder processBuilder) {
19 | _running = true;
20 | _processBuilder = processBuilder;
21 | }
22 |
23 | public void kill() {
24 | if (_running) {
25 | _process.destroy();
26 | _process = null;
27 | _running = false;
28 | Log.i(TAG, "Node.js process killed.");
29 | }
30 | }
31 |
32 | static class Logger implements Runnable {
33 | private BufferedReader reader;
34 | private final boolean isError;
35 |
36 | public Logger(InputStream rS, boolean isError) throws IOException {
37 | this.reader = new BufferedReader(new InputStreamReader(rS));
38 | this.isError = isError;
39 | }
40 |
41 | @Override
42 | public void run() {
43 | try {
44 | String line;
45 | while ((line = this.reader.readLine()) != null) {
46 | if (this.isError) {
47 | Log.e(NODETAG, line);
48 | } else {
49 | Log.v(NODETAG, line);
50 | }
51 | }
52 | } catch (IOException e) {
53 | Log.e(TAG + ".Logger", e.toString());
54 | }
55 | }
56 | }
57 |
58 | @Override
59 | public void run() {
60 | try {
61 | _process = _processBuilder.start();
62 | Log.i(TAG, "Node.js process is running...");
63 | final Thread stdoutThread = new Thread(new Logger(_process.getInputStream(), false));
64 | final Thread stderrThread = new Thread(new Logger(_process.getErrorStream(), true));
65 | stdoutThread.run();
66 | stderrThread.run();
67 | _process.waitFor();
68 | } catch (Exception e) {
69 | // probably interrupted
70 | Log.e(TAG, "Error running Node.js process:", e);
71 | }
72 | Log.i(TAG, "Node.js process terminated.");
73 | _running = false;
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/android/src/main/res/raw/bin_node_v710:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/staltz/react-native-node/63423a5becc55468f4d55258fef9a7aafade0f12/android/src/main/res/raw/bin_node_v710
--------------------------------------------------------------------------------
/bin.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | const path = require("path");
3 | const tar = require("tar");
4 | const fs = require("fs");
5 | const mkdirp = require("mkdirp");
6 | const cheerio = require("cheerio");
7 |
8 | const BUNDLE_TAR = "rnnodebundle.tgz";
9 | const BUNDLE_NO_EXT = "rnnodebundle";
10 | const SERVICE_CLASSNAME = "com.staltz.reactnativenode.RNNodeService";
11 |
12 | function assertCanInsert(workingDir, sourcePath) {
13 | const androidProjectPath = path.resolve(workingDir, "./android/app");
14 | if (!fs.existsSync(androidProjectPath)) {
15 | throw new Error(
16 | "Android project is missing, expected in\n" +
17 | androidProjectPath +
18 | "\n" +
19 | "when running react-native-node insert"
20 | );
21 | }
22 | }
23 |
24 | function bundle(originalWorkingDir, sourcePath) {
25 | const absoluteSourcePath = path.resolve(originalWorkingDir, sourcePath);
26 | console.log("Bundling the directory " + absoluteSourcePath + " ...");
27 | process.chdir(absoluteSourcePath);
28 | const bundleFileList = fs.readdirSync(absoluteSourcePath);
29 | const targetAbsolutePath = path.resolve(originalWorkingDir, BUNDLE_TAR);
30 | tar.create(
31 | { gzip: false, file: targetAbsolutePath, sync: true, portable: true },
32 | bundleFileList
33 | );
34 | process.chdir(originalWorkingDir);
35 | console.log("\tdone.");
36 | }
37 |
38 | function insertOnly(workingDir) {
39 | console.log("Inserting bundle into mobile app project ...");
40 | const androidRawResDir = "./android/app/src/main/res/raw";
41 | console.log("\tInto Android project, under " + androidRawResDir + " ...");
42 | mkdirp.sync(androidRawResDir);
43 | const before = path.resolve(workingDir, BUNDLE_TAR);
44 | const after = path.resolve(workingDir, androidRawResDir, BUNDLE_NO_EXT);
45 | fs.renameSync(before, after);
46 | console.log("\t\tdone");
47 | }
48 |
49 | function updateManifest(workingDir) {
50 | console.log("Updating AndroidManifest.xml in mobile app project ...");
51 | const absoluteManifestPath = path.resolve(
52 | workingDir,
53 | "./android/app/src/main/AndroidManifest.xml"
54 | );
55 | const xmlBefore = fs.readFileSync(absoluteManifestPath, "utf-8");
56 | const $ = cheerio.load(xmlBefore, { xmlMode: true });
57 | const serviceElems = $("manifest application service").filter(
58 | (i, elem) => elem.attribs["android:name"] === SERVICE_CLASSNAME
59 | );
60 | if (serviceElems.length === 0) {
61 | $("manifest application").append(
62 | ``
63 | );
64 | }
65 | fs.writeFileSync(absoluteManifestPath, $.xml(), "utf-8");
66 | console.log("\tdone");
67 | }
68 |
69 | function insert(path) {
70 | const workingDir = process.cwd();
71 | assertCanInsert(workingDir, path);
72 | bundle(workingDir, path);
73 | insertOnly(workingDir);
74 | updateManifest(workingDir);
75 | }
76 |
77 | const argv = require("yargs")
78 | .usage("Usage: $0 [options]")
79 | .example("$0 insert ./background")
80 | .command({
81 | command: "insert ",
82 | aliases: ["i"],
83 | desc:
84 | "Bundle and insert a background Node.js project from the " +
85 | "directory into the mobile app project"
86 | })
87 | .demandCommand(1, "ERROR: You need to run a command, e.g. insert")
88 | .help().argv;
89 |
90 | if (argv._[0] === "insert") {
91 | insert(argv.path);
92 | }
93 |
--------------------------------------------------------------------------------
/example/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": ["react-native"]
3 | }
4 |
--------------------------------------------------------------------------------
/example/.buckconfig:
--------------------------------------------------------------------------------
1 |
2 | [android]
3 | target = Google Inc.:Google APIs:23
4 |
5 | [maven_repositories]
6 | central = https://repo1.maven.org/maven2
7 |
--------------------------------------------------------------------------------
/example/.flowconfig:
--------------------------------------------------------------------------------
1 | [ignore]
2 | ; We fork some components by platform
3 | .*/*[.]android.js
4 |
5 | ; Ignore "BUCK" generated dirs
6 | /\.buckd/
7 |
8 | ; Ignore unexpected extra "@providesModule"
9 | .*/node_modules/.*/node_modules/fbjs/.*
10 |
11 | ; Ignore duplicate module providers
12 | ; For RN Apps installed via npm, "Libraries" folder is inside
13 | ; "node_modules/react-native" but in the source repo it is in the root
14 | .*/Libraries/react-native/React.js
15 | .*/Libraries/react-native/ReactNative.js
16 |
17 | [include]
18 |
19 | [libs]
20 | node_modules/react-native/Libraries/react-native/react-native-interface.js
21 | node_modules/react-native/flow
22 | flow/
23 |
24 | [options]
25 | emoji=true
26 |
27 | module.system=haste
28 |
29 | munge_underscores=true
30 |
31 | module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> 'RelativeImageStub'
32 |
33 | suppress_type=$FlowIssue
34 | suppress_type=$FlowFixMe
35 | suppress_type=$FixMe
36 |
37 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(4[0-7]\\|[1-3][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)
38 | suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(4[0-7]\\|[1-3][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+
39 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy
40 | suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError
41 |
42 | unsafe.enable_getters_and_setters=true
43 |
44 | [version]
45 | ^0.47.0
46 |
--------------------------------------------------------------------------------
/example/.gitattributes:
--------------------------------------------------------------------------------
1 | *.pbxproj -text
2 |
--------------------------------------------------------------------------------
/example/.gitignore:
--------------------------------------------------------------------------------
1 | # OSX
2 | #
3 | .DS_Store
4 |
5 | # Xcode
6 | #
7 | build/
8 | *.pbxuser
9 | !default.pbxuser
10 | *.mode1v3
11 | !default.mode1v3
12 | *.mode2v3
13 | !default.mode2v3
14 | *.perspectivev3
15 | !default.perspectivev3
16 | xcuserdata
17 | *.xccheckout
18 | *.moved-aside
19 | DerivedData
20 | *.hmap
21 | *.ipa
22 | *.xcuserstate
23 | project.xcworkspace
24 |
25 | # Android/IntelliJ
26 | #
27 | build/
28 | .idea
29 | .gradle
30 | local.properties
31 | *.iml
32 |
33 | # node.js
34 | #
35 | node_modules/
36 | npm-debug.log
37 | yarn-error.log
38 |
39 | # BUCK
40 | buck-out/
41 | \.buckd/
42 | *.keystore
43 |
44 | # fastlane
45 | #
46 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
47 | # screenshots whenever they are needed.
48 | # For more information about the recommended setup visit:
49 | # https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md
50 |
51 | fastlane/report.xml
52 | fastlane/Preview.html
53 | fastlane/screenshots
54 |
--------------------------------------------------------------------------------
/example/.watchmanconfig:
--------------------------------------------------------------------------------
1 | {}
--------------------------------------------------------------------------------
/example/README.md:
--------------------------------------------------------------------------------
1 | # Example
2 |
3 | A simple express.js app running in a background node.js process, which the React Native app can talk to through HTTP requests to localhost.
4 |
5 | ## Install
6 |
7 | ```
8 | yarn
9 | ```
10 |
11 | (note: after this you should also run `react-native link react-native-node`, but in this example we already ran that for you)
12 |
13 | ## Build the background process
14 |
15 | Run `npm run build` or follow these steps manually:
16 |
17 | The node.js project is in the directory `/background`, you need to install its `node_modules` **separately** from the `node_modules` for your React Native project:
18 |
19 | ```
20 | cd background
21 | yarn
22 | cd ..
23 | ```
24 |
25 | ```
26 | react-native-node insert ./background
27 | ```
28 |
29 | (or `./node_modules/.bin/react-native-node insert ./background`)
30 |
31 | ## Run
32 |
33 | ```
34 | react-native run-android
35 | ```
36 |
--------------------------------------------------------------------------------
/example/android/app/BUCK:
--------------------------------------------------------------------------------
1 | # To learn about Buck see [Docs](https://buckbuild.com/).
2 | # To run your application with Buck:
3 | # - install Buck
4 | # - `npm start` - to start the packager
5 | # - `cd android`
6 | # - `keytool -genkey -v -keystore keystores/debug.keystore -storepass android -alias androiddebugkey -keypass android -dname "CN=Android Debug,O=Android,C=US"`
7 | # - `./gradlew :app:copyDownloadableDepsToLibs` - make all Gradle compile dependencies available to Buck
8 | # - `buck install -r android/app` - compile, install and run application
9 | #
10 |
11 | lib_deps = []
12 |
13 | for jarfile in glob(['libs/*.jar']):
14 | name = 'jars__' + jarfile[jarfile.rindex('/') + 1: jarfile.rindex('.jar')]
15 | lib_deps.append(':' + name)
16 | prebuilt_jar(
17 | name = name,
18 | binary_jar = jarfile,
19 | )
20 |
21 | for aarfile in glob(['libs/*.aar']):
22 | name = 'aars__' + aarfile[aarfile.rindex('/') + 1: aarfile.rindex('.aar')]
23 | lib_deps.append(':' + name)
24 | android_prebuilt_aar(
25 | name = name,
26 | aar = aarfile,
27 | )
28 |
29 | android_library(
30 | name = "all-libs",
31 | exported_deps = lib_deps,
32 | )
33 |
34 | android_library(
35 | name = "app-code",
36 | srcs = glob([
37 | "src/main/java/**/*.java",
38 | ]),
39 | deps = [
40 | ":all-libs",
41 | ":build_config",
42 | ":res",
43 | ],
44 | )
45 |
46 | android_build_config(
47 | name = "build_config",
48 | package = "com.example",
49 | )
50 |
51 | android_resource(
52 | name = "res",
53 | package = "com.example",
54 | res = "src/main/res",
55 | )
56 |
57 | android_binary(
58 | name = "app",
59 | keystore = "//android/keystores:debug",
60 | manifest = "src/main/AndroidManifest.xml",
61 | package_type = "debug",
62 | deps = [
63 | ":app-code",
64 | ],
65 | )
66 |
--------------------------------------------------------------------------------
/example/android/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: "com.android.application"
2 |
3 | import com.android.build.OutputFile
4 |
5 | /**
6 | * The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
7 | * and bundleReleaseJsAndAssets).
8 | * These basically call `react-native bundle` with the correct arguments during the Android build
9 | * cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
10 | * bundle directly from the development server. Below you can see all the possible configurations
11 | * and their defaults. If you decide to add a configuration block, make sure to add it before the
12 | * `apply from: "../../node_modules/react-native/react.gradle"` line.
13 | *
14 | * project.ext.react = [
15 | * // the name of the generated asset file containing your JS bundle
16 | * bundleAssetName: "index.android.bundle",
17 | *
18 | * // the entry file for bundle generation
19 | * entryFile: "index.android.js",
20 | *
21 | * // whether to bundle JS and assets in debug mode
22 | * bundleInDebug: false,
23 | *
24 | * // whether to bundle JS and assets in release mode
25 | * bundleInRelease: true,
26 | *
27 | * // whether to bundle JS and assets in another build variant (if configured).
28 | * // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
29 | * // The configuration property can be in the following formats
30 | * // 'bundleIn${productFlavor}${buildType}'
31 | * // 'bundleIn${buildType}'
32 | * // bundleInFreeDebug: true,
33 | * // bundleInPaidRelease: true,
34 | * // bundleInBeta: true,
35 | *
36 | * // whether to disable dev mode in custom build variants (by default only disabled in release)
37 | * // for example: to disable dev mode in the staging build type (if configured)
38 | * devDisabledInStaging: true,
39 | * // The configuration property can be in the following formats
40 | * // 'devDisabledIn${productFlavor}${buildType}'
41 | * // 'devDisabledIn${buildType}'
42 | *
43 | * // the root of your project, i.e. where "package.json" lives
44 | * root: "../../",
45 | *
46 | * // where to put the JS bundle asset in debug mode
47 | * jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
48 | *
49 | * // where to put the JS bundle asset in release mode
50 | * jsBundleDirRelease: "$buildDir/intermediates/assets/release",
51 | *
52 | * // where to put drawable resources / React Native assets, e.g. the ones you use via
53 | * // require('./image.png')), in debug mode
54 | * resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
55 | *
56 | * // where to put drawable resources / React Native assets, e.g. the ones you use via
57 | * // require('./image.png')), in release mode
58 | * resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
59 | *
60 | * // by default the gradle tasks are skipped if none of the JS files or assets change; this means
61 | * // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
62 | * // date; if you have any other folders that you want to ignore for performance reasons (gradle
63 | * // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
64 | * // for example, you might want to remove it from here.
65 | * inputExcludes: ["android/**", "ios/**"],
66 | *
67 | * // override which node gets called and with what additional arguments
68 | * nodeExecutableAndArgs: ["node"],
69 | *
70 | * // supply additional arguments to the packager
71 | * extraPackagerArgs: []
72 | * ]
73 | */
74 |
75 | apply from: "../../node_modules/react-native/react.gradle"
76 |
77 | /**
78 | * Set this to true to create two separate APKs instead of one:
79 | * - An APK that only works on ARM devices
80 | * - An APK that only works on x86 devices
81 | * The advantage is the size of the APK is reduced by about 4MB.
82 | * Upload all the APKs to the Play Store and people will download
83 | * the correct one based on the CPU architecture of their device.
84 | */
85 | def enableSeparateBuildPerCPUArchitecture = false
86 |
87 | /**
88 | * Run Proguard to shrink the Java bytecode in release builds.
89 | */
90 | def enableProguardInReleaseBuilds = false
91 |
92 | android {
93 | compileSdkVersion 23
94 | buildToolsVersion "23.0.1"
95 |
96 | defaultConfig {
97 | applicationId "com.example"
98 | minSdkVersion 16
99 | targetSdkVersion 22
100 | versionCode 1
101 | versionName "1.0"
102 | ndk {
103 | abiFilters "armeabi-v7a", "x86"
104 | }
105 | }
106 | splits {
107 | abi {
108 | reset()
109 | enable enableSeparateBuildPerCPUArchitecture
110 | universalApk false // If true, also generate a universal APK
111 | include "armeabi-v7a", "x86"
112 | }
113 | }
114 | buildTypes {
115 | release {
116 | minifyEnabled enableProguardInReleaseBuilds
117 | proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
118 | }
119 | }
120 | // applicationVariants are e.g. debug, release
121 | applicationVariants.all { variant ->
122 | variant.outputs.each { output ->
123 | // For each separate APK per architecture, set a unique version code as described here:
124 | // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
125 | def versionCodes = ["armeabi-v7a":1, "x86":2]
126 | def abi = output.getFilter(OutputFile.ABI)
127 | if (abi != null) { // null for the universal-debug, universal-release variants
128 | output.versionCodeOverride =
129 | versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
130 | }
131 | }
132 | }
133 | }
134 |
135 | dependencies {
136 | compile project(':react-native-node')
137 | compile fileTree(dir: "libs", include: ["*.jar"])
138 | compile "com.android.support:appcompat-v7:23.0.1"
139 | compile "com.facebook.react:react-native:+" // From node_modules
140 | }
141 |
142 | // Run this once to be able to run the application with BUCK
143 | // puts all compile dependencies into folder libs for BUCK to use
144 | task copyDownloadableDepsToLibs(type: Copy) {
145 | from configurations.compile
146 | into 'libs'
147 | }
148 |
--------------------------------------------------------------------------------
/example/android/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /usr/local/Cellar/android-sdk/24.3.3/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Disabling obfuscation is useful if you collect stack traces from production crashes
20 | # (unless you are using a system that supports de-obfuscate the stack traces).
21 | -dontobfuscate
22 |
23 | # React Native
24 |
25 | # Keep our interfaces so they can be used by other ProGuard rules.
26 | # See http://sourceforge.net/p/proguard/bugs/466/
27 | -keep,allowobfuscation @interface com.facebook.proguard.annotations.DoNotStrip
28 | -keep,allowobfuscation @interface com.facebook.proguard.annotations.KeepGettersAndSetters
29 | -keep,allowobfuscation @interface com.facebook.common.internal.DoNotStrip
30 |
31 | # Do not strip any method/class that is annotated with @DoNotStrip
32 | -keep @com.facebook.proguard.annotations.DoNotStrip class *
33 | -keep @com.facebook.common.internal.DoNotStrip class *
34 | -keepclassmembers class * {
35 | @com.facebook.proguard.annotations.DoNotStrip *;
36 | @com.facebook.common.internal.DoNotStrip *;
37 | }
38 |
39 | -keepclassmembers @com.facebook.proguard.annotations.KeepGettersAndSetters class * {
40 | void set*(***);
41 | *** get*();
42 | }
43 |
44 | -keep class * extends com.facebook.react.bridge.JavaScriptModule { *; }
45 | -keep class * extends com.facebook.react.bridge.NativeModule { *; }
46 | -keepclassmembers,includedescriptorclasses class * { native ; }
47 | -keepclassmembers class * { @com.facebook.react.uimanager.UIProp ; }
48 | -keepclassmembers class * { @com.facebook.react.uimanager.annotations.ReactProp ; }
49 | -keepclassmembers class * { @com.facebook.react.uimanager.annotations.ReactPropGroup ; }
50 |
51 | -dontwarn com.facebook.react.**
52 |
53 | # TextLayoutBuilder uses a non-public Android constructor within StaticLayout.
54 | # See libs/proxy/src/main/java/com/facebook/fbui/textlayoutbuilder/proxy for details.
55 | -dontwarn android.text.StaticLayout
56 |
57 | # okhttp
58 |
59 | -keepattributes Signature
60 | -keepattributes *Annotation*
61 | -keep class okhttp3.** { *; }
62 | -keep interface okhttp3.** { *; }
63 | -dontwarn okhttp3.**
64 |
65 | # okio
66 |
67 | -keep class sun.misc.Unsafe { *; }
68 | -dontwarn java.nio.file.*
69 | -dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
70 | -dontwarn okio.**
71 |
--------------------------------------------------------------------------------
/example/android/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/example/android/app/src/main/java/com/example/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | import com.facebook.react.ReactActivity;
4 |
5 | public class MainActivity extends ReactActivity {
6 |
7 | /**
8 | * Returns the name of the main component registered from JavaScript.
9 | * This is used to schedule rendering of the component.
10 | */
11 | @Override
12 | protected String getMainComponentName() {
13 | return "Example";
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/example/android/app/src/main/java/com/example/MainApplication.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | import android.app.Application;
4 |
5 | import com.facebook.react.ReactApplication;
6 | import com.staltz.reactnativenode.RNNodePackage;
7 | import com.facebook.react.ReactNativeHost;
8 | import com.facebook.react.ReactPackage;
9 | import com.facebook.react.shell.MainReactPackage;
10 | import com.facebook.soloader.SoLoader;
11 |
12 | import java.util.Arrays;
13 | import java.util.List;
14 |
15 | public class MainApplication extends Application implements ReactApplication {
16 |
17 | private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
18 | @Override
19 | public boolean getUseDeveloperSupport() {
20 | return BuildConfig.DEBUG;
21 | }
22 |
23 | @Override
24 | protected List getPackages() {
25 | return Arrays.asList(
26 | new MainReactPackage(),
27 | new RNNodePackage()
28 | );
29 | }
30 | };
31 |
32 | @Override
33 | public ReactNativeHost getReactNativeHost() {
34 | return mReactNativeHost;
35 | }
36 |
37 | @Override
38 | public void onCreate() {
39 | super.onCreate();
40 | SoLoader.init(this, /* native exopackage */ false);
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/staltz/react-native-node/63423a5becc55468f4d55258fef9a7aafade0f12/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/staltz/react-native-node/63423a5becc55468f4d55258fef9a7aafade0f12/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/staltz/react-native-node/63423a5becc55468f4d55258fef9a7aafade0f12/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/staltz/react-native-node/63423a5becc55468f4d55258fef9a7aafade0f12/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/android/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Example
3 |
4 |
--------------------------------------------------------------------------------
/example/android/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/example/android/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.2.3'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | mavenLocal()
18 | jcenter()
19 | maven {
20 | // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
21 | url "$rootDir/../node_modules/react-native/android"
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/example/android/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
19 |
20 | android.useDeprecatedNdk=true
21 |
--------------------------------------------------------------------------------
/example/android/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/staltz/react-native-node/63423a5becc55468f4d55258fef9a7aafade0f12/example/android/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/example/android/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | zipStoreBase=GRADLE_USER_HOME
4 | zipStorePath=wrapper/dists
5 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
6 |
--------------------------------------------------------------------------------
/example/android/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/example/android/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/example/android/keystores/BUCK:
--------------------------------------------------------------------------------
1 | keystore(
2 | name = "debug",
3 | properties = "debug.keystore.properties",
4 | store = "debug.keystore",
5 | visibility = [
6 | "PUBLIC",
7 | ],
8 | )
9 |
--------------------------------------------------------------------------------
/example/android/keystores/debug.keystore.properties:
--------------------------------------------------------------------------------
1 | key.store=debug.keystore
2 | key.alias=androiddebugkey
3 | key.store.password=android
4 | key.alias.password=android
5 |
--------------------------------------------------------------------------------
/example/android/settings.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name = 'Example'
2 | include ':react-native-node'
3 | project(':react-native-node').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-node/android')
4 |
5 | include ':app'
6 |
--------------------------------------------------------------------------------
/example/app.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "Example",
3 | "displayName": "Example"
4 | }
--------------------------------------------------------------------------------
/example/background/index.js:
--------------------------------------------------------------------------------
1 | const express = require("express");
2 |
3 | const app = express();
4 |
5 | app.get("/", (req, res) => {
6 | res.json({ msg: "This is a response from the server running in the phone!" });
7 | });
8 |
9 | app.listen(5000);
10 |
--------------------------------------------------------------------------------
/example/background/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "background",
3 | "version": "1.0.0",
4 | "main": "index.js",
5 | "scripts": {},
6 | "dependencies": {
7 | "express": "^4.15.3"
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/example/background/yarn.lock:
--------------------------------------------------------------------------------
1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2 | # yarn lockfile v1
3 |
4 |
5 | accepts@~1.3.3:
6 | version "1.3.3"
7 | resolved "https://registry.yarnpkg.com/accepts/-/accepts-1.3.3.tgz#c3ca7434938648c3e0d9c1e328dd68b622c284ca"
8 | dependencies:
9 | mime-types "~2.1.11"
10 | negotiator "0.6.1"
11 |
12 | array-flatten@1.1.1:
13 | version "1.1.1"
14 | resolved "https://registry.yarnpkg.com/array-flatten/-/array-flatten-1.1.1.tgz#9a5f699051b1e7073328f2a008968b64ea2955d2"
15 |
16 | content-disposition@0.5.2:
17 | version "0.5.2"
18 | resolved "https://registry.yarnpkg.com/content-disposition/-/content-disposition-0.5.2.tgz#0cf68bb9ddf5f2be7961c3a85178cb85dba78cb4"
19 |
20 | content-type@~1.0.2:
21 | version "1.0.2"
22 | resolved "https://registry.yarnpkg.com/content-type/-/content-type-1.0.2.tgz#b7d113aee7a8dd27bd21133c4dc2529df1721eed"
23 |
24 | cookie-signature@1.0.6:
25 | version "1.0.6"
26 | resolved "https://registry.yarnpkg.com/cookie-signature/-/cookie-signature-1.0.6.tgz#e303a882b342cc3ee8ca513a79999734dab3ae2c"
27 |
28 | cookie@0.3.1:
29 | version "0.3.1"
30 | resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.3.1.tgz#e7e0a1f9ef43b4c8ba925c5c5a96e806d16873bb"
31 |
32 | debug@2.6.7:
33 | version "2.6.7"
34 | resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.7.tgz#92bad1f6d05bbb6bba22cca88bcd0ec894c2861e"
35 | dependencies:
36 | ms "2.0.0"
37 |
38 | depd@1.1.0:
39 | version "1.1.0"
40 | resolved "https://registry.yarnpkg.com/depd/-/depd-1.1.0.tgz#e1bd82c6aab6ced965b97b88b17ed3e528ca18c3"
41 |
42 | depd@~1.1.0:
43 | version "1.1.1"
44 | resolved "https://registry.yarnpkg.com/depd/-/depd-1.1.1.tgz#5783b4e1c459f06fa5ca27f991f3d06e7a310359"
45 |
46 | destroy@~1.0.4:
47 | version "1.0.4"
48 | resolved "https://registry.yarnpkg.com/destroy/-/destroy-1.0.4.tgz#978857442c44749e4206613e37946205826abd80"
49 |
50 | ee-first@1.1.1:
51 | version "1.1.1"
52 | resolved "https://registry.yarnpkg.com/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d"
53 |
54 | encodeurl@~1.0.1:
55 | version "1.0.1"
56 | resolved "https://registry.yarnpkg.com/encodeurl/-/encodeurl-1.0.1.tgz#79e3d58655346909fe6f0f45a5de68103b294d20"
57 |
58 | escape-html@~1.0.3:
59 | version "1.0.3"
60 | resolved "https://registry.yarnpkg.com/escape-html/-/escape-html-1.0.3.tgz#0258eae4d3d0c0974de1c169188ef0051d1d1988"
61 |
62 | etag@~1.8.0:
63 | version "1.8.0"
64 | resolved "https://registry.yarnpkg.com/etag/-/etag-1.8.0.tgz#6f631aef336d6c46362b51764044ce216be3c051"
65 |
66 | express@^4.15.3:
67 | version "4.15.3"
68 | resolved "https://registry.yarnpkg.com/express/-/express-4.15.3.tgz#bab65d0f03aa80c358408972fc700f916944b662"
69 | dependencies:
70 | accepts "~1.3.3"
71 | array-flatten "1.1.1"
72 | content-disposition "0.5.2"
73 | content-type "~1.0.2"
74 | cookie "0.3.1"
75 | cookie-signature "1.0.6"
76 | debug "2.6.7"
77 | depd "~1.1.0"
78 | encodeurl "~1.0.1"
79 | escape-html "~1.0.3"
80 | etag "~1.8.0"
81 | finalhandler "~1.0.3"
82 | fresh "0.5.0"
83 | merge-descriptors "1.0.1"
84 | methods "~1.1.2"
85 | on-finished "~2.3.0"
86 | parseurl "~1.3.1"
87 | path-to-regexp "0.1.7"
88 | proxy-addr "~1.1.4"
89 | qs "6.4.0"
90 | range-parser "~1.2.0"
91 | send "0.15.3"
92 | serve-static "1.12.3"
93 | setprototypeof "1.0.3"
94 | statuses "~1.3.1"
95 | type-is "~1.6.15"
96 | utils-merge "1.0.0"
97 | vary "~1.1.1"
98 |
99 | finalhandler@~1.0.3:
100 | version "1.0.3"
101 | resolved "https://registry.yarnpkg.com/finalhandler/-/finalhandler-1.0.3.tgz#ef47e77950e999780e86022a560e3217e0d0cc89"
102 | dependencies:
103 | debug "2.6.7"
104 | encodeurl "~1.0.1"
105 | escape-html "~1.0.3"
106 | on-finished "~2.3.0"
107 | parseurl "~1.3.1"
108 | statuses "~1.3.1"
109 | unpipe "~1.0.0"
110 |
111 | forwarded@~0.1.0:
112 | version "0.1.0"
113 | resolved "https://registry.yarnpkg.com/forwarded/-/forwarded-0.1.0.tgz#19ef9874c4ae1c297bcf078fde63a09b66a84363"
114 |
115 | fresh@0.5.0:
116 | version "0.5.0"
117 | resolved "https://registry.yarnpkg.com/fresh/-/fresh-0.5.0.tgz#f474ca5e6a9246d6fd8e0953cfa9b9c805afa78e"
118 |
119 | http-errors@~1.6.1:
120 | version "1.6.1"
121 | resolved "https://registry.yarnpkg.com/http-errors/-/http-errors-1.6.1.tgz#5f8b8ed98aca545656bf572997387f904a722257"
122 | dependencies:
123 | depd "1.1.0"
124 | inherits "2.0.3"
125 | setprototypeof "1.0.3"
126 | statuses ">= 1.3.1 < 2"
127 |
128 | inherits@2.0.3:
129 | version "2.0.3"
130 | resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de"
131 |
132 | ipaddr.js@1.4.0:
133 | version "1.4.0"
134 | resolved "https://registry.yarnpkg.com/ipaddr.js/-/ipaddr.js-1.4.0.tgz#296aca878a821816e5b85d0a285a99bcff4582f0"
135 |
136 | media-typer@0.3.0:
137 | version "0.3.0"
138 | resolved "https://registry.yarnpkg.com/media-typer/-/media-typer-0.3.0.tgz#8710d7af0aa626f8fffa1ce00168545263255748"
139 |
140 | merge-descriptors@1.0.1:
141 | version "1.0.1"
142 | resolved "https://registry.yarnpkg.com/merge-descriptors/-/merge-descriptors-1.0.1.tgz#b00aaa556dd8b44568150ec9d1b953f3f90cbb61"
143 |
144 | methods@~1.1.2:
145 | version "1.1.2"
146 | resolved "https://registry.yarnpkg.com/methods/-/methods-1.1.2.tgz#5529a4d67654134edcc5266656835b0f851afcee"
147 |
148 | mime-db@~1.29.0:
149 | version "1.29.0"
150 | resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.29.0.tgz#48d26d235589651704ac5916ca06001914266878"
151 |
152 | mime-types@~2.1.11, mime-types@~2.1.15:
153 | version "2.1.16"
154 | resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.16.tgz#2b858a52e5ecd516db897ac2be87487830698e23"
155 | dependencies:
156 | mime-db "~1.29.0"
157 |
158 | mime@1.3.4:
159 | version "1.3.4"
160 | resolved "https://registry.yarnpkg.com/mime/-/mime-1.3.4.tgz#115f9e3b6b3daf2959983cb38f149a2d40eb5d53"
161 |
162 | ms@2.0.0:
163 | version "2.0.0"
164 | resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8"
165 |
166 | negotiator@0.6.1:
167 | version "0.6.1"
168 | resolved "https://registry.yarnpkg.com/negotiator/-/negotiator-0.6.1.tgz#2b327184e8992101177b28563fb5e7102acd0ca9"
169 |
170 | on-finished@~2.3.0:
171 | version "2.3.0"
172 | resolved "https://registry.yarnpkg.com/on-finished/-/on-finished-2.3.0.tgz#20f1336481b083cd75337992a16971aa2d906947"
173 | dependencies:
174 | ee-first "1.1.1"
175 |
176 | parseurl@~1.3.1:
177 | version "1.3.1"
178 | resolved "https://registry.yarnpkg.com/parseurl/-/parseurl-1.3.1.tgz#c8ab8c9223ba34888aa64a297b28853bec18da56"
179 |
180 | path-to-regexp@0.1.7:
181 | version "0.1.7"
182 | resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-0.1.7.tgz#df604178005f522f15eb4490e7247a1bfaa67f8c"
183 |
184 | proxy-addr@~1.1.4:
185 | version "1.1.5"
186 | resolved "https://registry.yarnpkg.com/proxy-addr/-/proxy-addr-1.1.5.tgz#71c0ee3b102de3f202f3b64f608d173fcba1a918"
187 | dependencies:
188 | forwarded "~0.1.0"
189 | ipaddr.js "1.4.0"
190 |
191 | qs@6.4.0:
192 | version "6.4.0"
193 | resolved "https://registry.yarnpkg.com/qs/-/qs-6.4.0.tgz#13e26d28ad6b0ffaa91312cd3bf708ed351e7233"
194 |
195 | range-parser@~1.2.0:
196 | version "1.2.0"
197 | resolved "https://registry.yarnpkg.com/range-parser/-/range-parser-1.2.0.tgz#f49be6b487894ddc40dcc94a322f611092e00d5e"
198 |
199 | send@0.15.3:
200 | version "0.15.3"
201 | resolved "https://registry.yarnpkg.com/send/-/send-0.15.3.tgz#5013f9f99023df50d1bd9892c19e3defd1d53309"
202 | dependencies:
203 | debug "2.6.7"
204 | depd "~1.1.0"
205 | destroy "~1.0.4"
206 | encodeurl "~1.0.1"
207 | escape-html "~1.0.3"
208 | etag "~1.8.0"
209 | fresh "0.5.0"
210 | http-errors "~1.6.1"
211 | mime "1.3.4"
212 | ms "2.0.0"
213 | on-finished "~2.3.0"
214 | range-parser "~1.2.0"
215 | statuses "~1.3.1"
216 |
217 | serve-static@1.12.3:
218 | version "1.12.3"
219 | resolved "https://registry.yarnpkg.com/serve-static/-/serve-static-1.12.3.tgz#9f4ba19e2f3030c547f8af99107838ec38d5b1e2"
220 | dependencies:
221 | encodeurl "~1.0.1"
222 | escape-html "~1.0.3"
223 | parseurl "~1.3.1"
224 | send "0.15.3"
225 |
226 | setprototypeof@1.0.3:
227 | version "1.0.3"
228 | resolved "https://registry.yarnpkg.com/setprototypeof/-/setprototypeof-1.0.3.tgz#66567e37043eeb4f04d91bd658c0cbefb55b8e04"
229 |
230 | "statuses@>= 1.3.1 < 2", statuses@~1.3.1:
231 | version "1.3.1"
232 | resolved "https://registry.yarnpkg.com/statuses/-/statuses-1.3.1.tgz#faf51b9eb74aaef3b3acf4ad5f61abf24cb7b93e"
233 |
234 | type-is@~1.6.15:
235 | version "1.6.15"
236 | resolved "https://registry.yarnpkg.com/type-is/-/type-is-1.6.15.tgz#cab10fb4909e441c82842eafe1ad646c81804410"
237 | dependencies:
238 | media-typer "0.3.0"
239 | mime-types "~2.1.15"
240 |
241 | unpipe@~1.0.0:
242 | version "1.0.0"
243 | resolved "https://registry.yarnpkg.com/unpipe/-/unpipe-1.0.0.tgz#b2bf4ee8514aae6165b4817829d21b2ef49904ec"
244 |
245 | utils-merge@1.0.0:
246 | version "1.0.0"
247 | resolved "https://registry.yarnpkg.com/utils-merge/-/utils-merge-1.0.0.tgz#0294fb922bb9375153541c4f7096231f287c8af8"
248 |
249 | vary@~1.1.1:
250 | version "1.1.1"
251 | resolved "https://registry.yarnpkg.com/vary/-/vary-1.1.1.tgz#67535ebb694c1d52257457984665323f587e8d37"
252 |
--------------------------------------------------------------------------------
/example/index.android.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from "react";
2 | import { AppRegistry, StyleSheet, Text, View } from "react-native";
3 | import RNNode from "react-native-node";
4 |
5 | export default class Example extends Component {
6 | constructor() {
7 | super();
8 | this.state = { msg: "..." };
9 | }
10 |
11 | componentDidMount() {
12 | RNNode.start();
13 | }
14 |
15 | sendRequest() {
16 | fetch("http://localhost:5000").then(res => res.json()).then(json => {
17 | this.setState(json);
18 | });
19 | }
20 |
21 | render() {
22 | return (
23 |
24 |
25 | {this.state.msg}
26 |
27 | this.sendRequest()}>
28 | Tap to make a request
29 |
30 |
31 | );
32 | }
33 | }
34 |
35 | const styles = StyleSheet.create({
36 | container: {
37 | flex: 1,
38 | justifyContent: "center",
39 | alignItems: "center",
40 | backgroundColor: "#F5FCFF"
41 | },
42 | text: {
43 | fontSize: 20,
44 | textAlign: "center",
45 | margin: 10
46 | },
47 | button: {
48 | color: "white",
49 | fontSize: 20,
50 | marginTop: 40,
51 | backgroundColor: "#5c7cfa",
52 | borderRadius: 4,
53 | padding: 8,
54 | textAlign: "center"
55 | }
56 | });
57 |
58 | AppRegistry.registerComponent("Example", () => Example);
59 |
--------------------------------------------------------------------------------
/example/jsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "allowJs": true,
4 | "allowSyntheticDefaultImports": true
5 | },
6 | "exclude": [
7 | "node_modules"
8 | ]
9 | }
--------------------------------------------------------------------------------
/example/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "Example",
3 | "version": "0.0.1",
4 | "private": true,
5 | "scripts": {
6 | "start": "node node_modules/react-native/local-cli/cli.js start",
7 | "build": "cd background && yarn && cd .. && react-native-node insert ./background"
8 | },
9 | "dependencies": {
10 | "react": "16.0.0-alpha.12",
11 | "react-native": "0.48.3",
12 | "react-native-node": "file:../",
13 | "noderify": "3.0.2"
14 | },
15 | "devDependencies": {
16 | "babel-preset-react-native": "2.1.0"
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | const { NativeModules } = require("react-native");
2 |
3 | export const RNNode = {
4 | start(args) {
5 | NativeModules.RNNode.start(Array.isArray(args) ? args : []);
6 | },
7 |
8 | stop() {
9 | NativeModules.RNNode.stop();
10 | }
11 | };
12 |
13 | export default RNNode;
14 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "react-native-node",
3 | "version": "3.3.1",
4 | "description": "Run a separate Node.js process behind a React Native app",
5 | "author": {
6 | "name": "Andre Staltz",
7 | "url": "staltz.com"
8 | },
9 | "repository": {
10 | "type": "git",
11 | "url": "https://github.com/staltz/react-native-node"
12 | },
13 | "license": "MIT",
14 | "keywords": [
15 | "react-native",
16 | "reactnative",
17 | "node",
18 | "nodejs",
19 | "thread",
20 | "process",
21 | "background",
22 | "service"
23 | ],
24 | "main": "index.js",
25 | "bin": {
26 | "react-native-node": "./bin.js"
27 | },
28 | "peerDependencies": {
29 | "react-native": ">=0.47.0"
30 | },
31 | "dependencies": {
32 | "cheerio": "^1.0.0-rc.1",
33 | "mkdirp": "^0.5.1",
34 | "path": "^0.12.7",
35 | "tar": "^3.1.5",
36 | "yargs": "^8.0.2"
37 | },
38 | "devDependencies": {
39 | "babel-eslint": "^4.1.6",
40 | "eslint-plugin-react": "^3.11.3"
41 | }
42 | }
--------------------------------------------------------------------------------
/screenshot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/staltz/react-native-node/63423a5becc55468f4d55258fef9a7aafade0f12/screenshot.png
--------------------------------------------------------------------------------