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