-
Notifications
You must be signed in to change notification settings - Fork 79
/
index.js
220 lines (198 loc) · 11 KB
/
index.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
/* eslint-disable consistent-return */
const chalk = require('chalk');
const ServerGenerator = require('generator-jhipster/generators/server');
const jhipsterConstants = require('generator-jhipster/generators/generator-constants');
const os = require('os');
const jhipsterNodeConstants = require('../generator-nodejs-constants');
const packagejs = require('../../package.json');
const writeFiles = require('./files').writeFiles;
const prompts = require('./prompts');
module.exports = class extends ServerGenerator {
constructor(args, opts) {
super(args, Object.assign({ fromBlueprint: true }, opts)); // fromBlueprint variable is important
const jhContext = (this.jhipsterContext = this.options.jhipsterContext);
if (!jhContext) {
this.error(`This is a JHipster blueprint and should be used only like ${chalk.yellow('jhipster --blueprint nodejs')}`);
}
this.configOptions = jhContext.configOptions || {};
// This sets up options for this sub generator and is being reused from JHipster
jhContext.setupServerOptions(this, jhContext);
}
get initializing() {
const initPhaseFromJHipster = super._initializing();
const jhipsterInitNodePhaseSteps = {
/* eslint-disable */
displayNHipsterLogo() {
this.log('\n');
this.log(`${chalk.yellow(' ███╗ ██╗')}${chalk.green(' ██╗ ██╗ ████████╗ ███████╗ ██████╗ ████████╗ ████████╗ ███████╗')}`);
this.log(`${chalk.yellow(' ████╗ ██║')}${chalk.green(' ██║ ██║ ╚══██╔══╝ ██╔═══██╗ ██╔════╝ ╚══██╔══╝ ██╔═════╝ ██╔═══██╗')}`);
this.log(`${chalk.yellow(' ██╔██╗ ██║')}${chalk.green(' ████████║ ██║ ███████╔╝ ╚█████╗ ██║ ██████╗ ███████╔╝')}`);
this.log(`${chalk.yellow(' ██║╚██╗██║')}${chalk.green(' ██╔═══██║ ██║ ██╔════╝ ╚═══██╗ ██║ ██╔═══╝ ██╔══██║')}`);
this.log(`${chalk.yellow(' ██║ ╚████║')}${chalk.green(' ██║ ██║ ████████╗ ██║ ██████╔╝ ██║ ████████╗ ██║ ╚██╗')}`);
this.log(`${chalk.yellow(' ╚═╝ ╚═══╝')}${chalk.green(' ╚═╝ ╚═╝ ╚═══════╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══════╝ ╚═╝ ╚═╝')}\n`);
this.log(chalk.white.bold(' https://www.jhipster.tech\n'));
this.log(chalk.white('Welcome to NHipster (Jhipster NodeJS Official Blueprint) ') + chalk.yellow(`v${packagejs.version}`));
this.log(chalk.white('This blueprint generates your backend in NodeJS with NestJS framework'));
this.log(
chalk.green(
' _______________________________________________________________________________________________________________\n'
)
);
this.log(
chalk.white(
` For any questions or improvements refer to the stream lead at ${chalk.yellow('https://github.com/amanganiello90')}`
)
);
this.log(
chalk.white(
` If you find NHipster useful, support and star the project at ${chalk.yellow(
'https://github.com/jhipster/generator-jhipster-nodejs'
)}`
)
);
this.log(
chalk.green(
' _______________________________________________________________________________________________________________\n'
)
);
this.log(
chalk.green.bold(
' This NodeJS blueprint use these following configurations:\n'
)
);
this.log(
chalk.green.bold(
' 1. NestJS Framework with swagger doc\n'
)
);
this.log(
chalk.green.bold(
' 2. JWT Passport security authentication\n'
)
);
this.log(
chalk.green.bold(
' 3. TypeORM usage with SQLite development database\n'
)
);
this.log(
chalk.green.bold(
' 4. Initial load data seed with users (using auth roles) integrated with the angular client (monolithic application type)\n'
)
);
this.log(
chalk.green.bold(
' 5. Eureka JS client registry\n'
)
);
},
setupNodeServerconsts() {
this.packageName = jhipsterNodeConstants.PACKAGE_NAME_NODEJS;
this.cacheProvider = jhipsterNodeConstants.CACHE_PROVIDER_NODEJS;
this.enableHibernateCache = jhipsterNodeConstants.ENABLE_HIBERNATE_CACHE_NODEJS;
this.websocket = jhipsterNodeConstants.WEB_SOCKET_NODEJS;
this.databaseType = jhipsterNodeConstants.DATABASE_TYPE_NODEJS;
this.devDatabaseType = jhipsterNodeConstants.DEV_DATABASE_TYPE_NODEJS;
this.prodDatabaseType = jhipsterNodeConstants.PROD_DATABASE_TYPE_NODEJS;
this.searchEngine = jhipsterNodeConstants.SEARCH_ENGINE_NODEJS;
this.messageBroker = jhipsterNodeConstants.MESSAGE_BROKER_NODEJS;
this.serviceDiscoveryType = jhipsterNodeConstants.SERVICE_DISCOVERY_TYPE_NODEJS;
this.buildTool = jhipsterNodeConstants.BUILD_TOOL_NODEJS;
this.enableSwaggerCodegen = jhipsterNodeConstants.ENABLE_SWAGGER_CODEGEN_NODEJS;
this.authenticationType = jhipsterNodeConstants.AUTHENTICATION_TYPE_NODEJS;
this.testFrameworks =[];
/*
const configuration = this.getAllJhipsterConfig(this, true);
this.mongoProdDatabase = configuration.get('mongoProdDatabase');
*/
}
};
/* eslint-enable */
return Object.assign(initPhaseFromJHipster, jhipsterInitNodePhaseSteps);
// return initPhaseFromJHipster;
}
get prompting() {
// The prompting phase is being overriden so that we can ask our own questions
return {
askForModuleName: prompts.askForModuleName,
askForMainServerSideOpts: prompts.askForMainServerSideOpts,
setSharedNodeConfigOptions() {
this.configOptions.serverPort = this.serverPort;
this.configOptions.baseName = this.baseName;
this.configOptions.packageName = this.packageName;
this.configOptions.cacheProvider = this.cacheProvider;
this.configOptions.enableHibernateCache = this.enableHibernateCache;
this.configOptions.websocket = this.websocket;
this.configOptions.databaseType = this.databaseType;
this.configOptions.devDatabaseType = this.devDatabaseType;
this.configOptions.prodDatabaseType = this.prodDatabaseType;
this.configOptions.searchEngine = this.searchEngine;
this.configOptions.messageBroker = this.messageBroker;
this.configOptions.serviceDiscoveryType = this.serviceDiscoveryType;
this.configOptions.buildTool = this.buildTool;
this.configOptions.enableSwaggerCodegen = this.enableSwaggerCodegen;
this.configOptions.authenticationType = this.authenticationType;
this.configOptions.testFrameworks = this.testFrameworks;
// Make dist dir available in templates
this.BUILD_DIR = this.getBuildDirectoryForBuildTool(this.configOptions.buildTool);
this.CLIENT_DIST_DIR =
this.getResourceBuildDirectoryForBuildTool(this.configOptions.buildTool) + jhipsterConstants.CLIENT_DIST_DIR;
}
};
// If the prompts need to be overriden then use the code commented out above instead
// return super._prompting();
}
get configuring() {
const confPhaseFromJHipster = super._configuring();
const jhipsterConfigNodeSteps = {
jhipsterNodeSaveConfig() {
const config = {
databaseType: this.databaseType,
devDatabaseType: this.devDatabaseType,
prodDatabaseType: this.prodDatabaseType
};
this.config.set(config);
}
};
return Object.assign(confPhaseFromJHipster, jhipsterConfigNodeSteps);
// Here we are not overriding this phase and hence its being handled by JHipster
// return confPhaseFromJHipster;
}
get default() {
// Here we are not overriding this phase and hence its being handled by JHipster
return super._default();
}
get writing() {
// The writing phase is being overriden so that we can write our own templates as well.
return writeFiles();
}
get install() {
// Here we are not overriding this phase and hence its being handled by JHipster
return super._install();
}
get end() {
return {
jhipsterNodeEnd() {
this.log(chalk.green.bold('\nServer application generated successfully.\n'));
const executable = 'mvnw clean package -Pdev';
let logMsgComment = '';
const java = 'JAVA';
const serverREADME = 'server/README';
if (os.platform() === 'win32') {
logMsgComment = ` (${chalk.yellow.bold(executable)} if using Windows Command Prompt)`;
}
this.log(
chalk.green(
`Run your application:\n${chalk.yellow.bold(
`./${executable}`
)}${logMsgComment}.\n Otherwise, If you don't have ${chalk.yellow.bold(
java
)} installed, run the npm scripts explained under ${chalk.yellow.bold(serverREADME)}`
)
);
}
};
// Here we are not overriding this phase and hence its being handled by JHipster
// return super._end();
}
};