Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

regenerate blueprint files #35

Merged
merged 3 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
20 changes: 20 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,24 @@ const command = {
type: String,
},
},
configs: {
sampleName: {
prompt: gen => ({
when: !gen.all,
type: 'list',
message: 'which sample do you want to generate?',
choices: async () => readdir(gen.templatePath('samples')),
}),
scope: 'generator',
},
all: {
description: 'Generate every sample in a workspace',
cli: {
type: Boolean,
},
scope: 'generator',
},
},
options: {},
import: [GENERATOR_APP],
};
Expand Down
36 changes: 21 additions & 15 deletions .blueprint/generate-sample/generator.mjs
Original file line number Diff line number Diff line change
@@ -1,56 +1,62 @@
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;
all;

constructor(args, opts, features) {
super(args, opts, { ...features, jhipsterBootstrap: false });
}

get [BaseGenerator.INITIALIZING]() {
return this.asInitializingTaskGroup({
async parseCommand() {
await this.parseCurrentJHipsterCommand();
},
async initializeOptions() {
this.parseJHipsterArguments(command.arguments);
if (this.sampleName && !this.sampleName.endsWith('.jdl')) {
this.sampleName += '.jdl';
}
this.parseJHipsterOptions(command.options);
},
});
}

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.WRITING]() {
return this.asWritingTaskGroup({
async copySample() {
this.copyTemplate(`samples/${this.sampleName}`, this.sampleName, { noGlob: true });
if (this.all) {
this.copyTemplate('samples/*.jdl', '');
} else {
this.copyTemplate(`samples/${this.sampleName}`, this.sampleName, { noGlob: true });
}
},
});
}

get [BaseGenerator.END]() {
return this.asEndTaskGroup({
async generateSample() {
const packageJson = JSON.parse(readFileSync(new URL('../../package.json', import.meta.url)));
const projectVersion = `${packageJson.version}-git`;

await this.composeWithJHipster('jdl', {
generatorArgs: [this.sampleName],
generatorArgs: this.all ? await readdir(this.templatePath('samples')) : [this.sampleName],
generatorOptions: {
skipJhipsterDependencies: true,
insight: false,
skipChecks: true,
skipInstall: true,
projectVersion,
...(this.all ? { workspaces: true, monorepository: true } : { skipInstall: true }),
},
});
},
Expand Down
22 changes: 22 additions & 0 deletions .blueprint/github-build-matrix/build-matrix.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { readdir } from 'fs/promises';
import { RECOMMENDED_JAVA_VERSION, RECOMMENDED_NODE_VERSION } from 'generator-jhipster';
import { fromMatrix } from 'generator-jhipster/testing';

const defaultMatrix = {
os: ['ubuntu-latest'],
'node-version': [RECOMMENDED_NODE_VERSION],
'java-version': [RECOMMENDED_JAVA_VERSION],
'default-environment': ['prod'],
};

export const buildMatrix = async samplesFolder => {
const samples = await readdir(samplesFolder);
return {
include: Object.values(
fromMatrix({
...defaultMatrix,
'sample-name': samples.filter(sample => !sample.includes('disabled')),
}),
),
};
};
24 changes: 24 additions & 0 deletions .blueprint/github-build-matrix/generator.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { existsSync, appendFileSync } from 'node:fs';
import os from 'node:os';
import BaseGenerator from 'generator-jhipster/generators/base';
import { buildMatrix } from './build-matrix.mjs';

export default class extends BaseGenerator {
constructor(args, opts, features) {
super(args, opts, { ...features, jhipsterBootstrap: false });
}

get [BaseGenerator.WRITING]() {
return this.asWritingTaskGroup({
async buildMatrix() {
const matrix = await buildMatrix(this.templatePath('../../generate-sample/templates/samples'));
const matrixoutput = `matrix<<EOF${os.EOL}${JSON.stringify(matrix)}${os.EOL}EOF${os.EOL}`;
const filePath = process.env['GITHUB_OUTPUT'];
console.log(matrixoutput);
if (filePath && existsSync(filePath)) {
appendFileSync(filePath, matrixoutput, { encoding: 'utf8' });
}
},
});
}
}
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';
8 changes: 3 additions & 5 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"env": {
"node": true,
"es2020": true
"es2022": true
},
"extends": ["airbnb-base", "plugin:prettier/recommended"],
"extends": ["eslint:recommended", "plugin:prettier/recommended"],
"parserOptions": {
"ecmaVersion": 11,
"ecmaVersion": 13,
"sourceType": "module"
},
"overrides": [
Expand All @@ -15,8 +15,6 @@
],
"rules": {
"func-names": "off",
"import/no-extraneous-dependencies": ["error", { "devDependencies": true }],
"import/no-unresolved": "off",
"no-restricted-syntax": [
"error",
{
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/generator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ jobs:
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: 18
node-version: 20
cache: 'npm'
- run: npm ci
- run: npm run test
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ out/
######################
.gradle/
/build/
/buildSrc/.gradle/
/buildSrc/build/

######################
# Package Files
Expand Down
3 changes: 2 additions & 1 deletion .yo-resolve
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
!package.json skip
generators/** skip
README.md
2 changes: 1 addition & 1 deletion cli/cli.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const blueprint = packageFolderName.startsWith('jhipster-') ? `generator-${packa
console.log('===================== JHipster jooq =====================');
console.log('');
},
lookups: [{ packagePaths: [packagePath], lookups: ['generators'] }],
lookups: [{ packagePaths: [packagePath] }],
}).catch(done);

process.on('unhandledRejection', up => {
Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ export default defineConfig({
pool: 'forks',
hookTimeout: 20000,
exclude: [...defaultExclude.filter(val => val !== '**/cypress/**'), '**/templates/**', '**/resources/**'],
setupFiles: ['./vitest.test-setup.ts'],
},
});
6 changes: 6 additions & 0 deletions vitest.test-setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { vi } from 'vitest';
import { defineDefaults } from 'generator-jhipster/testing';

defineDefaults({
mockFactory: () => vi.fn(),
});
Loading