Scripts linted
This commit is contained in:
@ -4,11 +4,16 @@
|
||||
*/
|
||||
|
||||
// Load modules
|
||||
const fs = require('fs-extra'), path = require('path');
|
||||
const fs = require('fs-extra'),
|
||||
path = require('path');
|
||||
const childProcess = require('child_process');
|
||||
const chalk = require('chalk');
|
||||
const util = require('./util');
|
||||
if(util.isTravisCI() && process.env['TRAVIS_EVENT_TYPE'] !== 'cron' && process.env['TRAVIS_EVENT_TYPE'] !== 'api') {
|
||||
if (
|
||||
util.isTravisCI() &&
|
||||
process.env['TRAVIS_EVENT_TYPE'] !== 'cron' &&
|
||||
process.env['TRAVIS_EVENT_TYPE'] !== 'api'
|
||||
) {
|
||||
console.log(`${chalk.green('NOBUILD')} Testing terminated, not a cron job or a custom build!`);
|
||||
process.exit(0);
|
||||
}
|
||||
@ -20,8 +25,11 @@ const TEST_PATH = './test';
|
||||
// Array of snippet names
|
||||
const snippetFiles = [];
|
||||
|
||||
const snippetFilesActive = fs.readdirSync(SNIPPETS_ACTIVE, 'utf8').map(fileName => fileName.slice(0, -3));
|
||||
const snippetFilesArchive = fs.readdirSync(SNIPPETS_ARCHIVE, 'utf8')
|
||||
const snippetFilesActive = fs
|
||||
.readdirSync(SNIPPETS_ACTIVE, 'utf8')
|
||||
.map(fileName => fileName.slice(0, -3));
|
||||
const snippetFilesArchive = fs
|
||||
.readdirSync(SNIPPETS_ARCHIVE, 'utf8')
|
||||
.filter(fileName => !fileName.includes('README')) // -> Filters out main README.md file in Archieve which isn't a snippet
|
||||
.map(fileName => fileName.slice(0, -3));
|
||||
|
||||
@ -32,15 +40,17 @@ console.time('Tester');
|
||||
snippetFiles
|
||||
.map(fileName => {
|
||||
// Check if fileName for snippet exist in test/ dir, if doesnt create
|
||||
fs.ensureDirSync(path.join(TEST_PATH,fileName));
|
||||
fs.ensureDirSync(path.join(TEST_PATH, fileName));
|
||||
|
||||
// return fileName for later use
|
||||
return fileName;
|
||||
})
|
||||
.map(fileName => {
|
||||
const activeOrArchive = snippetFilesActive.includes(fileName) ? SNIPPETS_ACTIVE : SNIPPETS_ARCHIVE;
|
||||
const activeOrArchive = snippetFilesActive.includes(fileName)
|
||||
? SNIPPETS_ACTIVE
|
||||
: SNIPPETS_ARCHIVE;
|
||||
// Grab snippetData
|
||||
const fileData = fs.readFileSync(path.join(activeOrArchive,`${fileName}.md`), 'utf8');
|
||||
const fileData = fs.readFileSync(path.join(activeOrArchive, `${fileName}.md`), 'utf8');
|
||||
// Grab snippet Code blocks
|
||||
const fileCode = fileData.slice(fileData.search(/```\s*js/i), fileData.lastIndexOf('```') + 3);
|
||||
// Split code based on code markers
|
||||
@ -72,9 +82,9 @@ snippetFiles
|
||||
].join('\n');
|
||||
|
||||
// Write/Update exportFile which is snippetName.js in respective dir
|
||||
fs.writeFileSync(path.join(TEST_PATH,fileName,`${fileName}.js`), exportFile);
|
||||
fs.writeFileSync(path.join(TEST_PATH, fileName, `${fileName}.js`), exportFile);
|
||||
|
||||
if ( !fs.existsSync(path.join(TEST_PATH,fileName,`${fileName}.test.js`)) ) {
|
||||
if (!fs.existsSync(path.join(TEST_PATH, fileName, `${fileName}.test.js`))) {
|
||||
// if snippetName.test.js doesn't exist inrespective dir exportTest
|
||||
fs.writeFileSync(`${TEST_PATH}/${fileName}/${fileName}.test.js`, exportTest);
|
||||
}
|
||||
@ -83,10 +93,9 @@ snippetFiles
|
||||
return fileName;
|
||||
});
|
||||
try {
|
||||
fs.writeFileSync(path.join(TEST_PATH,'testlog'),`Test log for: ${new Date().toString()}\n`);
|
||||
fs.writeFileSync(path.join(TEST_PATH, 'testlog'), `Test log for: ${new Date().toString()}\n`);
|
||||
childProcess.execSync(`npm test`);
|
||||
}
|
||||
catch (e) {
|
||||
fs.appendFileSync(path.join(TEST_PATH,'testlog'));
|
||||
} catch (e) {
|
||||
fs.appendFileSync(path.join(TEST_PATH, 'testlog'));
|
||||
}
|
||||
console.timeEnd('Tester');
|
||||
|
||||
Reference in New Issue
Block a user