This repository has been archived by the owner on Jan 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgrove-demo.js
112 lines (104 loc) · 3.41 KB
/
grove-demo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
require('./src/init');
var util = require('util');
const program = require('commander');
const childProcess = require('child_process');
const spawn = require('cross-spawn');
const chalk = require('chalk');
var confirmAppName = require('./src/confirmAppName');
var createNew = require('./src/createNew');
var runConfig = require('./src/runConfig');
var utils = require('./src/utils');
const logger = require('./src/utils/logger');
const log = (command, info) => {
if (!info) return;
logger.info(`\nstdout for ${command}:\n${info.stdout}`);
if (info.stderr) {
logger.error(`\nstderr for ${command}:\n${info.stderr}`);
}
};
program
.option('-C, --confirmAppName', 'Confirm appName without interactive prompt')
.option(
'-t, --template <template>',
'Specify a template by id. Current choices: grove-react-template, grove-vue-template'
)
.option(
'-r, --templateRelease <templateRelease>',
'Use a specific version of the template, if available'
)
.option(
'-H, --mlHost <mlHost>',
'The host on which your MarkLogic REST server is available'
)
.option(
'-P, --mlRestPort <mlRestPort>',
'The port on which your MarkLogic REST server is available'
)
.option(
'-p, --nodePort <nodePort>',
'The port on which your Grove Node server will listen'
)
.option(
'-g, --git <gitOption>',
'By default, the cli will initialize a new git repo with an initial commit, unless you are generating within an existing git or mercurial repo. Specify "false" to prevent this. Specify "keep" to maintain upstream git remotes pointing to Grove core repos.'
)
.parse(process.argv);
confirmAppName(program)
.then(mlAppName => {
const config = { mlAppName };
return createNew({ config, program });
})
.then(() => {
const npmInstallPromise = util
.promisify(childProcess.exec)('npm install')
.then(output => log('npm install', output));
console.log(
chalk.cyan(
"\nWhile we are provisioning your app, which might take a while, let's be sure we have all the information we need for the next step."
)
);
const config = {
mlHost: program.mlHost,
mlRestPort: program.mlRestPort,
nodePort: program.nodePort
};
const runConfigPromise = runConfig({ config });
return Promise.all([npmInstallPromise, runConfigPromise]);
})
.then(() => {
console.log(chalk.cyan('\nProvisioning your MarkLogic database ...'));
process.chdir('marklogic');
return util.promisify(childProcess.exec)(
utils.gradleExecutable() + ' mlDeploy'
);
})
.then(output => log('mlDeploy', output))
.then(() => {
console.log(chalk.cyan('\nLoading sample data ...'));
return util.promisify(childProcess.exec)(
utils.gradleExecutable() + ' loadSampleData'
);
})
.then(output => log('loadSampleData', output))
.then(() => {
process.chdir('..');
console.log(
chalk.cyan(
'\nRunning your project. See grove-cli.log for logs. Hit <Ctrl-C> to terminate.'
)
);
const runningApp = spawn('npm', ['start']);
runningApp.stdout.on('data', function(data) {
logger.info(data.toString());
});
runningApp.stderr.on('data', function(data) {
logger.error(data.toString());
});
runningApp.on('exit', function(code) {
console.log(
chalk.red('Your Project exited with code ' + code.toString())
);
process.exit(1);
});
})
.catch(utils.handleError);