Skip to content

Commit

Permalink
style: format everything
Browse files Browse the repository at this point in the history
  • Loading branch information
micalevisk committed Apr 24, 2023
1 parent f37bde8 commit c140159
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 48 deletions.
16 changes: 8 additions & 8 deletions actions/add.action.ts
Expand Up @@ -3,20 +3,20 @@ import { Input } from '../commands';
import { getValueOrDefault } from '../lib/compiler/helpers/get-value-or-default';
import {
AbstractPackageManager,
PackageManagerFactory
PackageManagerFactory,
} from '../lib/package-managers';
import {
AbstractCollection,
CollectionFactory,
SchematicOption
SchematicOption,
} from '../lib/schematics';
import { MESSAGES } from '../lib/ui';
import { loadConfiguration } from '../lib/utils/load-configuration';
import {
askForProjectName,
hasValidOptionFlag,
moveDefaultProjectToStart,
shouldAskForProject
shouldAskForProject,
} from '../lib/utils/project-utils';
import { AbstractAction } from './abstract.action';

Expand All @@ -29,10 +29,8 @@ export class AddAction extends AbstractAction {
const collectionName = this.getCollectionName(libraryName, packageName);
const tagName = this.getTagName(packageName);
const skipInstall = hasValidOptionFlag('skip-install', options);
const packageInstallSuccess = skipInstall || await this.installPackage(
collectionName,
tagName,
);
const packageInstallSuccess =
skipInstall || (await this.installPackage(collectionName, tagName));
if (packageInstallSuccess) {
const sourceRootOption: Input = await this.getSourceRoot(
inputs.concat(options),
Expand All @@ -46,7 +44,9 @@ export class AddAction extends AbstractAction {
MESSAGES.LIBRARY_INSTALLATION_FAILED_BAD_PACKAGE(libraryName),
),
);
throw new Error(MESSAGES.LIBRARY_INSTALLATION_FAILED_BAD_PACKAGE(libraryName));
throw new Error(
MESSAGES.LIBRARY_INSTALLATION_FAILED_BAD_PACKAGE(libraryName),
);
}
}

Expand Down
2 changes: 1 addition & 1 deletion actions/build.action.ts
Expand Up @@ -13,7 +13,7 @@ import { WebpackCompiler } from '../lib/compiler/webpack-compiler';
import { WorkspaceUtils } from '../lib/compiler/workspace-utils';
import {
ConfigurationLoader,
NestConfigurationLoader
NestConfigurationLoader,
} from '../lib/configuration';
import { defaultOutDir } from '../lib/configuration/defaults';
import { FileSystemReader } from '../lib/readers';
Expand Down
9 changes: 3 additions & 6 deletions commands/generate.command.ts
Expand Up @@ -107,9 +107,7 @@ export class GenerateCommand extends AbstractCommand {
const collection = await this.getCollection();
return (
'Generate a Nest element.\n' +
` Schematics available on ${chalk.bold(
collection,
)} collection:\n` +
` Schematics available on ${chalk.bold(collection)} collection:\n` +
this.buildSchematicsListAsTable(await this.getSchematics(collection))
);
}
Expand Down Expand Up @@ -145,9 +143,8 @@ export class GenerateCommand extends AbstractCommand {
}

private async getSchematics(collection: string): Promise<Schematic[]> {
const abstractCollection: AbstractCollection = CollectionFactory.create(
collection,
);
const abstractCollection: AbstractCollection =
CollectionFactory.create(collection);
return abstractCollection.getSchematics();
}
}
2 changes: 1 addition & 1 deletion commands/new.command.ts
Expand Up @@ -13,7 +13,7 @@ export class NewCommand extends AbstractCommand {
.option(
'-d, --dry-run',
'Report actions that would be performed without writing out results.',
false
false,
)
.option('-g, --skip-git', 'Skip git repository initialization.', false)
.option('-s, --skip-install', 'Skip package installation.', false)
Expand Down
8 changes: 7 additions & 1 deletion lib/compiler/helpers/get-value-or-default.ts
Expand Up @@ -5,7 +5,13 @@ export function getValueOrDefault<T = any>(
configuration: Required<Configuration>,
propertyPath: string,
appName: string,
key?: 'path' | 'webpack' | 'webpackPath' | 'entryFile' | 'sourceRoot' | 'exec',
key?:
| 'path'
| 'webpack'
| 'webpackPath'
| 'entryFile'
| 'sourceRoot'
| 'exec',
options: Input[] = [],
defaultValue?: T,
): T {
Expand Down
8 changes: 6 additions & 2 deletions lib/package-managers/package-manager.factory.ts
Expand Up @@ -26,10 +26,14 @@ export class PackageManagerFactory {
const files = await fs.promises.readdir(process.cwd());

const hasYarnLockFile = files.includes('yarn.lock');
if (hasYarnLockFile) return this.create(PackageManager.YARN);
if (hasYarnLockFile) {
return this.create(PackageManager.YARN);
}

const hasPnpmLockFile = files.includes('pnpm-lock.yaml');
if (hasPnpmLockFile) return this.create(PackageManager.PNPM);
if (hasPnpmLockFile) {
return this.create(PackageManager.PNPM);
}

return this.create(DEFAULT_PACKAGE_MANAGER);
} catch (error) {
Expand Down
4 changes: 3 additions & 1 deletion lib/schematics/collection.factory.ts
Expand Up @@ -7,7 +7,9 @@ import { NestCollection } from './nest.collection';

export class CollectionFactory {
public static create(collection: Collection | string): AbstractCollection {
const schematicRunner = RunnerFactory.create(Runner.SCHEMATIC) as SchematicRunner;
const schematicRunner = RunnerFactory.create(
Runner.SCHEMATIC,
) as SchematicRunner;

if (collection === Collection.NESTJS) {
return new NestCollection(schematicRunner);
Expand Down
42 changes: 23 additions & 19 deletions lib/utils/project-utils.ts
Expand Up @@ -69,19 +69,19 @@ export function shouldGenerateSpec(
}

export function shouldGenerateFlat(
configuration: Required<Configuration>,
appName: string,
flatValue: boolean,
configuration: Required<Configuration>,
appName: string,
flatValue: boolean,
): boolean {
// CLI parameters have the highest priority
if (flatValue === true) {
return flatValue;
}

const flatConfiguration = getValueOrDefault(
configuration,
'generateOptions.flat',
appName || '',
configuration,
'generateOptions.flat',
appName || '',
);
if (typeof flatConfiguration === 'boolean') {
return flatConfiguration;
Expand All @@ -90,30 +90,29 @@ export function shouldGenerateFlat(
}

export function getSpecFileSuffix(
configuration: Required<Configuration>,
appName: string,
specFileSuffixValue: string,
configuration: Required<Configuration>,
appName: string,
specFileSuffixValue: string,
): string {
// CLI parameters have the highest priority
if (specFileSuffixValue) {
return specFileSuffixValue;
}

const specFileSuffixConfiguration = getValueOrDefault(
configuration,
'generateOptions.specFileSuffix',
appName || '',
undefined,
undefined,
'spec',
configuration,
'generateOptions.specFileSuffix',
appName || '',
undefined,
undefined,
'spec',
);
if (typeof specFileSuffixConfiguration === 'string') {
return specFileSuffixConfiguration;
}
return specFileSuffixValue;
}


export async function askForProjectName(
promptQuestion: string,
projects: string[],
Expand Down Expand Up @@ -141,8 +140,13 @@ export function moveDefaultProjectToStart(
return projects;
}

export function hasValidOptionFlag(queriedOptionName: string, options: Input[], queriedValue: string|number|boolean = true): boolean {
export function hasValidOptionFlag(
queriedOptionName: string,
options: Input[],
queriedValue: string | number | boolean = true,
): boolean {
return options.some(
(option: Input) => option.name === queriedOptionName && option.value === queriedValue
(option: Input) =>
option.name === queriedOptionName && option.value === queriedValue,
);
}
}
6 changes: 5 additions & 1 deletion test/lib/package-managers/pnpm.package-manager.spec.ts
Expand Up @@ -39,7 +39,11 @@ describe('PnpmPackageManager', () => {
const dirName = '/tmp';
const testDir = join(process.cwd(), dirName);
packageManager.install(dirName, 'pnpm');
expect(spy).toBeCalledWith('install --strict-peer-dependencies=false --reporter=silent', true, testDir);
expect(spy).toBeCalledWith(
'install --strict-peer-dependencies=false --reporter=silent',
true,
testDir,
);
});
});
describe('addProduction', () => {
Expand Down
14 changes: 6 additions & 8 deletions test/lib/readers/file-system.reader.spec.ts
@@ -1,14 +1,12 @@
import * as fs from 'fs';
import { FileSystemReader, Reader } from '../../../lib/readers';

jest.mock('fs', () =>
({
promises: {
readdir: jest.fn().mockResolvedValue([]),
readFile: jest.fn().mockResolvedValue('content'),
},
})
);
jest.mock('fs', () => ({
promises: {
readdir: jest.fn().mockResolvedValue([]),
readFile: jest.fn().mockResolvedValue('content'),
},
}));

const dir: string = process.cwd();
const reader: Reader = new FileSystemReader(dir);
Expand Down

0 comments on commit c140159

Please sign in to comment.