Skip to content

Commit

Permalink
Merge pull request #145 from jhipster/feature/nhipster-cli
Browse files Browse the repository at this point in the history
added nhipster cli
  • Loading branch information
Angelo Manganiello authored Jun 9, 2020
2 parents 6533692 + 036b0eb commit 21bdaa6
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

# [1.1.0](https://github.com/jhipster/generator-jhipster-nodejs/tree/v1.1.0)

- Create a nhipster command line [issue #143](https://github.com/jhipster/generator-jhipster-nodejs/issues/143)
- Enhancement suggestions list tasks for 1.1.0 version [issue #136](https://github.com/jhipster/generator-jhipster-nodejs/issues/136)
- Support enum fields entity generation without giving conflicts in sqlite dev database [issue #74](https://github.com/jhipster/generator-jhipster-nodejs/issues/74)

Expand Down
20 changes: 14 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,25 +109,33 @@ yarn global upgrade generator-jhipster-nodejs

## 🚦 What we have now

This is a blueprint that it is runnable by:

```bash
jhipster --blueprints nodejs
```

However, it also ships with an `nhipster` CLI that you can use as a shortcut.

✅ General App generation

- `jhipster --blueprints nodejs`
- `nhipster`

✅ Controller generation

- `jhipster spring-controller <controller-name> --blueprints nodejs`
- `nhipster spring-controller <controller-name>`

✅ Service generation

- `jhipster spring-service <service-name> --blueprints nodejs`
- `nhipster spring-service <service-name>`

✅ Entity generation

- `jhipster entity <entity-name> --blueprints nodejs`
- `nhipster entity <entity-name>`

✅ JDL Entity model support generation

- `jhipster import-jdl my_file.jdl --blueprints nodejs`
- `nhipster import-jdl my_file.jdl`

For the last, in the **test-integration/samples/FOLDER_NAME-jdl** there are some examples of jdl models.

Expand Down Expand Up @@ -156,7 +164,7 @@ $ npm link generator-jhipster-nodejs
Now you will develop under the **generator-jhipster-nodejs** that you have cloned with git.
After finish, to generate the app and check your feature, run in **test-generation** folder:

- `jhipster --blueprints nodejs`
- `nhipster`

## ❤️ For community

Expand Down
92 changes: 92 additions & 0 deletions cli/nhipster.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,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}\nNHipster 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 nodejs as a blueprint module.
// User passes in blueprints flag but without Nodejs :> append Nodejs
if (!process.argv.includes('nodejs') && 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(',')},nodejs`;
}
}
// User passes in blueprint flag but without Nodejs :> append Nodejs
} else if (!process.argv.includes('nodejs') && 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]},nodejs`;
}
}
// User do not pass in blueprints or blueprint flag but without Nodejs :> append Nodejs
} else if (!process.argv.includes('nodejs') && !process.argv.includes('--blueprint') && !process.argv.includes('--blueprints')) {
process.argv.push('--blueprints');
process.argv.push('nodejs');
}

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 */
}
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@
"Daniel Franco <dandrfranco@gmail.com> (https://github.com/DanielFran)"
],
"files": [
"generators"
"generators",
"cli"
],
"bin": {
"nhipster": "./cli/nhipster.js"
},
"main": "generators/app/index.js",
"repository": {
"type": "git",
Expand Down

0 comments on commit 21bdaa6

Please sign in to comment.