@@ -5,9 +5,20 @@ import BaseGenerator from 'generator-jhipster/generators/base';
55import { getGithubSamplesGroup } from 'generator-jhipster/testing' ;
66
77export default class extends BaseGenerator {
8+ /** @type {string | undefined } */
9+ samplesFolder ;
10+ /** @type {string } */
11+ samplesGroup ;
12+ /** @type {string } */
813 sampleName ;
14+ /** @type {boolean } */
915 all ;
10- samplesFolder ;
16+ /** @type {string } */
17+ sampleType ;
18+ /** @type {string } */
19+ sampleFile ;
20+ /** @type {any } */
21+ generatorOptions ;
1122
1223 constructor ( args , opts , features ) {
1324 super ( args , opts , { ...features , queueCommandTasks : true , jhipsterBootstrap : false } ) ;
@@ -16,20 +27,33 @@ export default class extends BaseGenerator {
1627 get [ BaseGenerator . WRITING ] ( ) {
1728 return this . asWritingTaskGroup ( {
1829 async copySample ( ) {
19- const { samplesFolder, all, sampleName } = this ;
30+ const { samplesFolder, samplesGroup, all, sampleName } = this ;
31+ const samplesPath = samplesFolder ? join ( samplesFolder , samplesGroup ) : samplesGroup ;
2032 if ( all ) {
21- this . copyTemplate ( `${ samplesFolder } /*.jdl` , '' ) ;
33+ this . copyTemplate ( `${ samplesPath } /*.jdl` , '' ) ;
34+ this . sampleType = 'jdl' ;
2235 } else if ( extname ( sampleName ) === '.jdl' ) {
23- this . copyTemplate ( join ( samplesFolder , sampleName ) , sampleName , { noGlob : true } ) ;
36+ this . copyTemplate ( join ( samplesPath , sampleName ) , sampleName , { noGlob : true } ) ;
37+ this . sampleType = 'jdl' ;
2438 } else {
25- const { samples } = await getGithubSamplesGroup ( this . templatePath ( ) , samplesFolder ) ;
26- const { 'sample-type' : sampleType } = samples [ sampleName ] ;
39+ const { samples } = await getGithubSamplesGroup ( this . templatePath ( ) , samplesPath ) ;
40+ const {
41+ 'sample-type' : sampleType ,
42+ 'sample-file' : sampleFile = sampleName ,
43+ 'sample-folder' : sampleFolder = samplesPath ,
44+ generatorOptions,
45+ } = samples [ sampleName ] ;
46+
47+ this . generatorOptions = generatorOptions ;
48+ this . sampleType = sampleType ;
49+
2750 if ( sampleType === 'jdl' ) {
28- const jdlFile = `${ sampleName } .jdl` ;
29- this . copyTemplate ( join ( samplesFolder , jdlFile ) , jdlFile , { noGlob : true } ) ;
51+ const jdlFile = `${ sampleFile } .jdl` ;
52+ this . copyTemplate ( join ( sampleFolder , jdlFile ) , jdlFile , { noGlob : true } ) ;
3053 } else if ( sampleType === 'yo-rc' ) {
31- this . copyTemplate ( join ( samplesFolder , sampleName , '**' ) , '' , {
32- fromBasePath : this . templatesPath ( samplesFolder , sampleName ) ,
54+ this . copyTemplate ( '**' , '' , {
55+ fromBasePath : this . templatePath ( sampleFolder , sampleFile ) ,
56+ globOptions : { dot : true } ,
3357 } ) ;
3458 }
3559 }
@@ -39,17 +63,23 @@ export default class extends BaseGenerator {
3963
4064 get [ BaseGenerator . END ] ( ) {
4165 return this . asEndTaskGroup ( {
42- async generateSample ( ) {
43- const packageJson = JSON . parse ( readFileSync ( new URL ( '../../package.json' , import . meta. url ) ) ) ;
44- const projectVersion = `${ packageJson . version } -git` ;
66+ async generateYoRcSample ( ) {
67+ if ( this . sampleType !== 'yo-rc' ) return ;
68+
69+ const generatorOptions = this . getDefaultComposeOptions ( ) ;
70+ await this . composeWithJHipster ( 'app' , { generatorOptions } ) ;
71+ } ,
72+ async generateJdlSample ( ) {
73+ if ( this . sampleType !== 'jdl' ) return ;
74+
75+ const generatorOptions = this . getDefaultComposeOptions ( ) ;
76+ const folderContent = await readdir ( this . destinationPath ( ) ) ;
77+ const jdlFiles = folderContent . filter ( file => file . endsWith ( '.jdl' ) ) ;
4578
4679 await this . composeWithJHipster ( 'jdl' , {
47- generatorArgs : this . all ? await readdir ( this . templatePath ( 'samples' ) ) : [ this . sampleName ] ,
80+ generatorArgs : jdlFiles ,
4881 generatorOptions : {
49- skipJhipsterDependencies : true ,
50- insight : false ,
51- skipChecks : true ,
52- projectVersion,
82+ ...generatorOptions ,
5383 ...( this . all ? { workspaces : true , monorepository : true } : { skipInstall : true } ) ,
5484 } ,
5585 } ) ;
@@ -59,4 +89,14 @@ export default class extends BaseGenerator {
5989 } ,
6090 } ) ;
6191 }
92+
93+ getDefaultComposeOptions ( ) {
94+ const packageJson = JSON . parse ( readFileSync ( new URL ( '../../package.json' , import . meta. url ) ) ) ;
95+ const projectVersion = `${ packageJson . version } -git` ;
96+ return {
97+ skipJhipsterDependencies : true ,
98+ projectVersion,
99+ ...this . generatorOptions ,
100+ } ;
101+ }
62102}
0 commit comments