Skip to content

Commit e890824

Browse files
committed
Add cordova custom config to Gruntfile
1 parent 0915364 commit e890824

File tree

2 files changed

+50
-3
lines changed

2 files changed

+50
-3
lines changed

Gruntfile.js

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ module.exports = function (grunt) {
1919
var appConfig = {
2020
app: require('./bower.json').appPath || 'app',
2121
dist: 'dist',
22-
cordova: 'cordova'
22+
cordova: 'cordova',
23+
appName: 'YoAngularChrome'
2324
};
2425

2526
// Define the configuration for all the tasks
@@ -363,7 +364,7 @@ module.exports = function (grunt) {
363364
command: 'rm -Rf <%= yeoman.cordova %>'
364365
},
365366
cordovaCreate: {
366-
command: 'cordova create <%= yeoman.cordova %> com.sample.YoAngularCordova "YoAngularCordova" --copy-from=<%= yeoman.dist %>'
367+
command: 'cordova create <%= yeoman.cordova %> com.sample.<%= yeoman.appName %> "<%= yeoman.appName %>" --copy-from=<%= yeoman.dist %>'
367368
},
368369
cordovaPrepare: {
369370
command: 'cordova prepare',
@@ -395,6 +396,47 @@ module.exports = function (grunt) {
395396
}
396397
});
397398

399+
var xpath = require('xpath');
400+
var dom = require('xmldom').DOMParser;
401+
grunt.registerTask('addCordovaPreferences', function(){
402+
var cordovaConfig = appConfig.cordova + '/config.xml';
403+
var xml = grunt.file.read(cordovaConfig);
404+
var doc = new dom().parseFromString(xml);
405+
406+
var node = doc.getElementsByTagName('widget')[0];
407+
408+
//var author = node.getElementsByTagName("author")[0];
409+
//author.setAttribute('email','[email protected]');
410+
//author.setAttribute('href','http://example.com');
411+
//author.nodeValue='[email protected]';
412+
413+
// grunt.log.writeln('Adding to: ' + node);
414+
var KeyboardShrinksView = doc.createElement('preference');
415+
KeyboardShrinksView.setAttribute('name', 'KeyboardShrinksView');
416+
KeyboardShrinksView.setAttribute('value', true);
417+
grunt.log.writeln('Adding: ' + KeyboardShrinksView);
418+
node.appendChild(KeyboardShrinksView);
419+
420+
var StatusBarOverlaysWebView = doc.createElement('preference');
421+
StatusBarOverlaysWebView.setAttribute('name', 'StatusBarOverlaysWebView');
422+
StatusBarOverlaysWebView.setAttribute('value', false);
423+
grunt.log.writeln('Adding: ' + StatusBarOverlaysWebView);
424+
node.appendChild(StatusBarOverlaysWebView);
425+
426+
var StatusBarBackgroundColor = doc.createElement('preference');
427+
StatusBarBackgroundColor.setAttribute('name', 'StatusBarBackgroundColor');
428+
StatusBarBackgroundColor.setAttribute('value', '#388E3C'); // Should be the 700 color for your main color http://www.google.com/design/spec/style/color.html#color-color-palette
429+
grunt.log.writeln('Adding: ' + StatusBarBackgroundColor);
430+
node.appendChild(StatusBarBackgroundColor);
431+
432+
var KeyboardDisplayRequiresUserAction = doc.createElement('preference');
433+
KeyboardDisplayRequiresUserAction.setAttribute('name', 'KeyboardDisplayRequiresUserAction');
434+
KeyboardDisplayRequiresUserAction.setAttribute('value', false);
435+
grunt.log.writeln('Adding: ' + KeyboardDisplayRequiresUserAction);
436+
node.appendChild(KeyboardDisplayRequiresUserAction);
437+
438+
grunt.file.write(cordovaConfig, doc);
439+
});
398440

399441
grunt.registerTask('serve', 'Compile then start a connect web server', function (target) {
400442
if (target === 'dist') {
@@ -452,6 +494,7 @@ module.exports = function (grunt) {
452494
'build',
453495
'shell:cordovaClean',
454496
'shell:cordovaCreate',
497+
'addCordovaPreferences',
455498
'shell:cordovaPlatformInstallAndroid',
456499
'shell:cordovaPlatformInstallIos'
457500
]);

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
{
22
"name": "yoangularchrome",
33
"version": "0.0.0",
4-
"dependencies": {},
4+
"dependencies": {
5+
"grunt-bower-task": "^0.4.0",
6+
"xmldom": "^0.1.19",
7+
"xpath": "0.0.9"
8+
},
59
"devDependencies": {
610
"grunt": "^0.4.1",
711
"grunt-autoprefixer": "^0.7.3",

0 commit comments

Comments
 (0)