-
-
Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy pathgenerator.ts
More file actions
96 lines (86 loc) · 3.4 KB
/
generator.ts
File metadata and controls
96 lines (86 loc) · 3.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import { readFileSync } from 'node:fs';
import { readdir } from 'node:fs/promises';
import { extname, join } from 'node:path';
import { getGithubSamplesGroup } from 'generator-jhipster/ci';
import BaseCoreGenerator from 'generator-jhipster/generators/base-core';
export default class extends BaseCoreGenerator {
samplesFolder?: string;
samplesGroup!: string;
sampleName!: string;
all?: boolean;
sampleType?: string;
sampleFile?: string;
generatorOptions: any;
get [BaseCoreGenerator.WRITING]() {
return this.asAnyTaskGroup({
async copySample() {
const { samplesFolder, samplesGroup, all, sampleName } = this;
const samplesPath = samplesFolder ? join(samplesFolder, samplesGroup) : samplesGroup;
if (all) {
this.copyTemplate(`${samplesPath}/*.jdl`, '');
this.sampleType = 'jdl';
} else if (extname(sampleName) === '.jdl') {
this.copyTemplate(join(samplesPath, sampleName), sampleName, { noGlob: true });
this.sampleType = 'jdl';
} else {
const { samples } = await getGithubSamplesGroup(this.templatePath(), samplesPath);
const {
'sample-type': sampleType,
'sample-file': sampleFile = sampleName,
'sample-folder': sampleFolder = samplesPath,
generatorOptions,
templateOptions = {},
} = samples[sampleName] as any;
this.generatorOptions = generatorOptions;
this.sampleType = sampleType === 'jdl-ejs' ? 'jdl' : sampleType;
if (sampleType === 'jdl') {
const jdlFile = `${sampleFile}.jdl`;
this.copyTemplate(join(sampleFolder, jdlFile), jdlFile, { noGlob: true });
} else if (sampleType === 'jdl-ejs') {
const jdlFile = `${sampleFile}.jdl`;
this.renderTemplate(join(sampleFolder, `${jdlFile}.ejs`), jdlFile, templateOptions, { noGlob: true });
} else if (sampleType === 'yo-rc') {
this.copyTemplate('**', '', {
fromBasePath: this.templatePath(sampleFolder, sampleFile),
globOptions: { dot: true },
});
}
}
},
});
}
get [BaseCoreGenerator.END]() {
return this.asAnyTaskGroup({
async generateYoRcSample() {
if (this.sampleType !== 'yo-rc') return;
const generatorOptions = this.getDefaultComposeOptions();
await this.composeWithJHipster('app', { generatorOptions });
},
async generateJdlSample() {
if (this.sampleType !== 'jdl') return;
const generatorOptions = this.getDefaultComposeOptions();
const folderContent = await readdir(this.destinationPath());
const jdlFiles = folderContent.filter(file => file.endsWith('.jdl'));
await this.composeWithJHipster('jdl', {
generatorArgs: jdlFiles,
generatorOptions: {
...generatorOptions,
...(this.all ? { workspaces: true, monorepository: true } : { skipInstall: true }),
},
});
},
async jhipsterInfo() {
await this.composeWithJHipster('info');
},
});
}
getDefaultComposeOptions() {
const packageJson = JSON.parse(readFileSync(new URL('../../package.json', import.meta.url), { encoding: 'utf-8' }));
const projectVersion = `${packageJson.version}-git`;
return {
skipJhipsterDependencies: true,
projectVersion,
...this.generatorOptions,
};
}
}