From 2614d70434330f00493f24ba1b6a3c0a27c528a0 Mon Sep 17 00:00:00 2001 From: "Micael Levi L. Cavalcante" Date: Sat, 5 Aug 2023 17:49:54 -0400 Subject: [PATCH 1/2] feat(lib): support undefined project for 'configuration' schematic --- .../configuration.factory.test.ts | 18 +++++++++++++++++- src/lib/configuration/configuration.factory.ts | 3 ++- .../configuration/configuration.schema.d.ts | 3 ++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/lib/configuration/configuration.factory.test.ts b/src/lib/configuration/configuration.factory.test.ts index 9700edc4b..8d4e1c37e 100644 --- a/src/lib/configuration/configuration.factory.test.ts +++ b/src/lib/configuration/configuration.factory.test.ts @@ -10,7 +10,23 @@ describe('Configuration Factory', () => { '.', path.join(process.cwd(), 'src/collection.json'), ); - it('should manage a default configuation', async () => { + it('should support missing project name by using the current working directory instead', async () => { + const options: ConfigurationOptions = { + project: undefined, + }; + const tree: UnitTestTree = await runner.runSchematicAsync('configuration', options).toPromise(); + const files: string[] = tree.files; + console.log(files) + expect( + files.find(filename => filename === '/nest-cli.json'), + ).not.toBeUndefined(); + expect(JSON.parse(tree.readContent('/nest-cli.json'))).toEqual({ + $schema: 'https://json.schemastore.org/nest-cli', + collection: '@nestjs/schematics', + sourceRoot: 'src', + }); + }); + it('should manage a default configuration', async () => { const options: ConfigurationOptions = { project: 'project', }; diff --git a/src/lib/configuration/configuration.factory.ts b/src/lib/configuration/configuration.factory.ts index d7b1538e3..ee959f1bd 100644 --- a/src/lib/configuration/configuration.factory.ts +++ b/src/lib/configuration/configuration.factory.ts @@ -25,11 +25,12 @@ function transform(options: ConfigurationOptions): ConfigurationOptions { } function generate(options: ConfigurationOptions): Source { + const projectOrPath = options.project ?? '.'; return apply(url(join('./files' as Path, options.language)), [ template({ ...strings, ...options, }), - move(options.project), + move(projectOrPath), ]); } diff --git a/src/lib/configuration/configuration.schema.d.ts b/src/lib/configuration/configuration.schema.d.ts index a8c036eaf..295e8bda8 100644 --- a/src/lib/configuration/configuration.schema.d.ts +++ b/src/lib/configuration/configuration.schema.d.ts @@ -1,8 +1,9 @@ export interface ConfigurationOptions { /** * The project where generate the configuration. + * If not supplied or nil, the file will be created in the current working directory instead. */ - project: string; + project?: string; /** * The language to use in configuration (ts | js). */ From 0edaf5be4c940d20b7c4178ae01294eb682aa9c1 Mon Sep 17 00:00:00 2001 From: Kamil Mysliwiec Date: Mon, 7 Aug 2023 08:58:46 +0200 Subject: [PATCH 2/2] Update src/lib/configuration/configuration.factory.test.ts --- src/lib/configuration/configuration.factory.test.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lib/configuration/configuration.factory.test.ts b/src/lib/configuration/configuration.factory.test.ts index 8d4e1c37e..8cf7be3cf 100644 --- a/src/lib/configuration/configuration.factory.test.ts +++ b/src/lib/configuration/configuration.factory.test.ts @@ -16,7 +16,6 @@ describe('Configuration Factory', () => { }; const tree: UnitTestTree = await runner.runSchematicAsync('configuration', options).toPromise(); const files: string[] = tree.files; - console.log(files) expect( files.find(filename => filename === '/nest-cli.json'), ).not.toBeUndefined();