Optimize a bit
This commit is contained in:
@ -54,8 +54,7 @@ try {
|
|||||||
const lintedCode = [];
|
const lintedCode = [];
|
||||||
|
|
||||||
for (const tempName of snippet.tempNames) {
|
for (const tempName of snippet.tempNames) {
|
||||||
let data = fs.readFileSync(`${TEMP_PATH}/${tempName}.js`,'utf8');
|
let data = fs.readFileSync(`${TEMP_PATH}/${tempName}.js`, 'utf8');
|
||||||
|
|
||||||
// prettier sometimes throws an error..
|
// prettier sometimes throws an error..
|
||||||
try {
|
try {
|
||||||
data = prettier.format(data, {
|
data = prettier.format(data, {
|
||||||
@ -63,24 +62,19 @@ try {
|
|||||||
singleQuote: true
|
singleQuote: true
|
||||||
});
|
});
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
|
|
||||||
lintedCode.push(data);
|
lintedCode.push(data);
|
||||||
|
|
||||||
fs.unlink(`${TEMP_PATH}/${tempName}.js`);
|
fs.unlink(`${TEMP_PATH}/${tempName}.js`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// We replace each ```js ``` code block with the newly linted code
|
// We replace each ```js ``` code block with the newly linted code
|
||||||
let index = -1;
|
let index = 0;
|
||||||
snippet.data = snippet.data.replace(codeRE, () => {
|
snippet.data = snippet.data.replace(codeRE, () => '```js\n' + lintedCode[index++] + '```')
|
||||||
index++;
|
|
||||||
return '```js\n' + lintedCode[index] + '```';
|
|
||||||
});
|
|
||||||
|
|
||||||
fs.writeFileSync(path.join(SNIPPETS_PATH, snippet.name), snippet.data);
|
fs.writeFileSync(path.join(SNIPPETS_PATH, snippet.name), snippet.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
fs.removeSync(TEMP_PATH);
|
fs.removeSync(TEMP_PATH);
|
||||||
|
|
||||||
console.timeEnd('lint');
|
console.timeEnd('lint');
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
Reference in New Issue
Block a user