Created
July 14, 2014 20:45
-
-
Save lukluk/b181c685948fdfdeb41d to your computer and use it in GitHub Desktop.
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
var S = require('string'); | |
var fs = require('fs'); | |
var filendir = require('filendir') | |
module.exports = function(grunt) { | |
var coreWEBPath = "../../CoreWEB/", | |
wwwPath = "Hertz/www", | |
androidPhoneAssets = "Hertz/www/androidphone", | |
contentSourceRoot = "https://172.25.23.8"; // prk-agavecell cell 3 machine | |
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; // disable SSL checking if content against cell machine | |
// Project configuration. | |
grunt.initConfig({ | |
pkg: grunt.file.readJSON('package.json'), | |
clean: { | |
assests: [ | |
wwwPath + "/images/apps/kui", | |
wwwPath + "/images/apps/logo", | |
wwwPath + "/images/apps/weather", | |
wwwPath + "/images/apps/iostablet", | |
wwwPath + "/images/apps/misc", | |
wwwPath + "/images/weather", | |
wwwPath + "/js/content.js", | |
androidPhoneAssets | |
] | |
}, | |
compass: { | |
coreweb_scss: { | |
options: { | |
config: coreWEBPath + 'assets/config.rb', | |
basePath: coreWEBPath + 'assets/' | |
} | |
} | |
}, | |
sed: { | |
remove_cache_manifest: { | |
path: wwwPath, | |
pattern: /manifest="\/rentacar\/handlers\/manifest\/[a-z]*\/cache.manifest\?deviceGroup=[a-z]*\&edge=Y"/g, | |
replacement: ' ', | |
recursive: true | |
}, | |
css_and_javascript_paths: { | |
path: wwwPath, | |
pattern: /\/rentacar\/assets\/\d*\/((androidphone)\/?)?/g, | |
replacement: 'generated/', | |
recursive: true | |
}, | |
image_paths: { | |
path: [androidPhoneAssets], | |
pattern: /\/rentacar\/assets\/images\//g, | |
replacement: '../images/', | |
recursive: true | |
}, | |
css: { | |
path: [androidPhoneAssets], | |
pattern: /-webkit-mask-box-image:( ?)url\("..\/images\//g, | |
replacement: '-webkit-mask-box-image:url("../../images/', | |
recursive: true | |
} | |
}, | |
copy: { | |
static_resources: { | |
files: [ | |
// includes files within path | |
{ | |
src: [coreWEBPath + 'assets/html/androidphone/hub/**'], | |
dest: androidPhoneAssets, | |
expand: true, | |
flatten: true, | |
filter: 'isFile' | |
}, { | |
src: [coreWEBPath + 'assets/images/apps/kui/*'], | |
dest: wwwPath + "/images/apps/kui", | |
expand: true, | |
flatten: true, | |
filter: 'isFile' | |
}, { | |
src: [coreWEBPath + 'assets/images/apps/logo/*'], | |
dest: wwwPath + "/images/apps/logo", | |
expand: true, | |
flatten: true, | |
filter: 'isFile' | |
}, { | |
src: [coreWEBPath + 'assets/images/apps/weather/*'], | |
dest: wwwPath + "/images/apps/weather", | |
expand: true, | |
flatten: true, | |
filter: 'isFile' | |
}, { | |
src: [coreWEBPath + 'assets/images/apps/misc/*'], | |
dest: wwwPath + "/images/apps/misc", | |
expand: true, | |
flatten: true, | |
filter: 'isFile' | |
}, { | |
src: [coreWEBPath + 'assets/images/weather/*'], | |
dest: wwwPath + "/images/weather", | |
expand: true, | |
flatten: true, | |
filter: 'isFile' | |
} | |
] | |
} | |
}, | |
concat: { | |
css: { | |
files: { | |
"Hertz/www/androidphone/generated/global.css": [ | |
coreWEBPath + '/assets/css/libs/kendo.common.min.css', | |
coreWEBPath + '/assets/css/libs/kendo.mobile.ios.min.css', | |
coreWEBPath + '/assets/css/androidphone/global.css' | |
] | |
} | |
}, | |
}, | |
javascripts: { | |
"Hertz/www/androidphone/generated/libs.js": [ | |
coreWEBPath + 'js/htz.js', | |
coreWEBPath + 'assets/js/libs/app/androidphone/cordova-3.1.1.js', | |
coreWEBPath + 'assets/js/libs/app/androidphone/cordova_plugins.js', | |
coreWEBPath + 'assets/js/libs/app/iosphone/progress.min.js', | |
coreWEBPath + 'assets/jsinclude/libs/js.jsp', | |
coreWEBPath + 'assets/js/libs/app/kendo.mobile.min.js', | |
coreWEBPath + 'assets/js/libs/app/androidphone/fastclick.js', | |
coreWEBPath + 'assets/js/apps/plugins/preloader.js', | |
coreWEBPath + 'assets/js/apps/plugins/remoteToLocal.js', | |
coreWEBPath + 'assets/js/apps/androidphone/plugins/MapKit.js', | |
coreWEBPath + 'assets/js/apps/plugins/splashControl.js', | |
coreWEBPath + 'assets/js/apps/androidphone/plugins/applicationPreferences.js', | |
coreWEBPath + 'assets/js/apps/plugins/Geocode.js', | |
coreWEBPath + 'assets/js/apps/plugins/PhoneDialer.js', | |
coreWEBPath + 'assets/js/apps/plugins/detectApp.js', | |
coreWEBPath + 'assets/js/apps/plugins/PushNotification.js', | |
coreWEBPath + 'assets/js/apps/plugins/CardIOPGPlugin.js', | |
coreWEBPath + 'assets/js/apps/androidphone/plugins/network.js', | |
coreWEBPath + 'assets/js/apps/androidphone/plugins/Connection.js', | |
coreWEBPath + 'assets/js/apps/androidphone/backbutton.js' | |
], | |
"Hertz/www/androidphone/generated/hub/mobileapp.js": [ | |
coreWEBPath + 'assets/jsinclude/global/js.jsp', | |
coreWEBPath + 'assets/js/utils/app/slider.js', | |
coreWEBPath + 'assets/jsinclude/global/app/config/js.jsp', | |
coreWEBPath + 'assets/js/apps/iosphone/HzConstants.js', | |
coreWEBPath + 'assets/js/apps/iosphone/HzEvents.js', | |
coreWEBPath + 'assets/js/apps/iosphone/HzGUI.js', | |
coreWEBPath + 'assets/js/apps/iosphone/HzStorage.js', | |
coreWEBPath + 'assets/js/apps/iosphone/HzMessages.js', | |
coreWEBPath + 'assets/js/apps/iosphone/HzMember.js', | |
coreWEBPath + 'assets/js/apps/iosphone/HzUtils.js', | |
coreWEBPath + 'assets/js/apps/iosphone/HzVC.js', | |
coreWEBPath + 'assets/js/apps/iosphone/HzOauth.js', | |
coreWEBPath + 'assets/js/apps/androidphone/global.js', | |
coreWEBPath + 'assets/js/apps/iosphone/ErrorHelper.js', | |
coreWEBPath + 'assets/js/apps/iosphone/customer-support.js', | |
coreWEBPath + 'assets/js/utils/omniture-helper.js' | |
] | |
}, | |
content: { | |
dialects: [ | |
"csCZ", | |
"deDE", | |
"dkDK", | |
"enGB", | |
"enUS", | |
"esES", | |
"esLA", | |
"fiFI", | |
"frFR", | |
"hrHR", | |
"huHU", | |
"idID", | |
"itIT", | |
"jaJP", | |
"koKR", | |
"nlNL", | |
"noNO", | |
"plPL", | |
"ptBR", | |
"ptPT", | |
"ruRU", | |
"siSI", | |
"svSE", | |
"trTR", | |
"zhCN", | |
"zhHK" | |
] | |
} | |
}); | |
grunt.registerTask('js', 'javascript process', function() { | |
grunt.config.requires('javascripts'); | |
var js = grunt.config('javascripts'); | |
for (var key in js) { | |
var data = ''; | |
console.log('#--->' + key); | |
for (var n in js[key]) { | |
var jsurl = js[key][n]; | |
var jstxt = fs.readFileSync(jsurl); | |
if (jsurl.indexOf('.jsp') > 0) { | |
jstxt = S(jstxt).replaceAll('<%@ include file="', ''); | |
jstxt = S(jstxt).replaceAll('<jsp:includepage="', ''); | |
jstxt = S(jstxt).replaceAll('<jsp:include page="', ''); | |
jstxt = S(jstxt).replaceAll('" ', ''); | |
jstxt = S(jstxt).replaceAll('/assets', 'assets'); | |
jstxt = S(jstxt).replaceAll("\n", ''); | |
jstxt = S(jstxt).replaceAll("\n", ''); | |
if (jstxt.indexOf('%>') > -1) { | |
var links = jstxt.split('%>'); | |
} else | |
if (jstxt.indexOf('/>') > -1) { | |
var links = jstxt.split('/>'); | |
} | |
for (var link in links) { | |
var url = S(links[link]).replaceAll(' ', ''); | |
if (url != '') { | |
console.log('--->include JS '+url); | |
data = data + '\n // includeJS :' + url +'\n'+ fs.readFileSync(coreWEBPath + url); | |
} | |
} | |
} else { | |
console.log('--->include JS '+jsurl); | |
data = data + '\n // includeJS :' + jsurl +'\n'+ jstxt; | |
} | |
} | |
var xdata=data; | |
filendir.ws(key, xdata); | |
} | |
}), | |
grunt.registerTask('content', 'Get language translations', function() { | |
var done = this.async(), | |
request = require('request-json'), | |
async = require('async'), | |
dialects, | |
i = 0, | |
count, | |
url, | |
content = {}, | |
deviceGroup = 'iosphone'; | |
grunt.config.requires('content.dialects'); | |
dialects = grunt.config('content.dialects'); | |
var client = request.newClient(contentSourceRoot); | |
count = dialects.length; | |
function getContent(deviceGroup, callback) { | |
var q = async.queue(function(task, callback) { | |
client.get(task.url, function(err, res, body) { | |
if (err) { | |
grunt.log.writeln("Error getting content >> " + err); | |
} | |
content[task.dialect] = body.data; | |
grunt.log.writeln("Get content for dialect:" + task.dialect + " from: " + contentSourceRoot + task.url); | |
callback(); | |
}); | |
}, 4); | |
// assign a callback | |
q.drain = function() { | |
var data = ""; | |
data += "htz.content = htz.content || {} ;" + | |
"htz.content.hub = htz.content.hub || " + JSON.stringify(content) + ";" | |
fs.writeFile('Hertz/www/' + deviceGroup + '/generated/content.js', data, function(err) { | |
if (err) throw err; | |
grunt.log.ok("Write content to file"); | |
callback(); | |
}); | |
} | |
for (i = 0; i < count; i++) { | |
url = '/rentacar/rest/config/{deviceGroup}/{dialect}'.replace('{deviceGroup}', deviceGroup); | |
url = url.replace('{dialect}', dialects[i]); | |
q.push({ | |
dialect: dialects[i], | |
url: url | |
}, function(err) {}); | |
} | |
}; | |
async.series([ | |
function(callback) { | |
getContent('androidphone', callback); | |
} | |
], | |
done | |
); | |
}); | |
// measures the time each task takes | |
require('time-grunt')(grunt); | |
require('load-grunt-tasks')(grunt); | |
// Default task(s). | |
grunt.registerTask('default', ['clean', 'compass', 'copy', 'concat:css', 'sed', 'content', 'js']) | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment