-
Notifications
You must be signed in to change notification settings - Fork 516
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'chore/Update-package-dependencies' of https://github.co…
…m/dotintent/react-native-ble-plx into chore/Update-package-dependencies
- Loading branch information
Showing
7 changed files
with
255 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
name: Setup | ||
description: Setup Node.js and install dependencies | ||
inputs: | ||
REACT_NATIVE_VERSION: | ||
description: React Native version to use | ||
required: false | ||
|
||
runs: | ||
using: composite | ||
steps: | ||
- name: Setup Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version-file: .nvmrc | ||
|
||
- name: Initialize project template | ||
run: npx react-native@latest init BlePlxExample --version ${{ inputs.REACT_NATIVE_VERSION }} --directory test_project --skip-install --verbose | ||
shell: bash | ||
|
||
- name: Cache dependencies | ||
id: yarn-cache | ||
uses: actions/cache@v3 | ||
with: | ||
path: | | ||
**/node_modules | ||
key: ${{ runner.os }}-${{ inputs.REACT_NATIVE_VERSION }}-yarn-${{ hashFiles('**/yarn.lock') }}-${{ hashFiles('**/package.json') }} | ||
restore-keys: | | ||
${{ runner.os }}-${{ inputs.REACT_NATIVE_VERSION }}-yarn-${{ hashFiles('**/yarn.lock') }} | ||
${{ runner.os }}-${{ inputs.REACT_NATIVE_VERSION }}-yarn- | ||
- name: Copy project files | ||
run: node ./scripts/copyExampleProjectFiles.js | ||
shell: bash | ||
|
||
- name: Install dependencies | ||
if: steps.yarn-cache.outputs.cache-hit != 'true' | ||
run: | | ||
yarn install --cwd test_project | ||
yarn install | ||
shell: bash |
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 |
---|---|---|
|
@@ -59,3 +59,5 @@ buck-out/ | |
|
||
# Bundle artifact | ||
*.jsbundle | ||
/lib | ||
/test_project |
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 |
---|---|---|
@@ -1 +1 @@ | ||
v18 | ||
v16 |
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,151 @@ | ||
const path = require('path') | ||
const fs = require('fs') | ||
|
||
const TEST_PROJECT_DIR_NAME = '../test_project' | ||
const EXAMPLE_PROJECT_DIR_NAME = '../example' | ||
|
||
const indexJsPath = path.join(__dirname, EXAMPLE_PROJECT_DIR_NAME, 'index.js') | ||
const indexJsDestinationPath = path.join(__dirname, TEST_PROJECT_DIR_NAME, 'index.js') | ||
|
||
const copyExampleProjectIndexJs = () => { | ||
console.info('Deleting index.js from test_project') | ||
fs.unlinkSync(indexJsDestinationPath) | ||
console.info('Copying index.js from example to test_project') | ||
fs.copyFileSync(indexJsPath, indexJsDestinationPath) | ||
} | ||
|
||
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 androidManifestPath = path.join( | ||
__dirname, | ||
EXAMPLE_PROJECT_DIR_NAME, | ||
'android', | ||
'app', | ||
'src', | ||
'main', | ||
'AndroidManifest.xml' | ||
) | ||
const androidManifestDestinationPath = path.join( | ||
__dirname, | ||
TEST_PROJECT_DIR_NAME, | ||
'android', | ||
'app', | ||
'src', | ||
'main', | ||
'AndroidManifest.xml' | ||
) | ||
const manifestPermissions = [ | ||
`<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />`, | ||
`<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />`, | ||
`<uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30" />`, | ||
`<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:maxSdkVersion="30" />`, | ||
`<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />` | ||
] | ||
|
||
const addAndroidManifestPermissions = () => { | ||
const destinationAndroidManifestLines = fs.readFileSync(androidManifestDestinationPath, 'utf8').split('\n') | ||
const indexOfManifestTagEndLine = destinationAndroidManifestLines.findIndex(line => line.includes('>')) | ||
|
||
console.info('Adding permissions to AndroidManifest.xml') | ||
const joinedPermissions = manifestPermissions.join('\n') | ||
destinationAndroidManifestLines.splice(indexOfManifestTagEndLine + 1, 0, joinedPermissions) | ||
|
||
console.info('Writing new AndroidManifest.xml to test_project') | ||
fs.writeFileSync(androidManifestDestinationPath, destinationAndroidManifestLines.join('\n')) | ||
} | ||
|
||
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 metroDestinationPath = path.join(__dirname, TEST_PROJECT_DIR_NAME, 'metro.config.js') | ||
const metroSourcePath = path.join(__dirname, EXAMPLE_PROJECT_DIR_NAME, 'metro.config.js') | ||
|
||
const copyMetroConfig = () => { | ||
console.info('Deleting metro.config.js from test_project') | ||
fs.unlinkSync(metroDestinationPath) | ||
console.info('Copying metro.config.js from example to test_project') | ||
fs.copyFileSync(metroSourcePath, metroDestinationPath) | ||
} | ||
|
||
const reactNativeDestinationPath = path.join(__dirname, TEST_PROJECT_DIR_NAME, 'react-native.config.js') | ||
const reactNativeSourcePath = path.join(__dirname, EXAMPLE_PROJECT_DIR_NAME, 'react-native.config.js') | ||
|
||
const copyReactNativeConfig = () => { | ||
const doesDestinationFileExist = fs.existsSync(reactNativeDestinationPath) | ||
|
||
if (doesDestinationFileExist) { | ||
console.info('Deleting react-native.config.js from test_project') | ||
fs.unlinkSync(reactNativeDestinationPath) | ||
} | ||
|
||
console.info('Copying react-native.config.js from example to test_project') | ||
fs.copyFileSync(reactNativeSourcePath, reactNativeDestinationPath) | ||
} | ||
|
||
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 changePackageJsonName = () => { | ||
const packageJson = require(packageJsonDestinationPath) | ||
|
||
packageJson.name = 'test_project' | ||
fs.writeFileSync(packageJsonDestinationPath, JSON.stringify(packageJson, null, 2) + '\n') | ||
} | ||
|
||
const setMinSdkVersion = () => { | ||
const gradlePath = path.join(__dirname, TEST_PROJECT_DIR_NAME, 'android', 'app', 'build.gradle') | ||
const gradleLines = fs.readFileSync(gradlePath, 'utf8').split('\n') | ||
const indexOfManifestTagEndLine = gradleLines.findIndex(line => line.includes('minSdkVersion')) | ||
gradleLines[indexOfManifestTagEndLine] = 'minSdkVersion 23' | ||
fs.writeFileSync(gradlePath, gradleLines.join('\n')) | ||
} | ||
|
||
const copyExampleProjectFiles = () => { | ||
copyExampleProjectIndexJs() | ||
copyExampleProjectJsFiles() | ||
addAndroidManifestPermissions() | ||
addMissingDependencies() | ||
copyMetroConfig() | ||
copyReactNativeConfig() | ||
copyBabelConfig() | ||
changePackageJsonName() | ||
setMinSdkVersion() | ||
} | ||
|
||
copyExampleProjectFiles() |
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