Created
July 16, 2014 08:45
-
-
Save lukluk/2fb3adbc2ac27bfab132 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://edyhertz.ngrok.com"; // 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: [ | |
androidPhoneAssets+'/generated/libs.js', | |
androidPhoneAssets+'/generated/hub/mobileapp.js' | |
] | |
}, | |
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 + '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/androidphone/hub/js.jsp' | |
] | |
}, | |
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) { | |
data=data+'\n // JSP :'+jsurl+'\n'; | |
jstxt = S(jstxt).replaceAll('<%@ include file="', ''); | |
jstxt = S(jstxt).replaceAll('<jsp:includepage="', ''); | |
jstxt = S(jstxt).replaceAll('<jsp:include page="', ''); | |
jstxt = S(jstxt).replaceAll("<jsp:include page='", ''); | |
jstxt = S(jstxt).replaceAll('" ', ''); | |
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', 'content','concat:css', 'sed', 'js']) | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment