-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from rnpm/feature/support-0.18
Support react-native 0.18+
- Loading branch information
Showing
20 changed files
with
528 additions
and
56 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const path = require('path'); | ||
const semver = require('semver'); | ||
|
||
module.exports = function getPrefix(config) { | ||
const rnpkg = require( | ||
path.join(config.folder, 'node_modules', 'react-native', 'package.json') | ||
); | ||
|
||
var prefix = 'patches/0.18'; | ||
|
||
if (semver.lt(rnpkg.version, '0.18.0')) { | ||
prefix = 'patches/0.17'; | ||
} | ||
|
||
return prefix; | ||
}; |
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,27 @@ | ||
const append = (scope, pattern, patch) => | ||
scope.replace(pattern, `${pattern}\n${patch}`); | ||
|
||
module.exports = function makeMainActivityPatch(config) { | ||
const importPattern = `import android.app.Activity;`; | ||
const packagePattern = `.addPackage(new MainReactPackage())`; | ||
|
||
/** | ||
* Make a MainActivity.java program patcher | ||
* @param {String} importPath Import path, e.g. com.oblador.vectoricons.VectorIconsPackage; | ||
* @param {String} instance Code to instance a package, e.g. new VectorIconsPackage(); | ||
* @return {Function} Patcher function | ||
*/ | ||
return function applyMainActivityPatch(content) { | ||
const patched = append( | ||
content, | ||
importPattern, | ||
config.packageImportPath | ||
); | ||
|
||
return append( | ||
patched, | ||
packagePattern, | ||
` .addPackage(${config.packageInstance})` | ||
); | ||
}; | ||
}; |
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,27 @@ | ||
const append = (scope, pattern, patch) => | ||
scope.replace(pattern, `${pattern}${patch}`); | ||
|
||
module.exports = function makeMainActivityPatch(config) { | ||
const importPattern = 'import com.facebook.react.ReactActivity;'; | ||
const packagePattern = 'new MainReactPackage()'; | ||
|
||
/** | ||
* Make a MainActivity.java program patcher | ||
* @param {String} importPath Import path, e.g. com.oblador.vectoricons.VectorIconsPackage; | ||
* @param {String} instance Code to instance a package, e.g. new VectorIconsPackage(); | ||
* @return {Function} Patcher function | ||
*/ | ||
return function applyMainActivityPatch(content) { | ||
const patched = append( | ||
content, | ||
importPattern, | ||
'\n' + config.packageImportPath | ||
); | ||
|
||
return append( | ||
patched, | ||
packagePattern, | ||
',\n ' + config.packageInstance | ||
); | ||
}; | ||
}; |
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,13 @@ | ||
module.exports = function makeBuildPatch(name) { | ||
/** | ||
* Replace pattern by patch in the passed content | ||
* @param {String} content Content of the build.gradle file | ||
* @return {String} Patched content of build.gradle | ||
*/ | ||
return function applyBuildPatch(content) { | ||
const pattern = `dependencies {`; | ||
const patch = ` compile project(':${name}')`; | ||
|
||
return content.replace(pattern, `${pattern}\n${patch}`); | ||
}; | ||
}; |
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,22 @@ | ||
const path = require('path'); | ||
|
||
module.exports = function makeSettingsPatch(name, dependencyConfig, projectConfig) { | ||
const relative = path.relative( | ||
projectConfig.sourceDir, | ||
dependencyConfig.sourceDir | ||
); | ||
|
||
/** | ||
* Replace pattern by patch in the passed content | ||
* @param {String} content Content of the Settings.gradle file | ||
* @return {String} Patched content of Settings.gradle | ||
*/ | ||
return function applySettingsPatch(content) { | ||
const pattern = `include ':app'`; | ||
const patch = `include ':${name}'\n` + | ||
`project(':${name}').projectDir = ` + | ||
`new File(rootProject.projectDir, '${relative}')`; | ||
|
||
return content.replace(pattern, `${pattern}\n${patch}`); | ||
}; | ||
}; |
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,31 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const chai = require('chai'); | ||
const expect = chai.expect; | ||
const makeMainActivityPatch = require( | ||
'../../../../src/android/patches/0.17/makeMainActivityPatch' | ||
); | ||
|
||
const config = { | ||
packageInstance: 'new VectorIconsPackage()', | ||
packageImportPath: 'import com.oblador.vectoricons.VectorIconsPackage;', | ||
}; | ||
const mainActivityPatch = fs.readFileSync( | ||
path.join(process.cwd(), 'test/fixtures/android/0.17/MainActivity.java'), | ||
'utf-8' | ||
); | ||
const patchedMainActivity = fs.readFileSync( | ||
path.join(process.cwd(), 'test/fixtures/android/0.17/patchedMainActivity.java'), | ||
'utf-8' | ||
); | ||
|
||
describe('[email protected]', () => { | ||
it('should build a patch function', () => { | ||
expect(makeMainActivityPatch(config)).to.be.a('function'); | ||
}); | ||
|
||
it('should make a correct patch', () => { | ||
const patch = makeMainActivityPatch(config); | ||
expect(patch(mainActivityPatch)).to.be.equal(patchedMainActivity); | ||
}); | ||
}); |
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,31 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const chai = require('chai'); | ||
const expect = chai.expect; | ||
const makeMainActivityPatch = require( | ||
'../../../../src/android/patches/0.18/makeMainActivityPatch' | ||
); | ||
|
||
const config = { | ||
packageInstance: 'new VectorIconsPackage()', | ||
packageImportPath: 'import com.oblador.vectoricons.VectorIconsPackage;', | ||
}; | ||
const mainActivityPatch = fs.readFileSync( | ||
path.join(process.cwd(), 'test/fixtures/android/0.18/MainActivity.java'), | ||
'utf-8' | ||
); | ||
const patchedMainActivity = fs.readFileSync( | ||
path.join(process.cwd(), 'test/fixtures/android/0.18/patchedMainActivity.java'), | ||
'utf-8' | ||
); | ||
|
||
describe('[email protected]', () => { | ||
it('should build a patch function', () => { | ||
expect(makeMainActivityPatch(config)).to.be.a('function'); | ||
}); | ||
|
||
it('should make a correct patch', () => { | ||
const patch = makeMainActivityPatch(config); | ||
expect(patch(mainActivityPatch)).to.be.equal(patchedMainActivity); | ||
}); | ||
}); |
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,26 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const chai = require('chai'); | ||
const expect = chai.expect; | ||
const makeBuildPatch = require('../../../src/android/patches/makeBuildPatch'); | ||
|
||
const name = 'test'; | ||
const buildGradle = fs.readFileSync( | ||
path.join(process.cwd(), 'test/fixtures/android/build.gradle'), | ||
'utf-8' | ||
); | ||
const patchedBuildGradle = fs.readFileSync( | ||
path.join(process.cwd(), 'test/fixtures/android/patchedBuild.gradle'), | ||
'utf-8' | ||
); | ||
|
||
describe('makeBuildPatch', () => { | ||
it('should build a patch function', () => { | ||
expect(makeBuildPatch(name)).to.be.a('function'); | ||
}); | ||
|
||
it('should make a correct patch', () => { | ||
const patch = makeBuildPatch('test'); | ||
expect(patch(buildGradle)).to.be.equal(patchedBuildGradle); | ||
}); | ||
}); |
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,30 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const chai = require('chai'); | ||
const expect = chai.expect; | ||
const makeSettingsPatch = require('../../../src/android/patches/makeSettingsPatch'); | ||
|
||
const name = 'test'; | ||
const projectConfig = { sourceDir: '.' }; | ||
const dependencyConfig = { sourceDir: `../node_modules/${name}/android` }; | ||
const settingsGradle = fs.readFileSync( | ||
path.join(process.cwd(), 'test/fixtures/android/settings.gradle'), | ||
'utf-8' | ||
); | ||
const patchedSettingsGradle = fs.readFileSync( | ||
path.join(process.cwd(), 'test/fixtures/android/patchedSettings.gradle'), | ||
'utf-8' | ||
); | ||
|
||
describe('makeSettingsPatch', () => { | ||
it('should build a patch function', () => { | ||
expect( | ||
makeSettingsPatch(name, dependencyConfig, projectConfig) | ||
).to.be.a('function'); | ||
}); | ||
|
||
it('should make a correct patch', () => { | ||
const patch = makeSettingsPatch('test', dependencyConfig, projectConfig); | ||
expect(patch(settingsGradle)).to.be.equal(patchedSettingsGradle); | ||
}); | ||
}); |
Oops, something went wrong.