Created
May 15, 2014 15:33
-
-
Save birkir/2d85c35169bd64c52f3e to your computer and use it in GitHub Desktop.
Grunt task to save compiled file as Lisa SupportFile
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
watch: { | |
// ... | |
less: { | |
files: 'less/*.less', | |
// tasks: 'less', | |
tasks: ['less', 'save-support-file'] | |
} | |
} | |
// ... | |
var saveSupportFile = require('./lisa.js'); | |
grunt.registerTask('save-support-file', saveSupportFile); | |
// ... |
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
// Dependencies: | |
// * npm install request | |
// * npm install cheerio | |
// | |
var fs = require('fs'), | |
request = require('request'), | |
cheerio = require('cheerio'); | |
// Configuration array | |
var config = { | |
proxy: '', // Proxy settings if needed ex. http://websense:8090 | |
website: '', // Lisa WebsiteID | |
username: 'sysadmin', | |
password: '123', | |
domain: 'http://www.example.com', // Domain of LiSA CMS | |
supportfile: { | |
id: '', // Support File Id | |
name: '' // Support File Name | |
} | |
}; | |
module.exports = function saveSupportFile() { | |
// Read compiled and minified css | |
var distCssFile = fs.readFileSync('dist/css/bootstrap.min.css', 'utf8'); | |
/** | |
* Login to LiSA CMS | |
* | |
* @param array | |
* @param function | |
* @return void | |
*/ | |
function login(config, callback) { | |
// Create login URL | |
var loginUrl = config.domain + '/lisa/Login.aspx?ReturnUrl=%2flisa'; | |
// Request login page for viewstate | |
request({ | |
jar: true, | |
url: loginUrl, | |
proxy: config.proxy | |
}, | |
function (error, response, body) { | |
// Load body in cheerio | |
var $ = cheerio.load(body); | |
// Create login HTTP request | |
request({ | |
jar: true, | |
url: loginUrl, | |
method: 'POST', | |
followRedirect: false, | |
form: { | |
'__VIEWSTATE': $('[name=__VIEWSTATE]').val(), | |
'LisaLoginCtrl$username': config.username, | |
'LisaLoginCtrl$password': config.password, | |
'LisaLoginCtrl$Website': config.website, | |
'LisaLoginCtrl$RememberMe': 'on', | |
'LisaLoginCtrl$ctl01': 'Innskrá' | |
}, | |
proxy: config.proxy | |
}, | |
// Get login HTTP response | |
function (error, response, body) { | |
if (response.headers.location === '/lisa') { | |
callback(); | |
} | |
}) | |
}); | |
} | |
// Login and save support file logic | |
login(config, function () { | |
// Create HTTP request | |
request({ | |
json: true, | |
jar: true, | |
url: config.domain + '/lisa/Core/SupportFiles/WebMethods.asmx/SaveSupportFile', | |
proxy: config.proxy, | |
method: 'POST', | |
body: { | |
clientExpireDuration: "0", | |
content: distCssFile, | |
name: config.supportfile.name, | |
publish: null, | |
supportFileId: config.supportfile.id, | |
validate: true | |
} | |
}, function (error, response, body) { | |
// Awesome ! | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment