From c0361fa750c78df24b61d426c662133c558263bf Mon Sep 17 00:00:00 2001 From: Marcelo Shima Date: Wed, 5 Jun 2024 21:51:27 -0300 Subject: [PATCH] add samplesFolder option to local blueprints. --- .blueprint/generate-sample/command.mjs | 8 ++++ .blueprint/generate-sample/generator.mjs | 13 ++++++- .../github-build-matrix/build-matrix.mjs | 4 +- .blueprint/github-build-matrix/command.mjs | 38 +++++++++++++++++++ .blueprint/github-build-matrix/generator.mjs | 20 +++++++++- .blueprint/github-build-matrix/index.mjs | 1 + 6 files changed, 79 insertions(+), 5 deletions(-) create mode 100644 .blueprint/github-build-matrix/command.mjs diff --git a/.blueprint/generate-sample/command.mjs b/.blueprint/generate-sample/command.mjs index f1c986d5f..f4dca9347 100644 --- a/.blueprint/generate-sample/command.mjs +++ b/.blueprint/generate-sample/command.mjs @@ -45,6 +45,14 @@ const command = { }, scope: 'generator', }, + samplesFolder: { + description: 'Path to the samples folder', + cli: { + type: String, + }, + default: 'samples', + scope: 'generator', + }, }, options: {}, import: [GENERATOR_APP], diff --git a/.blueprint/generate-sample/generator.mjs b/.blueprint/generate-sample/generator.mjs index 37b72273c..a0019cc77 100644 --- a/.blueprint/generate-sample/generator.mjs +++ b/.blueprint/generate-sample/generator.mjs @@ -5,6 +5,7 @@ import BaseGenerator from 'generator-jhipster/generators/base'; export default class extends BaseGenerator { sampleName; all; + samplesFolder; constructor(args, opts, features) { super(args, opts, { ...features, jhipsterBootstrap: false }); @@ -31,13 +32,21 @@ export default class extends BaseGenerator { }); } + get [BaseGenerator.LOADING]() { + return this.asLoadingTaskGroup({ + async loadCommand() { + await this.loadCurrentJHipsterCommandConfig(undefined); + }, + }); + } + get [BaseGenerator.WRITING]() { return this.asWritingTaskGroup({ async copySample() { if (this.all) { - this.copyTemplate('samples/*.jdl', ''); + this.copyTemplate(`${this.samplesFolder}/*.jdl`, ''); } else { - this.copyTemplate(`samples/${this.sampleName}`, this.sampleName, { noGlob: true }); + this.copyTemplate(`${this.samplesFolder}/${this.sampleName}`, this.sampleName, { noGlob: true }); } }, }); diff --git a/.blueprint/github-build-matrix/build-matrix.mjs b/.blueprint/github-build-matrix/build-matrix.mjs index d60e02c3f..a4fac05d3 100644 --- a/.blueprint/github-build-matrix/build-matrix.mjs +++ b/.blueprint/github-build-matrix/build-matrix.mjs @@ -3,10 +3,10 @@ import { RECOMMENDED_JAVA_VERSION, RECOMMENDED_NODE_VERSION } from 'generator-jh import { fromMatrix } from 'generator-jhipster/testing'; const defaultMatrix = { - os: ['ubuntu-latest'], + os: ['macos-13'], 'node-version': [RECOMMENDED_NODE_VERSION], 'java-version': [RECOMMENDED_JAVA_VERSION], - 'default-environment': ['prod'], + 'default-environment': ['dev'], }; export const buildMatrix = async samplesFolder => { diff --git a/.blueprint/github-build-matrix/command.mjs b/.blueprint/github-build-matrix/command.mjs new file mode 100644 index 000000000..b62fa1e19 --- /dev/null +++ b/.blueprint/github-build-matrix/command.mjs @@ -0,0 +1,38 @@ +/** + * Copyright 2013-2024 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 + * + * https://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. + */ +import { readdir } from 'node:fs/promises'; + +/** + * @type {import('generator-jhipster').JHipsterCommandDefinition} + */ +const command = { + configs: { + samplesFolder: { + description: 'Samples folder', + cli: { + type: String, + }, + default: 'samples', + scope: 'generator', + }, + }, + options: {}, +}; + +export default command; diff --git a/.blueprint/github-build-matrix/generator.mjs b/.blueprint/github-build-matrix/generator.mjs index 2535cccb0..d36967455 100644 --- a/.blueprint/github-build-matrix/generator.mjs +++ b/.blueprint/github-build-matrix/generator.mjs @@ -4,14 +4,32 @@ import BaseGenerator from 'generator-jhipster/generators/base'; import { buildMatrix } from './build-matrix.mjs'; export default class extends BaseGenerator { + samplesFolder; + constructor(args, opts, features) { super(args, opts, { ...features, jhipsterBootstrap: false }); } + get [BaseGenerator.INITIALIZING]() { + return this.asInitializingTaskGroup({ + async parseCommand() { + await this.parseCurrentJHipsterCommand(); + }, + }); + } + + get [BaseGenerator.LOADING]() { + return this.asLoadingTaskGroup({ + async loadCommand() { + await this.loadCurrentJHipsterCommandConfig(undefined); + }, + }); + } + get [BaseGenerator.WRITING]() { return this.asWritingTaskGroup({ async buildMatrix() { - const matrix = await buildMatrix(this.templatePath('../../generate-sample/templates/samples')); + const matrix = await buildMatrix(this.templatePath(`../../generate-sample/templates/${this.samplesFolder}`)); const matrixoutput = `matrix<