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 genI18n() {
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```';
}
});
exports.fileExist = async function(path) {
const exist = await fs.exists(path);
if (!exist) throw Error(path + ' does not exist.');
};