Skip to content

Commit

Permalink
handle common args
Browse files Browse the repository at this point in the history
  • Loading branch information
barbados-clemens committed Feb 9, 2023
1 parent ae3ab3a commit 2f1c8a6
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 136 deletions.
49 changes: 2 additions & 47 deletions packages/deno/src/executors/build/build.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { dirname, join, resolve } from 'path';
import { BuildExecutorSchema } from './schema';

import { ensureDirSync } from 'fs-extra';
import { processTypeCheckOption } from '../../utils/arg-utils';
import { processCommonArgs } from '../../utils/arg-utils';
import { runDeno } from '../../utils/run-deno';

export async function denoBuildExecutor(options: BuildExecutorSchema) {
Expand Down Expand Up @@ -43,52 +43,7 @@ function createArgs(options: BuildExecutorSchema) {

args.push(`--config=${options.denoConfig}`);

if (options.cert) {
args.push(`--cert=${options.cert}`);
}
if (options.check !== undefined) {
args.push(processTypeCheckOption(options.check));
}

if (options.lockWrite) {
args.push(`--lock-write`);
}

if (options.noLock) {
args.push(`--no-lock`);
}

if (options.noNpm) {
args.push(`--no-npm`);
}

if (options.noRemote) {
args.push(`--no-remote`);
}

if (options.nodeModulesDir) {
args.push(`--node-modules-dir=${options.nodeModulesDir}`);
}

if (options.quiet) {
args.push(`--quiet`);
}

if (options.reload) {
args.push(
`--reload${
typeof options.reload === 'string' ? `=${options.reload}` : ''
}`
);
}

if (options.unstable) {
args.push(`--unstable`);
}

if (options.watch) {
args.push(`--watch`);
}
args.push(...processCommonArgs(options));

args.push(options.main);

Expand Down
19 changes: 5 additions & 14 deletions packages/deno/src/executors/lint/lint.impl.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ExecutorContext, ProjectConfiguration } from '@nrwl/devkit';
import { processCommonArgs } from '../../utils/arg-utils';
import { runDeno } from '../../utils/run-deno';
import { LintExecutorSchema } from './schema';

Expand Down Expand Up @@ -41,7 +42,10 @@ function normalizeOpitons(
}

function createArgs(options: LintExecutorNormalizedSchema) {
const args: Array<string | boolean> = ['lint'];
const args: string[] = ['lint'];

args.push(`--config=${options.denoConfig}`);
args.push(...processCommonArgs(options));

if (options.compact) {
args.push('--compact');
Expand All @@ -55,10 +59,6 @@ function createArgs(options: LintExecutorNormalizedSchema) {
args.push('--json');
}

if (options.quiet) {
args.push('--quiet');
}

if (options.rulesExclude) {
args.push(`--rules-exclude=${options.rulesExclude}`);
}
Expand All @@ -71,15 +71,6 @@ function createArgs(options: LintExecutorNormalizedSchema) {
args.push(`--rules-tags=${options.rulesTags}`);
}

if (options.unstable) {
args.push('--unstable');
}

if (options.watch) {
args.push('--watch');
}

args.push(`--config=${options.denoConfig}`);
args.push(options.lintDir);

return args;
Expand Down
43 changes: 4 additions & 39 deletions packages/deno/src/executors/serve/serve.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
parseTargetString,
readTargetOptions,
} from '@nrwl/devkit';
import { processTypeCheckOption } from '../../utils/arg-utils';
import { processCommonArgs } from '../../utils/arg-utils';
import { runDeno } from '../../utils/run-deno';
import { BuildExecutorSchema } from '../build/schema';
import { ServeExecutorSchema } from './schema';
Expand Down Expand Up @@ -60,12 +60,7 @@ function createArgs(options: ServeExecutorSchema) {
const args = ['run', '--allow-all'];

args.push(`--config=${options.denoConfig}`);
if (options.cert) {
args.push(`--cert=${options.cert}`);
}
if (options.check !== undefined) {
args.push(processTypeCheckOption(options.check));
}
args.push(...processCommonArgs(options));

if (options.inspect) {
args.push(
Expand All @@ -76,44 +71,14 @@ function createArgs(options: ServeExecutorSchema) {
}`
);
}

if (options.location) {
args.push(`--location=${options.location}`);
}
if (options.lockWrite) {
args.push(`--lock-write`);
}
if (options.noLock) {
args.push(`--no-lock`);
}
if (options.noNpm) {
args.push(`--no-npm`);
}
if (options.noRemote) {
args.push(`--no-remote`);
}
if (options.nodeModulesDir) {
args.push(`--node-modules-dir=${options.nodeModulesDir}`);
}
if (options.quiet) {
args.push(`--quiet`);
}
if (options.reload) {
args.push(
`--reload${
typeof options.reload === 'string' ? `=${options.reload}` : ''
}`
);
}

if (options.seed) {
args.push(`--seed=${options.seed}`);
}
if (options.unstable) {
args.push('--unstable');
}

if (options.watch) {
args.push('--watch');
}

args.push(options.main);

Expand Down
38 changes: 2 additions & 36 deletions packages/deno/src/executors/test/test.impl.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ExecutorContext, logger } from '@nrwl/devkit';
import { emptyDirSync } from 'fs-extra';
import { join, posix, resolve, sep } from 'path';
import { processTypeCheckOption } from '../../utils/arg-utils';
import { processCommonArgs } from '../../utils/arg-utils';
import { runDeno } from '../../utils/run-deno';
import { DenoTestExecutorSchema } from './schema';

Expand Down Expand Up @@ -91,9 +91,7 @@ function createArgs(options: DenoTestExecutorNormalizedSchema) {
const args: Array<string | boolean | number> = ['test', '-A'];

args.push(`--config=${options.denoConfig}`);
if (options.watch) {
args.push('--watch');
}
args.push(...processCommonArgs(options));

if (options.coverageDirectory) {
if (options.inspect) {
Expand All @@ -103,14 +101,6 @@ function createArgs(options: DenoTestExecutorNormalizedSchema) {
}
}

if (options.check !== undefined) {
args.push(processTypeCheckOption(options.check));
}

if (options.cert) {
args.push('--cert', options.cert);
}

if (options.failFast) {
args.push(
`--fail-fast${
Expand All @@ -127,14 +117,6 @@ function createArgs(options: DenoTestExecutorNormalizedSchema) {
args.push(`--ignore=${options.ignore.join(',')}`);
}

if (options.inspect) {
args.push(
`--inspect-brk=${
typeof options.inspect === 'string' ? options.inspect : '127.0.0.1:9229'
}`
);
}

if (options.location) {
args.push(`--location=${options.location}`);
}
Expand All @@ -146,18 +128,6 @@ function createArgs(options: DenoTestExecutorNormalizedSchema) {
}
}

if (options.quiet) {
args.push('--quiet');
}

if (options.reload) {
args.push(
`--reload${
typeof options.reload === 'string' ? `=${options.reload}` : ''
}`
);
}

if (options.seed) {
args.push(`--seed=${options.seed}`);
}
Expand All @@ -166,10 +136,6 @@ function createArgs(options: DenoTestExecutorNormalizedSchema) {
args.push(`--shuffle=${options.shuffle}`);
}

if (options.unstable) {
args.push('--unstable');
}

args.push(options.testDir);
return args;
}
Expand Down
66 changes: 66 additions & 0 deletions packages/deno/src/utils/arg-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,69 @@ export function processTypeCheckOption(check: DenoTypeCheck): string {
}
return '--check';
}

/**
* handle args for:
* --cert
* --check
* --lock-write
* --no-lock
* --no-npm
* --no-remote
* --node-modules-dir
* --quiet
* --reload
* --unstable
* --watch
**/
export function processCommonArgs(options: Record<string, any>): string[] {
const args: string[] = [];
if (options.cert) {
args.push(`--cert=${options.cert}`);
}
if (options.check !== undefined) {
args.push(processTypeCheckOption(options.check));
}

if (options.lockWrite) {
args.push(`--lock-write`);
}

if (options.noLock) {
args.push(`--no-lock`);
}

if (options.noNpm) {
args.push(`--no-npm`);
}

if (options.noRemote) {
args.push(`--no-remote`);
}

if (options.nodeModulesDir) {
args.push(`--node-modules-dir=${options.nodeModulesDir}`);
}

if (options.quiet) {
args.push(`--quiet`);
}

if (options.reload) {
args.push(
`--reload${
typeof options.reload === 'string' ? `=${options.reload}` : ''
}`
);
}

if (options.unstable) {
args.push(`--unstable`);
}

if (options.watch) {
args.push(`--watch`);
}

return args;
}

0 comments on commit 2f1c8a6

Please sign in to comment.