@@ -16,6 +16,8 @@ var _ = require('lodash');
1616var $ = require ( 'gulp-load-plugins' ) ( { lazy : true } ) ;
1717/* jshint ignore:end */
1818
19+ var _s = require ( 'underscore.string' ) ;
20+
1921/**
2022 * yargs variables can be passed in to alter the behavior, when present.
2123 * Example: gulp serve-dev
@@ -203,31 +205,24 @@ gulp.task('inject', ['wiredep', 'styles', 'templatecache'], function() {
203205} ) ;
204206
205207/**
206- * Creates a sample local.json; can be used as model for dev.json and prod.json
208+ * Initialize config files for local environment
207209 */
208- gulp . task ( 'init-local' , function ( ) {
209- //copy from slushfile - config gulp - with modifications to use config instead
210- log ( 'Creating local.json sample document with values drawn from gulp.config.js' ) ;
211- try {
212- var configJSON = { } ;
213- configJSON [ 'ml-version' ] = config . marklogic . version ;
214- configJSON [ 'ml-host' ] = config . marklogic . host ;
215- configJSON [ 'ml-admin-user' ] = config . marklogic . username ;
216- configJSON [ 'ml-admin-pass' ] = config . marklogic . password ;
217- configJSON [ 'ml-app-user' ] = config . marklogic . username ;
218- configJSON [ 'ml-app-pass' ] = config . marklogic . password ;
219- configJSON [ 'ml-http-port' ] = config . marklogic . httpPort ;
220- configJSON [ 'node-port' ] = config . defaultPort ;
221-
222- if ( config . marklogic . version < 8 ) {
223- configJSON [ 'ml-xcc-port' ] = config . marklogic . xccPort ;
224- }
210+ gulp . task ( 'init-local' , function ( done ) {
211+ init ( 'local' , done ) ;
212+ } ) ;
225213
226- var configString = JSON . stringify ( configJSON , null , 2 ) + '\n' ;
227- fs . writeFileSync ( 'local.json' , configString , { encoding : 'utf8' } ) ;
228- } catch ( e ) {
229- log ( 'failed to write local.json: ' + e . message ) ;
230- }
214+ /**
215+ * Initialize config files for dev environment
216+ */
217+ gulp . task ( 'init-dev' , function ( done ) {
218+ init ( 'dev' , done ) ;
219+ } ) ;
220+
221+ /**
222+ * Initialize config files for prod environment
223+ */
224+ gulp . task ( 'init-prod' , function ( done ) {
225+ init ( 'prod' , done ) ;
231226} ) ;
232227
233228/**
@@ -518,6 +513,129 @@ function clean(files) {
518513 } ) ;
519514}
520515
516+ /**
517+ * Initialize config files for given env
518+ * @param {String } env The environment name (local, dev, prod)
519+ * @param {Function } done - callback when complete
520+ */
521+ function init ( env , done ) {
522+ if ( fs . existsSync ( env + '.json' ) ) {
523+ log ( env + '.json already exists!' ) ;
524+ done ( ) ;
525+ } else {
526+ //copy from slushfile - config gulp - with modifications to use config instead
527+ var inquirer = require ( 'inquirer' ) ;
528+
529+ var properties = fs . readFileSync ( 'deploy/build.properties' , { encoding : 'utf8' } ) ;
530+
531+ // capture app-name entered earlier
532+ var appNameMatch = / ^ a p p \- n a m e = ( .* ) $ / m;
533+ var matches = appNameMatch . exec ( properties ) ;
534+ var appName = matches [ 1 ] ;
535+
536+ var prompts = [
537+ { type : 'list' , name : 'mlVersion' , message : 'MarkLogic version?' , choices : [ '8' , '7' , '6' , '5' ] , default : 0 } ,
538+ { type : 'input' , name : 'marklogicHost' , message : 'MarkLogic Host?' , default : 'localhost' } ,
539+ { type : 'input' , name : 'marklogicAdminUser' , message : 'MarkLogic Admin User?' , default : 'admin' } ,
540+ { type : 'input' , name : 'marklogicAdminPass' , message : 'Note: consider keeping the following blank, ' +
541+ 'you will be asked to enter it at appropriate commands.\n? MarkLogic Admin Password?' , default : '' } ,
542+ { type : 'input' , name : 'appPort' , message : 'MarkLogic App/Rest port?' , default : 8040 } ,
543+ { type : 'input' , name : 'xccPort' , message : 'XCC port?' , default :8041 , when : function ( answers ) {
544+ return answers . mlVersion < 8 ;
545+ } } ,
546+ { type : 'input' , name : 'nodePort' , message : 'Node app port?' , default : 9070 } ,
547+ { type : 'input' , name : 'guestAccess' , message : 'Allow anonymous users to search data?' , default : 'false' } ,
548+ { type : 'input' , name : 'readOnlyAccess' , message : 'Disallow proxying update requests?' , default : 'false' } ,
549+ { type : 'input' , name : 'appUsersOnly' , message : 'Only allow access to users created for this app? Disallows admin users.' , default : 'false' }
550+ ] ;
551+
552+ if ( typeof appName === 'undefined' ) {
553+ prompts . unshift (
554+ { type : 'input' , name : 'name' , message : 'Name for the app?' } ) ;
555+ }
556+
557+ inquirer . prompt ( prompts , function ( settings ) {
558+ if ( typeof appName === 'undefined' ) {
559+ settings . nameDashed = _s . slugify ( settings . name ) ;
560+ } else {
561+ settings . nameDashed = _s . slugify ( appName ) ;
562+ }
563+
564+ try {
565+ var configJSON = { } ;
566+ configJSON [ 'app-name' ] = settings . nameDashed ;
567+ configJSON [ 'ml-version' ] = settings . mlVersion ;
568+ configJSON [ 'ml-host' ] = settings . marklogicHost ;
569+ configJSON [ 'ml-admin-user' ] = settings . marklogicAdminUser ;
570+ configJSON [ 'ml-admin-pass' ] = settings . marklogicAdminPass ;
571+ configJSON [ 'ml-app-user' ] = settings . nameDashed + '-user' ;
572+ configJSON [ 'ml-app-pass' ] = settings . appuserPassword ;
573+ configJSON [ 'ml-http-port' ] = settings . appPort ;
574+
575+ if ( settings . mlVersion < 8 ) {
576+ configJSON [ 'ml-xcc-port' ] = settings . xccPort ;
577+ }
578+
579+ configJSON [ 'node-port' ] = settings . nodePort ;
580+ configJSON [ 'guest-access' ] = settings . guestAccess ;
581+ configJSON [ 'readonly-access' ] = settings . readOnlyAccess ;
582+ configJSON [ 'appusers-only' ] = settings . appUsersOnly ;
583+
584+ var configString = JSON . stringify ( configJSON , null , 2 ) + '\n' ;
585+ fs . writeFileSync ( env + '.json' , configString , { encoding : 'utf8' } ) ;
586+ log ( 'Created ' + env + '.json.' ) ;
587+
588+ if ( fs . existsSync ( 'deploy/' + env + '.properties' ) ) {
589+ log ( 'deploy/' + env + '.properties already exists!' ) ;
590+ } else {
591+ var envProperties = '#################################################################\n' +
592+ '# This file contains overrides to values in build.properties\n' +
593+ '# These only affect your local environment and should not be checked in\n' +
594+ '#################################################################\n' +
595+ '\n' +
596+ 'server-version=' + settings . mlVersion + '\n' +
597+ '\n' +
598+ '#\n' +
599+ '# The ports used by your application\n' +
600+ '#\n' +
601+ 'app-port=' + settings . appPort + '\n' ;
602+ if ( settings . mlVersion < 8 ) {
603+ envProperties += 'xcc-port=' + settings . xccPort + '\n' ;
604+ }
605+ else
606+ {
607+ envProperties += '# Taking advantage of not needing a XCC Port for ML8\n' +
608+ 'xcc-port=${app-port}\n' +
609+ 'install-xcc=false\n' ;
610+ }
611+
612+ envProperties += '\n' +
613+ '#\n' +
614+ '# the uris or IP addresses of your servers\n' +
615+ '# WARNING: if you are running these scripts on WINDOWS you may need to change localhost to 127.0.0.1\n' +
616+ '# There have been reported issues with dns resolution when localhost wasn\'t in the hosts file.\n' +
617+ '#\n' +
618+ env + '-server=' + settings . marklogicHost + '\n' +
619+ 'content-forests-per-host=3\n' +
620+ '\n' +
621+ '#\n' +
622+ '# Admin username/password that will exist on the local/dev/prod servers\n' +
623+ '#\n' +
624+ 'user=' + settings . marklogicAdminUser + '\n' +
625+ 'password=' + settings . marklogicAdminPass + '\n' ;
626+
627+ fs . writeFileSync ( 'deploy/' + env + '.properties' , envProperties , { encoding : 'utf8' } ) ;
628+ log ( 'Created deploy/' + env + '.properties.' ) ;
629+ }
630+ done ( ) ;
631+ } catch ( e ) {
632+ log ( 'Failed to write ' + env + ' config files: ' + e . message ) ;
633+ done ( ) ;
634+ }
635+ } ) ;
636+ }
637+ }
638+
521639/**
522640 * Inject files in a sorted sequence at a specified inject label
523641 * @param {Array } src glob pattern for source files
0 commit comments