From 8852587b63e8f1fcbbf17774019b33fb37dfefdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20My=C5=9Bliwiec?= Date: Mon, 17 Sep 2018 19:30:51 +0200 Subject: [PATCH 1/3] feature: add sourceRoot option --- actions/generate.action.ts | 26 ++++++++++++++++++++------ lib/configuration/configuration.ts | 2 +- lib/configuration/defaults.ts | 1 + 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/actions/generate.action.ts b/actions/generate.action.ts index e0977f07e..18538d4c4 100644 --- a/actions/generate.action.ts +++ b/actions/generate.action.ts @@ -3,7 +3,11 @@ import { Input } from '../commands'; import { Configuration, ConfigurationLoader } from '../lib/configuration'; import { NestConfigurationLoader } from '../lib/configuration/nest-configuration.loader'; import { FileSystemReader } from '../lib/readers'; -import { AbstractCollection, CollectionFactory, SchematicOption } from '../lib/schematics'; +import { + AbstractCollection, + CollectionFactory, + SchematicOption, +} from '../lib/schematics'; import { AbstractAction } from './abstract.action'; export class GenerateAction extends AbstractAction { @@ -14,11 +18,19 @@ export class GenerateAction extends AbstractAction { const generateFiles = async (inputs: Input[]) => { const configuration: Configuration = await loadConfiguration(); - const collection: AbstractCollection = CollectionFactory.create(configuration.collection); + const collection: AbstractCollection = CollectionFactory.create( + configuration.collection, + ); const schematicOptions: SchematicOption[] = mapSchematicOptions(inputs); - schematicOptions.push(new SchematicOption('language', configuration.language)); + + schematicOptions.push( + new SchematicOption('language', configuration.language), + ); + schematicOptions.push( + new SchematicOption('sourceRoot', configuration.sourceRoot), + ); try { - const schematicInput = inputs.find((input) => input.name === 'schematic'); + const schematicInput = inputs.find(input => input.name === 'schematic'); if (!schematicInput) { throw new Error('Unable to find a schematic for this configuration'); } @@ -31,13 +43,15 @@ const generateFiles = async (inputs: Input[]) => { }; const loadConfiguration = async (): Promise => { - const loader: ConfigurationLoader = new NestConfigurationLoader(new FileSystemReader(process.cwd())); + const loader: ConfigurationLoader = new NestConfigurationLoader( + new FileSystemReader(process.cwd()), + ); return loader.load(); }; const mapSchematicOptions = (inputs: Input[]): SchematicOption[] => { const options: SchematicOption[] = []; - inputs.forEach((input) => { + inputs.forEach(input => { if (input.name !== 'schematic' && input.value !== undefined) { options.push(new SchematicOption(input.name, input.value)); } diff --git a/lib/configuration/configuration.ts b/lib/configuration/configuration.ts index 9d808dcb0..0fedc98be 100644 --- a/lib/configuration/configuration.ts +++ b/lib/configuration/configuration.ts @@ -1,3 +1,3 @@ export interface Configuration { - [ key: string ]: any; + [key: string]: any; } diff --git a/lib/configuration/defaults.ts b/lib/configuration/defaults.ts index 0b25c2d26..e92138600 100644 --- a/lib/configuration/defaults.ts +++ b/lib/configuration/defaults.ts @@ -1,4 +1,5 @@ export const defaultConfiguration = { language: 'ts', + sourceRoot: 'src', collection: '@nestjs/schematics', }; From 8ec2647f1b1ffbff8ab6a69ad81d72a624ab717a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20My=C5=9Bliwiec?= Date: Mon, 17 Sep 2018 19:31:05 +0200 Subject: [PATCH 2/3] improvement: support nest-cli.json (w/ dot) --- .../nest-configuration.loader.ts | 2 ++ .../nest.dependency-manager.ts | 19 +++++++------------ .../nest-configuration.loader.spec.ts | 2 ++ 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/lib/configuration/nest-configuration.loader.ts b/lib/configuration/nest-configuration.loader.ts index adf24de51..0b75012f8 100644 --- a/lib/configuration/nest-configuration.loader.ts +++ b/lib/configuration/nest-configuration.loader.ts @@ -9,6 +9,8 @@ export class NestConfigurationLoader implements ConfigurationLoader { const content: string | undefined = await this.reader.readAnyOf([ '.nestcli.json', '.nest-cli.json', + 'nest-cli.json', + 'nest.json', ]); return content ? JSON.parse(content) : defaultConfiguration; } diff --git a/lib/dependency-managers/nest.dependency-manager.ts b/lib/dependency-managers/nest.dependency-manager.ts index debfff326..a53a9aacc 100644 --- a/lib/dependency-managers/nest.dependency-manager.ts +++ b/lib/dependency-managers/nest.dependency-manager.ts @@ -6,32 +6,27 @@ export class NestDependencyManager { constructor(private packageManager: AbstractPackageManager) {} public async read(): Promise { - const dependencies: string[] = []; const production: ProjectDependency[] = await this.packageManager.getProduction(); return production - .filter((dependency) => dependency.name.indexOf('@nestjs') > -1) - .map((dependency) => dependency.name); + .filter(dependency => dependency.name.indexOf('@nestjs') > -1) + .map(dependency => dependency.name); } public async update(force: boolean, tag: string) { const spinner = ora({ spinner: { interval: 120, - frames: [ - '▹▹▹▹▹', - '▸▹▹▹▹', - '▹▸▹▹▹', - '▹▹▸▹▹', - '▹▹▹▸▹', - '▹▹▹▹▸', - ], + frames: ['▹▹▹▹▹', '▸▹▹▹▹', '▹▸▹▹▹', '▹▹▸▹▹', '▹▹▹▸▹', '▹▹▹▹▸'], }, text: messages.PACKAGE_MANAGER_UPDATE_IN_PROGRESS, }); spinner.start(); const dependencies: string[] = await this.read(); if (force) { - await this.packageManager.upgradeProduction(dependencies, tag !== undefined ? tag : 'latest'); + await this.packageManager.upgradeProduction( + dependencies, + tag !== undefined ? tag : 'latest', + ); } else { await this.packageManager.updateProduction(dependencies); } diff --git a/test/lib/configuration/nest-configuration.loader.spec.ts b/test/lib/configuration/nest-configuration.loader.spec.ts index c25d42ed7..29d8d73db 100644 --- a/test/lib/configuration/nest-configuration.loader.spec.ts +++ b/test/lib/configuration/nest-configuration.loader.spec.ts @@ -26,6 +26,8 @@ describe('Nest Configuration Loader', () => { expect(reader.readAnyOf).toHaveBeenCalledWith([ '.nestcli.json', '.nest-cli.json', + 'nest-cli.json', + 'nest.json', ]); expect(configuration).toEqual({ language: 'ts', From 5aeea6b1baa39491c6f516eb7051aeb963d54730 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20My=C5=9Bliwiec?= Date: Wed, 19 Sep 2018 12:20:39 +0200 Subject: [PATCH 3/3] chore: publish 5.5.0 release --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 4817a2f77..3f9858f78 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@nestjs/cli", - "version": "5.4.1", + "version": "5.5.0", "description": "Nest CLI", "publishConfig": { "access": "public" @@ -33,7 +33,7 @@ "dependencies": { "@angular-devkit/core": "^0.8.1", "@angular-devkit/schematics-cli": "^0.8.1", - "@nestjs/schematics": "^5.7.1", + "@nestjs/schematics": "^5.8.0", "@nuxtjs/opencollective": "^0.1.0", "@types/jest": "^22.2.3", "chalk": "^2.4.1",