Skip to content

Commit

Permalink
add import-jdl subgenerator
Browse files Browse the repository at this point in the history
Fix #31
  • Loading branch information
ruddell committed Feb 17, 2018
1 parent 842c8dc commit 1cfb3f0
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 3 deletions.
1 change: 1 addition & 0 deletions boilerplate/ignite.json.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
"redux": "ignite-ir-boilerplate",
"saga": "ignite-ir-boilerplate",
"screen": "ignite-ir-boilerplate"
"import-jdl": "ignite-jhipster",
}
}
2 changes: 2 additions & 0 deletions commands/import-jdl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// @cliDescription Imports a JHipster JDL file and generates the entities within the file
module.exports = require('../src/import-jdl')
10 changes: 8 additions & 2 deletions docs/generators-and-plugins.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
### Generators

##### JHipster Entity Generator
##### Custom Generators
- Entity - `ignite generate entity <name>`
- Prompts for the path to the entity's config (`.jhipster` folder in your app)
- Generates all files needed for fetching and displaying the entity.
- Generates all files needed for fetching and displaying the entity
- Includes the API endpoints, redux/saga config, and the user interface
- Import JDL - `ignite generate import-jdl <jdl-filename>`
- Import several entities at once using JDL
- Runs the entity generator for each entity present in the JDL
- Upgrade - `ignite generate upgrade`
- Upgrades your generated app to the latest template code
- Use a branch to merge just the updates into your code

##### Ignite Generators
This generator adds Ignite's usual generators to the mix as well. We have access to:
Expand Down
2 changes: 2 additions & 0 deletions docs/upgrading.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
- Make sure to upgrade ignite-jhipster by running `npm upgrade ignite-jhipster`
- Use `ignite g upgrade` to upgrade any template files to their updated boilerplate code.
- It's recommended to use `git` and branches to merge changes into your code.
- The command below will keep all of your changes while merging any updates. If there are conflicts, you will need to manually merge the changes.
- `git merge -s recursive -Xours <branch name>`
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"babel-eslint": "7.2.3",
"fs-jetpack": "1.0.0",
"jest": "21.0.2",
"jhipster-core": "1.4.6",
"np": "2.15.0",
"sinon": "2.3.1",
"standard": "10.0.2",
Expand Down
2 changes: 1 addition & 1 deletion src/entity/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module.exports = async function (context) {

// if the file exists, skip loading it
if (fs.existsSync(localEntityFilePath)) {
print.success(`Found the entity config locally in .jhipster`)
print.success(`Found the ${this.name} entity config locally in .jhipster`)
} else if (jhDirectoryFlag) {
if (!fs.existsSync(`${jhDirectoryFlag}/${localEntityFilePath}`)) {
print.error(`No entity configuration file found at ${jhDirectoryFlag}/${localEntityFilePath}`)
Expand Down
62 changes: 62 additions & 0 deletions src/import-jdl/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
const fs = require('fs-extra')
const Insight = require('../lib/insight')
const jhiCore = require('jhipster-core')

module.exports = async function (context) {
// grab some features
const { parameters, print, strings, system } = context
const { isBlank } = strings

// validation
if (isBlank(parameters.first)) {
print.info(`${context.runtime.brand} generate import-jdl <jdl-filename>\n`)
print.info('A JDL filename is required.')
return
}

// load the ignite config and set the default jhipster directory
const jdlFiles = parameters.array
print.info('The jdl is being parsed.')
const jhipsterConfig = await fs.readJson(`.jhipster/yo-rc.json`)
const prodDatabaseType = jhipsterConfig['generator-jhipster'].prodDatabaseType
const applicationType = jhipsterConfig['generator-jhipster'].applicationType
const baseName = jhipsterConfig['generator-jhipster'].baseName
try {
const jdlObject = jhiCore.convertToJDLFromConfigurationObject({
document: jhiCore.parseFromFiles(jdlFiles),
databaseType: prodDatabaseType,
applicationType: applicationType,
applicationName: baseName
})
const entities = jhiCore.convertToJHipsterJSON({
jdlObject,
databaseType: prodDatabaseType,
applicationType: applicationType
})
print.info('Writing entity JSON files.')
this.changedEntities = jhiCore.exportEntities({
entities,
forceNoFiltering: false
})

this.updatedKeys = Object.keys(this.changedEntities)
if (this.updatedKeys.length > 0) {
print.info(`Updated entities: ${this.updatedKeys}`)
} else {
print.info('No change in entity configurations. No entities were updated')
}

// generate update entities
for (let i = 0; i < this.updatedKeys.length; i++) {
await system.spawn(`ignite g entity ${this.updatedKeys[i]}`, { stdio: 'inherit' })
}

print.success(`JDL successfully imported!`)
} catch (e) {
print.error('\nError while parsing entities from JDL\n')
if (e && e.message) {
print.error(`${e.name || ''}: ${e.message}`)
}
}
Insight.trackGenerator(context, 'import-jdl')
}

0 comments on commit 1cfb3f0

Please sign in to comment.