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 cf7e19b
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 7 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
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
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_PRIORITY,
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';

0 comments on commit cf7e19b

Please sign in to comment.