-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(buildNumber): store or change build number in config.xml
closes #18
- Loading branch information
Showing
15 changed files
with
261 additions
and
10 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 |
---|---|---|
@@ -1,7 +1,9 @@ | ||
'use strict'; | ||
|
||
import setVersion from './set-version'; | ||
import setBuildNumber from './set-build-number'; | ||
|
||
export default { | ||
setVersion | ||
setVersion, | ||
setBuildNumber | ||
}; |
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,23 @@ | ||
'use strict'; | ||
|
||
import fs from 'mz/fs'; | ||
import xml2js from 'xml2js-es6-promise'; | ||
import { Builder } from 'xml2js'; | ||
|
||
const xmlBuilder = new Builder(); | ||
|
||
function setBuildNumber(configPath, buildNumber) { | ||
return fs.readFile(configPath, { encoding: 'UTF-8' }) | ||
.then((xmlString) => xml2js(xmlString)) | ||
.then((xml) => writeBuildNumber(configPath, buildNumber, xml)); | ||
} | ||
|
||
function writeBuildNumber(configPath, buildNumber, xml) { | ||
xml.widget.$['android-versionCode'] = buildNumber; | ||
xml.widget.$['ios-CFBundleVersion'] = buildNumber; | ||
xml.widget.$['osx-CFBundleVersion'] = buildNumber; | ||
let newConfigData = xmlBuilder.buildObject(xml); | ||
return fs.writeFile(configPath, newConfigData, { encoding: 'UTF-8' }); | ||
} | ||
|
||
export default setBuildNumber; |
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,93 @@ | ||
'use strict'; | ||
|
||
import chai from 'chai'; | ||
import chaiAsPromised from 'chai-as-promised'; | ||
import fs from 'fs-promise'; | ||
|
||
import cordovaSetVersion from '../src/index'; | ||
|
||
const fileParams = { encoding: 'UTF-8' }; | ||
const configPaths = { | ||
COPY: './config.xml', | ||
GOOD: './set-build-number/configs/config.good.xml', | ||
WITHOUT: './set-build-number/configs/config.good.xml', | ||
MALFORMED: './set-build-number/configs/config.malformed.xml', | ||
MISSING: './set-build-number/configs/config.missing.xml', | ||
EXPECTED: './set-build-number/configs/config.expected.xml' | ||
}; | ||
|
||
chai.use(chaiAsPromised); | ||
chai.should(); | ||
|
||
describe('setBuildNumber', () => { | ||
before(() => { | ||
process.chdir(__dirname); | ||
}); | ||
|
||
it('should exist', () => { | ||
cordovaSetVersion.should.have.property('setBuildNumber'); | ||
}); | ||
|
||
it('should be a function', () => { | ||
let type = typeof cordovaSetVersion.setBuildNumber; | ||
type.should.equal('function'); | ||
}); | ||
|
||
it('should replace existing build number attribute values', () => { | ||
fs.copySync(configPaths.GOOD, configPaths.COPY); | ||
|
||
let promise = cordovaSetVersion.setBuildNumber(configPaths.COPY, 24) | ||
.then(() => fs.readFile(configPaths.COPY, fileParams)); | ||
|
||
let expectedConfig = fs.readFileSync(configPaths.EXPECTED, fileParams); | ||
|
||
return promise.should.be.fulfilled | ||
.then((result) => { | ||
result.should.equal(expectedConfig); | ||
}); | ||
}); | ||
|
||
|
||
it('should create build number attributes, when missing', () => { | ||
fs.copySync(configPaths.WITHOUT, configPaths.COPY); | ||
|
||
let promise = cordovaSetVersion.setBuildNumber(configPaths.COPY, 24) | ||
.then(() => fs.readFile(configPaths.COPY, fileParams)); | ||
|
||
let expectedConfig = fs.readFileSync(configPaths.EXPECTED, fileParams); | ||
|
||
return promise.should.be.fulfilled | ||
.then((result) => { | ||
result.should.equal(expectedConfig); | ||
}); | ||
}); | ||
|
||
it('should return an error about missing config.xml file', () => { | ||
let promise = cordovaSetVersion.setBuildNumber(configPaths.MISSING, '1.0.0') | ||
.then(() => fs.readFile(configPaths.COPY, fileParams)); | ||
|
||
return promise.should.be.rejected | ||
.then((error) => { | ||
error.should.be.instanceOf(Error); | ||
error.should.have.property('message'); | ||
error.message.should.contain('no such file or directory'); | ||
error.message.should.contain(configPaths.MISSING); | ||
}); | ||
}); | ||
|
||
it('should return an error about bad config.xml file', () => { | ||
let promise = cordovaSetVersion.setVersion(configPaths.MALFORMED, '1.0.0') | ||
|
||
return promise.should.be.rejected | ||
.then((error) => { | ||
error.should.be.instanceOf(Error); | ||
error.message.should.not.contain('no such file or directory'); | ||
}); | ||
}); | ||
|
||
afterEach(function () { | ||
if (fs.existsSync(configPaths.COPY)) { | ||
fs.removeSync(configPaths.COPY); | ||
} | ||
}); | ||
}); |
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,39 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
<widget id="com.ionicframework.ionic2" version="0.0.0" android-versionCode="24" ios-CFBundleVersion="24" osx-CFBundleVersion="24" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0"> | ||
<name>ionic2-rc6</name> | ||
<description>An awesome Ionic/Cordova app.</description> | ||
<author email="hi@ionicframework" href="http://ionicframework.com/">Ionic Framework Team</author> | ||
<content src="index.html"/> | ||
<access origin="*"/> | ||
<allow-navigation href="http://ionic.local/*"/> | ||
<allow-intent href="http://*/*"/> | ||
<allow-intent href="https://*/*"/> | ||
<allow-intent href="tel:*"/> | ||
<allow-intent href="sms:*"/> | ||
<allow-intent href="mailto:*"/> | ||
<allow-intent href="geo:*"/> | ||
<platform name="android"> | ||
<allow-intent href="market:*"/> | ||
</platform> | ||
<platform name="ios"> | ||
<allow-intent href="itms:*"/> | ||
<allow-intent href="itms-apps:*"/> | ||
</platform> | ||
<preference name="webviewbounce" value="false"/> | ||
<preference name="UIWebViewBounce" value="false"/> | ||
<preference name="DisallowOverscroll" value="true"/> | ||
<preference name="android-minSdkVersion" value="16"/> | ||
<preference name="BackupWebStorage" value="none"/> | ||
<preference name="SplashMaintainAspectRatio" value="true"/> | ||
<preference name="FadeSplashScreenDuration" value="300"/> | ||
<preference name="SplashShowOnlyFirstTime" value="false"/> | ||
<feature name="StatusBar"> | ||
<param name="ios-package" onload="true" value="CDVStatusBar"/> | ||
</feature> | ||
<plugin name="ionic-plugin-keyboard" spec="~2.2.1"/> | ||
<plugin name="cordova-plugin-whitelist" spec="1.3.1"/> | ||
<plugin name="cordova-plugin-console" spec="1.0.5"/> | ||
<plugin name="cordova-plugin-statusbar" spec="2.2.1"/> | ||
<plugin name="cordova-plugin-device" spec="1.1.4"/> | ||
<plugin name="cordova-plugin-splashscreen" spec="~4.0.1"/> | ||
</widget> |
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,39 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
<widget id="com.ionicframework.ionic2" version="0.0.0" android-versionCode="0" ios-CFBundleVersion="0" osx-CFBundleVersion="0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0"> | ||
<name>ionic2-rc6</name> | ||
<description>An awesome Ionic/Cordova app.</description> | ||
<author email="hi@ionicframework" href="http://ionicframework.com/">Ionic Framework Team</author> | ||
<content src="index.html"/> | ||
<access origin="*"/> | ||
<allow-navigation href="http://ionic.local/*"/> | ||
<allow-intent href="http://*/*"/> | ||
<allow-intent href="https://*/*"/> | ||
<allow-intent href="tel:*"/> | ||
<allow-intent href="sms:*"/> | ||
<allow-intent href="mailto:*"/> | ||
<allow-intent href="geo:*"/> | ||
<platform name="android"> | ||
<allow-intent href="market:*"/> | ||
</platform> | ||
<platform name="ios"> | ||
<allow-intent href="itms:*"/> | ||
<allow-intent href="itms-apps:*"/> | ||
</platform> | ||
<preference name="webviewbounce" value="false"/> | ||
<preference name="UIWebViewBounce" value="false"/> | ||
<preference name="DisallowOverscroll" value="true"/> | ||
<preference name="android-minSdkVersion" value="16"/> | ||
<preference name="BackupWebStorage" value="none"/> | ||
<preference name="SplashMaintainAspectRatio" value="true"/> | ||
<preference name="FadeSplashScreenDuration" value="300"/> | ||
<preference name="SplashShowOnlyFirstTime" value="false"/> | ||
<feature name="StatusBar"> | ||
<param name="ios-package" onload="true" value="CDVStatusBar"/> | ||
</feature> | ||
<plugin name="ionic-plugin-keyboard" spec="~2.2.1"/> | ||
<plugin name="cordova-plugin-whitelist" spec="1.3.1"/> | ||
<plugin name="cordova-plugin-console" spec="1.0.5"/> | ||
<plugin name="cordova-plugin-statusbar" spec="2.2.1"/> | ||
<plugin name="cordova-plugin-device" spec="1.1.4"/> | ||
<plugin name="cordova-plugin-splashscreen" spec="~4.0.1"/> | ||
</widget> |
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
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,39 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
<widget id="com.ionicframework.ionic2" version="0.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0"> | ||
<name>ionic2-rc6</name> | ||
<description>An awesome Ionic/Cordova app.</description> | ||
<author email="hi@ionicframework" href="http://ionicframework.com/">Ionic Framework Team</author> | ||
<content src="index.html"/> | ||
<access origin="*"/> | ||
<allow-navigation href="http://ionic.local/*"/> | ||
<allow-intent href="http://*/*"/> | ||
<allow-intent href="https://*/*"/> | ||
<allow-intent href="tel:*"/> | ||
<allow-intent href="sms:*"/> | ||
<allow-intent href="mailto:*"/> | ||
<allow-intent href="geo:*"/> | ||
<platform name="android"> | ||
<allow-intent href="market:*"/> | ||
</platform> | ||
<platform name="ios"> | ||
<allow-intent href="itms:*"/> | ||
<allow-intent href="itms-apps:*"/> | ||
</platform> | ||
<preference name="webviewbounce" value="false"/> | ||
<preference name="UIWebViewBounce" value="false"/> | ||
<preference name="DisallowOverscroll" value="true"/> | ||
<preference name="android-minSdkVersion" value="16"/> | ||
<preference name="BackupWebStorage" value="none"/> | ||
<preference name="SplashMaintainAspectRatio" value="true"/> | ||
<preference name="FadeSplashScreenDuration" value="300"/> | ||
<preference name="SplashShowOnlyFirstTime" value="false"/> | ||
<feature name="StatusBar"> | ||
<param name="ios-package" onload="true" value="CDVStatusBar"/> | ||
</feature> | ||
<plugin name="ionic-plugin-keyboard" spec="~2.2.1"/> | ||
<plugin name="cordova-plugin-whitelist" spec="1.3.1"/> | ||
<plugin name="cordova-plugin-console" spec="1.0.5"/> | ||
<plugin name="cordova-plugin-statusbar" spec="2.2.1"/> | ||
<plugin name="cordova-plugin-device" spec="1.1.4"/> | ||
<plugin name="cordova-plugin-splashscreen" spec="~4.0.1"/> | ||
</widget> |
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 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
<widget id="com.ionicframework.ionic2" version="0.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0"> | ||
<name>ionic2-rc6</name> | ||
<description>An awesome Ionic/Cordova app.</description> | ||
<author email="hi@ionicframework" href="http://ionicframework.com/">Ionic Framework Team</author> | ||
<content src="index.html"/> | ||
<access origin="*"/> | ||
<allow-navigation href="http://ionic.local/*"/> | ||
<allow-intent href="http://*/*"/> | ||
<allow-intent href="https://*/*"/> | ||
<allow-intent href="tel:*"/> | ||
<allow-intent href="sms:*"/> | ||
<allow-intent href="mailto:*"/> | ||
<allow-intent href="geo:*"/> | ||
<platform name="android"> | ||
|
File renamed without changes.
File renamed without changes.
File renamed without changes.