Skip to content

Commit 3065d12

Browse files
author
徐远翔
committed
feat: React Naitve CLI hooks supporting
1 parent 22fe6ff commit 3065d12

File tree

6 files changed

+62
-3
lines changed

6 files changed

+62
-3
lines changed

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules
22
packages/*/lib
33
types
4+
*.config.js

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
umi 在 RN 中仅用来生成中间代码(临时文件),介于**编码****构建**的之间,旨在引入 umi 的开发姿势来提升 RN 编程体验。
1111

12-
下游可以使用[React Native CLI](https://github.com/react-native-community/cli/blob/master/docs/commands.md#start)来开发和打包,也可以使用像[expo](https://expo.io/)这样的开发工具。
12+
下游可以使用[React Native CLI](https://github.com/react-native-community/cli/blob/master/docs/commands.md#commands)来开发和打包,也可以使用像[expo](https://expo.io/)这样的开发工具。
1313

1414
| NPM 包 | 当前版本 | 简介 |
1515
| --- | --- | --- |
@@ -218,7 +218,7 @@ _上文未列出的[umi 配置](https://umijs.org/config)对 **umi-preset-react-
218218
}
219219
```
220220

221-
先启动 watch 进程监听源码文件变动,重新生成中间代码
221+
启动 watch 进程,监听源码文件变动并重新生成中间代码
222222

223223
```npm
224224
yarn watch
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env node
2+
3+
const { join } = require('path');
4+
const { execFileSync } = require('child_process');
5+
6+
const cwd = process.cwd();
7+
const umi = join(cwd, 'node_modules', 'umi', 'bin', 'umi.js');
8+
9+
const child = execFileSync(umi, ['g', 'rn', '--dev'], { cwd, stdio: 'inherit' });
10+
11+
child.on('close', (code) => {
12+
process.exit(code);
13+
});
14+
15+
process.on('SIGINT', () => {
16+
child.kill('SIGINT');
17+
});
18+
19+
process.on('SIGTERM', () => {
20+
child.kill('SIGTERM');
21+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env node
2+
3+
const { join } = require('path');
4+
const { fork } = require('child_process');
5+
6+
const cwd = process.cwd();
7+
const umi = join(cwd, 'node_modules', 'umi', 'bin', 'umi.js');
8+
9+
const child = fork(umi, ['g', 'rn', '--dev'], { cwd, stdio: 'inherit' });
10+
11+
child.on('close', (code) => {
12+
process.exit(code);
13+
});
14+
15+
process.on('SIGINT', () => {
16+
child.kill('SIGINT');
17+
});
18+
19+
process.on('SIGTERM', () => {
20+
child.kill('SIGTERM');
21+
});

packages/umi-preset-react-native/package.json

+9-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
"lib": "lib"
2121
},
2222
"files": [
23-
"lib"
23+
"lib",
24+
"hooks",
25+
"react-native.config.js"
2426
],
2527
"publishConfig": {
2628
"registry": "https://registry.npmjs.org/"
@@ -45,5 +47,11 @@
4547
"babel-plugin-module-resolver": "^4.0.0",
4648
"memoizerific": "^1.11.3",
4749
"react-router-native": "5.1.2"
50+
},
51+
"rnpm": {
52+
"hooks": {
53+
"prestart": "./hooks/prestart.js",
54+
"prebundle": "./hooks/prebundle.js"
55+
}
4856
}
4957
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
dependency: {
3+
hooks: {
4+
prestart: './hooks/prestart.js',
5+
prebundle: './hooks/prebundle.js',
6+
},
7+
},
8+
};

0 commit comments

Comments
 (0)