本文整理汇总了TypeScript中chalk.white.bgRed方法的典型用法代码示例。如果您正苦于以下问题:TypeScript white.bgRed方法的具体用法?TypeScript white.bgRed怎么用?TypeScript white.bgRed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类chalk.white
的用法示例。
在下文中一共展示了white.bgRed方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: async
async ({
flags: {
path,
'output-dir': outputDir,
'output-format': outputFormat,
'include-config': includeConfig,
},
}) => {
if (!outputDir || typeof outputDir !== 'string') {
throw createFailError(
`${chalk.white.bgRed(' I18N ERROR ')} --output-dir option should be specified.`
);
}
if (typeof path === 'boolean' || typeof includeConfig === 'boolean') {
throw createFailError(
`${chalk.white.bgRed(' I18N ERROR ')} --path and --include-config require a value`
);
}
const config = await mergeConfigs(includeConfig);
const defaultMessages = await extractDefaultMessages({ path, config });
// Messages shouldn't be written to a file if output is not supplied.
if (!outputDir || !defaultMessages.size) {
return;
}
const sortedMessages = [...defaultMessages].sort(([key1], [key2]) => key1.localeCompare(key2));
await writeFileAsync(
resolve(outputDir, 'en.json'),
outputFormat === 'json5' ? serializeToJson5(sortedMessages) : serializeToJson(sortedMessages)
);
},
示例2: onRootShutdown
function onRootShutdown(reason?: any) {
if (reason !== undefined) {
// There is a chance that logger wasn't configured properly and error that
// that forced root to shut down could go unnoticed. To prevent this we always
// mirror such fatal errors in standard output with `console.error`.
// tslint:disable no-console
console.error(`\n${chalk.white.bgRed(' FATAL ')} ${reason}\n`);
}
process.exit(reason === undefined ? 0 : (reason as any).processExitCode || 1);
}
示例3: extractDefaultMessages
export async function extractDefaultMessages({
path,
config,
}: {
path?: string | string[];
config: I18nConfig;
}) {
const filteredPaths = filterConfigPaths(Array.isArray(path) ? path : [path || './'], config);
if (filteredPaths.length === 0) {
throw createFailError(
`${chalk.white.bgRed(
' I18N ERROR '
)} None of input paths is covered by the mappings in .i18nrc.json.`
);
}
const reporter = new ErrorReporter();
const list = new Listr(
filteredPaths.map(filteredPath => ({
task: async (messages: Map<string, unknown>) => {
const initialErrorsNumber = reporter.errors.length;
// Return result if no new errors were reported for this path.
const result = await extractMessagesFromPathToMap(filteredPath, messages, config, reporter);
if (reporter.errors.length === initialErrorsNumber) {
return result;
}
// Throw an empty error to make Listr mark the task as failed without any message.
throw new Error('');
},
title: filteredPath,
})),
{
exitOnError: false,
}
);
try {
return await list.run(new Map());
} catch (error) {
if (error.name === 'ListrError' && reporter.errors.length) {
throw createFailError(reporter.errors.join('\n\n'));
}
throw error;
}
}
示例4: banner
/**
* Standard output block to help call out these interstitial messages amidst
* large test suite outputs.
*/
function banner(text: string): string {
return chalk.white.bgRed(
`*************************\n\n${text}\n\n*************************`);
}
示例5: async
async ({
flags: {
'dry-run': dryRun = false,
'ignore-incompatible': ignoreIncompatible = false,
'ignore-missing': ignoreMissing = false,
'ignore-unused': ignoreUnused = false,
'include-config': includeConfig,
path,
source,
target,
},
log,
}) => {
if (!source || typeof source === 'boolean') {
throw createFailError(`${chalk.white.bgRed(' I18N ERROR ')} --source option isn't provided.`);
}
if (Array.isArray(source)) {
throw createFailError(
`${chalk.white.bgRed(' I18N ERROR ')} --source should be specified only once.`
);
}
if (typeof target === 'boolean' || Array.isArray(target)) {
throw createFailError(
`${chalk.white.bgRed(
' I18N ERROR '
)} --target should be specified only once and must have a value.`
);
}
if (typeof path === 'boolean' || typeof includeConfig === 'boolean') {
throw createFailError(
`${chalk.white.bgRed(' I18N ERROR ')} --path and --include-config require a value`
);
}
if (
typeof ignoreIncompatible !== 'boolean' ||
typeof ignoreUnused !== 'boolean' ||
typeof ignoreMissing !== 'boolean' ||
typeof dryRun !== 'boolean'
) {
throw createFailError(
`${chalk.white.bgRed(
' I18N ERROR '
)} --ignore-incompatible, --ignore-unused, --ignore-missing, and --dry-run can't have values`
);
}
const config = await mergeConfigs(includeConfig);
const defaultMessages = await extractDefaultMessages({ path, config });
await integrateLocaleFiles(defaultMessages, {
sourceFileName: source,
targetFileName: target,
dryRun,
ignoreIncompatible,
ignoreUnused,
ignoreMissing,
config,
log,
});
},
示例6: async
async ({
flags: {
'ignore-incompatible': ignoreIncompatible,
'ignore-missing': ignoreMissing,
'ignore-unused': ignoreUnused,
'include-config': includeConfig,
fix = false,
path,
},
log,
}) => {
if (
fix &&
(ignoreIncompatible !== undefined ||
ignoreUnused !== undefined ||
ignoreMissing !== undefined)
) {
throw createFailError(
`${chalk.white.bgRed(
' I18N ERROR '
)} none of the --ignore-incompatible, --ignore-unused or --ignore-missing is allowed when --fix is set.`
);
}
if (typeof path === 'boolean' || typeof includeConfig === 'boolean') {
throw createFailError(
`${chalk.white.bgRed(' I18N ERROR ')} --path and --include-config require a value`
);
}
if (typeof fix !== 'boolean') {
throw createFailError(`${chalk.white.bgRed(' I18N ERROR ')} --fix can't have a value`);
}
const config = await mergeConfigs(includeConfig);
const defaultMessages = await extractDefaultMessages({ path, config });
if (config.translations.length === 0) {
return;
}
const list = new Listr(
config.translations.map(translationsPath => ({
task: async () => {
// If `--fix` is set we should try apply all possible fixes and override translations file.
await integrateLocaleFiles(defaultMessages, {
sourceFileName: translationsPath,
targetFileName: fix ? translationsPath : undefined,
dryRun: !fix,
ignoreIncompatible: fix || !!ignoreIncompatible,
ignoreUnused: fix || !!ignoreUnused,
ignoreMissing: fix || !!ignoreMissing,
config,
log,
});
},
title: `Compatibility check with ${translationsPath}`,
})),
{
concurrent: true,
exitOnError: false,
}
);
try {
await list.run();
} catch (error) {
process.exitCode = 1;
if (!error.errors) {
log.error('Unhandled exception!');
log.error(error);
process.exit();
}
for (const e of error.errors) {
log.error(e);
}
}
},