-
-
Notifications
You must be signed in to change notification settings - Fork 27
/
mhipster.js
executable file
·92 lines (85 loc) · 3.73 KB
/
mhipster.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
#!/usr/bin/env node
/**
* Copyright 2013-2020 the original author or authors from the JHipster project.
*
* This file is part of the JHipster project, see https://www.jhipster.tech/
* for more information.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const semver = require('semver');
const path = require('path');
const { logger } = require('generator-jhipster/cli/utils');
const packageJson = require('../package.json');
const currentNodeVersion = process.versions.node;
const minimumNodeVersion = packageJson.engines.node;
if (!semver.satisfies(currentNodeVersion, minimumNodeVersion)) {
/* eslint-disable no-console */
logger.error(
`You are running Node version ${currentNodeVersion}\nMHipster requires Node version ${minimumNodeVersion}\nPlease update your version of Node.`
);
/* eslint-enable */
}
let preferLocal = true;
// Don't use commander for parsing command line to avoid polluting it in cli.js
// --prefer-local: Always resolve node modules locally (useful when using linked module)
if (process.argv.includes('upgrade') && !process.argv.includes('--prefer-local')) {
// Prefer global version for `jhipster upgrade` to get most recent code
preferLocal = false;
}
// Pass in micronaut as a blueprint module.
// User passes in blueprints flag but without micronaut :> append micronaut
if (!process.argv.includes('micronaut') && process.argv.includes('--blueprints')) {
for (let i = 0; i < process.argv.length; i++) {
if (process.argv[i] === '--blueprints') {
process.argv[i + 1] = `${process.argv[i + 1].split(',')},micronaut`;
}
}
// User passes in blueprint flag but without micronaut :> append micronaut
} else if (!process.argv.includes('micronaut') && process.argv.includes('--blueprint')) {
for (let i = 0; i < process.argv.length; i++) {
if (process.argv[i] === '--blueprint') {
process.argv[i] = '--blueprints';
process.argv[i + 1] = `${process.argv[i + 1]},micronaut`;
}
}
// User donot pass in blueprints or blueprint flag but without micronaut :> append micronaut
} else if (!process.argv.includes('micronaut') && !process.argv.includes('--blueprint') && !process.argv.includes('--blueprints')) {
process.argv.push('--blueprints');
process.argv.push('micronaut');
}
requireCLI(preferLocal);
/*
* Require cli.js giving priority to local version over global one if it exists.
*/
function requireCLI(preferLocal) {
/* eslint-disable global-require */
if (preferLocal) {
try {
const localCLI = require.resolve(path.join(process.cwd(), 'node_modules', 'generator-jhipster', 'cli', 'cli.js'));
if (__dirname !== path.dirname(localCLI)) {
// load local version
/* eslint-disable import/no-dynamic-require */
logger.info("Using JHipster version installed locally in current project's node_modules");
require(localCLI);
return;
}
} catch (e) {
// Unable to find local version, so global one will be loaded anyway
}
}
// load global version
logger.info('Using JHipster version installed globally');
require('generator-jhipster/cli/cli.js');
/* eslint-enable */
}