-
Notifications
You must be signed in to change notification settings - Fork 0
/
boilerplate.js
120 lines (102 loc) · 3.64 KB
/
boilerplate.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/**
* This file provides an `install` function that should install React Native,
* copy over any folders and template files, and install any desired plugins.
*
* It's a simpler version of the one found in https://github.com/infinitered/ignite-ir-boilerplate.
* Refer to that one to see a more full featured example of what you can do.
*
*/
const REACT_NATIVE_VERSION = '0.47.2'
/**
* Let's install.
*
* @param {any} context - The gluegun context. Docs: https://infinitered.github.io/gluegun/#/context-api.md
*/
async function install (context) {
const APP_PATH = process.cwd()
const PLUGIN_PATH = __dirname
const {
filesystem,
parameters,
ignite,
reactNative,
print,
system
} = context
const name = parameters.third
const spinner = print
.spin(`using the ${print.colors.cyan('ssscassio')} boilerplate`)
.succeed()
// attempt to install React Native or die trying
// this will also chdir into the new directory
const rnInstall = await reactNative.install({ name, version: REACT_NATIVE_VERSION })
if (rnInstall.exitCode > 0) { process.exit(rnInstall.exitCode) }
// copy our App & Tests directories
spinner.text = '▸ copying files'
spinner.start()
filesystem.copy(`${PLUGIN_PATH}/boilerplate/app`, `${APP_PATH}/app`, {
overwrite: true
})
spinner.stop()
// generate some templates
spinner.text = '▸ generating files'
spinner.start()
const templates = [
{ template: 'index.js.ejs', target: 'index.ios.js' },
{ template: 'index.js.ejs', target: 'index.android.js' },
{ template: 'ignite/ignite.json', target: 'ignite/ignite.json' }
]
await ignite.copyBatch(context, templates, { name: name }, {
quiet: true,
directory: `${PLUGIN_PATH}/boilerplate`
})
spinner.stop()
// run npm install
spinner.text = '▸ installing ignite dependencies'
spinner.start()
await system.run('npm i')
spinner.stop()
// react native link -- must use spawn & stdio: ignore or it hangs!! :(
spinner.text = `▸ linking native libraries`
spinner.start()
await system.spawn('react-native link', { stdio: 'ignore' })
spinner.stop()
//Add Expo
// install an NPM module
await ignite.addModule('@expo/ex-navigation', { link: false, version: '^3.1.0' })
await ignite.addModule('babel-preset-react-native-stage-0', { link: false, version: '^1.0.1' })
const babelrcString =
`{
"presets": ["react-native-stage-0/decorator-support"]
}`;
filesystem.write(`.babelrc`, babelrcString);
// install any plugins, including ourselves if we have generators.
// please note you should always do `stdio: 'inherit'` or it'll hang
try {
// pass along the debug flag if we're running in that mode
const debugFlag = parameters.options.debug ? '--debug' : ''
await system.spawn(`ignite add ${__dirname} ${debugFlag}`, { stdio: 'inherit' })
// example of another plugin you could install
// await system.spawn(`ignite add i18n ${debugFlag}`, { stdio: 'inherit' })
} catch (e) {
ignite.log(e)
throw e
}
// initialize git
const gitExists = await filesystem.exists('.git')
if (!gitExists && !parameters.options['skip-git'] && system.which('git')) {
spinner.text = 'setting up git'
spinner.start()
await system.run('git init . && git add . && git commit -m "Initial commit."')
spinner.succeed()
}
// Wrap it up with our success message.
print.info('')
print.info('🍽 Installed!')
print.info('')
print.info(print.colors.yellow(` cd ${name}`))
print.info(print.colors.yellow(' react-native run-ios'))
print.info(print.colors.yellow(' react-native run-android'))
print.info('')
}
module.exports = { install }