This repository has been archived by the owner on Apr 9, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 29
/
_index.js
111 lines (95 loc) · 4.06 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
const chalk = require('chalk');
const BaseGenerator = require('generator-jhipster/generators/generator-base');
const jhipsterConstants = require('generator-jhipster/generators/generator-constants');
const packagejs = require('../../package.json');
module.exports = class extends BaseGenerator {
get initializing() {
return {
readConfig() {
this.entityConfig = this.options.entityConfig;
this.jhipsterAppConfig = this.getAllJhipsterConfig();
if (!this.jhipsterAppConfig) {
this.error('Cannot read .yo-rc.json');
}
},
displayLogo() {
this.log(chalk.white(`Running ${chalk.bold('JHipster rain')} Generator! ${chalk.yellow(`v${packagejs.version}\n`)}`));
},
validate() {
// this shouldn't be run directly
if (!this.entityConfig) {
this.env.error(`${chalk.red.bold('ERROR!')} This sub generator should be used only from JHipster and cannot be run directly...\n`);
}
}
};
}
prompting() {
// don't prompt if data are imported from a file
if (this.entityConfig.useConfigurationFile === true && this.entityConfig.data && typeof this.entityConfig.data.yourOptionKey !== 'undefined') {
this.yourOptionKey = this.entityConfig.data.yourOptionKey;
return;
}
const done = this.async();
const prompts = [
{
type: 'confirm',
name: 'enableOption',
message: 'Some option here?',
default: false
}
];
this.prompt(prompts).then((props) => {
this.props = props;
// To access props later use this.props.someOption;
done();
});
}
get writing() {
return {
updateFiles() {
// read config from .yo-rc.json
this.baseName = this.jhipsterAppConfig.baseName;
this.packageName = this.jhipsterAppConfig.packageName;
this.packageFolder = this.jhipsterAppConfig.packageFolder;
this.clientFramework = this.jhipsterAppConfig.clientFramework;
this.clientPackageManager = this.jhipsterAppConfig.clientPackageManager;
this.buildTool = this.jhipsterAppConfig.buildTool;
// use function in generator-base.js from generator-jhipster
this.angularAppName = this.getAngularAppName();
// use constants from generator-constants.js
const javaDir = `${jhipsterConstants.SERVER_MAIN_SRC_DIR + this.packageFolder}/`;
const resourceDir = jhipsterConstants.SERVER_MAIN_RES_DIR;
const webappDir = jhipsterConstants.CLIENT_MAIN_SRC_DIR;
const entityName = this.entityConfig.entityClass;
// show all variables
this.log('\n--- some const ---');
this.log(`javaDir=${javaDir}`);
this.log(`resourceDir=${resourceDir}`);
this.log(`webappDir=${webappDir}`);
this.log('\n--- entityName ---');
this.log(`\nentityName=${entityName}`);
this.log('------\n');
// do your stuff here
},
writeFiles() {
// function to use directly template
this.template = function (source, destination) {
this.fs.copyTpl(
this.templatePath(source),
this.destinationPath(destination),
this
);
};
this.template('dummy.txt', 'dummy.txt', this, {});
},
updateConfig() {
this.updateEntityConfig(this.entityConfig.filename, 'yourOptionKey', this.yourOptionKey);
}
};
}
end() {
if (this.yourOptionKey) {
this.log(`\n${chalk.bold.green('rain enabled')}`);
}
}
};