()
| 182 | // multiple test or sample apps in the future. |
| 183 | const generateExampleApp = |
| 184 | () => { |
| 185 | info(`CREATE example app with the following template: ${exampleReactNativeTemplate}`); |
| 186 | |
| 187 | // resolve **absolute** module & example paths before |
| 188 | // react-native-init-func function call |
| 189 | // which may affect the process cwd state |
| 190 | // (absolute paths seem to be needed for the steps below function properly) |
| 191 | const modulePath = path.resolve('.', packageName); |
| 192 | const pathExampleApp = path.join(modulePath, exampleName); |
| 193 | const exampleAppSubdirectory = path.join('.', packageName, exampleName); |
| 194 | |
| 195 | // (with the work done in a promise chain) |
| 196 | return Promise.resolve() |
| 197 | .then(() => { |
| 198 | return reactNativeInit([exampleName], { |
| 199 | template: exampleReactNativeTemplate, |
| 200 | directory: exampleAppSubdirectory |
| 201 | }); |
| 202 | }) |
| 203 | .then(() => { |
| 204 | // Render the example template |
| 205 | const templateArgs = { |
| 206 | packageName, |
| 207 | objectClassName, |
| 208 | isView, |
| 209 | useAppleNetworking, |
| 210 | exampleFileLinkage, |
| 211 | exampleName, |
| 212 | writeExamplePodfile, |
| 213 | }; |
| 214 | |
| 215 | return Promise.all( |
| 216 | exampleTemplates.map((template) => { |
| 217 | return renderTemplateIfValid(fs, modulePath, template, templateArgs); |
| 218 | }) |
| 219 | ); |
| 220 | }) |
| 221 | .then(() => { |
| 222 | // Adds and link the new library |
| 223 | return new Promise((resolve) => { |
| 224 | // postinstall workaround script *only* needed in case |
| 225 | // the DEPRECATED --example-file-linkage option |
| 226 | // (exampleFileLinkage: true) is used |
| 227 | // (not needed otherwise): |
| 228 | if (exampleFileLinkage) { |
| 229 | info('Adding the cleanup postinstall *workaround* task to the example app'); |
| 230 | npmAddScriptSync(`${pathExampleApp}/package.json`, { |
| 231 | key: 'postinstall', |
| 232 | value: `node ../scripts/examples_postinstall.js` |
| 233 | }, fs); |
| 234 | } |
| 235 | |
| 236 | // Add and link the new library |
| 237 | info('Linking the new module library to the example app'); |
| 238 | const addLinkLibraryCommand = exampleFileLinkage |
| 239 | ? 'yarn add file:../' |
| 240 | : 'yarn add link:../'; |
| 241 | const addLinkLibraryOptions = { cwd: pathExampleApp, stdio: 'inherit' }; |
no test coverage detected