Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function extractInfo() {
const files = await glob('src/*/*.js', {
ignore: ['src/*/*.*.js']
});
const regDependency = /\s*\b_\(\s*['"]([\w\s$]+)['"]\s*\);?/m;
for (const file of files) {
let modName = last(file.split('/')).slice(0, -3);
const data = await fs.readFile(file, 'utf8');
let desc = 'No description.';
let comments = extractBlockCmts(data);
if (comments.length > 0) {
desc = trim(comments[0]).split('\n')[0];
}
let modInfo = extend(
{
description: desc,
dependencies: extractDependencies(data)
},
extractCmts(comments)
);
output[modName] = modInfo;
}
function extractDependencies(data) {
let doc = await fs.readFile(OUTPUT_DOC_PATH, 'utf8');
doc = splitH2(doc);
const i18n = {};
for (let i = 0, len = doc.length; i < len; i++) {
const name = doc[i].name;
const i18nPath =
'src/' + name[0].toLowerCase() + '/' + name + '.i18n.md';
if (await fs.exists(i18nPath)) {
let doc = await fs.readFile(i18nPath, 'utf8');
let code = await fs.readFile(
i18nPath.replace('.i18n.md', '.js'),
'utf8'
);
let comments = extractBlockCmts(code);
let example = '';
comments.forEach(comment => {
comment = trim(comment);
if (startWith(comment, 'example')) {
example = comment.replace(/^example/, '');
example = outdentOneSpace(example);
example = example.replace(regTsIgnore, '');
example = '```javascript\n' + trim(example) + '\n```';
}
});
doc = splitH2(doc);
doc.forEach(locale => {
i18n[locale.name] = i18n[locale.name] || {};
i18n[locale.name][name] = locale.content;
if (example) {
i18n[locale.name][name] += '\n\n' + example;
function extractTsDefinition(data, modName, dependencies) {
const comments = extractBlockCmts(data);
let tsDefinition = '';
each(comments, comment => {
comment = trim(comment);
if (startWith(comment, 'typescript')) {
tsDefinition = comment.replace(/^typescript/, '');
tsDefinition = outdentOneSpace(tsDefinition);
tsDefinition = tsDefinition.replace(/export declare/g, 'declare');
tsDefinition += '\n\nexport = ' + modName;
}
});
let imports = '';
if (dependencies) {