Skip to content

Commit 3702de6

Browse files
author
Chris Brody
authored
replace --use-cocoapods with 2 options (#167)
replace --use-cocoapods with --use-apple-networking & --write-example-podfile extra example ios/Podfile is now behind its own experimental option flag, with a couple of trailing tabs removed update the final CLI log message to always include instructions to do pod install, with a comment depending on use of --write-example-podfile or not and with an outdated DEFAULT constant removed, as it is not really needed and with CLI error logging test snapshot updated (due to the effect on the stack trace)
1 parent 1f78dc4 commit 3702de6

File tree

20 files changed

+91
-45
lines changed

20 files changed

+91
-45
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,11 @@ Options:
107107
--author-email <authorEmail> The author's email (Default: `[email protected]`)
108108
--license <license> The license type (Default: `MIT`)
109109
--view Generate the module as a very simple native view component
110-
--use-cocoapods [iOS] EXPERIMENTAL FEATURE NOT SUPPORTED: Use `AFNetworking` dependency as a sample in the podspec; use it from the iOS code & add `ios/Podfile` to generated example
110+
--use-apple-networking [iOS] Use `AFNetworking` dependency as a sample in the podspec & use it from the iOS code
111111
--generate-example Generate an example project and links the library module to it, requires both react-native-cli and yarn to be installed globally
112112
--example-name <exampleName> Name for the example project (default: `example`)
113113
--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
114115
-h, --help output usage information
115116
```
116117

@@ -141,11 +142,12 @@ createLibraryModule({
141142
authorName: String, /* The author's name (Default: `Your Name`) */
142143
authorEmail: String, /* The author's email (Default: `[email protected]`) */
143144
license: String, /* The license type of this library (Default: `MIT`) */
144-
useCocoapods: Boolean, /* [iOS] EXPERIMENTAL FEATURE NOT SUPPORTED: Use `AFNetworking` dependency as a sample in the podspec; use it from the iOS code & add `ios/Podfile` to generated example (Default: false) */
145+
useAppleNetworking: Boolean, /* [iOS] Use `AFNetworking` dependency as a sample in the podspec & use it from the iOS code (Default: false) */
145146
view: Boolean, /* Generate the module as a very simple native view component (Default: false) */
146147
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) */
147148
exampleName: String, /* Name for the example project (Default: `example`) */
148149
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) */
149151
}
150152
```
151153

lib/cli-command.js

Lines changed: 9 additions & 7 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
};
@@ -98,8 +97,8 @@ ${postCreateInstructions(createOptions)}`);
9897
command: '--view',
9998
description: 'Generate the module as a very simple native view component',
10099
}, {
101-
command: '--use-cocoapods',
102-
description: '[iOS] EXPERIMENTAL FEATURE NOT SUPPORTED: Use `AFNetworking` dependency as a sample in the podspec; use it from the iOS code & add `ios/Podfile` to generated example',
100+
command: '--use-apple-networking',
101+
description: '[iOS] Use `AFNetworking` dependency as a sample in the podspec & use it from the iOS code',
103102
}, {
104103
command: '--generate-example',
105104
description: 'Generate an example project and links the library module to it, requires both react-native-cli and yarn to be installed globally',
@@ -111,5 +110,8 @@ ${postCreateInstructions(createOptions)}`);
111110
command: '--example-react-native-version [exampleReactNativeVersion]',
112111
description: 'React Native version for the generated example project',
113112
default: '[email protected]',
113+
}, {
114+
command: '--write-example-podfile',
115+
description: '[iOS] EXPERIMENTAL FEATURE NOT SUPPORTED: write (or overwrite) example ios/Podfile',
114116
}]
115117
};

lib/lib.js

Lines changed: 7 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]';
@@ -76,10 +75,11 @@ const generateWithNormalizedOptions = ({
7675
authorEmail = DEFAULT_AUTHOR_EMAIL,
7776
license = DEFAULT_LICENSE,
7877
view = false,
79-
useCocoapods = DEFAULT_USE_COCOAPODS,
78+
useAppleNetworking = false,
8079
generateExample = DEFAULT_GENERATE_EXAMPLE,
8180
exampleName = DEFAULT_EXAMPLE_NAME,
8281
exampleReactNativeVersion = DEFAULT_EXAMPLE_REACT_NATIVE_VERSION,
82+
writeExamplePodfile = false,
8383
}, {
8484
fs = fsExtra, // (this can be mocked out for testing purposes)
8585
execa = execaDefault, // (this can be mocked out for testing purposes)
@@ -108,9 +108,10 @@ const generateWithNormalizedOptions = ({
108108
authorEmail: ${authorEmail}
109109
license: ${license}
110110
view: ${view}
111-
useCocoapods: ${useCocoapods}
111+
useAppleNetworking: ${useAppleNetworking}
112112
generateExample: ${generateExample}
113113
exampleName: ${exampleName}
114+
writeExamplePodfile: ${writeExamplePodfile}
114115
`);
115116

116117
// QUICK LOCAL INJECTION overwite of existing execSync / commandSync call from
@@ -166,7 +167,7 @@ const generateWithNormalizedOptions = ({
166167
authorEmail,
167168
license,
168169
view,
169-
useCocoapods,
170+
useAppleNetworking,
170171
generateExample,
171172
exampleName,
172173
};
@@ -203,8 +204,9 @@ const generateWithNormalizedOptions = ({
203204
name: className,
204205
moduleName,
205206
view,
206-
useCocoapods,
207+
useAppleNetworking,
207208
exampleName,
209+
writeExamplePodfile,
208210
};
209211

210212
return Promise.all(

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/ios.js

Lines changed: 5 additions & 5 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, tvosEnabled, 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
@@ -22,7 +22,7 @@ Pod::Spec.new do |s|
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) {

tests/integration/cli/help/__snapshots__/cli-help.test.js.snap

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ Options:
1818
--author-email [authorEmail] The author's email (default: \\"[email protected]\\")
1919
--license [license] The license type (default: \\"MIT\\")
2020
--view Generate the module as a very simple native view component
21-
--use-cocoapods [iOS] EXPERIMENTAL FEATURE NOT SUPPORTED: Use \`AFNetworking\` dependency as a sample in the podspec; use it from the iOS code & add \`ios/Podfile\` to generated example
21+
--use-apple-networking [iOS] Use \`AFNetworking\` dependency as a sample in the podspec & use it from the iOS code
2222
--generate-example Generate an example project and links the library module to it, requires both react-native-cli and yarn to be installed globally
2323
--example-name [exampleName] Name for the example project (default: \\"example\\")
2424
--example-react-native-version [exampleReactNativeVersion] React Native version for the generated example project (default: \\"[email protected]\\")
25+
--write-example-podfile [iOS] EXPERIMENTAL FEATURE NOT SUPPORTED: write (or overwrite) example ios/Podfile
2526
-h, --help output usage information"
2627
`;

tests/integration/cli/noargs/__snapshots__/cli-noargs.test.js.snap

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ Options:
1818
--author-email [authorEmail] The author's email (default: \\"[email protected]\\")
1919
--license [license] The license type (default: \\"MIT\\")
2020
--view Generate the module as a very simple native view component
21-
--use-cocoapods [iOS] EXPERIMENTAL FEATURE NOT SUPPORTED: Use \`AFNetworking\` dependency as a sample in the podspec; use it from the iOS code & add \`ios/Podfile\` to generated example
21+
--use-apple-networking [iOS] Use \`AFNetworking\` dependency as a sample in the podspec & use it from the iOS code
2222
--generate-example Generate an example project and links the library module to it, requires both react-native-cli and yarn to be installed globally
2323
--example-name [exampleName] Name for the example project (default: \\"example\\")
2424
--example-react-native-version [exampleReactNativeVersion] React Native version for the generated example project (default: \\"[email protected]\\")
25+
--write-example-podfile [iOS] EXPERIMENTAL FEATURE NOT SUPPORTED: write (or overwrite) example ios/Podfile
2526
-h, --help output usage information"
2627
`;

tests/with-injection/cli/command/object/__snapshots__/lib-cli-command-object-text.test.js.snap

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ Object {
5959
"description": "Generate the module as a very simple native view component",
6060
},
6161
Object {
62-
"command": "--use-cocoapods",
63-
"description": "[iOS] EXPERIMENTAL FEATURE NOT SUPPORTED: Use \`AFNetworking\` dependency as a sample in the podspec; use it from the iOS code & add \`ios/Podfile\` to generated example",
62+
"command": "--use-apple-networking",
63+
"description": "[iOS] Use \`AFNetworking\` dependency as a sample in the podspec & use it from the iOS code",
6464
},
6565
Object {
6666
"command": "--generate-example",
@@ -76,6 +76,10 @@ Object {
7676
"default": "[email protected]",
7777
"description": "React Native version for the generated example project",
7878
},
79+
Object {
80+
"command": "--write-example-podfile",
81+
"description": "[iOS] EXPERIMENTAL FEATURE NOT SUPPORTED: write (or overwrite) example ios/Podfile",
82+
},
7983
],
8084
"usage": "[options] <name>",
8185
}

tests/with-injection/create/with-example/with-options/__snapshots__/create-with-example-with-options.test.js.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,7 @@ platform :ios, '10.0'
902902
903903
target 'test-demo' do
904904
rn_path = '../node_modules/react-native'
905-
905+
906906
pod 'yoga', path: \\"#{rn_path}/ReactCommon/yoga/yoga.podspec\\"
907907
pod 'DoubleConversion', :podspec => \\"#{rn_path}/third-party-podspecs/DoubleConversion.podspec\\"
908908
pod 'Folly', :podspec => \\"#{rn_path}/third-party-podspecs/Folly.podspec\\"
@@ -926,7 +926,7 @@ platform :ios, '10.0'
926926
'RCTGeolocation',
927927
'DevSupport'
928928
]
929-
929+
930930
pod 'react-native-alice-bobbi', :path => '../../react-native-alice-bobbi.podspec'
931931
end
932932

tests/with-injection/create/with-example/with-options/create-with-example-with-options.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ test('create alice-bobbi module with example, with config options', () => {
1717
generateExample: true,
1818
exampleName: 'test-demo',
1919
exampleReactNativeVersion: '[email protected]',
20-
useCocoapods: true
20+
useAppleNetworking: true,
21+
writeExamplePodfile: true,
2122
};
2223

2324
return lib(options, inject)

0 commit comments

Comments
 (0)