-
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(version): add setVersion to write version number in config.xml
- Loading branch information
Showing
7 changed files
with
144 additions
and
7 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,4 +1,5 @@ | ||
node_modules | ||
.vscode | ||
npm-debug*.log | ||
coverage | ||
coverage | ||
test/config.xml |
Empty file.
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 |
---|---|---|
@@ -1,5 +1,28 @@ | ||
'use strict'; | ||
|
||
module.exports = () => { | ||
var fs = require('fs'); | ||
var xml2js = require('xml2js'); | ||
var xmlParser = new xml2js.Parser(); | ||
var xmlBuilder = new xml2js.Builder(); | ||
|
||
}; | ||
module.exports = { | ||
setVersion: setVersion | ||
}; | ||
|
||
function setVersion(configPath, version, callback) { | ||
fs.readFile(configPath, { encoding: 'UTF-8' }, function (readError, configData) { | ||
if (readError) { | ||
callback(readError); | ||
} | ||
|
||
xmlParser.parseString(configData, function (parseError, configXml) { | ||
if (parseError) { | ||
callback(parseError); | ||
} | ||
|
||
configXml.widget.$.version = version; | ||
var newConfigData = xmlBuilder.buildObject(configXml); | ||
fs.writeFile(configPath, newConfigData, { encoding: 'UTF-8' }, callback); | ||
}); | ||
}); | ||
} |
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="1.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,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 |
---|---|---|
@@ -1,8 +1,40 @@ | ||
var expect = require('chai').expect; | ||
var cordovaSetVersion = require('../src/index'); | ||
var fs = require('fs-extra'); | ||
|
||
describe('cordova-set-version', function() { | ||
it('should work!', function() { | ||
var originalPath = './test/config.original.xml'; | ||
var configPath = './test/config.xml'; | ||
var expectedConfigPath = './test/config.expected.xml'; | ||
var fileParams = { encoding: 'UTF-8' }; | ||
|
||
describe('cordova-set-version', () => { | ||
it('should exist', () => { | ||
expect(cordovaSetVersion).to.exist; | ||
}); | ||
|
||
describe('setVersion', () => { | ||
beforeEach(() => { | ||
fs.copySync(originalPath, configPath); | ||
}); | ||
|
||
it('should exist', () => { | ||
expect(cordovaSetVersion).to.have.property('setVersion'); | ||
}); | ||
|
||
it('should be a function', () => { | ||
expect(typeof cordovaSetVersion.setVersion).to.equal('function'); | ||
}); | ||
|
||
it('should produce same content as in `config.expected.xml` when passed the argument `1.0.0`', (done) => { | ||
cordovaSetVersion.setVersion(configPath, '1.0.0', function (error) { | ||
expect(error).to.not.exist; | ||
|
||
var config = fs.readFileSync(configPath, fileParams); | ||
var expectedConfig = fs.readFileSync(expectedConfigPath, fileParams); | ||
expect(config).to.equal(expectedConfig); | ||
|
||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |