generator-easy-ui5 3.1.5 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/generators/app/index.js +138 -44
- package/package.json +8 -7
package/generators/app/index.js
CHANGED
|
@@ -14,6 +14,18 @@ const { throttling } = require("@octokit/plugin-throttling");
|
|
|
14
14
|
const MyOctokit = Octokit.plugin(throttling);
|
|
15
15
|
const AdmZip = require("adm-zip");
|
|
16
16
|
|
|
17
|
+
// helper to retrieve config entries from npm
|
|
18
|
+
// --> npm config set easy-ui5_addGhOrg XYZ
|
|
19
|
+
const NPM_CONFIG_PREFIX = "easy-ui5_";
|
|
20
|
+
let npmConfig;
|
|
21
|
+
const getNPMConfig = (configName) => {
|
|
22
|
+
if (!npmConfig) {
|
|
23
|
+
npmConfig = require("libnpmconfig").read();
|
|
24
|
+
}
|
|
25
|
+
return npmConfig && npmConfig[`${NPM_CONFIG_PREFIX}${configName}`]
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// the command line options of the generator
|
|
17
29
|
const generatorOptions = {
|
|
18
30
|
ghAuthToken: {
|
|
19
31
|
type: String,
|
|
@@ -24,7 +36,26 @@ const generatorOptions = {
|
|
|
24
36
|
type: String,
|
|
25
37
|
description: "GitHub organization to lookup for available generators",
|
|
26
38
|
default: "ui5-community",
|
|
27
|
-
|
|
39
|
+
hide: true // we don't want to recommend to use this option
|
|
40
|
+
},
|
|
41
|
+
subGeneratorPrefix: {
|
|
42
|
+
type: String,
|
|
43
|
+
description: "Prefix used for the lookup of the available generators",
|
|
44
|
+
default: "generator-ui5-",
|
|
45
|
+
hide: true // we don't want to recommend to use this option
|
|
46
|
+
},
|
|
47
|
+
addGhOrg: {
|
|
48
|
+
type: String,
|
|
49
|
+
description: `GitHub organization to lookup for additional available generators`,
|
|
50
|
+
hide: true, // we don't want to recommend to use this option
|
|
51
|
+
npmConfig: true
|
|
52
|
+
},
|
|
53
|
+
addSubGeneratorPrefix: {
|
|
54
|
+
type: String,
|
|
55
|
+
description: `Prefix used for the lookup of the additional available generators`,
|
|
56
|
+
default: "generator-",
|
|
57
|
+
hide: true, // we don't want to recommend to use this option
|
|
58
|
+
npmConfig: true
|
|
28
59
|
},
|
|
29
60
|
list: {
|
|
30
61
|
type: Boolean,
|
|
@@ -71,12 +102,14 @@ module.exports = class extends Generator {
|
|
|
71
102
|
});
|
|
72
103
|
|
|
73
104
|
Object.keys(generatorOptions).forEach((optionName) => {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
105
|
+
const initialValue = this.options[optionName];
|
|
106
|
+
// register the option for being displayed in the help
|
|
107
|
+
this.option(optionName, generatorOptions[optionName]);
|
|
108
|
+
const defaultedValue = this.options[optionName];
|
|
109
|
+
if (generatorOptions[optionName].npmConfig) {
|
|
110
|
+
// if a value is set, use the set value (parameter has higher precedence than npm config)
|
|
111
|
+
// => this.option(...) applies the default value to this.options[...] used as last resort
|
|
112
|
+
this.options[optionName] = initialValue || getNPMConfig(optionName) || defaultedValue;
|
|
80
113
|
}
|
|
81
114
|
});
|
|
82
115
|
}
|
|
@@ -105,30 +138,50 @@ module.exports = class extends Generator {
|
|
|
105
138
|
|
|
106
139
|
async prompting() {
|
|
107
140
|
|
|
141
|
+
this.log(yosay(`Welcome to the ${chalk.red("easy-ui5")} generator!`));
|
|
142
|
+
|
|
143
|
+
const home = path.join(__dirname, "..", "..");
|
|
144
|
+
|
|
145
|
+
// check the permissions to Easy UI5s plugin directory which must
|
|
146
|
+
// allow read/write to install additional plugin generators
|
|
147
|
+
let pluginsHome = path.join(home, "plugin-generators");
|
|
148
|
+
try {
|
|
149
|
+
fs.accessSync(pluginsHome, fs.constants.R_OK | fs.constants.W_OK);
|
|
150
|
+
} catch (e) {
|
|
151
|
+
pluginsHome = path.join(require("os").homedir(), ".npm", "_generator-easy-ui5", "plugin-generators");
|
|
152
|
+
if (this.options.verbose) {
|
|
153
|
+
console.error(`Plugin directory: ${chalk.green(pluginsHome)}`);
|
|
154
|
+
console.error(chalk.red(e.message));
|
|
155
|
+
}
|
|
156
|
+
fs.mkdirSync(pluginsHome, { recursive: true });
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// log the plugins and configuration
|
|
108
160
|
if (this.options.plugins) {
|
|
109
161
|
const glob = require("glob");
|
|
110
162
|
const yeoman = require("yeoman-environment/package.json");
|
|
111
|
-
const home = __dirname.slice(0, -14);
|
|
112
163
|
|
|
113
164
|
const components = {
|
|
114
165
|
"Node.js": process.version,
|
|
166
|
+
"yeoman-environment": yeoman.version,
|
|
167
|
+
"generator-easy-ui5": require(path.join(home, "package.json")).version,
|
|
115
168
|
"home": home,
|
|
116
|
-
"
|
|
169
|
+
"pluginsHome": pluginsHome,
|
|
117
170
|
};
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
components[name] = lib.version;
|
|
171
|
+
|
|
172
|
+
Object.keys(components).forEach((component) => {
|
|
173
|
+
this.log(`${chalk.green(component)}: ${components[component]}`);
|
|
122
174
|
});
|
|
123
175
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
176
|
+
this.log(chalk.green("\nAvailable generators:"));
|
|
177
|
+
glob.sync(`${pluginsHome}/*/package.json`).forEach((plugin) => {
|
|
178
|
+
const name = plugin.match(/.*\/(.+)\/package\.json/)[1];
|
|
179
|
+
const lib = require(plugin);
|
|
180
|
+
this.log(` - ${chalk.green(name)}: ${lib.version}`);
|
|
127
181
|
});
|
|
128
|
-
;
|
|
129
|
-
}
|
|
130
182
|
|
|
131
|
-
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
132
185
|
|
|
133
186
|
// create the octokit client to retrieve the generators from GH org
|
|
134
187
|
const octokit = new MyOctokit({
|
|
@@ -156,19 +209,68 @@ module.exports = class extends Generator {
|
|
|
156
209
|
}
|
|
157
210
|
});
|
|
158
211
|
|
|
212
|
+
// helper for filtering repos with corresponding subGenerator prefix
|
|
213
|
+
const filterReposWithSubGeneratorPrefix = (repos, subGeneratorPrefix) => {
|
|
214
|
+
if (!Array.isArray(repos)) {
|
|
215
|
+
return [];
|
|
216
|
+
}
|
|
217
|
+
return repos.filter((repo) =>
|
|
218
|
+
repo.name.startsWith(`${subGeneratorPrefix}`)
|
|
219
|
+
).map((repo) => {
|
|
220
|
+
return {
|
|
221
|
+
org: repo.owner?.login,
|
|
222
|
+
name: repo.name,
|
|
223
|
+
branch: repo.default_branch,
|
|
224
|
+
subGeneratorName: repo.name.substring(subGeneratorPrefix.length),
|
|
225
|
+
};
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// helper to retrieve the available repositories for a GH org
|
|
230
|
+
const listGeneratorsForOrg = async (ghOrg, subGeneratorPrefix) => {
|
|
231
|
+
const response = await octokit.repos.listForOrg({
|
|
232
|
+
org: ghOrg,
|
|
233
|
+
});
|
|
234
|
+
return filterReposWithSubGeneratorPrefix(response?.data, subGeneratorPrefix);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// helper to retrieve the available repositories for a GH user
|
|
238
|
+
const listGeneratorsForUser = async (ghUser, subGeneratorPrefix) => {
|
|
239
|
+
const response = await octokit.repos.listForUser({
|
|
240
|
+
username: ghUser,
|
|
241
|
+
});
|
|
242
|
+
return filterReposWithSubGeneratorPrefix(response?.data, subGeneratorPrefix);
|
|
243
|
+
}
|
|
244
|
+
|
|
159
245
|
// retrieve the available repositories
|
|
160
|
-
let
|
|
246
|
+
let availGenerators;
|
|
161
247
|
try {
|
|
162
|
-
|
|
163
|
-
org: this.options.ghOrg,
|
|
164
|
-
});
|
|
248
|
+
availGenerators = await listGeneratorsForOrg(this.options.ghOrg, this.options.subGeneratorPrefix);
|
|
165
249
|
} catch (e) {
|
|
166
|
-
console.error(`Failed to connect to GitHub to retrieve available
|
|
250
|
+
console.error(`Failed to connect to GitHub to retrieve available generators for "${this.options.ghOrg}" organization! Run with --verbose for details!`);
|
|
167
251
|
if (this.options.verbose) {
|
|
168
252
|
console.error(e);
|
|
169
253
|
}
|
|
170
254
|
return;
|
|
171
255
|
}
|
|
256
|
+
try {
|
|
257
|
+
if (this.options.addGhOrg && this.options.addSubGeneratorPrefix) {
|
|
258
|
+
availGenerators = availGenerators.concat(await listGeneratorsForOrg(this.options.addGhOrg, this.options.addSubGeneratorPrefix));
|
|
259
|
+
}
|
|
260
|
+
} catch (e) {
|
|
261
|
+
if (this.options.verbose) {
|
|
262
|
+
this.log(`Failed to connect to GitHub retrieve additional generators for "${this.options.addGhOrg}" organization! Try to retrieve for user...`);
|
|
263
|
+
}
|
|
264
|
+
try {
|
|
265
|
+
availGenerators = availGenerators.concat(await listGeneratorsForUser(this.options.addGhOrg, this.options.addSubGeneratorPrefix));
|
|
266
|
+
} catch (e) {
|
|
267
|
+
console.error(`Failed to connect to GitHub to retrieve additional generators for organization or user "${this.options.addGhOrg}"! Run with --verbose for details!`);
|
|
268
|
+
if (this.options.verbose) {
|
|
269
|
+
console.error(e);
|
|
270
|
+
}
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
172
274
|
|
|
173
275
|
// download the generator from GH (or the test generator)
|
|
174
276
|
let generatorPath;
|
|
@@ -180,11 +282,9 @@ module.exports = class extends Generator {
|
|
|
180
282
|
} else {
|
|
181
283
|
|
|
182
284
|
// check for provided generator being available on GH
|
|
183
|
-
let generator =
|
|
184
|
-
this.options.generator
|
|
185
|
-
|
|
186
|
-
(repo) => repo.name === `generator-ui5-${this.options.generator}`
|
|
187
|
-
);
|
|
285
|
+
let generator = this.options.generator && availGenerators.find((repo) =>
|
|
286
|
+
repo.subGeneratorName === this.options.generator
|
|
287
|
+
);
|
|
188
288
|
|
|
189
289
|
// if no generator is provided and doesn't exist, ask for generator name
|
|
190
290
|
if (!generator) {
|
|
@@ -195,37 +295,35 @@ module.exports = class extends Generator {
|
|
|
195
295
|
)} was not found. Please select an existing generator!`
|
|
196
296
|
);
|
|
197
297
|
}
|
|
198
|
-
|
|
199
|
-
/^generator-ui5-.+/.test(repo.name)
|
|
200
|
-
);
|
|
298
|
+
|
|
201
299
|
const generatorIdx = (
|
|
202
300
|
await this.prompt([
|
|
203
301
|
{
|
|
204
302
|
type: "list",
|
|
205
303
|
name: "generator",
|
|
206
304
|
message: "Select your generator?",
|
|
207
|
-
choices:
|
|
208
|
-
name:
|
|
305
|
+
choices: availGenerators.map((availGenerator, idx) => ({
|
|
306
|
+
name: `${availGenerator.subGeneratorName}${this.options.addGhOrg ? ` [${availGenerator.org}]` : ""}`,
|
|
209
307
|
value: idx,
|
|
210
308
|
})),
|
|
211
309
|
},
|
|
212
310
|
])
|
|
213
311
|
).generator;
|
|
214
|
-
generator =
|
|
312
|
+
generator = availGenerators[generatorIdx];
|
|
215
313
|
}
|
|
216
314
|
|
|
217
315
|
// fetch the available branches to retrieve the latest commit SHA
|
|
218
316
|
let reqBranch;
|
|
219
317
|
try {
|
|
220
318
|
reqBranch = await octokit.repos.getBranch({
|
|
221
|
-
owner:
|
|
319
|
+
owner: generator.org,
|
|
222
320
|
repo: generator.name,
|
|
223
|
-
branch: generator.
|
|
321
|
+
branch: generator.branch,
|
|
224
322
|
});
|
|
225
323
|
} catch (e) {
|
|
226
|
-
console.error(`Failed to retrieve the default branch for repository "${generator.name}" for "${this.options.ghOrg}" organization! Run with --verbose for details!`);
|
|
324
|
+
console.error(chalk.red(`Failed to retrieve the default branch for repository "${generator.name}" for "${this.options.ghOrg}" organization! Run with --verbose for details!`));
|
|
227
325
|
if (this.options.verbose) {
|
|
228
|
-
console.error(e);
|
|
326
|
+
console.error(chalk.red(e.message));
|
|
229
327
|
}
|
|
230
328
|
return;
|
|
231
329
|
}
|
|
@@ -237,11 +335,7 @@ module.exports = class extends Generator {
|
|
|
237
335
|
`Using commit ${commitSHA} from @${this.options.ghOrg}/${generator.name}#${generator.default_branch}...`
|
|
238
336
|
);
|
|
239
337
|
}
|
|
240
|
-
generatorPath = path.join(
|
|
241
|
-
__dirname,
|
|
242
|
-
"../../plugin-generators",
|
|
243
|
-
generator.name
|
|
244
|
-
);
|
|
338
|
+
generatorPath = path.join(pluginsHome, generator.name);
|
|
245
339
|
const shaMarker = path.join(generatorPath, `.${commitSHA}`);
|
|
246
340
|
|
|
247
341
|
if (fs.existsSync(generatorPath) && !this.options.skipUpdate) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "generator-easy-ui5",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"description": "Generator for UI5-based project",
|
|
5
5
|
"main": "generators/app/index.js",
|
|
6
6
|
"files": [
|
|
@@ -40,18 +40,19 @@
|
|
|
40
40
|
"@octokit/rest": "^18.12.0",
|
|
41
41
|
"adm-zip": "^0.5.9",
|
|
42
42
|
"chalk": "^4.1.2",
|
|
43
|
-
"colors": "
|
|
43
|
+
"colors": "1.4.0",
|
|
44
44
|
"glob": "^7.2.0",
|
|
45
|
-
"
|
|
45
|
+
"libnpmconfig": "^1.2.1",
|
|
46
|
+
"mocha": "^9.2.0",
|
|
46
47
|
"rimraf": "^3.0.2",
|
|
47
48
|
"yarn-or-npm": "^3.0.1",
|
|
48
49
|
"yeoman-assert": "^3.1.1",
|
|
49
|
-
"yeoman-environment": "^3.
|
|
50
|
-
"yeoman-generator": "^5.
|
|
51
|
-
"yeoman-test": "^6.
|
|
50
|
+
"yeoman-environment": "^3.9.1",
|
|
51
|
+
"yeoman-generator": "^5.6.1",
|
|
52
|
+
"yeoman-test": "^6.3.0",
|
|
52
53
|
"yosay": "^2.0.2"
|
|
53
54
|
},
|
|
54
55
|
"devDependencies": {
|
|
55
|
-
"prettier": "2.
|
|
56
|
+
"prettier": "2.5.1"
|
|
56
57
|
}
|
|
57
58
|
}
|