Skip to content

Commit

Permalink
fix generate-blueprint test.
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Aug 30, 2022
1 parent c607da8 commit e227105
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/generator-generate-blueprint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ jobs:
mkdir generator-jhipster-foo
cd generator-jhipster-foo
cp $JHI_INTEG/generate-blueprint-samples/default/.yo-rc.json .
jhipster generate-blueprint --force --skip-jhipster-dependencies
jhipster generate-blueprint --force --skip-jhipster-dependencies --generate-snapshots
npm link generator-jhipster
npm link
- name: 'GENERATION: config'
Expand Down
2 changes: 1 addition & 1 deletion generators/cypress/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ module.exports = class extends BaseBlueprintGenerator {
_prompting() {
return {
async askForCypressOptions() {
if (this.options.existingProject || !this.jhipsterConfig.testFrameworks.includes(CYPRESS)) {
if (this.options.existingProject || !(this.jhipsterConfig.testFrameworks || []).includes(CYPRESS)) {
return;
}
await this.prompt(
Expand Down
5 changes: 5 additions & 0 deletions generators/generate-blueprint/constants.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { BASE_PRIORITY_NAMES, ENTITY_PRIORITY_NAMES } from '../../lib/constants/

const prioritiesForSub = subGenerator => (subGenerator.startsWith('entit') ? ENTITY_PRIORITY_NAMES : BASE_PRIORITY_NAMES);

export const GENERATE_SNAPSHOTS = 'generateSnapshots';
export const GENERATORS = 'generators';
export const SUB_GENERATORS = 'subGenerators';
export const ADDITIONAL_SUB_GENERATORS = 'additionalSubGenerators';
Expand All @@ -39,6 +40,10 @@ export const WRITTEN = 'written';
* Options exposed to cli
*/
export const options = () => ({
[GENERATE_SNAPSHOTS]: {
desc: 'Generate test snapshots',
type: Boolean,
},
[SUB_GENERATORS]: {
desc: 'Sub generators to generate',
type: Array,
Expand Down
17 changes: 12 additions & 5 deletions generators/generate-blueprint/generator.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
PREPARING_PRIORITY,
WRITING_PRIORITY,
POST_WRITING_PRIORITY,
INSTALL_PRIORITY,
POST_INSTALL_PRIORITY,
END_PRIORITY,
} from '../../lib/constants/priorities.mjs';
import {
Expand All @@ -42,6 +42,7 @@ import {
allGeneratorsConfig,
prompts,
subGeneratorPrompts,
GENERATE_SNAPSHOTS,
ALL_GENERATORS,
GENERATORS,
PRIORITIES,
Expand Down Expand Up @@ -321,25 +322,31 @@ export default class extends BaseBlueprintGenerator {
return this.postWriting;
}

get install() {
get postInstall() {
return {
async addSnapshot() {
if (this.options.skipInstall || this.options.skipGit || this.config.existed) return;
const generateSnapshots = this.options[GENERATE_SNAPSHOTS];
if (generateSnapshots === undefined ? this.options.skipInstall || this.options.skipGit || this.config.existed : !generateSnapshots)
return;
// Generate snapshots to add to git.
this.log(`
This is a new blueprint, executing '${chalk.yellow('npm run update-snapshot')}' to generate snapshots and commit to git.`);
try {
await this.spawnCommand('npm', ['run', 'update-snapshot']);
} catch (error) {
if (generateSnapshots !== undefined) {
// We are forcing to generate snapshots fail the generation.
throw error;
}
this.log('Fail to generate snapshots');
}
},
};
}

get [INSTALL_PRIORITY]() {
get [POST_INSTALL_PRIORITY]() {
if (this.delegateToBlueprint) return {};
return this.install;
return this.postInstall;
}

get end() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
See the License for the specific language governing permissions and
limitations under the License.
-%>
import expect from 'expect';
import { expect } from 'expect';

import { helpers, lookups } from '#test-utils';

Expand Down
18 changes: 18 additions & 0 deletions generators/generator-base-blueprint.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,24 @@ module.exports = class JHipsterBaseBlueprintGenerator extends BaseGenerator {
return {};
}

/**
* Priority API stub for blueprints.
*
* PostWriting priority should used to customize files.
*
* @returns {Object.<string, YeomanTask>} generator tasks
*/
get postInstall() {
return this._postInstall();
}

/**
* Public API method used by the getter and also by Blueprints
*/
_postInstall() {
return {};
}

/**
* Priority API stub for blueprints.
*
Expand Down
16 changes: 16 additions & 0 deletions lib/constants/priorities.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ const POST_WRITING_ENTITIES = 'postWritingEntities';
const POST_WRITING_ENTITIES_PRIORITY = `${PRIORITY_PREFIX}${POST_WRITING_ENTITIES}`;
const POST_WRITING_ENTITIES_QUEUE = `${QUEUE_PREFIX}${POST_WRITING_ENTITIES}`;

const POST_INSTALL = 'postInstall';
const POST_INSTALL_PRIORITY = `${PRIORITY_PREFIX}${POST_INSTALL}`;
const POST_INSTALL_QUEUE = `${QUEUE_PREFIX}${POST_INSTALL}`;

/** @private */
const PRE_CONFLICTS = 'preConflicts';
/** @private */
Expand Down Expand Up @@ -168,6 +172,12 @@ const CUSTOM_PRIORITIES = [
args: generator => generator.getArgsForPriority(INSTALL),
edit: true,
},
{
priorityName: POST_INSTALL,
queueName: POST_INSTALL_QUEUE,
before: END,
args: generator => generator.getArgsForPriority(POST_INSTALL),
},
{
priorityName: END,
args: generator => generator.getArgsForPriority(END),
Expand Down Expand Up @@ -200,6 +210,7 @@ const compat = {
POST_WRITING_ENTITIES_PRIORITY: POST_WRITING_ENTITIES,
PRE_CONFLICTS_PRIORITY: PRE_CONFLICTS,
INSTALL_PRIORITY: INSTALL,
POST_INSTALL_PRIORITY: POST_INSTALL,
END_PRIORITY: END,
};

Expand Down Expand Up @@ -227,6 +238,7 @@ const PRIORITY_NAMES = {
POST_WRITING_ENTITIES,
PRE_CONFLICTS,
INSTALL,
POST_INSTALL,
END,
};

Expand All @@ -241,6 +253,7 @@ const BASE_PRIORITY_NAMES = [
WRITING,
POST_WRITING,
INSTALL,
POST_INSTALL,
END,
];

Expand Down Expand Up @@ -318,6 +331,7 @@ const QUEUES = {
POST_WRITING_ENTITIES_QUEUE,
PRE_CONFLICTS_QUEUE,
INSTALL_QUEUE: INSTALL,
POST_INSTALL_QUEUE,
END_QUEUE: END,
};

Expand All @@ -334,6 +348,7 @@ const ENTITY_PRIORITY_NAMES = [
WRITING,
POST_WRITING,
INSTALL,
POST_INSTALL,
END,
];

Expand Down Expand Up @@ -382,5 +397,6 @@ module.exports = {
POST_WRITING_ENTITIES_PRIORITY,
PRE_CONFLICTS_PRIORITY,
INSTALL_PRIORITY,
POST_INSTALL_PRIORITY,
END_PRIORITY,
};
1 change: 1 addition & 0 deletions lib/constants/priorities.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@ export {
POST_WRITING_ENTITIES_PRIORITY,
PRE_CONFLICTS_PRIORITY,
INSTALL_PRIORITY,
POST_INSTALL_PRIORITY,
END_PRIORITY,
} from './priorities.cjs';
4 changes: 4 additions & 0 deletions test/__snapshots__/api.spec.mjs.snap
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ Object {
"writing",
"postWriting",
"install",
"postInstall",
"end",
],
"COMPOSING_PRIORITY": ">composing",
Expand All @@ -88,12 +89,14 @@ Object {
"writing",
"postWriting",
"install",
"postInstall",
"end",
],
"INITIALIZING_PRIORITY": ">initializing",
"INSTALL_PRIORITY": ">install",
"LOADING_EACH_ENTITY_PRIORITY": ">loadingEachEntity",
"LOADING_PRIORITY": ">loading",
"POST_INSTALL_PRIORITY": ">postInstall",
"POST_PREPARING_EACH_ENTITY_PRIORITY": ">postPreparingEachEntity",
"POST_WRITING_ENTITIES_PRIORITY": ">postWritingEntities",
"POST_WRITING_PRIORITY": ">postWriting",
Expand All @@ -114,6 +117,7 @@ Object {
"INSTALL": "install",
"LOADING": "loading",
"LOADING_EACH_ENTITY": "loadingEachEntity",
"POST_INSTALL": "postInstall",
"POST_PREPARING_EACH_ENTITY": "postPreparingEachEntity",
"POST_WRITING": "postWriting",
"POST_WRITING_ENTITIES": "postWritingEntities",
Expand Down

0 comments on commit e227105

Please sign in to comment.