Skip to content

Commit ffb9918

Browse files
committed
chore: migrate to typescript
1 parent 7e60a6d commit ffb9918

71 files changed

Lines changed: 333 additions & 235 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
* See the License for the specific language governing permissions and
1717
* limitations under the License.
1818
*/
19+
import type { JHipsterCommandDefinition } from 'generator-jhipster';
1920
import { getGithubSamplesGroup, getGithubSamplesGroups } from 'generator-jhipster/ci';
2021

22+
import type Generator from './generator.js';
23+
2124
const DEFAULT_SAMPLES_GROUP = 'samples';
2225

23-
/**
24-
* @type {import('generator-jhipster').JHipsterCommandDefinition}
25-
*/
2626
const command = {
2727
arguments: {
2828
sampleName: {
@@ -59,7 +59,7 @@ const command = {
5959
when: !gen.all,
6060
type: 'select',
6161
message: 'which sample do you want to generate?',
62-
choices: async answers => {
62+
choices: async (answers: any) => {
6363
const samples = await getGithubSamplesGroup(gen.templatePath(), answers.samplesGroup ?? gen.samplesGroup);
6464
return Object.keys(samples.samples);
6565
},
@@ -75,6 +75,6 @@ const command = {
7575
},
7676
},
7777
import: ['app'],
78-
};
78+
} as const satisfies JHipsterCommandDefinition<Generator>;
7979

8080
export default command;
Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,13 @@ import { getGithubSamplesGroup } from 'generator-jhipster/ci';
66
import BaseCoreGenerator from 'generator-jhipster/generators/base-core';
77

88
export default class extends BaseCoreGenerator {
9-
/** @type {string | undefined} */
10-
samplesFolder;
11-
/** @type {string} */
12-
samplesGroup;
13-
/** @type {string} */
14-
sampleName;
15-
/** @type {boolean} */
16-
all;
17-
/** @type {string} */
18-
sampleType;
19-
/** @type {string} */
20-
sampleFile;
21-
/** @type {any} */
22-
generatorOptions;
9+
samplesFolder?: string;
10+
samplesGroup!: string;
11+
sampleName!: string;
12+
all?: boolean;
13+
sampleType?: string;
14+
sampleFile?: string;
15+
generatorOptions: any;
2316

2417
get [BaseCoreGenerator.WRITING]() {
2518
return this.asAnyTaskGroup({
@@ -40,7 +33,7 @@ export default class extends BaseCoreGenerator {
4033
'sample-folder': sampleFolder = samplesPath,
4134
generatorOptions,
4235
templateOptions = {},
43-
} = samples[sampleName];
36+
} = samples[sampleName] as any;
4437

4538
this.generatorOptions = generatorOptions;
4639
this.sampleType = sampleType === 'jdl-ejs' ? 'jdl' : sampleType;
@@ -92,7 +85,7 @@ export default class extends BaseCoreGenerator {
9285
}
9386

9487
getDefaultComposeOptions() {
95-
const packageJson = JSON.parse(readFileSync(new URL('../../package.json', import.meta.url)));
88+
const packageJson = JSON.parse(readFileSync(new URL('../../package.json', import.meta.url), { encoding: 'utf-8' }));
9689
const projectVersion = `${packageJson.version}-git`;
9790
return {
9891
skipJhipsterDependencies: true,

.blueprint/generate-sample/index.mjs

Lines changed: 0 additions & 2 deletions
This file was deleted.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export { default } from './generator.ts';
2+
export { default as command } from './command.ts';
File renamed without changes.

.blueprint/github-build-matrix/__snapshots__/generator.spec.mjs.snap renamed to .blueprint/github-build-matrix/__snapshots__/generator.spec.ts.snap

File renamed without changes.

.blueprint/github-build-matrix/command.mjs renamed to .blueprint/github-build-matrix/command.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
/**
2-
* @type {import('generator-jhipster').JHipsterCommandDefinition}
3-
*/
1+
import type { JHipsterCommandDefinition } from 'generator-jhipster';
2+
43
const command = {
54
configs: {
65
samplesFolder: {
@@ -19,6 +18,6 @@ const command = {
1918
scope: 'generator',
2019
},
2120
},
22-
};
21+
} as const satisfies JHipsterCommandDefinition;
2322

2423
export default command;

.blueprint/github-build-matrix/generator.spec.mjs renamed to .blueprint/github-build-matrix/generator.spec.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
11
import { beforeAll, describe, expect, it } from 'vitest';
2-
import { basename, join } from 'path';
2+
import { basename, join } from 'node:path';
33

44
import { getGithubSamplesGroups } from 'generator-jhipster/ci';
5-
import { defaultHelpers as helpers, runResult } from 'generator-jhipster/testing';
5+
import { createTestHelpers, typedResult } from 'generator-jhipster/testing';
66

7+
import type Generator from './index.js';
8+
9+
const helpers = createTestHelpers<Generator>({
10+
importMeta: import.meta,
11+
});
12+
const result = typedResult<Generator>();
713
const generator = basename(import.meta.dirname);
814

915
describe(`generator - ${generator}`, async () => {
1016
const groups = await getGithubSamplesGroups(join(import.meta.dirname, '../generate-sample/templates/'));
1117
for (const workflow of groups.map(sample => sample.split('.')[0])) {
1218
describe(`with ${workflow}`, () => {
1319
beforeAll(async () => {
14-
await helpers.runJHipster(join(import.meta.dirname, 'index.mjs'), { prepareEnvironment: true }).withArguments(workflow);
20+
await helpers.runDefault().withArguments(workflow);
1521
});
1622

1723
it('should match matrix value', () => {
18-
expect(runResult.generator.matrix).toMatchSnapshot();
24+
expect(result.generator.matrix).toMatchSnapshot();
1925
});
2026
});
2127
}

.blueprint/github-build-matrix/generator.mjs renamed to .blueprint/github-build-matrix/generator.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
import { join } from 'node:path';
22

3-
import { convertToGitHubMatrix, getGithubOutputFile, getGithubSamplesGroup, setGithubTaskOutput } from 'generator-jhipster/ci';
3+
import {
4+
type GitHubMatrixOutput,
5+
convertToGitHubMatrix,
6+
getGithubOutputFile,
7+
getGithubSamplesGroup,
8+
setGithubTaskOutput,
9+
} from 'generator-jhipster/ci';
410
import BaseCoreGenerator from 'generator-jhipster/generators/base-core';
511

612
export default class extends BaseCoreGenerator {
7-
/** @type {string} */
8-
samplesFolder;
9-
/** @type {string} */
10-
samplesGroup;
11-
/** @type {object} */
12-
matrix;
13+
samplesFolder?: string;
14+
samplesGroup?: string;
15+
matrix?: GitHubMatrixOutput;
1316

1417
get [BaseCoreGenerator.WRITING]() {
1518
return this.asAnyTaskGroup({

0 commit comments

Comments
 (0)