Generate a util-lib
workspace generator:
nx generate @nrwl/workspace:workspace-generator util-lib
Running the generator in dry mode
nx workspace-generator util-lib test --dry-run
import { Tree , formatFiles , installPackagesTask } from '@nrwl/devkit' ;
import { libraryGenerator } from '@nrwl/workspace/generators' ;
export default async function ( host : Tree , schema : any ) {
await libraryGenerator ( host , {
name : `util-${ schema . name } ` ,
} ) ;
await formatFiles ( host ) ;
return ( ) => {
installPackagesTask ( host ) ;
} ;
}
Adding an enum to a generator that prompts when empty
{
"directory" : {
"type" : " string" ,
"description" : " The scope of your lib." ,
"x-prompt" : {
"message" : " Which directory do you want the lib to be in?" ,
"type" : " list" ,
"items" : [
{
"value" : " store" ,
"label" : " store"
},
{
"value" : " api" ,
"label" : " api"
},
{
"value" : " shared" ,
"label" : " shared"
}
]
}
}
}
import { Tree , formatFiles , installPackagesTask } from '@nrwl/devkit' ;
import { libraryGenerator } from '@nrwl/workspace/generators' ;
export default async function ( host : Tree , schema : any ) {
await libraryGenerator ( host , {
name : `util-${ schema . name } ` ,
directory : schema . directory
} ) ;
await formatFiles ( host ) ;
return ( ) => {
installPackagesTask ( host ) ;
} ;
}
import { Tree , formatFiles , installPackagesTask } from '@nrwl/devkit' ;
import { libraryGenerator } from '@nrwl/workspace/generators' ;
export default async function ( host : Tree , schema : any ) {
await libraryGenerator ( host , {
name : `util-${ schema . name } ` ,
directory : schema . directory ,
tags : `type:util, scope:${ schema . directory } `
} ) ;
await formatFiles ( host ) ;
return ( ) => {
installPackagesTask ( host ) ;
} ;
}
interface Schema {
name : string ;
directory : 'store' | 'api' | 'shared' ;
}