Skip to content

Commit 6d0be48

Browse files
committed
refactor: minor tweaks
1 parent 6a5ecd4 commit 6d0be48

File tree

6 files changed

+20
-31
lines changed

6 files changed

+20
-31
lines changed

src/create.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const BINARIES = /(gradlew|\.(jar|keystore|png|jpg|gif))$/;
1414

1515
const COMMON_FILES = path.resolve(__dirname, '../templates/common');
1616
const NATIVE_FILES = path.resolve(__dirname, '../templates/native-library');
17+
const JS_FILES = path.resolve(__dirname, '../templates/js-library');
1718
const EXPO_FILES = path.resolve(__dirname, '../templates/expo-library');
1819
const CPP_FILES = path.resolve(__dirname, '../templates/cpp-library');
1920
const OBJC_FILES = path.resolve(__dirname, '../templates/objc-library');
@@ -170,12 +171,12 @@ export default async function create(argv: yargs.Arguments<any>) {
170171
{ name: 'Native module in Kotlin and Swift', value: 'native-swift' },
171172
{ name: 'Native module with C++ code', value: 'cpp' },
172173
{
173-
name: 'JavaScript module with Web support using Expo',
174-
value: 'expo',
174+
name: 'JavaScript module with native example',
175+
value: 'js',
175176
},
176177
{
177-
name: 'JavaScript module',
178-
value: 'js',
178+
name: 'JavaScript module with Web support using Expo',
179+
value: 'expo',
179180
},
180181
],
181182
default: 'native',
@@ -227,7 +228,7 @@ export default async function create(argv: yargs.Arguments<any>) {
227228
native: type === 'native' || type === 'cpp' || 'native-swift',
228229
cpp: type === 'cpp',
229230
swift: type === 'native-swift',
230-
type,
231+
module: type !== 'js',
231232
},
232233
author: {
233234
name: authorName,
@@ -263,19 +264,18 @@ export default async function create(argv: yargs.Arguments<any>) {
263264
await copyDir(COMMON_FILES, folder);
264265

265266
if (type === 'expo') {
267+
await copyDir(JS_FILES, folder);
266268
await copyDir(EXPO_FILES, folder);
269+
} else if (type === 'js') {
270+
await copyDir(JS_FILES, folder);
271+
await copyDir(
272+
path.join(EXPO_FILES, 'example'),
273+
path.join(folder, 'example')
274+
);
267275
} else {
268276
await copyDir(NATIVE_FILES, folder);
269277

270-
if (type === 'js') {
271-
await Promise.all(
272-
[
273-
`android`,
274-
`ios`,
275-
`${options.project.podspec}.podspec`,
276-
].map((file) => fs.remove(path.join(folder, file)))
277-
);
278-
} else if (type === 'cpp') {
278+
if (type === 'cpp') {
279279
await copyDir(CPP_FILES, folder);
280280
} else if (type === 'native-swift') {
281281
await copyDir(SWIFT_FILES, folder);

templates/native-library/example/android/app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ dependencies {
209209
implementation jscFlavor
210210
}
211211

212-
<% if (project.type !== 'js') { -%>
212+
<% if (project.module) { -%>
213213
implementation project(':<%= project.package %>')
214214
<% } -%>
215215
}

templates/native-library/example/android/settings.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ rootProject.name = '<%= project.name %>Example'
22
apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
33
include ':app'
44

5-
<% if (project.type !== 'js') { -%>
5+
<% if (project.module) { -%>
66
include ':<%= project.package %>'
77
project(':<%= project.package %>').projectDir = new File(rootProject.projectDir, '../../android')
8-
<% } -%>
8+
<% } -%>

templates/native-library/example/ios/Podfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ target '<%= project.name %>Example' do
5353
pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec'
5454
pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'
5555

56-
<% if (project.type !== 'js') { -%>
56+
<% if (project.module) { -%>
5757
pod '<%= project.podspec %>', :path => '../..'
5858
<% } -%>
5959
6060
use_native_modules!
61-
61+
6262
# Enables Flipper.
6363
#
6464
# Note that if you have use_frameworks! enabled, Flipper will not work and
Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,9 @@
1-
<% if (project.type !== 'js') { -%>
21
import { NativeModules } from 'react-native';
3-
<% } -%>
2+
43
type <%= project.name %>Type = {
54
multiply(a: number, b: number): Promise<number>;
65
};
76

8-
<% if (project.type === 'js') { -%>
9-
const multiply = (a: number, b: number) => {
10-
return Promise.resolve(a * b);
11-
}
12-
13-
export default {
14-
multiply
15-
} as <%= project.name %>Type;
16-
<% } else { -%>
177
const { <%= project.name %> } = NativeModules;
188

199
export default <%= project.name %> as <%= project.name %>Type;
20-
<% } -%>

0 commit comments

Comments
 (0)