Skip to content

Commit

Permalink
add samplesFolder option to local blueprints.
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Jun 6, 2024
1 parent a7399e4 commit c0361fa
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 5 deletions.
8 changes: 8 additions & 0 deletions .blueprint/generate-sample/command.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
13 changes: 11 additions & 2 deletions .blueprint/generate-sample/generator.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand All @@ -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 });
}
},
});
Expand Down
4 changes: 2 additions & 2 deletions .blueprint/github-build-matrix/build-matrix.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
38 changes: 38 additions & 0 deletions .blueprint/github-build-matrix/command.mjs
Original file line number Diff line number Diff line change
@@ -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;
20 changes: 19 additions & 1 deletion .blueprint/github-build-matrix/generator.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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<<EOF${os.EOL}${JSON.stringify(matrix)}${os.EOL}EOF${os.EOL}`;
const filePath = process.env['GITHUB_OUTPUT'];
console.log(matrixoutput);
Expand Down
1 change: 1 addition & 0 deletions .blueprint/github-build-matrix/index.mjs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { default } from './generator.mjs';
export { default as command } from './command.mjs';

0 comments on commit c0361fa

Please sign in to comment.