Updated linter, linted scripts

This commit is contained in:
Angelos Chalaris
2017-12-23 11:52:07 +02:00
parent 20347facda
commit 8caafdf1d9
5 changed files with 10 additions and 4 deletions

View File

@ -10,6 +10,7 @@ var snippetsPath = './snippets';
// Read files, lint each one individually and update
try {
let snippetFilenames = fs.readdirSync(snippetsPath);
let jobCounter = 0;
snippetFilenames.sort((a, b) => {
a = a.toLowerCase();
b = b.toLowerCase();
@ -25,10 +26,14 @@ try {
// Synchronously read data from the snippet, get the code, write it to a temporary file
let snippetData = fs.readFileSync(path.join(snippetsPath,snippet),'utf8');
let originalCode = snippetData.slice(snippetData.indexOf('```js')+5,snippetData.lastIndexOf('```'));
while(jobCounter >= 20){
setTimeout(()=>{},5000);
}
fs.writeFileSync(`${snippet}.temp.js`,`${originalCode}`);
// Run semistandard asynchronously (only way this manages to run), get linted code
// and write back to the original snippet file. Remove temporary file
cp.exec(`semistandard "${snippet}.temp.js" --fix`,{},(error, stdOut, stdErr) => {
jobCounter += 1;
let lintedCode = fs.readFileSync(`${snippet}.temp.js`,'utf8');
fs.writeFile(path.join(snippetsPath,snippet), `${snippetData.slice(0, snippetData.indexOf('```js')+5)+lintedCode+'```\n'}`);
fs.unlink(`${snippet}.temp.js`);
@ -36,6 +41,7 @@ try {
console.log(`${chalk.green('SUCCESS!')} Linted snippet: ${snippet}`);
// Log the time taken for the file
console.timeEnd(`Linter (${snippet})`);
jobCounter -= 1;
});
}
}