Skip to content

Commit f04f573

Browse files
committed
feat: initial implementation
1 parent 36d1ef6 commit f04f573

File tree

15 files changed

+5448
-33
lines changed

15 files changed

+5448
-33
lines changed

.babelrc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"presets": [
3+
["@babel/preset-env", {
4+
"targets": {
5+
"node": "8"
6+
}
7+
}],
8+
"@babel/preset-typescript"
9+
]
10+
}

.gitignore

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
### OS Junk ###
2+
.DS_Store
3+
*~
4+
5+
### Node ###
6+
# Logs
7+
logs
8+
*.log
9+
npm-debug.log*
10+
yarn-debug.log*
11+
yarn-error.log*
12+
13+
# Runtime data
14+
pids
15+
*.pid
16+
*.seed
17+
*.pid.lock
18+
19+
# Directory for instrumented libs generated by jscoverage/JSCover
20+
lib-cov
21+
22+
# Coverage directory used by tools like istanbul
23+
coverage
24+
25+
# nyc test coverage
26+
.nyc_output
27+
28+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
29+
.grunt
30+
31+
# Bower dependency directory (https://bower.io/)
32+
bower_components
33+
34+
# node-waf configuration
35+
.lock-wscript
36+
37+
# Compiled binary addons (http://nodejs.org/api/addons.html)
38+
build/Release
39+
40+
# Dependency directories
41+
node_modules/
42+
jspm_packages/
43+
44+
# Typescript v1 declaration files
45+
typings/
46+
47+
# Optional npm cache directory
48+
.npm
49+
50+
# Optional eslint cache
51+
.eslintcache
52+
53+
# Optional REPL history
54+
.node_repl_history
55+
56+
# Output of 'npm pack'
57+
*.tgz
58+
59+
# Yarn Integrity file
60+
.yarn-integrity
61+
62+
# dotenv environment variables file
63+
.env
64+
65+
# generated files
66+
lib/

LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2017 React Native Community
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 48 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ The CLI can build code for following targets:
1515

1616
Metro handles compiling source code for React Native libraries, but it's possible to use them in other targets such as web. Currently, to handle this, we need to have multiple babel configs and write a long `babel-cli` command in our `package.json`. We also need to keep the configs in sync between our projects.
1717

18-
Just as an example, this is a command we have in one of the packages: `babel --extensions '.js,.ts,.tsx' --no-babelrc --config-file=./babel.config.publish.js src --ignore '**/__tests__/**' --copy-files --source-maps --delete-dir-on-start --out-dir dist && del-cli 'dist/**/__tests__' && yarn tsc --emitDeclarationOnly`. This isn't all, there's even a separate `babel.config.publish.js` file. And this only works for webpack and Metro, and will fail on Node due to ESM usage.
18+
Just as an example, this is a command we have in one of the packages: `babel --extensions '.js,.ts,.tsx' --no-babelrc --config-file=./babel.config.publish.js src --ignore '**/__tests__/**' --copy-files --source-maps --delete-dir-on-start --out-dir dist && del-cli 'dist/**/__tests__' && yarn tsc --emitDeclarationOnly`. This isn't all, there's even a separate `babel.config.publish.js` file. And this only works for webpack and Metro, and will fail on Node due to ESM usage.
1919

2020
Bob wraps tools such as `babel-cli` and simplifies these common tasks across multiple projects. It's tailored specifically to React Native projects to minimize the configuration required.
2121

@@ -29,39 +29,56 @@ yarn add --dev @react-native-community/bob
2929

3030
## Usage
3131

32-
In your `package.json`, specify the targets to build for:
32+
To configure your project to use Bob, open a Terminal and run `yarn bob init` for automatic configuration.
3333

34-
```json
35-
"@react-native-community/bob": {
36-
"targets": [
37-
"commonjs",
38-
"module",
39-
"typescript"
40-
]
41-
}
42-
```
34+
To configure your project manually, follow these steps:
4335

44-
Then add `bob` to your `prepare` step:
36+
1. In your `package.json`, specify the targets to build for:
4537

46-
```js
47-
"scripts": {
48-
"prepare": "bob build"
49-
}
50-
```
38+
```json
39+
"@react-native-community/bob": {
40+
"source": "src",
41+
"output": "lib",
42+
"targets": [
43+
["commonjs", {"flow": true}],
44+
"module"
45+
]
46+
}
47+
```
5148

52-
And finally, configure the appropriate entry points:
53-
54-
```json
55-
"main": "commonjs/index.js",
56-
"module": "module/index.js",
57-
"react-native": "src/index.js",
58-
"types": "typescript/index.d.ts",
59-
"files": [
60-
"commonjs/",
61-
"module/",
62-
"src/",
63-
"typescript/"
64-
]
65-
```
49+
1. Add `bob` to your `prepare` step:
50+
51+
```js
52+
"scripts": {
53+
"prepare": "bob build"
54+
}
55+
```
56+
57+
1. Configure the appropriate entry points:
58+
59+
```json
60+
"main": "lib/commonjs/index.js",
61+
"module": "lib/module/index.js",
62+
"react-native": "src/index.js",
63+
"files": [
64+
"lib/",
65+
"src/"
66+
]
67+
```
68+
69+
1. Add the output directory to `.gitignore`
70+
71+
```gitignore
72+
# generated files by bob
73+
lib/
74+
```
6675

6776
And we're done 🎉
77+
78+
## TODO
79+
80+
- TypeScript support
81+
82+
## LICENSE
83+
84+
MIT

bin/bob.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env node
2+
3+
require('../lib/cli');

package.json

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,49 @@
22
"name": "@react-native-community/bob",
33
"version": "0.1.0",
44
"description": "CLI to build JavaScript files for React Native libraries",
5-
"main": "src/index.js",
65
"repository": "git@github.com:react-native-community/bob.git",
76
"author": "Satyajit Sahoo <satyajit.happy@gmail.com>",
8-
"license": "MIT"
7+
"license": "MIT",
8+
"main": "src/index.js",
9+
"bin": {
10+
"bob": "bin/bob.js"
11+
},
12+
"files": [
13+
"bin",
14+
"lib"
15+
],
16+
"scripts": {
17+
"typescript": "tsc --noEmit",
18+
"build": "babel --extensions .ts,.tsx src --out-dir lib --ignore '**/__tests__/**' --source-maps --delete-dir-on-start",
19+
"watch": "yarn build --watch",
20+
"prepare": "yarn build"
21+
},
22+
"dependencies": {
23+
"@babel/core": "^7.4.0",
24+
"chalk": "^2.4.2",
25+
"cosmiconfig": "^5.2.0",
26+
"fs-extra": "^7.0.1",
27+
"glob": "^7.1.3",
28+
"inquirer": "^6.2.2",
29+
"is-git-dirty": "^1.0.0",
30+
"metro-react-native-babel-preset": "^0.53.1",
31+
"ora": "^3.3.0",
32+
"yargs": "^13.2.2"
33+
},
34+
"devDependencies": {
35+
"@babel/cli": "^7.2.3",
36+
"@babel/preset-env": "^7.4.2",
37+
"@babel/preset-typescript": "^7.3.3",
38+
"@types/babel__core": "^7.1.0",
39+
"@types/chalk": "^2.2.0",
40+
"@types/cosmiconfig": "^5.0.3",
41+
"@types/fs-extra": "^5.0.5",
42+
"@types/glob": "^7.1.1",
43+
"@types/inquirer": "^6.0.0",
44+
"@types/ora": "^3.2.0",
45+
"@types/yargs": "^12.0.11",
46+
"conventional-changelog-cli": "^2.0.12",
47+
"release-it": "^10.4.0",
48+
"typescript": "^3.4.1"
49+
}
950
}

0 commit comments

Comments
 (0)