Skip to content

Commit ae505ef

Browse files
committed
feat(typescript): use TypeScript as plugin source code
Also automate release and generally improve and overhaul the setup. release-npm BREAKING CHANGE: source code switches from JavaScript (with Flow) to TypeScript
1 parent 6442467 commit ae505ef

File tree

19 files changed

+223
-265
lines changed

19 files changed

+223
-265
lines changed

.github/workflows/push.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: push
2+
3+
on:
4+
push:
5+
branches: [main]
6+
7+
jobs:
8+
test-release:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v3
12+
- uses: tobua/release-npm-action@v1
13+
with:
14+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

CHANGELOG.md

Lines changed: 0 additions & 53 deletions
This file was deleted.

README.md

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
# create-react-native-plugin
22

3-
<img align="right" src="https://github.com/tobua/create-react-native-plugin/raw/master/logo.png" width="20%" alt="Create React Native Plugin" />
3+
<img align="right" src="https://github.com/tobua/create-react-native-plugin/raw/main/logo.png" width="20%" alt="Create React Native Plugin" />
44

5-
Starting point for creating React Native plugins without native code.
5+
Starting point for creating React Native plugins in TypeScript without native code.
66

7-
- Setup demo app with plugin
8-
- Watch plugin source for changes
7+
- Bundle plugin in TypeScript with esbuild
8+
- Setup demo app with plugin installed
9+
- Watch plugin for changes
910

1011
## Usage
1112

@@ -17,7 +18,7 @@ npx create-react-native-plugin react-native-my-plugin
1718

1819
This will bootstrap a new plugin inside a folder named `react-native-my-plugin` accordingly. Inside that folder the commands mentioned hereafter are available. The prefix `react-native-` is optional and will be removed where the React Native context is implied.
1920

20-
Start working on your plugin by editing `src/index.js` which will be the entry point for the plugin.
21+
Start working on your plugin by editing `index.tsx` which will be the entry point for the plugin.
2122

2223
## App
2324

@@ -33,7 +34,7 @@ This will create an app inside `/app` where except `/app/App.js` all files are g
3334
npm run watch
3435
```
3536

36-
Running the above will watch the plugin `/src/` folder for any kind of changes and copy them over to the app which will then automatically hot-reload.
37+
Running the above will watch the plugin source code for any kind of changes, rebuild and copy over the changes to the app which will then automatically hot-reload.
3738

3839
Don't forget to always check your plugin both on Android and iOS even though your not using native code the provided components might still differ depending on the platform.
3940

@@ -43,11 +44,12 @@ The template is configured to work with Jest out of the box. All non-native func
4344

4445
```
4546
npm test
47+
npm run test:watch # Keep watching and retesting on changes.
4648
```
4749

48-
## Types
50+
## TypeScript
4951

50-
Since React Native will usually run in a modern JavaScript engine there is no need to transpile your source code and apps can directly use the plugin source code. The Flow type checker is the default type system for react native and the source code is writting in flow. While TypeScript is the more popular type checker overall flow is more popular in the React Native ecosystem and can be used out of the box. Therefore this package will only support flow.
52+
Flow the type checker native to React Native has largely failed to gain popularity and also lags behind TypeScript in many other important aspects. Since a good chunk of bigger React Native projects are written in TypeScript plugins should provide type definitions.
5153

5254
## Troubleshooting
5355

@@ -57,6 +59,8 @@ If you have issues building the app for iOS try the following
5759
- Update Cocoapods with `sudo gem install cocoapods`
5860
- Update Pod dependencies in `app/ios` folder with `pod update`
5961

62+
To avoid bundling additional dependencies with `esbuild` mark them as `--external` in the `npm run build` script.
63+
6064
## Examples
6165

6266
The following plugins have been created with create-react-native-plugin as a starting point.
@@ -65,5 +69,11 @@ The following plugins have been created with create-react-native-plugin as a sta
6569
JS-only navigation for React Native.
6670
- [React Native Cols](https://github.com/tobua/react-native-cols)
6771
Grid for React Native.
68-
- [React Native Indicate](https://github.com/tobua/indicate/tree/master/plugins/react-native)
72+
- [React Native Indicate](https://github.com/tobua/react-native-indicate)
6973
Scroll indicator for views with overflow.
74+
- [Naxos](https://github.com/tobua/naxos)
75+
UI Library.
76+
77+
<p align="center">
78+
<img src="https://github.com/tobua/create-react-native-plugin/raw/main/app.png" alt="Plugin running in Preview App" width="250">
79+
</p>

app.png

466 KB
Loading

customize.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ import { readFileSync, writeFileSync } from 'fs'
33

44
const files = [
55
'app/App.js',
6-
'src/index.js',
7-
'test/basic.test.js',
8-
'test/docs.test.js',
9-
'.flowconfig',
6+
'test/basic.test.tsx',
7+
'test/docs.test.tsx',
8+
'babel.config.json',
109
'create-app.js',
10+
'index.tsx',
1111
'package.json',
1212
'README.md',
13+
'tsconfig.json',
1314
]
1415

1516
// Replace template values with plugin name.

index.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ if (args.length < 3) {
1616
const name = names(args[2])
1717

1818
if (existsSync(name.regular)) {
19-
console.warn(
20-
`A folder or file named ${name.regular} already exists in ${process.cwd()}.`
21-
)
19+
console.warn(`A folder or file named ${name.regular} already exists in ${process.cwd()}.`)
2220
process.exit()
2321
}
2422

@@ -49,12 +47,8 @@ execSync('npm install --legacy-peer-deps', {
4947
})
5048

5149
console.log('')
52-
console.log(
53-
`😃 Created new plugin called ${name.regular} in ${destinationDirectory}.`
54-
)
55-
console.log(`🛠️ Start coding in the file src/index.js.`)
56-
console.log(
57-
`🛠️ To preview the plugin edit app/App.js and create a RN installation with:`
58-
)
50+
console.log(`😃 Created new plugin called ${name.regular} in ${destinationDirectory}.`)
51+
console.log(`🛠️ Start coding in the file ./index.tsx.`)
52+
console.log(`🛠️ To preview the plugin edit app/App.js and create a RN installation with:`)
5953
console.log(`🐚 cd ${name.regular}`)
6054
console.log('🐚 npm run app')

package.json

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "create-react-native-plugin",
33
"description": "Template for creating React Native plugins without native code.",
4-
"version": "1.1.5",
4+
"version": "0.0.0-development",
55
"repository": "github:tobua/create-react-native-plugin",
66
"license": "MIT",
77
"author": "Matthias Giger",
@@ -10,28 +10,23 @@
1010
},
1111
"dependencies": {
1212
"change-case": "4.1.2",
13-
"fs-extra": "10.0.0"
13+
"fs-extra": "10.1.0"
1414
},
1515
"type": "module",
16-
"main": "index.js",
17-
"exports": {
18-
"default": "./index.js"
19-
},
20-
"sideEffects": true,
2116
"bin": "index.js",
2217
"source": "index.js",
2318
"files": [
2419
"template",
2520
"template/.gitignore",
26-
"**/*.js"
21+
"*.js"
2722
],
2823
"keywords": [
2924
"react-native",
3025
"plugin",
3126
"template"
3227
],
3328
"devDependencies": {
34-
"padua": "^0.3.9"
29+
"padua": "^0.5.6"
3530
},
3631
"prettier": "padua/configuration/.prettierrc.json",
3732
"eslintConfig": {
@@ -42,8 +37,5 @@
4237
"ignorePackages"
4338
]
4439
}
45-
},
46-
"engines": {
47-
"node": ">= 14"
4840
}
4941
}

template/.flowconfig

Lines changed: 0 additions & 76 deletions
This file was deleted.

template/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
node_modules
22
# package-lock.json has no effect when publishing your plugin to npm.
33
package-lock.json
4+
dist
45
app/**/*
56
!app/App.js

template/README.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ npm i <%= name %>
1313
```jsx
1414
import React from 'react'
1515
import { Text } from 'react-native'
16-
import <%= pascal %> from '<%= name %>'
16+
import { <%= pascal %> } from '<%= name %>'
1717

1818
export () =>
1919
<<%= pascal %>>
@@ -23,20 +23,19 @@ export () =>
2323

2424
## Development
2525

26-
### Tests
26+
### Build
2727

28-
Tests configured for React Native can be run as follows
28+
Run a single build with `npm run build` and find the output in `/dist`.
2929

30-
```
31-
npm test
32-
```
30+
### Tests
31+
32+
Tests configured for React Native can be run with `npm test` or `npm run test:watch` in watch mode.
3333

3434
### Preview App
3535

3636
To test your plugin on a device run the following to create a React Native app using it.
3737

3838
```
39-
npm install
4039
npm run app
4140
cd app
4241
react-native run-ios / react-native run-android

0 commit comments

Comments
 (0)