-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
72 lines (69 loc) · 2.5 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
var Generator = require('yeoman-generator');
var jsyaml = require("js-yaml");
const OPTION_BLUEMIX = "bluemix";
const OPTION_STARTER = "starter";
const OPTION_BACKEND_PLATFORM = "bp";
const OPTION_DEBUG = "debug";
module.exports = class extends Generator {
constructor(args, opts) {
super(args, opts);
console.log(">> Constructor");
this.option(OPTION_BLUEMIX, {
description: "Project configuration received from Scaffolder. Stringified JSON object.",
type: String
});
this.option(OPTION_STARTER, {
description: "Generator options received from Scaffolder, as defined in blueprint.json. Stringified JSON object.",
type: String
});
this.option(OPTION_BACKEND_PLATFORM, {
description: "Use this option to override the backendPlatform value received from Scaffolder",
type: String
});
this.option(OPTION_DEBUG, {
description: "Use this option to print options object passed to the generator",
type: Boolean
});
this._sanitizeOption(this.options, OPTION_BLUEMIX);
this._sanitizeOption(this.options, OPTION_STARTER);
var projectConfig = this.options.bluemix || {};
projectConfig.hasServer = projectConfig.hasOwnProperty("server") && projectConfig.server;
projectConfig.backendPlatform = this.options.bp || projectConfig.backendPlatform || "JAVA";
var platform = projectConfig.backendPlatform.toLowerCase();
if (projectConfig.hasServer) {
projectConfig.server.organization = projectConfig.server.organization || "antonal";
}
this._generateSampleFiles(platform, projectConfig);
}
_sanitizeOption(options, name) {
if (!options[name]) {
console.log("--" + name + " parameter was not used. Loading data from default_" + name + ".js");
this.options[name] = JSON.parse(require("./default_" + name));
} else {
try {
this.options[name] = typeof(this.options[name]) === "string" ?
JSON.parse(this.options[name]) : this.options[name];
} catch (e) {
throw "--" + name + " parameter is expected to be a valid stringified JSON object";
}
}
}
_generateSampleFiles(platform, projectConfig) {
console.log("_generateKubeFiles :: platform ::", platform);
console.log("_generateKubeFiles :: projectConfig ::", JSON.stringify(projectConfig));
if (!projectConfig.hasServer) {
console.warn("No server configuration received. Skipping.");
return;
}
this.fs.copy(
this.templatePath("**/*"),
this.destinationPath(".")
);
this.fs.copyTpl(
this.templatePath("Liberty/"),
this.destinationPath("Liberty/"),
projectConfig
);
}
method() {}
};