-
Notifications
You must be signed in to change notification settings - Fork 514
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
186 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import App from './src/App' | ||
|
||
export default App |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
const path = require('path') | ||
const fs = require('fs') | ||
|
||
const TEST_PROJECT_DIR_NAME = '../test_project' | ||
const EXAMPLE_PROJECT_DIR_NAME = '../example' | ||
const REPO_UTILS_DIR_NAME = '../repoUtils' | ||
|
||
const expoAppEntryPath = path.join(__dirname, REPO_UTILS_DIR_NAME, 'expoAppExporter.js') | ||
const expoAppEntryPathDestinationPath = path.join(__dirname, TEST_PROJECT_DIR_NAME, 'App.js') | ||
|
||
const copyExampleProjectExpoAppEntry = () => { | ||
console.info('Deleting expo App entry from test_project') | ||
fs.unlinkSync(expoAppEntryPathDestinationPath) | ||
console.info('Copying expo App entry from repoUtils to test_project') | ||
fs.copyFileSync(expoAppEntryPath, expoAppEntryPathDestinationPath) | ||
} | ||
|
||
const jsSourceDirectory = path.join(__dirname, EXAMPLE_PROJECT_DIR_NAME, 'src') | ||
const jsSourceDestinationDirectory = path.join(__dirname, TEST_PROJECT_DIR_NAME, 'src') | ||
|
||
const copyExampleProjectJsFiles = () => { | ||
console.info('Copying src from example to test_project') | ||
fs.cpSync(jsSourceDirectory, jsSourceDestinationDirectory, { recursive: true }) | ||
} | ||
|
||
const packageJsonPath = path.join(__dirname, EXAMPLE_PROJECT_DIR_NAME, 'package.json') | ||
const packageJsonDestinationPath = path.join(__dirname, TEST_PROJECT_DIR_NAME, 'package.json') | ||
|
||
const addMissingDependencies = () => { | ||
const sourcePackageJson = require(packageJsonPath) | ||
const editedPackageJson = require(packageJsonDestinationPath) | ||
|
||
console.info('Checking for missing dependencies') | ||
const missingDependencies = Object.keys(sourcePackageJson.dependencies).filter( | ||
dependency => !editedPackageJson.dependencies[dependency] | ||
) | ||
const missingDevDependencies = Object.keys(sourcePackageJson.devDependencies).filter( | ||
dependency => !editedPackageJson.devDependencies[dependency] | ||
) | ||
|
||
missingDependencies.forEach(dependency => { | ||
editedPackageJson.dependencies[dependency] = sourcePackageJson.dependencies[dependency] | ||
}) | ||
missingDevDependencies.forEach(dependency => { | ||
editedPackageJson.devDependencies[dependency] = sourcePackageJson.devDependencies[dependency] | ||
}) | ||
|
||
console.info('Writing new package.json to test_project') | ||
fs.writeFileSync(packageJsonDestinationPath, JSON.stringify(editedPackageJson, null, 2) + '\n') | ||
} | ||
|
||
const babelConfigDestinationPath = path.join(__dirname, TEST_PROJECT_DIR_NAME, 'babel.config.js') | ||
const babelConfigSourcePath = path.join(__dirname, EXAMPLE_PROJECT_DIR_NAME, 'babel.config.js') | ||
|
||
const copyBabelConfig = () => { | ||
console.info('Deleting babel.config.js from test_project') | ||
fs.unlinkSync(babelConfigDestinationPath) | ||
console.info('Copying babel.config.js from example to test_project') | ||
fs.copyFileSync(babelConfigSourcePath, babelConfigDestinationPath) | ||
} | ||
|
||
const fixExpoBabelConfig = () => { | ||
const currentData = fs.readFileSync(babelConfigDestinationPath, 'utf-8') | ||
|
||
const updatedData = currentData.replace( | ||
"presets: ['module:metro-react-native-babel-preset']", | ||
"presets: ['babel-preset-expo']" | ||
) | ||
|
||
fs.writeFileSync(babelConfigDestinationPath, updatedData, 'utf-8') | ||
|
||
console.info('Expo babel update complete') | ||
} | ||
|
||
const copyExampleProjectFiles = () => { | ||
copyExampleProjectExpoAppEntry() | ||
copyExampleProjectJsFiles() | ||
copyBabelConfig() | ||
fixExpoBabelConfig() | ||
addMissingDependencies() | ||
} | ||
|
||
copyExampleProjectFiles() |