Ionic Entity Generator with Blueprint

202 views
Skip to first unread message

Matt Raible

unread,
Nov 13, 2017, 1:42:04 PM11/13/17
to JHipster dev team
Hey all,

I’m trying to use the blueprint feature to create an entity generator for Ionic.

I have an index.js that’s as follows:

const chalk = require('chalk');
const packagejs = require('../../package.json');
const jsonfile = require('jsonfile');
const BaseGenerator = require('generator-jhipster/generators/generator-base');
const jhipsterConstants = require('generator-jhipster/generators/generator-constants');
const prompts = require('./prompts');

module.exports = class extends BaseGenerator {
get initializing() {
return {
readConfig() {
this.jhipsterAppConfig = this.getJhipsterAppConfig();
},
displayLogo() {
this.log(chalk.white(`Running ${chalk.bold('JHipster')} ${chalk.blue.bold('Ionic')} Entity Generator! ${chalk.yellow(`v${packagejs.version}\n`)}`));
}
};
}

get prompting() {
return {
askForPath: prompts.askForPath
};
}

get writing() {
const fromPath = `${this.appPath}/.yo-rc.json`;
this.jhipsterAppConfig = this.fs.readJSON(fromPath)['generator-jhipster'];

return {
writeFiles() {
// function to use directly template
this.template = function (source, destination) {
this.fs.copyTpl(
this.templatePath(source),
this.destinationPath(destination),
this
);
};

this.template('dummy.txt', 'dummy.txt', this, {});
}
};
}

end() {
this.log(`\n${chalk.bold.green('Finished!')}`);
}
};

My prompts.js looks like this:

const chalk = require('chalk');
const shelljs = require('shelljs');

module.exports = {
askForPath
};

/**
* Ask For Path
*/
function askForPath(meta) {
if (!meta && this.existingProject) return;

const done = this.async();
const messageAskForPath = 'Enter the directory where your JHipster app is located:';
const prompts = [{
type: 'confirm',
name: 'useAppJson',
message: 'Do you want to generate this entity from an existing app?',
default: true
},
{
type: 'input',
name: 'appPath',
message: messageAskForPath,
default: 'backend',
store: true,
validate: (input) => {
const path = this.destinationPath(input);
if (shelljs.test('-d', path)) {
const appsFolders = getAppFolder.call(this, input);
if (appsFolders.length === 0) {
return `No application found in ${path}`;
}
return true;
}
return `${path} is not a directory or doesn't exist`;
}
}];

this.prompt(prompts).then((props) => {
this.appPath = props.appPath;
done();
});
}

/**
* Get App Folders
* @param input path to join to destination path
* @returns {Array} array of string representing app folders
*/
function getAppFolder(input) {
const destinationPath = this.destinationPath(input);
const appsFolders = [];

if (shelljs.test('-f', `${destinationPath}/.yo-rc.json`)) {
try {
const fileData = this.fs.readJSON(`${destinationPath}/.yo-rc.json`);
if (fileData['generator-jhipster'].baseName !== undefined) {
appsFolders.push(destinationPath);
}
} catch (err) {
this.log(chalk.red(`The .yo-rc.json in ${destinationPath} can't be read!`));
this.debug('Error:', err);
}
}

return appsFolders;
}
For some reason, I’m getting the following error and I’m not getting prompted. Any ideas?

/Users/mraible/dev/jhipster/generator-jhipster-ionic/generators/entity/index.js:28
        this.jhipsterAppConfig = this.fs.readJSON(fromPath)['generator-jhipster'];
                                         ^
TypeError: Cannot read property 'readJSON' of undefined

If I change index.js#writing to the following:
get writing() {
const fromPath = `${this.appPath}/.yo-rc.json`;
console.log('fromPath: ' + fromPath);
//this.jhipsterAppConfig = this.fs.readJSON(fromPath)['generator-jhipster'];
}
It prompts me correctly, but it seems to try and read the file path before I enter it.

fromPath: undefined/.yo-rc.json
Running JHipster Ionic Entity Generator! v0.0.0

? Do you want to generate this entity from an existing app? Yes
? Enter the directory where your JHipster app is located: ../ionic-workspace/backend

Any ideas?

Thanks,

Matt



Matt Raible

unread,
Nov 13, 2017, 7:37:45 PM11/13/17
to JHipster dev team
Hey all,

I’m not sure the blueprint feature is working as expected. I’m working off the latest master branch and I’ve run `npm link` to use master.

Steps to reproduce:

1. mkdir foo && cd foo
2. yo jhipster --blueprint generator-jhipster-sample-blueprint (I’ve run npm link on generator-jhipster-sample-blueprint too)

It fails with the following error:

```
Welcome to the JHipster Generator v4.10.2
Documentation for creating an application: http://www.jhipster.tech/creating-an-app/
Application files will be generated in folder: /Users/mraible/foo
? Which *type* of application would you like to create? Monolithic application (recommended for simp
le projects)
? What is the base name of your application? foo
Error jhipster --blueprint generator-jhipster-sample-blueprint

You don't seem to have a generator with the name “jhipster-sample-blueprint:server” installed.
But help is on the way:

You can see available generators via npm search yeoman-generator or via http://yeoman.io/generators/.
Install them with npm install generator-jhipster-sample-blueprint:server.

To see all your installed generators run yo without any arguments. Adding the --help option will also show subgenerators.

If yo cannot find the generator, run yo doctor to troubleshoot your system.
```

However, if I run `jhipster --blueprint generator-jhipster-sample-blueprint`, it works!

```
jhipster --blueprint generator-jhipster-sample-blueprint
Using JHipster version installed globally
Running default command
Executing jhipster:app
Options: blueprint: generator-jhipster-sample-blueprint

Welcome to the JHipster Generator v4.10.2
Documentation for creating an application: http://www.jhipster.tech/creating-an-app/
Application files will be generated in folder: /Users/mraible/foo
? Which *type* of application would you like to create? Monolithic application (recommended for simp
le projects)
? What is the base name of your application? foo
WARNING! No blueprint found for server falling back to default generator
? What is your default Java package name? (com.okta.developer)
```

Is this expected behavior? Does this feature only work with `jhipster` and not `yo jhipster`?

Thanks,

Matt

Matt Raible

unread,
Nov 13, 2017, 7:44:54 PM11/13/17
to JHipster dev team
I spoke too soon. Using `jhipster` w/o the `yo` doesn’t work either. It doesn’t prompt me with the new client options, it just warns me and prompts me for Angular.

WARNING! No blueprint found for client falling back to default generator
? Which *Framework* would you like to use for the client? (Use arrow keys)
❯ Angular 4
  AngularJS 1.x

I’ve tried this with Node v8.9.0 and v6.11.0 and the results are the same.

Deepu K Sasidharan

unread,
Nov 14, 2017, 4:51:28 AM11/14/17
to Matt Raible, JHipster dev team
Hi Matt,

I'll take a look later today. May until the blueprint support is ready and out of Beta you should build the Ionic generator as a normal module as we discussed earlier.

Also please note the procedure I used when testing was

cd generator-jhipster
npm link

cd generator-jhipster-sample-blueprint
npm link
npm link generator-jhipster

cd my-test-app
jhipster --blueprint generator-jhipster-sample-blueprint



Thanks & Regards,
Deepu

--
You received this message because you are subscribed to the Google Groups "JHipster dev team" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jhipster-dev+unsubscribe@googlegroups.com.
To post to this group, send email to jhipst...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jhipster-dev/31B5ADC3-A38A-4151-BF6F-93C5AFD9E41D%40raibledesigns.com.

For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages