Skip to content

Commit

Permalink
Merge branch 'main' into skip_ci-generate_blueprint
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima authored Sep 1, 2022
2 parents e897b86 + d038530 commit d583c19
Show file tree
Hide file tree
Showing 21 changed files with 265 additions and 61 deletions.
16 changes: 15 additions & 1 deletion cli/environment-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const assert = require('assert');
const chalk = require('chalk');
const _ = require('lodash');
const path = require('path');
const { existsSync } = require('fs');
const Environment = require('yeoman-environment');
const { CLI_NAME, logger } = require('./utils');
const { loadYoRc, packageNameToNamespace } = require('../generators/utils');
Expand Down Expand Up @@ -88,7 +89,7 @@ module.exports = class EnvironmentBuilder {
}

prepare({ blueprints, lookups } = {}) {
this._lookupJHipster()._loadBlueprints(blueprints)._lookups(lookups)._lookupBlueprints()._loadSharedOptions();
this._lookupJHipster()._lookupLocalBlueprint()._loadBlueprints(blueprints)._lookups(lookups)._lookupBlueprints()._loadSharedOptions();
return this;
}

Expand Down Expand Up @@ -125,6 +126,19 @@ module.exports = class EnvironmentBuilder {
return this;
}

_lookupLocalBlueprint() {
const localBlueprintPath = path.join(process.cwd(), '.blueprint');
if (existsSync(localBlueprintPath)) {
// Register jhipster generators.
const generators = this.env.lookup({ packagePaths: [localBlueprintPath], lookups: ['.'] });
if (generators.length > 0) {
this.env.alias(/^@jhipster\/jhipster-local(:(.*))?$/, '.blueprint$1');
this.env.sharedOptions.localBlueprint = true;
}
}
return this;
}

_lookups(lookups = []) {
lookups = [].concat(lookups);
lookups.forEach(lookup => {
Expand Down
6 changes: 3 additions & 3 deletions generators/client/templates/angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"dependencies": {
"@angular/common": "14.2.0",
"@fortawesome/angular-fontawesome": "0.11.1",
"@fortawesome/fontawesome-svg-core": "6.1.2",
"@fortawesome/free-solid-svg-icons": "6.1.2",
"@fortawesome/fontawesome-svg-core": "6.2.0",
"@fortawesome/free-solid-svg-icons": "6.2.0",
"@ng-bootstrap/ng-bootstrap": "13.0.0",
"@ngx-translate/core": "14.0.0",
"@ngx-translate/http-loader": "7.0.0",
Expand All @@ -24,7 +24,7 @@
"@angular-eslint/eslint-plugin": "14.0.3",
"@types/node": "16.11.56",
"@types/jest": "28.1.8",
"@typescript-eslint/eslint-plugin": "5.36.0",
"@typescript-eslint/eslint-plugin": "5.36.1",
"browser-sync": "2.27.10",
"browser-sync-webpack-plugin": "2.3.0",
"copy-webpack-plugin": "11.0.0",
Expand Down
4 changes: 2 additions & 2 deletions generators/client/templates/angular/package.json.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@
"default_environment": "prod"
},
"scripts": {
"prettier:check": "prettier --check \"{,src/**/,webpack/}*.{<%= getPrettierExtensions() %>}\"",
"prettier:format": "prettier --write \"{,src/**/,webpack/}*.{<%= getPrettierExtensions() %>}\"",
"prettier:check": "prettier --check \"{,src/**/,webpack/,.blueprint/**/}*.{<%= getPrettierExtensions() %>}\"",
"prettier:format": "prettier --write \"{,src/**/,webpack/,.blueprint/**/}*.{<%= getPrettierExtensions() %>}\"",
"lint": "eslint . --ext .js,.ts",
"lint:fix": "<%= clientPackageManager %> run lint -- --fix",
"cleanup": "rimraf <%= DIST_DIR %>",
Expand Down
2 changes: 1 addition & 1 deletion generators/client/templates/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"@cypress/code-coverage": "3.10.0",
"babel-loader": "8.2.5",
"babel-plugin-istanbul": "6.1.1",
"cypress": "10.6.0",
"cypress": "10.7.0",
"cypress-audit": "1.1.0",
"eslint-plugin-cypress": "2.12.1",
"lighthouse": "9.6.6",
Expand Down
12 changes: 6 additions & 6 deletions generators/client/templates/react/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"dependencies": {
"@fortawesome/fontawesome-svg-core": "6.1.2",
"@fortawesome/free-solid-svg-icons": "6.1.2",
"@fortawesome/fontawesome-svg-core": "6.2.0",
"@fortawesome/free-solid-svg-icons": "6.2.0",
"@fortawesome/react-fontawesome": "0.2.0",
"@reduxjs/toolkit": "1.8.5",
"axios": "0.27.2",
Expand Down Expand Up @@ -31,13 +31,13 @@
"@types/jest": "28.1.8",
"@types/lodash": "4.14.184",
"@types/node": "16.11.56",
"@types/react": "18.0.17",
"@types/react": "18.0.18",
"@types/react-dom": "18.0.6",
"@types/react-redux": "7.1.24",
"@types/redux": "3.6.31",
"@types/webpack-env": "1.18.0",
"@typescript-eslint/eslint-plugin": "5.35.1",
"@typescript-eslint/parser": "5.36.0",
"@typescript-eslint/eslint-plugin": "5.36.1",
"@typescript-eslint/parser": "5.36.1",
"autoprefixer": "10.4.8",
"browser-sync": "2.27.10",
"browser-sync-webpack-plugin": "2.3.0",
Expand Down Expand Up @@ -66,7 +66,7 @@
"react-infinite-scroll-component": "6.1.0",
"redux-mock-store": "1.5.4",
"rimraf": "3.0.2",
"sass": "1.54.6",
"sass": "1.54.8",
"sass-loader": "13.0.2",
"simple-progress-webpack-plugin": "2.0.0",
"sinon": "14.0.0",
Expand Down
4 changes: 2 additions & 2 deletions generators/client/templates/react/package.json.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@
"default_environment": "prod"
},
"scripts": {
"prettier:check": "prettier --check \"{,src/**/,webpack/}*.{<%= getPrettierExtensions() %>}\"",
"prettier:format": "prettier --write \"{,src/**/,webpack/}*.{<%= getPrettierExtensions() %>}\"",
"prettier:check": "prettier --check \"{,src/**/,webpack/,.blueprint/**/}*.{<%= getPrettierExtensions() %>}\"",
"prettier:format": "prettier --write \"{,src/**/,webpack/,.blueprint/**/}*.{<%= getPrettierExtensions() %>}\"",
"lint": "eslint . --ext .js,.ts,.jsx,.tsx",
"lint:fix": "<%= clientPackageManager %> run lint -- --fix",
"cleanup": "rimraf <%= DIST_DIR %>",
Expand Down
10 changes: 5 additions & 5 deletions generators/client/templates/vue/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"dependencies": {
"@fortawesome/fontawesome-svg-core": "6.1.2",
"@fortawesome/free-solid-svg-icons": "6.1.2",
"@fortawesome/fontawesome-svg-core": "6.2.0",
"@fortawesome/free-solid-svg-icons": "6.2.0",
"@fortawesome/vue-fontawesome": "2.0.8",
"axios": "0.27.2",
"bootstrap": "4.6.2",
Expand Down Expand Up @@ -46,11 +46,11 @@
"merge-jsons-webpack-plugin": "2.0.1",
"mini-css-extract-plugin": "2.6.1",
"numeral": "2.0.6",
"postcss-import": "14.1.0",
"postcss-import": "15.0.0",
"postcss-loader": "7.0.1",
"postcss-url": "10.1.3",
"rimraf": "3.0.2",
"sass": "1.54.6",
"sass": "1.54.8",
"sass-loader": "13.0.2",
"sinon": "14.0.0",
"terser-webpack-plugin": "5.3.6",
Expand All @@ -59,7 +59,7 @@
"eslint": "8.23.0",
"eslint-plugin-prettier": "4.2.1",
"eslint-plugin-vue": "8.7.1",
"typescript": "4.7.4",
"typescript": "4.8.2",
"webpack": "5.74.0",
"webpack-bundle-analyzer": "4.6.1",
"webpack-cli": "4.10.0",
Expand Down
4 changes: 2 additions & 2 deletions generators/client/templates/vue/package.json.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@
"default_environment": "prod"
},
"scripts": {
"prettier:check": "prettier --check \"{,src/**/,webpack/}*.{<%= getPrettierExtensions() %>}\"",
"prettier:format": "prettier --write \"{,src/**/,webpack/}*.{<%= getPrettierExtensions() %>}\"",
"prettier:check": "prettier --check \"{,src/**/,webpack/,.blueprint/**/}*.{<%= getPrettierExtensions() %>}\"",
"prettier:format": "prettier --write \"{,src/**/,webpack/,.blueprint/**/}*.{<%= getPrettierExtensions() %>}\"",
"lint": "eslint . --ext .ts,.vue ",
"lint:fix": "eslint . --ext .ts,.vue --fix",
"cleanup": "rimraf <%= DIST_DIR %>",
Expand Down
2 changes: 1 addition & 1 deletion generators/common/templates/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"concurrently": "7.3.0",
"husky": "7.0.4",
"lint-staged": "13.0.3",
"npm": "8.18.0",
"npm": "8.19.0",
"wait-on": "6.0.1"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export default class <%= entityAngularName %> extends <% if (fieldsContainBlob |
<%_ if (paginationInfiniteScroll) { _%>
if ((<any>this.$refs.infiniteLoading)) {
(<any>this.$refs.infiniteLoading).stateChanger.loaded();
if (this.links !== {} && this.page > this.links['last']) {
if (JSON.stringify(this.links) !== JSON.stringify({}) && this.page > this.links['last']) {
(<any>this.$refs.infiniteLoading).stateChanger.complete();
}
}
Expand Down Expand Up @@ -144,7 +144,7 @@ export default class <%= entityAngularName %> extends <% if (fieldsContainBlob |
<%_ if (paginationInfiniteScroll) { _%>
if ((<any>this.$refs.infiniteLoading)) {
(<any>this.$refs.infiniteLoading).stateChanger.loaded();
if (this.links !== {} && this.page > this.links['last']) {
if (JSON.stringify(this.links) !== JSON.stringify({}) && this.page > this.links['last']) {
(<any>this.$refs.infiniteLoading).stateChanger.complete();
}
}
Expand Down
41 changes: 35 additions & 6 deletions generators/generate-blueprint/constants.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@ export const SUB_GENERATORS = 'subGenerators';
export const ADDITIONAL_SUB_GENERATORS = 'additionalSubGenerators';
export const DYNAMIC = 'dynamic';
export const JS = 'js';
export const LOCAL_BLUEPRINT_OPTION = 'localBlueprint';
export const CLI_OPTION = 'cli';

export const SBS = 'sbs';
export const COMMAND = 'command';
export const PRIORITIES = 'priorities';
export const ALL_GENERATORS = 'allGenerators';
export const ALL_PRIORITIES = 'allPriorities';
export const WRITTEN = 'written';

/**
Expand Down Expand Up @@ -70,11 +73,25 @@ export const options = () => ({
type: Boolean,
scope: 'storage',
},
[LOCAL_BLUEPRINT_OPTION]: {
desc: 'Generate a local blueprint',
type: Boolean,
scope: 'storage',
},
[CLI_OPTION]: {
desc: 'Generate a cli for the blueprint',
type: Boolean,
scope: 'storage',
},
[ALL_GENERATORS]: {
desc: 'Use js extension',
desc: 'Generate every sub generator',
type: Boolean,
scope: 'generator',
},
[ALL_PRIORITIES]: {
desc: 'Generate every priority',
type: Boolean,
},
});

/**
Expand All @@ -85,10 +102,12 @@ export const requiredConfig = () => ({});
/**
* Default config that will be used for templates
*/
export const defaultConfig = () => ({
export const defaultConfig = ({ config = {} } = {}) => ({
...requiredConfig,
[DYNAMIC]: false,
[JS]: false,
[LOCAL_BLUEPRINT_OPTION]: false,
[CLI_OPTION]: !config[LOCAL_BLUEPRINT_OPTION],
[SUB_GENERATORS]: [],
[ADDITIONAL_SUB_GENERATORS]: '',
});
Expand Down Expand Up @@ -120,7 +139,14 @@ export const allGeneratorsConfig = () => ({
});

export const prompts = () => {
const { [LOCAL_BLUEPRINT_OPTION]: LOCAL_BLUEPRINT_OPTION_DEFAULT_VALUE, [CLI_OPTION]: CLI_OPTION_DEFAULT_VALUE } = defaultConfig();
return [
{
type: 'confirm',
name: LOCAL_BLUEPRINT_OPTION,
message: 'Do you want to generate a local blueprint inside your application?',
default: LOCAL_BLUEPRINT_OPTION_DEFAULT_VALUE,
},
{
type: 'checkbox',
name: SUB_GENERATORS,
Expand All @@ -141,24 +167,27 @@ export const prompts = () => {
},
},
{
when: answers => !answers[LOCAL_BLUEPRINT_OPTION],
type: 'confirm',
name: 'cli',
name: CLI_OPTION,
message: 'Add a cli?',
default: true,
default: CLI_OPTION_DEFAULT_VALUE,
},
];
};

export const subGeneratorPrompts = (subGenerator, additionalSubGenerator) => {
export const subGeneratorPrompts = ({ subGenerator, additionalSubGenerator, localBlueprint }) => {
const { [SBS]: SBS_DEFAULT_VALUE } = defaultSubGeneratorConfig();
return [
{
type: 'confirm',
name: SBS,
when: !additionalSubGenerator,
message: `Is ${chalk.yellow(subGenerator)} generator a side-by-side blueprint?`,
default: true,
default: SBS_DEFAULT_VALUE,
},
{
when: !localBlueprint,
type: 'confirm',
name: COMMAND,
message: `Is ${chalk.yellow(subGenerator)} generator a cli command?`,
Expand Down
12 changes: 7 additions & 5 deletions generators/generate-blueprint/files.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { LOCAL_BLUEPRINT_OPTION } from './constants.mjs';

export const files = {
baseFiles: [
{
condition: ctx => !ctx[LOCAL_BLUEPRINT_OPTION],
templates: [
'.github/workflows/generator.yml',
'.eslintrc.json',
Expand All @@ -44,18 +46,18 @@ export const generatorFiles = {
generator: [
{
path: 'generators/generator',
to: ctx => `generators/${ctx.generator}`,
to: ctx => `${ctx.application.blueprintsPath}${ctx.generator}`,
templates: [{ file: 'generator.mjs.jhi', renameTo: ctx => (ctx.js ? 'generator.js.jhi' : 'generator.mjs.jhi') }],
},
{
path: 'generators/generator',
to: ctx => `generators/${ctx.generator}`,
to: ctx => `${ctx.application.blueprintsPath}${ctx.generator}`,
templates: [{ file: 'index.mjs', renameTo: ctx => (ctx.js ? 'index.js' : 'index.mjs') }],
},
{
path: 'generators/generator',
to: ctx => `generators/${ctx.generator}`,
condition: ctx => !ctx.generator.startsWith('entity'),
to: ctx => `${ctx.application.blueprintsPath}${ctx.generator}`,
condition: ctx => !ctx.generator.startsWith('entity') && !ctx.application[LOCAL_BLUEPRINT_OPTION],
templates: [
{
file: 'generator.spec.mjs',
Expand All @@ -65,7 +67,7 @@ export const generatorFiles = {
},
{
path: 'generators/generator',
to: ctx => `generators/${ctx.generator}`,
to: ctx => `${ctx.application.blueprintsPath}${ctx.generator}`,
condition(ctx) {
return (this.options.force || !ctx.written) && ctx.priorities.find(priority => priority.name === 'writing');
},
Expand Down
Loading

0 comments on commit d583c19

Please sign in to comment.