Skip to content

Commit

Permalink
Merge pull request #1508 from micalevisk/fix/issue-generate-config-fo…
Browse files Browse the repository at this point in the history
…r-non-monorepo

feat(lib): support undefined project for 'configuration' schematic
  • Loading branch information
kamilmysliwiec committed Aug 7, 2023
2 parents fbe2727 + 0edaf5b commit d8cdf37
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
17 changes: 16 additions & 1 deletion src/lib/configuration/configuration.factory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,22 @@ 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;
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',
};
Expand Down
3 changes: 2 additions & 1 deletion src/lib/configuration/configuration.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
]);
}
3 changes: 2 additions & 1 deletion src/lib/configuration/configuration.schema.d.ts
Original file line number Diff line number Diff line change
@@ -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).
*/
Expand Down

0 comments on commit d8cdf37

Please sign in to comment.