Skip to content

Instantly share code, notes, and snippets.

@ryanjdew
Last active August 29, 2015 14:22
Show Gist options
  • Save ryanjdew/2267b963810654db4261 to your computer and use it in GitHub Desktop.
Save ryanjdew/2267b963810654db4261 to your computer and use it in GitHub Desktop.
Example using MarkLogic Node API to deploy code with gulp task
/*jshint node: true */
'use strict';
var gulp = require('gulp');
var config = require('konphyg')(__dirname+'/config');
var appConfig = config('app');
var marklogic = require('marklogic');
var qb = marklogic.queryBuilder;
gulp.task('deploy', function() {
var transformTypes = {
'xqy': 'xquery',
'sjs': 'javascript',
'xsl': 'xslt'
};
gulp.src(['config/transforms/**/*.sjs', 'config/transforms/**/*.xqy', 'config/transforms/**/*.xsl'])
.on('data', function(file){
var fullPath = file.history[0];
var fileName = fullPath.substring(fullPath.indexOf(file.base) + file.base.length,fullPath.length);
var transformName = fileName.replace(/\.[a-z]+$/, '');
var transformExtension = fileName.replace(/^.+\.([a-z]+)$/, '$1');
adminMLClient.config.transforms.write(transformName,transformTypes[transformExtension], ''+file.contents);
});
gulp.src(['config/resources/**/*.sjs', 'config/resources/**/*.xqy', 'config/resources/**/*.xsl'])
.on('data', function(file){
var fullPath = file.history[0];
var fileName = fullPath.substring(fullPath.indexOf(file.base) + file.base.length,fullPath.length);
var resourceName = fileName.replace(/\.[a-z]+$/, '');
var resourceExtension = fileName.replace(/^.+\.([a-z]+)$/, '$1');
adminMLClient.config.resources.write(resourceName,transformTypes[resourceExtension], ''+file.contents);
});
var mimeTypes = {
'xqy': 'application/xquery',
'sjs': 'application/javascript'
};
gulp.src(['config/ext/**/*.sjs', 'config/ext/**/*.xqy'])
.on('data', function(file){
var fullPath = file.history[0];
var extDir = 'config/ext/';
var fileURI = fullPath.substring(fullPath.indexOf(extDir) + extDir.length,fullPath.length);
var fileExtension = fileURI.replace(/^.+\.([a-z]+)$/, '$1');
adminMLClient.config.extlibs.write(fileURI, null, mimeTypes[fileExtension], ''+file.contents);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment