Skip to content

Commit d8cdf37

Browse files
Merge pull request #1508 from micalevisk/fix/issue-generate-config-for-non-monorepo
feat(lib): support undefined project for 'configuration' schematic
2 parents fbe2727 + 0edaf5b commit d8cdf37

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

src/lib/configuration/configuration.factory.test.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,22 @@ describe('Configuration Factory', () => {
1010
'.',
1111
path.join(process.cwd(), 'src/collection.json'),
1212
);
13-
it('should manage a default configuation', async () => {
13+
it('should support missing project name by using the current working directory instead', async () => {
14+
const options: ConfigurationOptions = {
15+
project: undefined,
16+
};
17+
const tree: UnitTestTree = await runner.runSchematicAsync('configuration', options).toPromise();
18+
const files: string[] = tree.files;
19+
expect(
20+
files.find(filename => filename === '/nest-cli.json'),
21+
).not.toBeUndefined();
22+
expect(JSON.parse(tree.readContent('/nest-cli.json'))).toEqual({
23+
$schema: 'https://json.schemastore.org/nest-cli',
24+
collection: '@nestjs/schematics',
25+
sourceRoot: 'src',
26+
});
27+
});
28+
it('should manage a default configuration', async () => {
1429
const options: ConfigurationOptions = {
1530
project: 'project',
1631
};

src/lib/configuration/configuration.factory.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ function transform(options: ConfigurationOptions): ConfigurationOptions {
2525
}
2626

2727
function generate(options: ConfigurationOptions): Source {
28+
const projectOrPath = options.project ?? '.';
2829
return apply(url(join('./files' as Path, options.language)), [
2930
template({
3031
...strings,
3132
...options,
3233
}),
33-
move(options.project),
34+
move(projectOrPath),
3435
]);
3536
}

src/lib/configuration/configuration.schema.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
export interface ConfigurationOptions {
22
/**
33
* The project where generate the configuration.
4+
* If not supplied or nil, the file will be created in the current working directory instead.
45
*/
5-
project: string;
6+
project?: string;
67
/**
78
* The language to use in configuration (ts | js).
89
*/

0 commit comments

Comments
 (0)