Skip to content

Commit

Permalink
style: update cli fns
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdbradley committed Jul 9, 2020
1 parent b24933d commit 4964ecf
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 33 deletions.
4 changes: 2 additions & 2 deletions src/cli/find-config.ts
@@ -1,7 +1,7 @@
import type { CompilerSystem, Diagnostic } from '../declarations';
import { isString, normalizePath, buildError } from '@utils';

export async function findConfig(opts: { sys: CompilerSystem; configPath: string }) {
export const findConfig = async (opts: { sys: CompilerSystem; configPath: string }) => {
const sys = opts.sys;
const cwd = sys.getCurrentDirectory();
const results = {
Expand Down Expand Up @@ -51,4 +51,4 @@ export async function findConfig(opts: { sys: CompilerSystem; configPath: string
}

return results;
}
};
4 changes: 2 additions & 2 deletions src/cli/load-compiler.ts
@@ -1,9 +1,9 @@
import type { CompilerSystem } from '../declarations';

export async function loadCoreCompiler(sys: CompilerSystem): Promise<CoreCompiler> {
export const loadCoreCompiler = async (sys: CompilerSystem): Promise<CoreCompiler> => {
await sys.dynamicImport(sys.getCompilerExecutingPath());

return (globalThis as any).stencil;
}
};

export type CoreCompiler = typeof import('@stencil/core/compiler');
12 changes: 6 additions & 6 deletions src/cli/logs.ts
Expand Up @@ -2,7 +2,7 @@ import type { Config, Logger, ConfigFlags, CompilerSystem } from '../declaration
import type { CoreCompiler } from './load-compiler';
import { version, vermoji } from '../version';

export function startupLog(logger: Logger, flags: ConfigFlags) {
export const startupLog = (logger: Logger, flags: ConfigFlags) => {
if (flags.task === 'info' || flags.task === 'serve') {
return;
}
Expand All @@ -19,9 +19,9 @@ export function startupLog(logger: Logger, flags: ConfigFlags) {
startupMsg += logger.emoji(' ' + vermoji);

logger.info(startupMsg);
}
};

export function loadedCompilerLog(sys: CompilerSystem, logger: Logger, flags: ConfigFlags, coreCompiler: CoreCompiler) {
export const loadedCompilerLog = (sys: CompilerSystem, logger: Logger, flags: ConfigFlags, coreCompiler: CoreCompiler) => {
const sysDetails = sys.details;
const runtimeInfo = `${sys.name} ${sys.version}`;
const platformInfo = `${sysDetails.platform}, ${sysDetails.cpuModel}`;
Expand All @@ -38,9 +38,9 @@ export function loadedCompilerLog(sys: CompilerSystem, logger: Logger, flags: Co
logger.info(platformInfo);
logger.info(statsInfo);
}
}
};

export function startupCompilerLog(coreCompiler: CoreCompiler, config: Config) {
export const startupCompilerLog = (coreCompiler: CoreCompiler, config: Config) => {
if (config.suppressLogs === true) {
return;
}
Expand Down Expand Up @@ -69,4 +69,4 @@ export function startupCompilerLog(coreCompiler: CoreCompiler, config: Config) {
logger.warn(`Disabling cache during development will slow down incremental builds.`);
}
}
}
};
12 changes: 6 additions & 6 deletions src/cli/parse-flags.ts
@@ -1,7 +1,7 @@
import type { CompilerSystem, ConfigFlags } from '../declarations';
import { dashToPascalCase } from '@utils';

export function parseFlags(sys: CompilerSystem, args: string[]): ConfigFlags {
export const parseFlags = (sys: CompilerSystem, args: string[]): ConfigFlags => {
const flags: any = {
task: null,
args: [],
Expand Down Expand Up @@ -39,9 +39,9 @@ export function parseFlags(sys: CompilerSystem, args: string[]): ConfigFlags {
});

return flags;
}
};

function parseArgs(flags: any, args: string[], knownArgs: string[]) {
const parseArgs = (flags: any, args: string[], knownArgs: string[]) => {
ARG_OPTS.boolean.forEach(booleanName => {
const alias = (ARG_OPTS.alias as any)[booleanName];
const flagKey = configCase(booleanName);
Expand Down Expand Up @@ -153,7 +153,7 @@ function parseArgs(flags: any, args: string[], knownArgs: string[]) {
}
}
});
}
};

const configCase = (prop: string) => {
prop = dashToPascalCase(prop);
Expand Down Expand Up @@ -203,7 +203,7 @@ const ARG_OPTS = {
},
};

function getNpmConfigEnvArgs(sys: CompilerSystem) {
const getNpmConfigEnvArgs = (sys: CompilerSystem) => {
// process.env.npm_config_argv
// {"remain":["4444"],"cooked":["run","serve","--port","4444"],"original":["run","serve","--port","4444"]}
let args: string[] = [];
Expand All @@ -217,4 +217,4 @@ function getNpmConfigEnvArgs(sys: CompilerSystem) {
}
} catch (e) {}
return args;
}
};
4 changes: 2 additions & 2 deletions src/cli/task-docs.ts
Expand Up @@ -3,7 +3,7 @@ import type { CoreCompiler } from './load-compiler';
import { isOutputTargetDocs } from '../compiler/output-targets/output-utils';
import { startupCompilerLog } from './logs';

export async function taskDocs(coreCompiler: CoreCompiler, config: Config) {
export const taskDocs = async (coreCompiler: CoreCompiler, config: Config) => {
config.devServer = null;
config.outputTargets = config.outputTargets.filter(isOutputTargetDocs);
config.devMode = true;
Expand All @@ -14,4 +14,4 @@ export async function taskDocs(coreCompiler: CoreCompiler, config: Config) {
await compiler.build();

await compiler.destroy();
}
};
4 changes: 2 additions & 2 deletions src/cli/task-generate.ts
Expand Up @@ -5,7 +5,7 @@ import { IS_NODE_ENV, validateComponentTag } from '@utils';
/**
* Task to generate component boilerplate.
*/
export async function taskGenerate(coreCompiler: CoreCompiler, config: Config) {
export const taskGenerate = async (coreCompiler: CoreCompiler, config: Config) => {
if (!IS_NODE_ENV) {
config.logger.error(`"generate" command is currently only implemented for a NodeJS environment`);
config.sys.exit(1);
Expand Down Expand Up @@ -60,7 +60,7 @@ export async function taskGenerate(coreCompiler: CoreCompiler, config: Config) {

const absoluteRootDir = config.rootDir;
writtenFiles.map(file => console.log(` - ${path.relative(absoluteRootDir, file)}`));
}
};

/**
* Show a checkbox prompt to select the files to be generated.
Expand Down
4 changes: 2 additions & 2 deletions src/cli/task-help.ts
@@ -1,6 +1,6 @@
import type { CompilerSystem, Logger } from '../declarations';

export function taskHelp(sys: CompilerSystem, logger: Logger) {
export const taskHelp = (sys: CompilerSystem, logger: Logger) => {
const p = logger.dim(sys.details.platform === 'windows' ? '>' : '$');

console.log(`
Expand Down Expand Up @@ -34,4 +34,4 @@ export function taskHelp(sys: CompilerSystem, logger: Logger) {
${p} ${logger.green('stencil test --spec --e2e')}
`);
}
};
4 changes: 2 additions & 2 deletions src/cli/task-info.ts
@@ -1,7 +1,7 @@
import type { CompilerSystem, Logger } from '../declarations';
import type { CoreCompiler } from './load-compiler';

export function taskInfo(coreCompiler: CoreCompiler, sys: CompilerSystem, logger: Logger) {
export const taskInfo = (coreCompiler: CoreCompiler, sys: CompilerSystem, logger: Logger) => {
const details = sys.details;
const versions = coreCompiler.versions;

Expand All @@ -16,4 +16,4 @@ export function taskInfo(coreCompiler: CoreCompiler, sys: CompilerSystem, logger
console.log(`${logger.cyan(' Rollup:')} ${versions.rollup}`);
console.log(`${logger.cyan(' Terser:')} ${versions.terser}`);
console.log(``);
}
};
10 changes: 5 additions & 5 deletions src/cli/task-prerender.ts
Expand Up @@ -3,7 +3,7 @@ import type { CoreCompiler } from './load-compiler';
import { catchError } from '@utils';
import { startupCompilerLog } from './logs';

export async function taskPrerender(coreCompiler: CoreCompiler, config: Config) {
export const taskPrerender = async (coreCompiler: CoreCompiler, config: Config) => {
startupCompilerLog(coreCompiler, config);

const hydrateAppFilePath = config.flags.unknownArgs[0];
Expand All @@ -21,15 +21,15 @@ export async function taskPrerender(coreCompiler: CoreCompiler, config: Config)
if (diagnostics.some(d => d.level === 'error')) {
config.sys.exit(1);
}
}
};

export async function runPrerenderTask(
export const runPrerenderTask = async (
coreCompiler: CoreCompiler,
config: Config,
hydrateAppFilePath: string,
componentGraph: BuildResultsComponentGraph,
srcIndexHtmlPath: string,
) {
) => {
const diagnostics: Diagnostic[] = [];

try {
Expand All @@ -46,4 +46,4 @@ export async function runPrerenderTask(
}

return diagnostics;
}
};
4 changes: 2 additions & 2 deletions src/cli/task-serve.ts
@@ -1,7 +1,7 @@
import type { Config } from '../declarations';
import { isString } from '@utils';

export async function taskServe(config: Config) {
export const taskServe = async (config: Config) => {
config.suppressLogs = true;

config.flags.serve = true;
Expand All @@ -25,4 +25,4 @@ export async function taskServe(config: Config) {
config.sys.onProcessInterrupt(() => {
devServer && devServer.close();
});
}
};
4 changes: 2 additions & 2 deletions src/cli/task-test.ts
@@ -1,7 +1,7 @@
import type { Config, TestingRunOptions } from '../declarations';
import { IS_NODE_ENV } from '@utils';

export async function taskTest(config: Config) {
export const taskTest = async (config: Config) => {
if (!IS_NODE_ENV) {
config.logger.error(`"test" command is currently only implemented for a NodeJS environment`);
config.sys.exit(1);
Expand Down Expand Up @@ -54,4 +54,4 @@ export async function taskTest(config: Config) {
config.logger.error(e);
config.sys.exit(1);
}
}
};

0 comments on commit 4964ecf

Please sign in to comment.