Skip to content

Commit 86d1961

Browse files
author
Christopher J. Brody
committed
Merge branch 'dev' of https://github.com/brodybits/create-react-native-module into with-native-section
2 parents 7e8cb06 + 3702de6 commit 86d1961

File tree

57 files changed

+610
-900
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+610
-900
lines changed

README.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,13 @@ This tool based on [`react-native-create-library`](https://www.npmjs.com/package
3434
- [issue #99](https://github.com/brodybits/create-react-native-module/issues/99) - additional `pod install` step needed for RN 0.60 on iOS
3535
- [issue #29](https://github.com/brodybits/create-react-native-module/issues/29) - View does not work with RN 0.60 on Android (quick patch needed)
3636
- React Native 0.60(+) currently not supported by Expo or react-native-windows
37+
- Platform fork support
38+
- tvOS platform support
39+
- requires use of `--tvos-enabled` option as documented below
40+
- requires the [`react-native-tvos`](https://www.npmjs.com/package/react-native-tvos) fork (see discussion in [react-native-community/react-native-tvos#11](https://github.com/react-native-community/react-native-tvos/issues/11))
41+
- unstable with very limited testing, with limited if any active support from the primary maintainer [@brodybits](https://github.com/brodybits) (see [issue #127](https://github.com/brodybits/create-react-native-module/issues/127))
42+
- minimum react-native-tvos version is 0.60 (see [issue #95](https://github.com/brodybits/create-react-native-module/issues/95))
3743
- Out-of-tree platform support
38-
- tvOS platform support - unstable with very limited testing, minimum react-native-tvos version is 0.60 (see [issue #95](https://github.com/brodybits/create-react-native-module/issues/95))
3944
- Windows - unstable (not tested, see [issue #23](https://github.com/brodybits/create-react-native-module/issues/23)); now deprecated and may be removed in the near future (see [issue #43](https://github.com/brodybits/create-react-native-module/issues/43))
4045
- for future consideration: macOS (see [issue #94](https://github.com/brodybits/create-react-native-module/issues/94))
4146
- Node.js pre-10 support is deprecated and will be removed in the near future (see [issue #38](https://github.com/brodybits/create-react-native-module/issues/38))
@@ -94,17 +99,19 @@ Options:
9499
--prefix <prefix> The prefix for the library module (Default: ``)
95100
--module-name <moduleName> The module library package name to be used in package.json. Default: react-native-(name in param-case)
96101
--module-prefix <modulePrefix> The module prefix for the library module, ignored if --module-name is specified (Default: `react-native`)
97-
--package-identifier <packageIdentifier> (Android only!) The package name for the Android module (Default: `com.reactlibrary`)
102+
--package-identifier <packageIdentifier> [Android] The Java package identifier used by the Android module (Default: `com.reactlibrary`)
98103
--platforms <platforms> Platforms the library module will be created for - comma separated (Default: `ios,android`)
104+
--tvos-enabled Generate the module with tvOS build enabled (requires react-native-tvos fork, with minimum version of 0.60, and iOS platform to be enabled)
99105
--github-account <githubAccount> The github account where the library module is hosted (Default: `github_account`)
100106
--author-name <authorName> The author's name (Default: `Your Name`)
101107
--author-email <authorEmail> The author's email (Default: `[email protected]`)
102108
--license <license> The license type (Default: `MIT`)
103109
--view Generate the module as a very simple native view component
104-
--use-cocoapods Generate a library with a sample podspec and third party pod usage example
110+
--use-apple-networking [iOS] Use `AFNetworking` dependency as a sample in the podspec & use it from the iOS code
105111
--generate-example Generate an example project and links the library module to it, requires both react-native-cli and yarn to be installed globally
106112
--example-name <exampleName> Name for the example project (default: `example`)
107113
--example-react-native-version <version> React Native version for the generated example project (default: `[email protected]`)
114+
--write-example-podfile [iOS] EXPERIMENTAL FEATURE NOT SUPPORTED: write (or overwrite) example ios/Podfile
108115
-h, --help output usage information
109116
```
110117

@@ -129,16 +136,18 @@ createLibraryModule({
129136
moduleName: String, /* The module library package name to be used in package.json. Default: react-native-(name in param-case) */
130137
modulePrefix: String, /* The module prefix for the library, ignored if moduleName is specified (Default: react-native) */
131138
platforms: Array | String, /* Platforms the library will be created for. (Default: ['android', 'ios']) */
132-
packageIdentifier: String, /* (Android only!) The package name for the Android module (Default: com.reactlibrary) */
139+
packageIdentifier: String, /* [Android] The Java package identifier used by the Android module (Default: com.reactlibrary) */
140+
tvosEnabled: Boolean, /* Generate the module with tvOS build enabled (requires react-native-tvos fork, with minimum version of 0.60, and iOS platform to be enabled) */
133141
githubAccount: String, /* The github account where the library is hosted (Default: `github_account`) */
134142
authorName: String, /* The author's name (Default: `Your Name`) */
135143
authorEmail: String, /* The author's email (Default: `[email protected]`) */
136144
license: String, /* The license type of this library (Default: `MIT`) */
137-
useCocoapods: Boolean, /* Generate a library with a sample podspec and third party pod usage example (Default: false) */
145+
useAppleNetworking: Boolean, /* [iOS] Use `AFNetworking` dependency as a sample in the podspec & use it from the iOS code (Default: false) */
138146
view: Boolean, /* Generate the module as a very simple native view component (Default: false) */
139147
generateExample: Boolean, /* Generate an example project and links the library module to it, requires both react-native-cli and yarn to be installed globally (Default: false) */
140148
exampleName: String, /* Name for the example project (Default: `example`) */
141149
exampleReactNativeVersion: String, /* React Native version for the generated example project (Default: `[email protected]`) */
150+
writeExamplePodfile: Boolean, /* [iOS] EXPERIMENTAL FEATURE NOT SUPPORTED: write (or overwrite) example ios/Podfile (Default: false) */
142151
}
143152
```
144153

lib/cli-command.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const normalizedOptions = require('./normalized-options');
44

55
const createLibraryModule = require('./lib');
66

7-
const postCreateInstructions = ({ moduleName, useCocoapods, exampleName }) => {
7+
const postCreateInstructions = ({ moduleName, exampleName, writeExamplePodfile }) => {
88
return `
99
====================================================
1010
YOU'RE ALL SET!
@@ -13,11 +13,10 @@ To build and run iOS example project, do:
1313
----
1414
cd ${moduleName}/${exampleName}
1515
yarn
16-
${useCocoapods ? `cd ios
17-
pod install
16+
cd ios
17+
pod install # ${writeExamplePodfile ? `required` : `required starting with React Native 0.60`}
1818
cd ..
19-
`
20-
: ``}react-native run-ios
19+
react-native run-ios
2120
----
2221
`;
2322
};
@@ -69,12 +68,15 @@ ${postCreateInstructions(createOptions)}`);
6968
default: 'react-native',
7069
}, {
7170
command: '--package-identifier [packageIdentifier]',
72-
description: '(Android only!) The package name for the Android module',
71+
description: '[Android] The Java package identifier used by the Android module',
7372
default: 'com.reactlibrary',
7473
}, {
7574
command: '--platforms <platforms>',
7675
description: 'Platforms the library module will be created for - comma separated',
7776
default: 'ios,android',
77+
}, {
78+
command: '--tvos-enabled',
79+
description: 'Generate the module with tvOS build enabled (requires react-native-tvos fork, with minimum version of 0.60, and iOS platform to be enabled)',
7880
}, {
7981
command: '--github-account [githubAccount]',
8082
description: 'The github account where the library module is hosted',
@@ -95,8 +97,8 @@ ${postCreateInstructions(createOptions)}`);
9597
command: '--view',
9698
description: 'Generate the module as a very simple native view component',
9799
}, {
98-
command: '--use-cocoapods',
99-
description: 'Generate a library with a sample podspec and third party pod usage example',
100+
command: '--use-apple-networking',
101+
description: '[iOS] Use `AFNetworking` dependency as a sample in the podspec & use it from the iOS code',
100102
}, {
101103
command: '--generate-example',
102104
description: 'Generate an example project and links the library module to it, requires both react-native-cli and yarn to be installed globally',
@@ -108,5 +110,8 @@ ${postCreateInstructions(createOptions)}`);
108110
command: '--example-react-native-version [exampleReactNativeVersion]',
109111
description: 'React Native version for the generated example project',
110112
default: '[email protected]',
113+
}, {
114+
command: '--write-example-podfile',
115+
description: '[iOS] EXPERIMENTAL FEATURE NOT SUPPORTED: write (or overwrite) example ios/Podfile',
111116
}]
112117
};

lib/lib.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ const DEFAULT_GITHUB_ACCOUNT = 'github_account';
2727
const DEFAULT_AUTHOR_NAME = 'Your Name';
2828
const DEFAULT_AUTHOR_EMAIL = '[email protected]';
2929
const DEFAULT_LICENSE = 'MIT';
30-
const DEFAULT_USE_COCOAPODS = false;
3130
const DEFAULT_GENERATE_EXAMPLE = false;
3231
const DEFAULT_EXAMPLE_NAME = 'example';
3332
const DEFAULT_EXAMPLE_REACT_NATIVE_VERSION = '[email protected]';
@@ -70,15 +69,17 @@ const generateWithNormalizedOptions = ({
7069
packageIdentifier = DEFAULT_PACKAGE_IDENTIFIER,
7170
namespace,
7271
platforms = DEFAULT_PLATFORMS,
72+
tvosEnabled = false,
7373
githubAccount = DEFAULT_GITHUB_ACCOUNT,
7474
authorName = DEFAULT_AUTHOR_NAME,
7575
authorEmail = DEFAULT_AUTHOR_EMAIL,
7676
license = DEFAULT_LICENSE,
7777
view = false,
78-
useCocoapods = DEFAULT_USE_COCOAPODS,
78+
useAppleNetworking = false,
7979
generateExample = DEFAULT_GENERATE_EXAMPLE,
8080
exampleName = DEFAULT_EXAMPLE_NAME,
8181
exampleReactNativeVersion = DEFAULT_EXAMPLE_REACT_NATIVE_VERSION,
82+
writeExamplePodfile = false,
8283
}, {
8384
fs = fsExtra, // (this can be mocked out for testing purposes)
8485
execa = execaDefault, // (this can be mocked out for testing purposes)
@@ -101,14 +102,16 @@ const generateWithNormalizedOptions = ({
101102
modulePrefix: ${modulePrefix}
102103
packageIdentifier: ${packageIdentifier}
103104
platforms: ${platforms}
105+
tvosEnabled: ${tvosEnabled}
104106
githubAccount: ${githubAccount}
105107
authorName: ${authorName}
106108
authorEmail: ${authorEmail}
107109
license: ${license}
108110
view: ${view}
109-
useCocoapods: ${useCocoapods}
111+
useAppleNetworking: ${useAppleNetworking}
110112
generateExample: ${generateExample}
111113
exampleName: ${exampleName}
114+
writeExamplePodfile: ${writeExamplePodfile}
112115
`);
113116

114117
// QUICK LOCAL INJECTION overwite of existing execSync / commandSync call from
@@ -158,12 +161,13 @@ const generateWithNormalizedOptions = ({
158161
packageIdentifier,
159162
namespace,
160163
platforms,
164+
tvosEnabled,
161165
githubAccount,
162166
authorName,
163167
authorEmail,
164168
license,
165169
view,
166-
useCocoapods,
170+
useAppleNetworking,
167171
generateExample,
168172
exampleName,
169173
};
@@ -200,8 +204,9 @@ const generateWithNormalizedOptions = ({
200204
name: className,
201205
moduleName,
202206
view,
203-
useCocoapods,
207+
useAppleNetworking,
204208
exampleName,
209+
writeExamplePodfile,
205210
};
206211

207212
return Promise.all(

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "create-react-native-module",
3-
"version": "0.11.1-dev",
3+
"version": "0.11.2-dev",
44
"description": "Tool to create a React Native library module or view module with a single command",
55
"bin": "bin/cli.js",
66
"main": "lib/lib.js",
@@ -55,10 +55,10 @@
5555
"@stryker-mutator/html-reporter": "^2.1.0",
5656
"@stryker-mutator/javascript-mutator": "^2.1.0",
5757
"@stryker-mutator/jest-runner": "^2.1.0",
58-
"eslint": "^6.3.0",
58+
"eslint": "^6.4.0",
5959
"eslint-config-standard": "^14.1.0",
6060
"eslint-plugin-import": "^2.18.2",
61-
"eslint-plugin-node": "^9.2.0",
61+
"eslint-plugin-node": "^10.0.0",
6262
"eslint-plugin-promise": "^4.2.1",
6363
"eslint-plugin-standard": "^4.0.1",
6464
"jest": "^24.9.0",

stryker.conf.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module.exports = config => {
22
config.set({
33
mutator: 'javascript',
4+
mutate: ['lib/**/*.js', 'templates/**/*.js'],
45
packageManager: 'yarn',
56
reporters: ['html', 'clear-text', 'progress'],
67
testRunner: 'jest',

templates/example.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,13 @@ module.exports = [{
114114
})();
115115
`
116116
}, {
117-
name: ({ useCocoapods, exampleName }) =>
118-
useCocoapods ? `${exampleName}/ios/Podfile` : undefined,
117+
name: ({ exampleName, writeExamplePodfile }) =>
118+
writeExamplePodfile ? `${exampleName}/ios/Podfile` : undefined,
119119
content: ({ moduleName, exampleName }) => `platform :ios, '10.0'
120120
121121
target '${exampleName}' do
122122
rn_path = '../node_modules/react-native'
123-
123+
124124
pod 'yoga', path: "#{rn_path}/ReactCommon/yoga/yoga.podspec"
125125
pod 'DoubleConversion', :podspec => "#{rn_path}/third-party-podspecs/DoubleConversion.podspec"
126126
pod 'Folly', :podspec => "#{rn_path}/third-party-podspecs/Folly.podspec"
@@ -144,7 +144,7 @@ module.exports = [{
144144
'RCTGeolocation',
145145
'DevSupport'
146146
]
147-
147+
148148
pod '${moduleName}', :path => '../../${moduleName}.podspec'
149149
end
150150
`,

templates/general.js

Lines changed: 3 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,7 @@
11
module.exports = [{
22
name: () => 'README.md',
3-
content: ({ moduleName, packageIdentifier, name, namespace, platforms }) => {
4-
let manualInstallation = '';
5-
6-
if (platforms.indexOf('ios') >= 0) {
7-
manualInstallation += `
8-
#### iOS
9-
10-
1. In XCode, in the project navigator, right click \`Libraries\` ➜ \`Add Files to [your project's name]\`
11-
2. Go to \`node_modules\` ➜ \`${moduleName}\` and add \`${name}.xcodeproj\`
12-
3. In XCode, in the project navigator, select your project. Add \`lib${name}.a\` to your project's \`Build Phases\` ➜ \`Link Binary With Libraries\`
13-
4. Run your project (\`Cmd+R\`)<
14-
`;
15-
}
16-
17-
if (platforms.indexOf('android') >= 0) {
18-
manualInstallation += `
19-
#### Android
20-
21-
1. Open up \`android/app/src/main/java/[...]/MainApplication.java\`
22-
- Add \`import ${packageIdentifier}.${name}Package;\` to the imports at the top of the file
23-
- Add \`new ${name}Package()\` to the list returned by the \`getPackages()\` method
24-
2. Append the following lines to \`android/settings.gradle\`:
25-
\`\`\`
26-
include ':${moduleName}'
27-
project(':${moduleName}').projectDir = new File(rootProject.projectDir, '../node_modules/${moduleName}/android')
28-
\`\`\`
29-
3. Insert the following lines inside the dependencies block in \`android/app/build.gradle\`:
30-
\`\`\`
31-
compile project(':${moduleName}')
32-
\`\`\`
33-
`;
34-
}
35-
36-
if (platforms.indexOf('windows') >= 0) {
37-
manualInstallation += `
38-
#### Windows
39-
[Read it! :D](https://github.com/ReactWindows/react-native)
40-
41-
1. In Visual Studio add the \`${name}.sln\` in \`node_modules/${moduleName}/windows/${name}.sln\` folder to their solution, reference from their app.
42-
2. Open up your \`MainPage.cs\` app
43-
- Add \`using ${namespace}.${name};\` to the usings at the top of the file
44-
- Add \`new ${name}Package()\` to the \`List<IReactPackage>\` returned by the \`Packages\` method
45-
`;
46-
}
47-
48-
return `# ${moduleName}
3+
content: ({ moduleName, name }) =>
4+
`# ${moduleName}
495
506
## Getting started
517
@@ -55,19 +11,14 @@ module.exports = [{
5511
5612
\`$ react-native link ${moduleName}\`
5713
58-
### Manual installation
59-
60-
${manualInstallation}
61-
6214
## Usage
6315
\`\`\`javascript
6416
import ${name} from '${moduleName}';
6517
6618
// TODO: What to do with the module?
6719
${name};
6820
\`\`\`
69-
`;
70-
},
21+
`,
7122
}, {
7223
name: () => 'package.json',
7324
content: ({ moduleName, packageIdentifier, platforms, githubAccount, authorName, authorEmail, license }) => {

templates/ios.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module.exports = platform => [{
22
name: ({ moduleName }) => `${moduleName}.podspec`,
3-
content: ({ moduleName, githubAccount, authorName, authorEmail, useCocoapods }) => `require "json"
3+
content: ({ moduleName, tvosEnabled, githubAccount, authorName, authorEmail, useAppleNetworking }) => `require "json"
44
55
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
66
@@ -15,14 +15,14 @@ Pod::Spec.new do |s|
1515
s.license = "MIT"
1616
# s.license = { :type => "MIT", :file => "FILE_LICENSE" }
1717
s.authors = { "${authorName}" => "${authorEmail}" }
18-
s.platforms = { :ios => "9.0", :tvos => "10.0" }
18+
s.platforms = { :ios => "9.0"${tvosEnabled ? `, :tvos => "10.0"` : ``} }
1919
s.source = { :git => "https://github.com/${githubAccount}/${moduleName}.git", :tag => "#{s.version}" }
2020
2121
s.source_files = "ios/**/*.{h,m,swift}"
2222
s.requires_arc = true
2323
2424
s.dependency "React"
25-
${useCocoapods ? `s.dependency 'AFNetworking', '~> 3.0'` : ``}
25+
${useAppleNetworking ? `s.dependency 'AFNetworking', '~> 3.0'` : ``}
2626
# s.dependency "..."
2727
end
2828
@@ -39,9 +39,9 @@ end
3939
}, {
4040
// implementation of module without view:
4141
name: ({ name, view }) => !view && `${platform}/${name}.m`,
42-
content: ({ name, useCocoapods }) => `#import "${name}.h"
42+
content: ({ name, useAppleNetworking }) => `#import "${name}.h"
4343
44-
${useCocoapods ? `#import <AFNetworking/AFNetworking.h>
44+
${useAppleNetworking ? `#import <AFNetworking/AFNetworking.h>
4545
` : ``}
4646
@implementation ${name}
4747
@@ -50,7 +50,7 @@ RCT_EXPORT_MODULE()
5050
RCT_EXPORT_METHOD(sampleMethod:(NSString *)stringArgument numberParameter:(nonnull NSNumber *)numberArgument callback:(RCTResponseSenderBlock)callback)
5151
{
5252
// TODO: Implement some actually useful functionality
53-
${useCocoapods
53+
${useAppleNetworking
5454
? `AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
5555
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/plain"];
5656
[manager GET:@"https://httpstat.us/200" parameters:nil progress:nil success:^(NSURLSessionTask *task, id responseObject) {

0 commit comments

Comments
 (0)