-
Notifications
You must be signed in to change notification settings - Fork 29
/
index.js
133 lines (120 loc) · 5.08 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
/* eslint-disable consistent-return */
const _ = require('lodash');
const chalk = require('chalk');
const ClientGenerator = require('generator-jhipster/generators/client');
const jhipsterConstants = require('generator-jhipster/generators/generator-constants');
const angularFiles = require('./files-angular');
const reactFiles = require('./files-react');
const mtUtils = require('../multitenancy-utils');
module.exports = class extends ClientGenerator {
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 multitenancy')}`);
}
this.configOptions = jhContext.configOptions || {};
// This sets up options for this sub generator and is being reused from JHipster
jhContext.setupClientOptions(this, jhContext);
}
get initializing() {
/**
* Any method beginning with _ can be reused from the superclass `ClientGenerator`
*
* There are multiple ways to customize a phase from JHipster.
*
* 1. Let JHipster handle a phase, blueprint doesnt override anything.
* ```
* return super._initializing();
* ```
*
* 2. Override the entire phase, this is when the blueprint takes control of a phase
* ```
* return {
* myCustomInitPhaseStep() {
* // Do all your stuff here
* },
* myAnotherCustomInitPhaseStep(){
* // Do all your stuff here
* }
* };
* ```
*
* 3. Partially override a phase, this is when the blueprint gets the phase from JHipster and customizes it.
* ```
* const phaseFromJHipster = super._initializing();
* const myCustomPhaseSteps = {
* displayLogo() {
* // override the displayLogo method from the _initializing phase of JHipster
* },
* myCustomInitPhaseStep() {
* // Do all your stuff here
* },
* }
* return Object.assign(phaseFromJHipster, myCustomPhaseSteps);
* ```
*/
// Here we are not overriding this phase and hence its being handled by JHipster
return super._initializing();
}
get prompting() {
// Here we are not overriding this phase and hence its being handled by JHipster
return super._prompting();
}
get configuring() {
// Here we are not overriding this phase and hence its being handled by JHipster
return super._configuring();
}
get default() {
// Here we are not overriding this phase and hence its being handled by JHipster
return super._default();
}
get writing() {
const writing = super._writing();
const myCustomPhaseSteps = {
// sets up all the variables we'll need for the templating
setUpVariables() {
// Ok
this.webappDir = jhipsterConstants.CLIENT_MAIN_SRC_DIR;
this.angularDir = jhipsterConstants.ANGULAR_DIR;
this.reactDir = jhipsterConstants.REACT_DIR;
this.CLIENT_TEST_SRC_DIR = jhipsterConstants.CLIENT_TEST_SRC_DIR;
// template variables
mtUtils.tenantVariables(this.config.get('tenantName'), this);
},
writeAdditionalFile() {
// make the necessary client code changes and adds the tenant UI
switch (this.clientFramework) {
case 'angularX':
return angularFiles.writeFiles.call(this);
case 'react':
return reactFiles.writeFiles.call(this);
default:
return angularFiles.writeFiles.call(this);
}
},
rewriteExistingFiles() {
// Rewrites to existing files
switch (this.clientFramework) {
case 'angularX':
mtUtils.processPartialTemplates(angularFiles.templates(this), this);
break;
case 'react':
mtUtils.processPartialTemplates(reactFiles.templates(this), this);
break;
default:
mtUtils.processPartialTemplates(angularFiles.templates(this), this);
}
}
};
return Object.assign(writing, myCustomPhaseSteps);
}
get install() {
// Here we are not overriding this phase and hence its being handled by JHipster
return super._install();
}
get end() {
// Here we are not overriding this phase and hence its being handled by JHipster
return super._end();
}
};