Skip to content
This repository was archived by the owner on Oct 5, 2020. It is now read-only.

Commit 0090340

Browse files
Nishad BakshiNishad Bakshi
authored andcommitted
Created an encoding variable in the slushfile
1 parent 8f4d0d6 commit 0090340

File tree

1 file changed

+149
-66
lines changed

1 file changed

+149
-66
lines changed

slushfile.js

Lines changed: 149 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,31 @@
33
'use strict';
44

55
var gulp = require('gulp'),
6-
FetchStream = require('fetch').FetchStream,
7-
fs = require('fs'),
8-
inquirer = require('inquirer'),
9-
install = require('gulp-install'),
10-
q = require('q'),
11-
rename = require('gulp-rename'),
12-
replace = require('gulp-replace'),
13-
pkgSettings = require('./package.json'),
14-
spawn = require('child_process').spawn,
15-
uuid = require('node-uuid'),
16-
win32 = process.platform === 'win32'
17-
;
6+
FetchStream = require('fetch').FetchStream,
7+
fs = require('fs'),
8+
inquirer = require('inquirer'),
9+
install = require('gulp-install'),
10+
q = require('q'),
11+
rename = require('gulp-rename'),
12+
replace = require('gulp-replace'),
13+
pkgSettings = require('./package.json'),
14+
spawn = require('child_process').spawn,
15+
uuid = require('node-uuid'),
16+
win32 = process.platform === 'win32';
1817

1918
/* jshint ignore:start */
2019
var colors = require('colors'),
21-
_ = require('underscore.string')
22-
;
20+
_ = require('underscore.string');
2321
/* jshint ignore:end */
2422

2523
var npmVersion = null;
2624

2725
var settings = {};
2826

27+
var encoding = {
28+
encoding: 'utf8'
29+
};
30+
2931
function printVersionWarning() {
3032
if (npmVersion && npmVersion !== pkgSettings.version.trim()) {
3133
process.stdout.write('\n------------------------------------\n'.red);
@@ -185,7 +187,7 @@ function configRoxy() {
185187
console.log('Configuring Roxy');
186188

187189
try {
188-
var properties = fs.readFileSync('deploy/build.properties', { encoding: 'utf8' });
190+
var properties = fs.readFileSync('deploy/build.properties', encoding);
189191

190192
// Set the authentication-method property to digestbasic
191193
properties = properties.replace(/^authentication\-method=digest/m, 'authentication-method=digestbasic');
@@ -241,17 +243,13 @@ function configRoxy() {
241243
'user=' + settings.marklogicAdminUser + '\n' +
242244
'password=' + settings.marklogicAdminPass + '\n';
243245

244-
fs.writeFileSync('deploy/local.properties', localProperties, {
245-
encoding: 'utf8'
246-
});
246+
fs.writeFileSync('deploy/local.properties', localProperties, encoding);
247247
} catch (e) {
248248
console.log('failed to write roxy local.properties');
249249
}
250250

251251
try {
252-
var foo = fs.readFileSync('deploy/ml-config.xml', {
253-
encoding: 'utf8'
254-
});
252+
var foo = fs.readFileSync('deploy/ml-config.xml', encoding);
255253

256254
// add an index for the default content
257255
foo = foo.replace(/^\s*<range-element-indexes>/m,
@@ -312,9 +310,7 @@ gulp.task('default', ['npmInstall'], function(done) {
312310
gulp.task('generateSecret', ['init'], function(done) {
313311
try {
314312

315-
var nodeApp = fs.readFileSync('node-server/node-app.js', {
316-
encoding: 'utf8'
317-
});
313+
var nodeApp = fs.readFileSync('node-server/node-app.js', encoding);
318314

319315
//generate new uuid
320316
var secret = uuid.v4();
@@ -351,9 +347,7 @@ gulp.task('configGulp', ['init'], function(done) {
351347
configJSON['appusers-only'] = settings.appUsersOnly;
352348

353349
var configString = JSON.stringify(configJSON, null, 2) + '\n';
354-
fs.writeFileSync('local.json', configString, {
355-
encoding: 'utf8'
356-
});
350+
fs.writeFileSync('local.json', configString, encoding);
357351
} catch (e) {
358352
console.log('failed to write local.json: ' + e.message);
359353
}
@@ -374,33 +368,108 @@ gulp.task('init', ['checkForUpdates'], function(done) {
374368
var appType = clArgs.appType;
375369
var branch = clArgs.branch;
376370

377-
var prompts = [
378-
{type: 'list', name: 'mlVersion', message: 'MarkLogic version?', choices: ['8','7', '6', '5'], default: 0},
379-
{type: 'input', name: 'marklogicHost', message: 'MarkLogic Host?', default: 'localhost'},
380-
{type: 'input', name: 'marklogicAdminUser', message: 'MarkLogic Admin User?', default: 'admin'},
381-
{type: 'input', name: 'marklogicAdminPass', message: 'Note: consider keeping the following blank, ' +
382-
'you will be asked to enter it at appropriate commands.\n? MarkLogic Admin Password?', default: ''},
383-
{type: 'input', name: 'appPort', message: 'MarkLogic App/Rest port?', default: 8040},
384-
{type: 'input', name: 'xccPort', message: 'XCC port?', default:8041, when: function(answers){return answers.mlVersion < 8;} },
385-
{type: 'input', name: 'nodePort', message: 'Node app port?', default: 9070},
386-
{type:'list', name: 'template', message: 'Select Template', choices: [
387-
{ name: 'default', value: 'default' },
388-
{ name: '3-columns', value: '3column' },
389-
{ name: 'Dashboard', value: 'dashboard' },
390-
{ name: 'Full-screen map', value: 'map' },
391-
{ name: 'I don\'t know', value: 'unsure' }
392-
]},
393-
{type:'list', name: 'theme', message: 'What is the main focus?', when: function(ans) { return ans.template === 'unsure'; }, choices: [
394-
{ name: 'Semantics', value: '3column' },
395-
{ name: 'Charts', value: 'dashboard' },
396-
{ name: 'Map/Graph', value: 'map' },
397-
{ name: 'Documents', value: '3column' },
398-
{ name: 'Other', value: 'default' }
399-
]},
400-
{type: 'list', name: 'guestAccess', message: 'Allow anonymous users to search data?', choices: ['false', 'true'], default: 0},
401-
{type: 'list', name: 'disallowUpdates', message: 'Disallow proxying update requests?', choices: ['false', 'true'], default: 0},
402-
{type: 'list', name: 'appUsersOnly', message: 'Only allow access to users created for this app? Note: disallows admin users.', choices: ['false', 'true'], default: 0}
403-
];
371+
var prompts = [{
372+
type: 'list',
373+
name: 'mlVersion',
374+
message: 'MarkLogic version?',
375+
choices: ['8', '7', '6', '5'],
376+
default: 0
377+
}, {
378+
type: 'input',
379+
name: 'marklogicHost',
380+
message: 'MarkLogic Host?',
381+
default: 'localhost'
382+
}, {
383+
type: 'input',
384+
name: 'marklogicAdminUser',
385+
message: 'MarkLogic Admin User?',
386+
default: 'admin'
387+
}, {
388+
type: 'input',
389+
name: 'marklogicAdminPass',
390+
message: 'Note: consider keeping the following blank, ' +
391+
'you will be asked to enter it at appropriate commands.\n? MarkLogic Admin Password?',
392+
default: ''
393+
}, {
394+
type: 'input',
395+
name: 'appPort',
396+
message: 'MarkLogic App/Rest port?',
397+
default: 8040
398+
}, {
399+
type: 'input',
400+
name: 'xccPort',
401+
message: 'XCC port?',
402+
default: 8041,
403+
when: function(answers) {
404+
return answers.mlVersion < 8;
405+
}
406+
}, {
407+
type: 'input',
408+
name: 'nodePort',
409+
message: 'Node app port?',
410+
default: 9070
411+
}, {
412+
type: 'list',
413+
name: 'template',
414+
message: 'Select Template',
415+
choices: [{
416+
name: 'default',
417+
value: 'default'
418+
}, {
419+
name: '3-columns',
420+
value: '3column'
421+
}, {
422+
name: 'Dashboard',
423+
value: 'dashboard'
424+
}, {
425+
name: 'Full-screen map',
426+
value: 'map'
427+
}, {
428+
name: 'I don\'t know',
429+
value: 'unsure'
430+
}]
431+
}, {
432+
type: 'list',
433+
name: 'theme',
434+
message: 'What is the main focus?',
435+
when: function(ans) {
436+
return ans.template === 'unsure';
437+
},
438+
choices: [{
439+
name: 'Semantics',
440+
value: '3column'
441+
}, {
442+
name: 'Charts',
443+
value: 'dashboard'
444+
}, {
445+
name: 'Map/Graph',
446+
value: 'map'
447+
}, {
448+
name: 'Documents',
449+
value: '3column'
450+
}, {
451+
name: 'Other',
452+
value: 'default'
453+
}]
454+
}, {
455+
type: 'list',
456+
name: 'guestAccess',
457+
message: 'Allow anonymous users to search data?',
458+
choices: ['false', 'true'],
459+
default: 0
460+
}, {
461+
type: 'list',
462+
name: 'disallowUpdates',
463+
message: 'Disallow proxying update requests?',
464+
choices: ['false', 'true'],
465+
default: 0
466+
}, {
467+
type: 'list',
468+
name: 'appUsersOnly',
469+
message: 'Only allow access to users created for this app? Note: disallows admin users.',
470+
choices: ['false', 'true'],
471+
default: 0
472+
}];
404473

405474
if (typeof appName === 'undefined') {
406475
prompts.unshift({
@@ -449,18 +518,32 @@ gulp.task('init', ['checkForUpdates'], function(done) {
449518
file.basename = '.' + file.basename.slice(1);
450519
}
451520

452-
}))
453-
.pipe(replace('@slush-version', pkgSettings.version.trim(), {skipBinary:true}))
454-
.pipe(replace('@sample-app-name', answers.nameDashed, {skipBinary:true}))
455-
.pipe(replace('@sample-app-role', answers.nameDashed + '-role', {skipBinary:true}))
456-
.pipe(replace('@node-port', answers.nodePort, {skipBinary:true}))
457-
.pipe(replace('@ml-http-port', answers.appPort, {skipBinary:true}))
458-
.pipe(replace('@ml-xcc-port', answers.xccPort || answers.appPort, {skipBinary:true}))
459-
.pipe(replace('@ml-host', answers.marklogicHost, {skipBinary:true}))
460-
.pipe(gulp.dest('./')) // Relative to cwd
461-
.on('end', function () {
462-
done(); // Finished!
463-
});
521+
}))
522+
.pipe(replace('@slush-version', pkgSettings.version.trim(), {
523+
skipBinary: true
524+
}))
525+
.pipe(replace('@sample-app-name', answers.nameDashed, {
526+
skipBinary: true
527+
}))
528+
.pipe(replace('@sample-app-role', answers.nameDashed + '-role', {
529+
skipBinary: true
530+
}))
531+
.pipe(replace('@node-port', answers.nodePort, {
532+
skipBinary: true
533+
}))
534+
.pipe(replace('@ml-http-port', answers.appPort, {
535+
skipBinary: true
536+
}))
537+
.pipe(replace('@ml-xcc-port', answers.xccPort || answers.appPort, {
538+
skipBinary: true
539+
}))
540+
.pipe(replace('@ml-host', answers.marklogicHost, {
541+
skipBinary: true
542+
}))
543+
.pipe(gulp.dest('./')) // Relative to cwd
544+
.on('end', function() {
545+
done(); // Finished!
546+
});
464547
},
465548
function(reason) {
466549
console.log('Caught an error: ' + reason);

0 commit comments

Comments
 (0)