Skip to content

Commit

Permalink
restructured server, added common sub-generator (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
rimselis authored Jun 25, 2020
1 parent 6df5807 commit aebbc0b
Show file tree
Hide file tree
Showing 11 changed files with 342 additions and 113 deletions.
51 changes: 51 additions & 0 deletions generators/common/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
const chalk = require('chalk');

const EntityServerGenerator = require('generator-jhipster/generators/common');

const entandoBlueprintWritingPhase = require('./phases/writing');

module.exports = class extends EntityServerGenerator {
constructor(args, opts) {
super(args, { fromBlueprint: true, ...opts }); // fromBlueprint variable is important

this.jhipsterContext = this.options.jhipsterContext;
const jhContext = this.jhipsterContext;

if (!jhContext) {
this.error(
`This is a JHipster blueprint and should be used only like ${chalk.yellow(
'jhipster --blueprints entando',
)}`,
);
}

this.configOptions = jhContext.configOptions || {};
// This sets up options for this sub generator and is being reused from JHipster
jhContext.setupClientOptions(this, jhContext);

if (jhContext.databaseType === 'cassandra') {
this.pkType = 'UUID';
}
const jhipsterConfig = this.getAllJhipsterConfig();
this.serverPort = jhipsterConfig.serverPort;
}

get initializing() {
// initializing - Your initialization methods (checking current project state, getting configs, etc)

return super._initializing();
}

get default() {
// default - If the method name doesn’t match a priority, it will be pushed to this group.
return super._default();
}

get writing() {
// writing - Where you write the generator specific files (routes, controllers, etc)
const jhipsterWritingPhase = super._writing();

// return entandoBlueprintWritingPhase;
return { ...jhipsterWritingPhase, ...entandoBlueprintWritingPhase };
}
};
21 changes: 21 additions & 0 deletions generators/common/phases/writing/files.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const commonFiles = {
global: [
{
templates: [
{
file: 'gitignore',
renameTo: () => '.gitignore',
},
],
},
],
};

function writeCommonFiles() {
this.writeFilesToDisk(commonFiles, this, false, null);
}

module.exports = {
writeCommonFiles,
commonFiles,
};
5 changes: 5 additions & 0 deletions generators/common/phases/writing/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const { writeCommonFiles } = require('./files');

module.exports = {
writeCommonFiles,
};
154 changes: 154 additions & 0 deletions generators/common/templates/gitignore.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
######################
# Project Specific
######################<% if (!skipClient) { %>
/<%= CLIENT_MAIN_SRC_DIR %>content/css/main.css<% } %>
/<%= CLIENT_DIST_DIR %>**
/<%= TEST_DIR %>javascript/coverage/

######################
# Node
######################
/node/
node_tmp/
node_modules/
npm-debug.log.*
/.awcache/*
/.cache-loader/*

######################
# SASS
######################
.sass-cache/

######################
# Eclipse
######################
*.pydevproject
.project
.metadata
tmp/
tmp/**/*
*.tmp
*.bak
*.swp
*~.nib
local.properties
.classpath
.settings/
.loadpath
.factorypath
/<%= SERVER_MAIN_RES_DIR %>rebel.xml

# External tool builders
.externalToolBuilders/**

# Locally stored "Eclipse launch configurations"
*.launch

# CDT-specific
.cproject

# PDT-specific
.buildpath

# STS-specific
/.sts4-cache/*

######################
# IntelliJ
######################
.idea/
*.iml
*.iws
*.ipr
*.ids
*.orig
classes/
out/

######################
# Visual Studio Code
######################
.vscode/

######################
# Maven
######################
/log/
/target/

######################
# Gradle
######################
.gradle/
/build/

######################
# Package Files
######################
*.jar
*.war
*.ear
*.db

######################
# Windows
######################
# Windows image file caches
Thumbs.db

# Folder config file
Desktop.ini

######################
# Mac OSX
######################
.DS_Store
.svn

# Thumbnails
._*

# Files that might appear on external disk
.Spotlight-V100
.Trashes

######################
# Directories
######################
/bin/
/deploy/

######################
# Logs
######################
*.log*

######################
# Others
######################
*.class
*.*~
*~
.merge_file*

######################
# Gradle Wrapper
######################
!gradle/wrapper/gradle-wrapper.jar

######################
# Maven Wrapper
######################
!.mvn/wrapper/maven-wrapper.jar

######################
# ESLint
######################
.eslintcache

######################
# Entando bundles
######################
bundle/
# !/bundle/descriptor.yaml
42 changes: 22 additions & 20 deletions generators/entity-server/lib/create-mfe-template-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,30 +59,32 @@ function getRenameToFunction(file) {

module.exports.generateFiles = function generateFiles(basePath) {
const files = getFiles(basePath).map(generate);
const templates = files.filter(file => !file.options.skip).map(iteratedFile => {
const file = { ...iteratedFile, filename: iteratedFile.filename.substring(basePath.length) };
const fileObj = {
file: file.filename,
};
const templates = files
.filter(file => !file.options.skip)
.map(iteratedFile => {
const file = { ...iteratedFile, filename: iteratedFile.filename.substring(basePath.length) };
const fileObj = {
file: file.filename,
};

Object.keys(file.options).forEach(opt => {
switch (opt) {
case 'skip':
break;
case 'renameTo':
fileObj.renameTo = getRenameToFunction(file);
break;
default:
fileObj[opt] = file.options[opt];
}
});

Object.keys(file.options).forEach(opt => {
switch (opt) {
case 'skip':
break;
case 'renameTo':
fileObj.renameTo = getRenameToFunction(file);
break;
default:
fileObj[opt] = file.options[opt];
if (!fileObj.renameTo) {
fileObj.renameTo = getRenameToFunction(file);
}
return fileObj;
});

if (!fileObj.renameTo) {
fileObj.renameTo = getRenameToFunction(file);
}
return fileObj;
});

return {
microFrontEnd: [
{
Expand Down
52 changes: 26 additions & 26 deletions generators/entity-server/phases/prompting/index.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
function askForMfeGeneration(meta) {
// defaulting to asking about MFE generation
const serverSetting = this.config.get('generateMicroFrontends') || 'ask';
// defaulting to asking about MFE generation
const serverSetting = this.config.get('generateMicroFrontends') || 'ask';

if (!meta && this.existingProject) {
return;
}
if (!meta && this.existingProject) {
return;
}

if (serverSetting === 'ask') {
const done = this.async();
const prompts = [
{
type: 'confirm',
name: 'generateMfeForEntity',
message: 'Do you want to generate micro frontends?',
default: true,
},
];
this.prompt(prompts).then(prompt => {
this.configOptions.generateMfeForEntity = prompt.generateMfeForEntity;
done();
});
} else {
if (serverSetting === 'never') {
this.configOptions.generateMfeForEntity = false;
}
if (serverSetting === 'always') {
this.configOptions.generateMfeForEntity = true;
}
if (serverSetting === 'ask') {
const done = this.async();
const prompts = [
{
type: 'confirm',
name: 'generateMfeForEntity',
message: 'Do you want to generate micro frontends?',
default: true,
},
];
this.prompt(prompts).then(prompt => {
this.configOptions.generateMfeForEntity = prompt.generateMfeForEntity;
done();
});
} else {
if (serverSetting === 'never') {
this.configOptions.generateMfeForEntity = false;
}
if (serverSetting === 'always') {
this.configOptions.generateMfeForEntity = true;
}
}
}

module.exports = { askForMfeGeneration };
Loading

0 comments on commit aebbc0b

Please sign in to comment.