Skip to content

Commit

Permalink
Merge pull request #23087 from mshima/skip_ci-dev-blueprint
Browse files Browse the repository at this point in the history
add a development blueprint
  • Loading branch information
DanielFran authored Aug 11, 2023
2 parents 7d60e90 + f0cee5e commit 417330f
Show file tree
Hide file tree
Showing 24 changed files with 553 additions and 185 deletions.
35 changes: 35 additions & 0 deletions .blueprint/cli/commands.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Copyright 2013-2023 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.
*/

const defaultCommands = {
'code-workspace': {
desc: 'Prepare a code-workspace for jhipster development',
blueprint: '@jhipster/jhipster-dev',
},
'generate-sample': {
desc: 'Generate a test sample',
blueprint: '@jhipster/jhipster-dev',
},
'update-vscode': {
desc: 'Update generator-jhipster vscode files',
blueprint: '@jhipster/jhipster-dev',
},
};

export default defaultCommands;
32 changes: 32 additions & 0 deletions .blueprint/code-workspace/command.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Copyright 2013-2023 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 { type JHipsterCommandDefinition } from '../../generators/base/api.mjs';

const command: JHipsterCommandDefinition = {
arguments: {},
options: {
sampleName: {
type: String,
description: 'Sample Name',
scope: 'generator',
},
},
};

export default command;
72 changes: 72 additions & 0 deletions .blueprint/code-workspace/generator.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { join } from 'path';
import _ from 'lodash';
import BaseGenerator from '../../generators/base/index.mjs';
import { getPackageRoot } from '../../lib/index.mjs';
import command from './command.mjs';
import { defaultSamplesFolder, promptSamplesFolder, samplesFolderConfig } from '../support.mjs';

const { merge } = _;

export default class extends BaseGenerator {
sampleName;

get [BaseGenerator.INITIALIZING]() {
return this.asInitializingTaskGroup({
async initializeOptions() {
this.parseJHipsterArguments(command.arguments);
this.parseJHipsterOptions(command.options);
},
});
}

get [BaseGenerator.PROMPTING]() {
return this.asPromptingTaskGroup({
promptSamplesFolder,
});
}

get [BaseGenerator.WRITING]() {
return this.asEndTaskGroup({
async generateCodeWorkspace() {
this.addSampleToCodeWorkspace(this.sampleName);
},
});
}

getCodeWorkspacePath() {
return join(this._globalConfig.get(samplesFolderConfig) ?? defaultSamplesFolder, 'jhipster-samples.code-workspace');
}

/**
* Merge value to an existing JSON and write to destination
*/
addSampleToCodeWorkspace(sampleName) {
this.editFile(this.getCodeWorkspacePath(), { create: true }, content => {
const data = content ? JSON.parse(content) : {};
merge(data, {
folders: [
{
path: getPackageRoot(),
},
],
settings: {
'debug.javascript.terminalOptions': {
skipFiles: ['node_modules/**', 'dist/**'],
},
},
launch: {
version: '0.2.0',
inputs: [],
configurations: [],
},
});
if (this.sampleName && !data.folders.find(folder => folder.path === sampleName)) {
data.folders.push({
path: this.sampleName,
});
}

return JSON.stringify(data, null, 2);
});
}
}
2 changes: 2 additions & 0 deletions .blueprint/code-workspace/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default } from './generator.mjs';
export { default as command } from './command.mjs';
15 changes: 15 additions & 0 deletions .blueprint/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { join } from 'path';
import { getPackageRoot } from '../lib/index.mjs';

const packageRoot = getPackageRoot();
export const defaultSamplesFolder = join(packageRoot, '../jhipster-samples');
export const testIntegrationFolder = join(packageRoot, 'test-integration');
export const samplesFolder = join(testIntegrationFolder, 'samples');

export const jhipsterBin = join(packageRoot, 'bin/jhipster.cjs');

export const jdlSamplesFolder = join(testIntegrationFolder, 'jdl-samples');
export const dailyBuildsFolder = join(testIntegrationFolder, 'daily-builds');
export const jdlEntitiesSamplesFolder = join(samplesFolder, 'jdl-entities');

export const entitiesSamplesDir = join(samplesFolder, '.jhipster');
42 changes: 42 additions & 0 deletions .blueprint/generate-sample/command.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* Copyright 2013-2023 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 { JHipsterCommandDefinition } from '../../generators/base/api.mjs';

const command: JHipsterCommandDefinition = {
arguments: {
sampleName: {
type: String,
},
},
options: {
global: {
type: Boolean,
description: 'Generate in global samples folder',
scope: 'generator',
},
projectFolder: {
type: String,
description: 'Folder to generate the sample',
scope: 'generator',
env: 'JHI_FOLDER_APP',
},
},
};

export default command;
47 changes: 47 additions & 0 deletions .blueprint/generate-sample/generator.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import BaseGenerator from '../../generators/base/index.mjs';
import command from './command.mjs';
import { generateSample } from './support/generate-sample.js';
import { promptSamplesFolder } from '../support.mjs';

export default class extends BaseGenerator {
sampleName;
global;
projectFolder;

get [BaseGenerator.INITIALIZING]() {
return this.asInitializingTaskGroup({
async initializeOptions() {
this.parseJHipsterArguments(command.arguments);
this.parseJHipsterOptions(command.options);
},
});
}

get [BaseGenerator.PROMPTING]() {
return this.asPromptingTaskGroup({
async promptOptions() {
if (this.global) {
promptSamplesFolder.call(this);
}
},
});
}

get [BaseGenerator.END]() {
return this.asEndTaskGroup({
async generateSample() {
await generateSample(this.sampleName, {
destSamplesFolder: this._globalConfig.get('samplesFolder'),
destProjectFolder: this.projectFolder ?? this.global ? undefined : process.cwd(),
});
if (this.global) {
await this.composeWithJHipster('@jhipster/jhipster-dev:code-workspace', {
generatorOptions: {
sampleName: this.sampleName,
},
});
}
},
});
}
}
2 changes: 2 additions & 0 deletions .blueprint/generate-sample/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default } from './generator.mjs';
export { default as command } from './command.mjs';
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { cpSync, mkdirSync } from 'fs';
import { dirname, join } from 'path';
import { fileURLToPath } from 'url';

const entitiesSamplesDir = join(dirname(fileURLToPath(import.meta.url)), '../../samples/.jhipster');
import { join } from 'path';
import { entitiesSamplesDir } from '../../constants.js';

const sqllight = ['BankAccount', 'Label', 'Operation'];

Expand Down Expand Up @@ -105,6 +103,9 @@ export const entitiesByType = {
};

export default function copyEntitySamples(dest, type) {
if (type === 'mongodb' || type === 'couchbase') {
type = 'document';
}
const entitiesFolder = join(dest, '.jhipster');
mkdirSync(entitiesFolder, { recursive: true });
const entities = entitiesByType[type];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { cpSync, mkdirSync, statSync } from 'fs';
import { dirname, extname, join } from 'path';
import { fileURLToPath } from 'url';

const samplesFolder = join(dirname(fileURLToPath(import.meta.url)), '../../samples');
const jdlEntitiesSamplesFolder = join(samplesFolder, 'jdl-entities');
import { extname, join } from 'path';
import { jdlEntitiesSamplesFolder } from '../../constants.js';

const isDirectory = dir => {
try {
Expand Down
Loading

0 comments on commit 417330f

Please sign in to comment.