Skip to content

Commit 6a5ecd4

Browse files
gorhomsatya164
andauthored
feat: add JS module option (#51)
Co-authored-by: Satyajit Sahoo <[email protected]>
1 parent 0b45cde commit 6a5ecd4

File tree

5 files changed

+34
-4
lines changed

5 files changed

+34
-4
lines changed

src/create.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ type Answers = {
3535
authorEmail: string;
3636
authorUrl: string;
3737
repoUrl: string;
38-
type: 'native' | 'native-swift' | 'cpp' | 'expo';
38+
type: 'native' | 'native-swift' | 'js' | 'cpp' | 'expo';
3939
};
4040

4141
export const args: Record<ArgName, yargs.Options> = {
@@ -65,7 +65,7 @@ export const args: Record<ArgName, yargs.Options> = {
6565
},
6666
'type': {
6767
description: 'Type package do you want to develop',
68-
choices: ['native', 'native-swift', 'cpp', 'expo'],
68+
choices: ['native', 'native-swift', 'js', 'cpp', 'expo'],
6969
},
7070
};
7171

@@ -173,6 +173,10 @@ export default async function create(argv: yargs.Arguments<any>) {
173173
name: 'JavaScript module with Web support using Expo',
174174
value: 'expo',
175175
},
176+
{
177+
name: 'JavaScript module',
178+
value: 'js',
179+
},
176180
],
177181
default: 'native',
178182
},
@@ -223,6 +227,7 @@ export default async function create(argv: yargs.Arguments<any>) {
223227
native: type === 'native' || type === 'cpp' || 'native-swift',
224228
cpp: type === 'cpp',
225229
swift: type === 'native-swift',
230+
type,
226231
},
227232
author: {
228233
name: authorName,
@@ -262,7 +267,15 @@ export default async function create(argv: yargs.Arguments<any>) {
262267
} else {
263268
await copyDir(NATIVE_FILES, folder);
264269

265-
if (type === 'cpp') {
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') {
266279
await copyDir(CPP_FILES, folder);
267280
} else if (type === 'native-swift') {
268281
await copyDir(SWIFT_FILES, folder);

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,9 @@ dependencies {
209209
implementation jscFlavor
210210
}
211211

212+
<% if (project.type !== 'js') { -%>
212213
implementation project(':<%= project.package %>')
214+
<% } -%>
213215
}
214216

215217
// Run this once to be able to run the application with BUCK

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +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') { -%>
56
include ':<%= project.package %>'
67
project(':<%= project.package %>').projectDir = new File(rootProject.projectDir, '../../android')
8+
<% } -%>

templates/native-library/example/ios/Podfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ 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') { -%>
5657
pod '<%= project.podspec %>', :path => '../..'
58+
<% } -%>
5759
5860
use_native_modules!
5961
Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
1+
<% if (project.type !== 'js') { -%>
12
import { NativeModules } from 'react-native';
2-
3+
<% } -%>
34
type <%= project.name %>Type = {
45
multiply(a: number, b: number): Promise<number>;
56
};
67

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 { -%>
717
const { <%= project.name %> } = NativeModules;
818

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

0 commit comments

Comments
 (0)