cq-sling
Version:
Sling your src files to CQ
155 lines (129 loc) • 5.98 kB
JavaScript
"use strict"
var fs = require('fs');
var sys = require('sys');
var exec = require('child_process').exec;
var child;
function cqSlinger() {
console.log("cqfile: " + process.argv[2]);
if(process.argv.length > 2) {
var cqfile = process.argv[2];
if(fs.existsSync(cqfile)) {
//var localPath = this.data.src,
var localPath = '',
options = {
stdout: false,
host: 'localhost',
port: '4503',
user: 'admin',
pass: 'admin',
ignorePaths: false,
checkedPaths: []
},
destPath,
publishfile;
console.log (cqfile);
/*
//$ ls /c/work/src/MR_DEV/TASK-Mobile/CQ5Workspace/uhc_framework/ui/src/main/content/jcr_root/etc/designs/uhc-common/mobileaarp/member/mobileuhcm/js
//email.js site.js
//localPath = '/c/work/src/MR_DEV/TASK-Mobile/CQ5Workspace/uhc_framework/ui/src/main/content/jcr_root/etc/designs/uhc-common/mobileaarp/member/mobileuhcm/js/'
localPath = "site.js";
destPath = '/c/work/src/MR_DEV/TASK-Mobile/CQ5Workspace/uhc_framework/ui/src/main/content/jcr_root';
"/c/work/src/MR_DEV/TASK-Mobile/CQ5Workspace/uhc_framework/ui/src/main/content/jcr_root/etc/designs/uhc-common/mobileaarp/member/mobileuhcm/js/site.js"
// checking if local path has jcr_root and stripping it and everything before it off
//destPath = localPath.replace(/\\/g, '/');
//if (path.dirname(destPath).indexOf('jcr_root/') !== -1) {
//destPath = destPath.substring(path.dirname(destPath).indexOf('jcr_root/') + 9);
//}
var command = 'curl -i -X POST -F ';
command += 'site.js' + '=@' + localPath;
command += ' -u ' + options.user + ':' + options.pass;
command += ' http://' + options.host + ':' + options.port + destPath;
console.log('cmd: ' + command);
exec(command, function (error, stdout, stderr) {
if (error !== null) {
//grunt.verbose.writeln('exec error: ' + error);
console.log('error ' + error);
} else {
//grunt.verbose.writeln('Response: ' + stdout);
console.log('success ' + stdout);
}
});
/*
// piecing together the curl command to push the file to sling
var slingFile = function slingFile(path) {
var command = 'curl -i -X POST -F';
command += path.file + '=@' + localPath;
command += ' -u ' + options.user + ':' + options.pass;
command += ' http://' + options.host + ':' + options.port + path.path;
// grunt.log.writeln('file: ' + localPath);
console.log('file: ' + localPath);
// grunt.log.writeln('slang to: ' + path.path + '/' + path.file);
console.log('slang to: ' + path.path + '/' + path.file);
exec(command, function (error, stdout, stderr) {
if (error !== null) {
//grunt.verbose.writeln('exec error: ' + error);
console.log('error ' + error);
} else {
//grunt.verbose.writeln('Response: ' + stdout);
console.log('success ' + stdout);
}
});
};
//piecing together the curl command to push the folders to sling
var slingFolder = function slingFolder(path) {
//grunt.log.writeln('create folder: ' + path);
console.log('create folder: ' + path);
var command = 'curl -i -X POST -F"jcr:primaryType=nt:folder" -u ' + options.user + ':' + options.pass + ' http://' + options.host + ':' + options.port + path;
//grunt.verbose.writeln('command: ' + command);
console.log('command: ' + command);
exec(command, function (error, stdout, stderr) {
if (error !== null) {
//grunt.verbose.writeln('exec error: ' + error);
console.log('exec error: ' + error);
} else {
//grunt.verbose.writeln('Response: ' + stdout);
console.log('Response: ' + stdout);
}
});
};
function pathBuilder ( path ) {
var aPath, // stores the path as an array split on the slash
newPath = '', // stores the new path tree as it gets built
filePath = ''; // use for file creation
if ( path.substr(0,1) === '/' ) {
path = path.substr(1);
}
aPath = path.split('/');
// loop through the items
for (var n=0; n<aPath.length; n++) {
// check for file
if ( n === aPath.length - 1 && aPath[n].indexOf('.') > -1 ) {
filePath = ( newPath === '' ) ? '/' : newPath;
// call the method to create the file and pass it the filename and the path (which we got in the previous iteration)
slingFile( {file: aPath[n], path: filePath} );
// otherwise create directory structure
} else {
// append the current path with a leading slash...
newPath += '/' + aPath[n];
if (checkedPaths.indexOf(newPath) < 0) {
checkedPaths.push(newPath);
if (!options.ignorePaths) {
// make the folder
slingFolder(newPath);
}
}
}
}
}
mergeCheckedPaths(checkedPaths, options.checkedPaths);
pathBuilder(destPath);
//var content = fs.readFileSync(myfile, 'utf8');
//fs.writeFileSync(myfile, content.toUpperCase());
*/
}
console.log("Done");
} else {
console.log("Pass on a file name/path");
}
}
exports.cqSlinger = cqSlinger;