Skip to content

Commit

Permalink
Merge pull request #26624 from mshima/javascript-bootstrap
Browse files Browse the repository at this point in the history
add javascript:bootstrap generator
  • Loading branch information
DanielFran authored Jul 4, 2024
2 parents 3d6488d + 99bb4b3 commit 612acef
Show file tree
Hide file tree
Showing 14 changed files with 334 additions and 139 deletions.
3 changes: 2 additions & 1 deletion generators/client/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import type { addIconImport, addItemToMenu, addRoute } from '../angular/support/
import type { AngularApplication } from '../angular/types.js';
import type { OptionWithDerivedProperties } from '../base-application/application-options.js';
import type { CypressApplication } from '../cypress/types.js';
import { JavaScriptSourceType } from '../javascript/types.js';
import type { JavaScriptApplication, JavaScriptSourceType } from '../javascript/types.js';

type ClientFrameworkType = ['no', 'angular', 'react', 'vue', 'svelte'];

type ClientFrameworkApplication = OptionWithDerivedProperties<'clientFramework', ClientFrameworkType>;

export type ClientApplication = ClientFrameworkApplication &
JavaScriptApplication &
AngularApplication &
CypressApplication & {
withAdminUi: boolean;
Expand Down
44 changes: 0 additions & 44 deletions generators/init/__snapshots__/generator.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -30,55 +30,11 @@ exports[`generator - init with default config should write files and match snaps
".gitignore": {
"stateCleared": "modified",
},
".husky/pre-commit": {
"stateCleared": "modified",
},
".lintstagedrc.cjs": {
"stateCleared": "modified",
},
".prettierignore": {
"stateCleared": "modified",
},
".prettierrc.yml": {
"stateCleared": "modified",
},
".yo-rc.json": {
"stateCleared": "modified",
},
"README.md": {
"stateCleared": "modified",
},
"package.json": {
"stateCleared": "modified",
},
}
`;
exports[`generator - init with skipCommitHook option should not create husky files and match snapshot 1`] = `
{
".editorconfig": {
"stateCleared": "modified",
},
".gitattributes": {
"stateCleared": "modified",
},
".gitignore": {
"stateCleared": "modified",
},
".prettierignore": {
"stateCleared": "modified",
},
".prettierrc.yml": {
"stateCleared": "modified",
},
".yo-rc.json": {
"stateCleared": "modified",
},
"README.md": {
"stateCleared": "modified",
},
"package.json": {
"stateCleared": "modified",
},
}
`;
24 changes: 3 additions & 21 deletions generators/init/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,10 @@
* limitations under the License.
*/
export const files = {
git: [
{
templates: ['.gitignore.jhi', '.gitattributes.jhi'],
},
],
global: [
{
templates: [
'.editorconfig.jhi',
{
override: false,
file: 'package.json',
},
],
},
],
git: [{ templates: ['.gitignore.jhi', '.gitattributes.jhi'] }],
global: [{ templates: ['.editorconfig.jhi'] }],
};

export const readme = {
global: [
{
templates: ['README.md'],
},
],
global: [{ templates: ['README.md'] }],
};
33 changes: 2 additions & 31 deletions generators/init/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
* limitations under the License.
*/
import BaseApplicationGenerator from '../base-application/index.js';
import { GENERATOR_GIT, GENERATOR_PROJECT_NAME } from '../generator-list.js';
import { packageJson } from '../../lib/index.js';
import { GENERATOR_GIT } from '../generator-list.js';
import { files, readme } from './files.js';

/**
Expand All @@ -34,7 +33,7 @@ export default class InitGenerator extends BaseApplicationGenerator {
}

if (!this.delegateToBlueprint) {
await this.dependsOnJHipster(GENERATOR_PROJECT_NAME);
await this.dependsOnJHipster('jhipster:javascript:bootstrap');
}
}

Expand All @@ -53,18 +52,6 @@ export default class InitGenerator extends BaseApplicationGenerator {
return this.delegateTasksToBlueprint(() => this.composing);
}

get loading() {
return this.asLoadingTaskGroup({
loadConfig({ application }) {
application.applicationNodeEngine = packageJson.engines.node;
},
});
}

get [BaseApplicationGenerator.LOADING]() {
return this.delegateTasksToBlueprint(() => this.loading);
}

get writing() {
return this.asWritingTaskGroup({
cleanup() {
Expand All @@ -86,20 +73,4 @@ export default class InitGenerator extends BaseApplicationGenerator {
get [BaseApplicationGenerator.WRITING]() {
return this.delegateTasksToBlueprint(() => this.writing);
}

get postWriting() {
return this.asPostWritingTaskGroup({
addPrettierDependencies({ application }) {
this.packageJson.merge({
engines: {
node: application.applicationNodeEngine,
},
});
},
});
}

get [BaseApplicationGenerator.POST_WRITING]() {
return this.delegateTasksToBlueprint(() => this.postWriting);
}
}
37 changes: 17 additions & 20 deletions generators/init/generator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ import { basename, dirname, join } from 'path';
import { fileURLToPath } from 'url';
import { before, it, describe, expect } from 'esmocha';
import { basicTests, getCommandHelpOutput, testBlueprintSupport } from '../../test/support/tests.js';
import { defaultHelpers as helpers } from '../../testing/index.js';
import { GENERATOR_JHIPSTER } from '../generator-constants.js';
import { defaultHelpers as helpers, result } from '../../testing/index.js';
import { GENERATOR_INIT } from '../generator-list.js';
import { defaultConfig, requiredConfig } from './config.js';

Expand Down Expand Up @@ -51,28 +50,26 @@ describe(`generator - ${generator}`, () => {
});
describe('with', () => {
describe('default config', () => {
let runResult;
before(async () => {
runResult = await helpers.run(generatorPath);
await helpers
.runJHipster('init')
.withMockedJHipsterGenerators(['bootstrap'])
.withSharedApplication({ projectDescription: 'projectDescription' })
.withJHipsterConfig();
});
it('should write files and match snapshot', () => {
expect(runResult.getStateSnapshot()).toMatchSnapshot();
expect(result.getStateSnapshot()).toMatchSnapshot();
});
});
describe('skipCommitHook option', () => {
let runResult;
const options = { skipCommitHook: true, baseName: 'jhipster' };
before(async () => {
runResult = await helpers
.run(generatorPath)
.withMockedGenerators(['jhipster:git'])
.withOptions({ ...options });
});
it('should write options to .yo-rc.json', () => {
runResult.assertJsonFileContent('.yo-rc.json', { [GENERATOR_JHIPSTER]: options });
});
it('should not create husky files and match snapshot', () => {
expect(runResult.getStateSnapshot()).toMatchSnapshot();

it('should compose with generators', () => {
expect(result.composedMockedGenerators).toMatchInlineSnapshot(`
[
"jhipster:git",
"jhipster:javascript:bootstrap",
"jhipster:javascript:husky",
"jhipster:javascript:prettier",
]
`);
});
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`generator - javascript:bootstrap customVersion-commonjs should call source snapshot 1`] = `{}`;

exports[`generator - javascript:bootstrap customVersion-commonjs should match files snapshot 1`] = `
{
".yo-rc.json": ObjectContaining {
"contents": Any<String>,
},
"package.json": {
"contents": "{
"name": "dasherizedBaseName",
"version": "0.0.0",
"description": "projectDescription",
"private": true,
"license": "UNLICENSED",
"dependencies": {},
"devDependencies": {},
"engines": {
"node": "customVersion"
},
"scripts": {},
"type": "commonjs"
}
",
"stateCleared": "modified",
},
}
`;
exports[`generator - javascript:bootstrap packageJsonNodeEngine(false)-module should call source snapshot 1`] = `{}`;
exports[`generator - javascript:bootstrap packageJsonNodeEngine(false)-module should match files snapshot 1`] = `
{
".yo-rc.json": ObjectContaining {
"contents": Any<String>,
},
"package.json": {
"contents": "{
"name": "dasherizedBaseName",
"version": "0.0.0",
"description": "projectDescription",
"private": true,
"license": "UNLICENSED",
"dependencies": {},
"devDependencies": {},
"engines": {},
"scripts": {},
"type": "module"
}
",
"stateCleared": "modified",
},
}
`;
exports[`generator - javascript:bootstrap packageJsonNodeEngine(true) should call source snapshot 1`] = `{}`;
exports[`generator - javascript:bootstrap packageJsonNodeEngine(true) should match files snapshot 1`] = `
{
".yo-rc.json": ObjectContaining {
"contents": Any<String>,
},
"package.json": {
"contents": "{
"name": "dasherizedBaseName",
"version": "0.0.0",
"description": "projectDescription",
"private": true,
"license": "UNLICENSED",
"dependencies": {},
"devDependencies": {},
"engines": {
"node": "^18.19.0 || >= 20.6.1"
},
"scripts": {}
}
",
"stateCleared": "modified",
},
}
`;
43 changes: 43 additions & 0 deletions generators/javascript/generators/bootstrap/command.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* Copyright 2013-2024 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 '../../../base/api.js';

const command: JHipsterCommandDefinition = {
configs: {
packageJsonNodeEngine: {
cli: {
// Accepts a boolean or a string
type: val => val,
hide: true,
},
scope: 'storage',
},
packageJsonType: {
cli: {
type: String,
hide: true,
},
choices: ['commonjs', 'module'],
scope: 'storage',
},
},
import: [],
};

export default command;
Loading

0 comments on commit 612acef

Please sign in to comment.