Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(): load configuration via same entry #1421

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 4 additions & 13 deletions actions/build.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,11 @@ import { TypeScriptBinaryLoader } from '../lib/compiler/typescript-loader';
import { WatchCompiler } from '../lib/compiler/watch-compiler';
import { WebpackCompiler } from '../lib/compiler/webpack-compiler';
import { WorkspaceUtils } from '../lib/compiler/workspace-utils';
import {
ConfigurationLoader,
NestConfigurationLoader,
} from '../lib/configuration';
import { defaultOutDir } from '../lib/configuration/defaults';
import { FileSystemReader } from '../lib/readers';
import { ERROR_PREFIX } from '../lib/ui';
import { AbstractAction } from './abstract.action';
import webpack = require('webpack');
import { loadConfiguration } from '../lib/utils/load-configuration';

export class BuildAction extends AbstractAction {
protected readonly pluginsLoader = new PluginsLoader();
Expand All @@ -36,10 +32,6 @@ export class BuildAction extends AbstractAction {
this.tsConfigProvider,
this.tsLoader,
);
protected readonly fileSystemReader = new FileSystemReader(process.cwd());
protected readonly loader: ConfigurationLoader = new NestConfigurationLoader(
this.fileSystemReader,
);
protected readonly assetsManager = new AssetsManager();
protected readonly workspaceUtils = new WorkspaceUtils();

Expand Down Expand Up @@ -75,7 +67,7 @@ export class BuildAction extends AbstractAction {
) {
const configFileName = options.find((option) => option.name === 'config')!
.value as string;
const configuration = await this.loader.load(configFileName);
const configuration = await loadConfiguration(configFileName);
const appName = inputs.find((input) => input.name === 'app')!
.value as string;

Expand All @@ -86,9 +78,8 @@ export class BuildAction extends AbstractAction {
'path',
options,
);
const { options: tsOptions } = this.tsConfigProvider.getByConfigFilename(
pathToTsconfig,
);
const { options: tsOptions } =
this.tsConfigProvider.getByConfigFilename(pathToTsconfig);
const outDir = tsOptions.outDir || defaultOutDir;
const isWebpackEnabled = getValueOrDefault<boolean>(
configuration,
Expand Down
3 changes: 2 additions & 1 deletion actions/start.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ import { Configuration } from '../lib/configuration';
import { defaultOutDir } from '../lib/configuration/defaults';
import { ERROR_PREFIX } from '../lib/ui';
import { BuildAction } from './build.action';
import { loadConfiguration } from '../lib/utils/load-configuration';

export class StartAction extends BuildAction {
public async handle(inputs: Input[], options: Input[]) {
try {
const configFileName = options.find((option) => option.name === 'config')!
.value as string;
const configuration = await this.loader.load(configFileName);
const configuration = await loadConfiguration(configFileName);
const appName = inputs.find((input) => input.name === 'app')!
.value as string;

Expand Down
13 changes: 9 additions & 4 deletions lib/utils/load-configuration.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { Configuration, ConfigurationLoader } from '../configuration';
import { NestConfigurationLoader } from '../configuration/nest-configuration.loader';
import {
Configuration,
ConfigurationLoader,
NestConfigurationLoader,
} from '../configuration';
import { FileSystemReader } from '../readers';

export async function loadConfiguration(): Promise<Required<Configuration>> {
export async function loadConfiguration(
name?: string,
): Promise<Required<Configuration>> {
const loader: ConfigurationLoader = new NestConfigurationLoader(
new FileSystemReader(process.cwd()),
);
return loader.load();
return loader.load(name);
}