|
1 | 1 | #!/usr/bin/env node |
2 | | - |
3 | | -import {join} from 'path'; |
4 | | -import {promisify} from 'util'; |
5 | | -import {exec} from 'child_process'; |
6 | | -import copy from 'recursive-copy'; |
7 | | -import rimraf from 'rimraf'; |
| 2 | +import { join } from 'path' |
| 3 | +import { execSync } from 'child_process' |
| 4 | +import copy from 'recursive-copy' |
| 5 | +import rimraf from 'rimraf' |
8 | 6 |
|
9 | 7 | // Enhances source files inside /app with a fresh RN project template. |
10 | | -(async () => { |
11 | | - const appName = 'MyPluginApp'; |
12 | | - const execute = promisify(exec); |
13 | | - |
14 | | - console.log('Initializing a fresh RN project...'); |
15 | | - console.log('⌛ This might take some time.'); |
16 | | - |
17 | | - // Remove local CLI, as it interferes with the global. |
18 | | - rimraf.sync('node_modules/@react-native-community/cli'); |
19 | | - // Remove existing installation in case it got stuck last time. |
20 | | - rimraf.sync(`app/${appName}`); |
21 | | - |
22 | | - const timer = setTimeout(() => { |
23 | | - // Warning after 5 minutes in case native dependencies missing for CLI. |
24 | | - console.log( |
25 | | - "If it's stuck at this point, try creating a RN project elsewhere with 'npx react-native init TestApp' and follow the instructions there before trying this again.", |
26 | | - ); |
27 | | - }, 300000); |
28 | | - |
29 | | - // Initialize RN project. |
30 | | - await execute(`npx react-native init ${appName}`, { |
31 | | - cwd: 'app', |
32 | | - }); |
33 | | - |
34 | | - clearTimeout(timer); |
35 | | - |
36 | | - // Copy to destination directory, leaving source files untouched. |
37 | | - await copy(`app/${appName}`, 'app', { |
38 | | - dot: true, |
39 | | - overwrite: false, |
40 | | - filter: ['**/*', '!App.js'], |
41 | | - }); |
42 | | - |
43 | | - // Remove temporary project directory. |
44 | | - rimraf.sync(`app/${appName}`); |
45 | | - |
46 | | - // Install this package locally, avoiding symlinks. |
47 | | - await execute('npm install $(npm pack .. | tail -1)', { |
48 | | - cwd: join(__dirname, 'app'), |
49 | | - }); |
50 | | - |
51 | | - console.log(''); |
52 | | - console.log('🍞 React Native App created inside /app.'); |
53 | | - console.log('🛠️ To run the example with the plugin included:'); |
54 | | - console.log('🐚 cd app'); |
55 | | - console.log('🐚 react-native run-ios / react-native run-android'); |
56 | | - console.log('🌪️ To copy over the changes from the plugin source run:'); |
57 | | - console.log('🐚 npm run watch'); |
58 | | - console.log('🛠️ This will copy changes over to the app.'); |
59 | | -})(); |
| 8 | +const appName = 'MyPluginApp' |
| 9 | + |
| 10 | +console.log('⌛ Initializing a fresh RN project...') |
| 11 | + |
| 12 | +execSync(`npx react-native init ${appName}`, { |
| 13 | + // Write output to cnosole. |
| 14 | + stdio: 'inherit', |
| 15 | +}) |
| 16 | + |
| 17 | +// Copy to destination directory, leaving source files untouched. |
| 18 | +await copy(appName, 'app', { |
| 19 | + dot: true, |
| 20 | + overwrite: false, |
| 21 | + filter: ['**/*', '!App.js'], |
| 22 | +}) |
| 23 | + |
| 24 | +// Remove temporary project directory. |
| 25 | +rimraf.sync(appName) |
| 26 | + |
| 27 | +// Install this package locally, avoiding symlinks. |
| 28 | +execSync('npm install $(npm pack .. | tail -1)', { |
| 29 | + cwd: join(process.cwd(), 'app'), |
| 30 | + stdio: 'inherit', |
| 31 | +}) |
| 32 | + |
| 33 | +console.log('') |
| 34 | +console.log('🍞 React Native App created inside /app.') |
| 35 | +console.log('🛠️ To run the example with the plugin included:') |
| 36 | +console.log('🐚 cd app') |
| 37 | +console.log('🐚 react-native run-ios / react-native run-android') |
| 38 | +console.log('🌪️ To copy over the changes from the plugin source run:') |
| 39 | +console.log('🐚 npm run watch') |
| 40 | +console.log('🛠️ This will copy changes over to the app.') |
0 commit comments