Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return require('./snyk-snapshot.json');
}
try {
const snykDBPath = require.resolve('./snyk-snapshot.json');
const snykStat = await promisify(fs.stat)(snykDBPath);
const modified = new Date(snykStat.mtime).getTime();
// We check if the file is older than 24h to update it
/* istanbul ignore if */
if (now - modified > oneDay) {
debug('snkyDB is older than 24h.');
debug('Updating snykDB');
const res = await requestAsync('https://snyk.io/partners/api/v2/vulndb/clientside.json');
await writeFileAsync(snykDBPath, res);
}
} catch (e) /* istanbul ignore next */ {
debug(e);
debug(`Error loading snyk's data`);
}
return require('./snyk-snapshot.json');
};
]);
const { metaPath, hintPath, testPath } = data.isMulti ?
{
hintPath: join(hintFile.destination, `${hint.normalizedName}.ts`),
metaPath: join(metaFile.destination, 'meta', `${hint.normalizedName}.ts`),
testPath: join(testFile.destination, `${hint.normalizedName}.ts`)
} :
{
hintPath: join(hintFile.destination, 'hint.ts'),
metaPath: join(metaFile.destination, 'meta.ts'),
testPath: join(testFile.destination, `tests.ts`)
};
await Promise.all([mkdirpAsync(dirname(hintPath)), mkdirpAsync(dirname(testPath)), mkdirpAsync(dirname(metaPath))]);
await Promise.all([writeFileAsync(hintPath, hintContent), writeFileAsync(testPath, testContent), writeFileAsync(metaPath, metaContent)]);
if (data.isMulti) {
const docContent = await compileTemplate(docFile.path, hint);
// e.g.: hint-typescript-config/docs/is-valid.ts
const docPath = join(docFile.destination, `${hint.normalizedName}.md`);
await mkdirpAsync(dirname(docPath));
await writeFileAsync(docPath, docContent);
}
}
// Create `_locales` directory
if (data.official) {
const localeDir = {
destination: join(destination, 'src', '_locales', 'en', 'messages.json'),
const { destination: dest, path: p } = file;
const fileContent = await compileTemplate(p, data);
await mkdirpAsync(dirname(dest));
await writeFileAsync(dest, fileContent);
}
// For packages with multiple hints, we need to create an "index" meta file.
if (data.isMulti) {
const metaIndexContent = await compileTemplate(metaIndexFile.path, data);
// e.g.: hint-ssllabs/src/meta.ts
const metaIndexPath = join(metaIndexFile.destination, 'meta.ts');
await mkdirpAsync(dirname(metaIndexPath));
await writeFileAsync(metaIndexPath, metaIndexContent);
}
for (const hint of data.hints) {
const [hintContent, testContent, metaContent] = await Promise.all([
compileTemplate(hintFile.path, { hint, packageData: data }),
compileTemplate(testFile.path, hint),
compileTemplate(metaFile.path, { hint, packageData: data })
]);
const { metaPath, hintPath, testPath } = data.isMulti ?
{
hintPath: join(hintFile.destination, `${hint.normalizedName}.ts`),
metaPath: join(metaFile.destination, 'meta', `${hint.normalizedName}.ts`),
testPath: join(testFile.destination, `${hint.normalizedName}.ts`)
} :
{
hintPath: join(hintFile.destination, 'hint.ts'),
metaPath: join(metaFile.destination, 'meta.ts'),
testPath: join(testFile.destination, `tests.ts`)
};
await Promise.all([mkdirpAsync(dirname(hintPath)), mkdirpAsync(dirname(testPath)), mkdirpAsync(dirname(metaPath))]);
await Promise.all([writeFileAsync(hintPath, hintContent), writeFileAsync(testPath, testContent), writeFileAsync(metaPath, metaContent)]);
if (data.isMulti) {
const docContent = await compileTemplate(docFile.path, hint);
// e.g.: hint-typescript-config/docs/is-valid.ts
const docPath = join(docFile.destination, `${hint.normalizedName}.md`);
await mkdirpAsync(dirname(docPath));
await writeFileAsync(docPath, docContent);
}
}
// Create `_locales` directory
if (data.official) {
const localeDir = {
destination: join(destination, 'src', '_locales', 'en', 'messages.json'),
path: join(__dirname, TEMPLATE_PATH, 'locales-messages.json.hbs')
};
const localesContent = await compileTemplate(localeDir.path, data);
await mkdirpAsync(dirname(localeDir.destination));
await writeFileAsync(localeDir.destination, localesContent);
}
};
await mkdirpAsync(dirname(docPath));
await writeFileAsync(docPath, docContent);
}
}
// Create `_locales` directory
if (data.official) {
const localeDir = {
destination: join(destination, 'src', '_locales', 'en', 'messages.json'),
path: join(__dirname, TEMPLATE_PATH, 'locales-messages.json.hbs')
};
const localesContent = await compileTemplate(localeDir.path, data);
await mkdirpAsync(dirname(localeDir.destination));
await writeFileAsync(localeDir.destination, localesContent);
}
};
];
if (!data.official) {
files.push({
destination: path.join(data.destination, '.hintrc'),
path: path.join(__dirname, SHARED_TEMPLATE_PATH, 'config.hbs')
});
}
for (const file of files) {
const { destination: dest, path: filePath } = file;
const fileContent = await compileTemplate(filePath, data);
await mkdirpAsync(path.dirname(dest));
await writeFileAsync(dest, fileContent);
}
};
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)
]);
const result = `${table(tableData)}
${color.bold(`${logSymbols.error} ${foundTotalMessage}`)}`;
if (!options.output) {
logger.log(result);
return;
}
await writeFileAsync(options.output, stripAnsi(result));
}
}
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));
}
}
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));
}
}