Skip to content

Commit

Permalink
feat(): add option to generate project using numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
pdobrowolski99 committed Apr 25, 2022
1 parent 47b61ba commit 4ad985c
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
32 changes: 32 additions & 0 deletions src/lib/application/application.factory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,38 @@ describe('Application Factory', () => {
});
});
});
it('should manage name as number', async () => {
const options: ApplicationOptions = {
name: 123,
};
const tree: UnitTestTree = await runner
.runSchematicAsync('application', options)
.toPromise();
const files: string[] = tree.files;
expect(files).toEqual([
'/123/.eslintrc.js',
'/123/.gitignore',
'/123/.prettierrc',
'/123/README.md',
'/123/nest-cli.json',
'/123/package.json',
'/123/tsconfig.build.json',
'/123/tsconfig.json',
'/123/src/app.controller.spec.ts',
'/123/src/app.controller.ts',
'/123/src/app.module.ts',
'/123/src/app.service.ts',
'/123/src/main.ts',
'/123/test/app.e2e-spec.ts',
'/123/test/jest-e2e.json',
]);

expect(
JSON.parse(tree.readContent('/123/package.json')),
).toMatchObject({
name: '123',
});
});
it('should manage javascript files', async () => {
const options: ApplicationOptions = {
name: 'project',
Expand Down
6 changes: 3 additions & 3 deletions src/lib/application/application.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
import { ApplicationOptions } from './application.schema';

export function main(options: ApplicationOptions): Rule {
options.name = normalizeToKebabOrSnakeCase(options.name);
options.name = normalizeToKebabOrSnakeCase(options.name.toString());

const path =
!options.directory || options.directory === 'undefined'
Expand Down Expand Up @@ -62,8 +62,8 @@ function transform(options: ApplicationOptions): ApplicationOptions {
* but only the rule *1* is addressed by this function as the other ones doesn't
* have a canonical representation.
*/
function resolvePackageName(path: string) {
const { base: baseFilename, dir: dirname } = parse(path);
function resolvePackageName(path: string | number) {
const { base: baseFilename, dir: dirname } = parse(path.toString());
if (baseFilename === '.') {
return basename(process.cwd());
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/application/application.schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export interface ApplicationOptions {
/**
* Nest application name.
*/
name: string;
name: string | number;
/**
* Nest application author.
*/
Expand Down
5 changes: 4 additions & 1 deletion src/lib/application/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
"type": "object",
"properties": {
"name": {
"type": "string",
"oneOf": [
{ "type": "string" },
{ "type": "number" }
],
"description": "The name of the application.",
"$default": {
"$source": "argv",
Expand Down

0 comments on commit 4ad985c

Please sign in to comment.