Skip to content

Commit

Permalink
improvements to dev blueprint
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Apr 22, 2024
1 parent d4ea0f0 commit 2291e83
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 10 deletions.
4 changes: 4 additions & 0 deletions .blueprint/cli/commands.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ const defaultCommands = {
desc: 'Generate a test sample',
blueprint: '@jhipster/jhipster-dev',
},
'github-build-matrix': {
desc: 'Build a matrix of jobs for github actions',
blueprint: '@jhipster/jhipster-dev',
},
};

export default defaultCommands;
15 changes: 15 additions & 0 deletions .blueprint/generate-sample/command.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { readdir } from 'node:fs/promises';
import { GENERATOR_APP } from 'generator-jhipster/generators';

/**
* @type {import('generator-jhipster').JHipsterCommandDefinition}
*/
Expand All @@ -26,6 +28,19 @@ const command = {
type: String,
},
},
configs: {
sampleName: {
argument: {
type: String,
},
prompt: gen => ({
type: 'list',
message: 'which sample do you want to generate?',
choices: async () => readdir(gen.templatePath('samples')),
}),
scope: 'generator',
},
},
options: {},
import: [GENERATOR_APP],
};
Expand Down
19 changes: 9 additions & 10 deletions .blueprint/generate-sample/generator.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { readdir } from 'node:fs/promises';
import { readFileSync } from 'node:fs';
import BaseGenerator from 'generator-jhipster/generators/base';
import command from './command.mjs';

export default class extends BaseGenerator {
sampleName;
Expand All @@ -26,15 +25,15 @@ export default class extends BaseGenerator {
get [BaseGenerator.PROMPTING]() {
return this.asPromptingTaskGroup({
async askForSample() {
if (!this.sampleName) {
const answers = await this.prompt({
type: 'list',
name: 'sampleName',
message: 'which sample do you want to generate?',
choices: async () => readdir(this.templatePath('samples')),
});
this.sampleName = answers.sampleName;
}
await this.promptCurrentJHipsterCommand();
},
});
}

get [BaseGenerator.LOADING]() {
return this.asPromptingTaskGroup({
async promptingTemplateTask({ application }) {
await this.loadCurrentJHipsterCommandConfig(application);
},
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
application {
config {
applicationType monolith
blueprints [tenantview]
cacheProvider no
creationTimestamp 1632872179205
jwtSecretKey "ZjY4MTM4YjI5YzMwZjhjYjI2OTNkNTRjMWQ5Y2Q0Y2YwOWNmZTE2NzRmYzU3NTMwM2NjOTE3MTllOTM3MWRkMzcyYTljMjVmNmQ0Y2MxOTUzODc0MDhhMTlkMDIxMzI2YzQzZDM2ZDE3MmQ3NjVkODk3OTVmYzljYTQyZDNmMTQ="
testFrameworks [cypress]
}

entities Blog, Post, Tag
}

@TenantAware
entity Blog {
name String required minlength(3)
handle String required minlength(2)
}

@TenantAware
entity Post {
title String required
content TextBlob required
date Instant required
}

@TenantAware
entity Tag {
name String required minlength(2)
}
Expand Down
31 changes: 31 additions & 0 deletions .blueprint/github-build-matrix/generator.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { existsSync, appendFileSync } from 'node:fs';
import os from 'node:os';
import { readdir } from 'node:fs/promises';
import BaseGenerator from 'generator-jhipster/generators/base';
import { RECOMMENDED_JAVA_VERSION, RECOMMENDED_NODE_VERSION } from 'generator-jhipster';

export default class extends BaseGenerator {
get [BaseGenerator.WRITING]() {
return this.asWritingTaskGroup({
async buildMatrix() {
const samples = await readdir(this.templatePath('../../generate-sample/templates/samples'));
const matrix = {
include: samples
.filter(sample => !sample.includes('disabled'))
.map(sample => ({
'sample-name': sample,
'node-version': RECOMMENDED_NODE_VERSION,
'java-version': RECOMMENDED_JAVA_VERSION,
})),
};
const matrixoutput = `matrix<<EOF${os.EOL}${JSON.stringify(matrix)}${os.EOL}EOF${os.EOL}`;
const filePath = process.env['GITHUB_OUTPUT'];
if (filePath && existsSync(filePath)) {
appendFileSync(filePath, matrixoutput, { encoding: 'utf8' });
} else {
console.log(matrixoutput);
}
},
});
}
}
1 change: 1 addition & 0 deletions .blueprint/github-build-matrix/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './generator.mjs';

0 comments on commit 2291e83

Please sign in to comment.