Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return false;
}
// This is for the `_` property. If there are sites, we don't show help neither
if (Array.isArray(value) && value.length > 0) {
return false;
}
return result && true;
}, true);
if (!showHelp) {
return Promise.resolve(false);
}
logger.log(options.generateHelp());
return Promise.resolve(true);
};
await removeLanguageFile();
// We save the result with the friendly target name
const name = target.replace(/:\/\//g, '-')
.replace(/:/g, '-')
.replace(/\./g, '-')
.replace(/\//g, '-')
.replace(/[?=]/g, '-query-')
.replace(/-$/, '');
const destDir = options.output || path.join(cwd(), 'hint-report');
const destination = path.join(destDir, `${name}.html`);
await fs.outputFile(destination, html);
logger.log(getMessageFormatter('youCanView', language, destination));
}
return result;
} catch (err) {
logger.error(err);
throw err;
}
}
}
export default async (): Promise => {
debug('Starting --init');
logger.log('Welcome to hint configuration generator');
const initialQuestion: inquirer.Questions = [{
choices: ['predefined', 'custom'],
default: 'predefined',
message: 'Do you want to use a predefined configuration or create your own based on your installed packages?',
name: 'configType',
type: 'list'
}];
const initialAnswer: inquirer.Answers = await inquirer.prompt(initialQuestion);
const result = initialAnswer.configType === 'predefined' ?
await extendConfig() :
await customConfig();
if (!result) {
const showDefaultMessage = () => {
const defaultMessage = `Using the built-in configuration.
Visit https://webhint.io/docs/user-guide/ to learn how to create your own configuration.`;
logger.log(defaultMessage);
};
export default (): Promise => {
const pkg = loadHintPackage();
logger.log(`v${pkg.version}`);
return Promise.resolve(true);
};
const copyFiles = async (origin: string, destination: string) => {
logger.log(`Creating new hint in ${destination}`);
await copy(origin, destination);
logger.log('External files copied');
};
return;
}
const language = options.language!;
const resources: _.Dictionary = _.groupBy(messages, 'resource');
const result = _.reduce(resources, (total: string, msgs: Problem[], resource: string) => {
const sortedMessages: Problem[] = _.sortBy(msgs, ['location.line', 'location.column']);
const result = `${total ? '\n\n' : ''}${resource}: ${getMessage('issues', language, msgs.length.toString())}
${JSON.stringify(sortedMessages, null, 2)}`;
return total + result;
}, '');
if (!options.output) {
logger.log(result);
return;
}
await writeFileAsync(options.output, result);
}
}
const copyFiles = async (data: NewParser) => {
const files = path.join(__dirname, 'files');
const noOfficialFiles = path.join(__dirname, 'no-official-files');
logger.log(`Creating new hint in ${data.destination}`);
if (!data.official) {
await fs.copy(noOfficialFiles, data.destination);
}
await fs.copy(files, data.destination);
logger.log('Files copied');
};
const showMissingAndIncompatiblePackages = (resources: HintResources) => {
if (resources.missing.length > 0) {
logger.log(`The following ${resources.missing.length === 1 ? 'package is' : 'packages are'} missing:
${resources.missing.join(', ')}`);
}
if (resources.incompatible.length > 0) {
logger.log(`The following ${resources.incompatible.length === 1 ? 'package is' : 'packages are'} incompatible:
${resources.incompatible.join(', ')}`);
}
};
const color = occurencesToColor(totals);
const foundTotalMessage = getMessage('totalFound', language, [
totals[Severity.error].toString(),
totals[Severity.error] === 1 ? getMessage('error', language) : getMessage('errors', language),
totals[Severity.warning].toString(),
totals[Severity.warning] === 1 ? getMessage('warning', language) : getMessage('warnings', language),
totals[Severity.hint].toString(),
totals[Severity.hint] === 1 ? getMessage('hint', language) : getMessage('hints', language),
totals[Severity.information].toString(),
totals[Severity.information] === 1 ? getMessage('information', language) : getMessage('informations', language)
]);
result += color.bold(`${logSymbols.error} ${foundTotalMessage}`);
if (!options.output) {
logger.log(result);
return;
}
await writeFileAsync(options.output, stripAnsi(result));
}
}