forked from jhipster/generator-jhipster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script-base.js
74 lines (67 loc) · 2.99 KB
/
script-base.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
'use strict';
var path = require('path'),
util = require('util'),
yeoman = require('yeoman-generator'),
jhipsterUtils = require('./util.js');
module.exports = Generator;
function Generator() {
yeoman.generators.NamedBase.apply(this, arguments);
this.env.options.appPath = this.config.get('appPath') || 'src/main/webapp';
}
util.inherits(Generator, yeoman.generators.NamedBase);
Generator.prototype.addScriptToIndex = function (script) {
try {
var appPath = this.env.options.appPath;
var fullPath = path.join(appPath, 'index.html');
jhipsterUtils.rewriteFile({
file: fullPath,
needle: '<!-- endbuild -->',
splicable: [
'<script src="scripts/' + script + '"></script>'
]
});
} catch (e) {
console.log('\nUnable to find '.yellow + fullPath + '. Reference to '.yellow + script + '.js ' + 'not added.\n'.yellow);
}
};
Generator.prototype.addRouterToMenu = function (entityName) {
try {
var appPath = this.env.options.appPath;
var fullPath = path.join(appPath, 'index.html');
jhipsterUtils.rewriteFile({
file: fullPath,
needle: '<!-- JHipster will add entities to the menu here -->',
splicable: [
'<li ng-switch-when="true"><a href="#/' + entityName + '"><span class="glyphicon glyphicon-asterisk"></span> ' + entityName + '</a></li>'
]
});
} catch (e) {
console.log('\nUnable to find '.yellow + fullPath + '. Reference to '.yellow + entityName + '.js ' + 'not added.\n'.yellow);
}
};
Generator.prototype.addChangelogToLiquibase = function (changelogName) {
try {
var appPath = this.env.options.appPath;
var fullPath = path.join(appPath, '../resources/config/liquibase/master.xml');
jhipsterUtils.rewriteFile({
file: fullPath,
needle: '<!-- JHipster will add liquibase changelogs here -->',
splicable: [
'<include file="classpath:config/liquibase/changelog/' + changelogName + '.xml" relativeToChangelogFile="false"/>'
]
});
} catch (e) {
console.log('\nUnable to find '.yellow + fullPath + '. Reference to '.yellow + changelogName + '.js ' + 'not added.\n'.yellow);
}
};
// This generates a date to be used by Liquibase changelogs
Generator.prototype.dateFormatForLiquibase = function (script) {
var now = new Date();
var year = "" + now.getFullYear();
var month = "" + (now.getMonth() + 1); if (month.length == 1) { month = "0" + month; }
var day = "" + now.getDate(); if (day.length == 1) { day = "0" + day; }
var hour = "" + now.getHours(); if (hour.length == 1) { hour = "0" + hour; }
var minute = "" + now.getMinutes(); if (minute.length == 1) { minute = "0" + minute; }
var second = "" + now.getSeconds(); if (second.length == 1) { second = "0" + second; }
return year + "" + month + "" + day + "" + hour + "" + minute + "" + second;
}