Script and tag cleanup, fixed select tests

This commit is contained in:
Angelos Chalaris
2018-01-16 15:15:51 +02:00
parent 336ce6f72b
commit 2a61e7671e
8 changed files with 33 additions and 24 deletions

View File

@ -12,7 +12,8 @@ script:
- npm run linter - npm run linter
- npm run builder - npm run builder
- npm run webber - npm run webber
- npm run module - npm run packager
- npm run tester
after_success: after_success:
- chmod +x .travis/push.sh - chmod +x .travis/push.sh
- .travis/push.sh - .travis/push.sh

View File

@ -26,8 +26,8 @@
"linter": "node ./scripts/lint.js", "linter": "node ./scripts/lint.js",
"tagger": "node ./scripts/tag.js", "tagger": "node ./scripts/tag.js",
"webber": "node ./scripts/web.js", "webber": "node ./scripts/web.js",
"tdd": "node ./scripts/tdd.js", "tester": "node ./scripts/tdd.js",
"module": "node ./scripts/module.js", "packager": "node ./scripts/module.js",
"test": "tape test/**/*.test.js | tap-spec" "test": "tape test/**/*.test.js | tap-spec"
}, },
"repository": { "repository": {

View File

@ -19,7 +19,7 @@ const IMPORTS = './imports.js';
// Regex for selecting code blocks // Regex for selecting code blocks
const codeRE = /```\s*js([\s\S]*?)```/; const codeRE = /```\s*js([\s\S]*?)```/;
// Start the timer of the script // Start the timer of the script
console.time('Module'); console.time('Packager');
// Load tag data from the database and snippets from their folder // Load tag data from the database and snippets from their folder
try { try {
const tagDatabase = fs.readFileSync('tag_database', 'utf8'); const tagDatabase = fs.readFileSync('tag_database', 'utf8');
@ -72,7 +72,7 @@ try {
// Log a success message // Log a success message
console.log(`${chalk.green('SUCCESS!')} Snippet module built!`); console.log(`${chalk.green('SUCCESS!')} Snippet module built!`);
// Log the time taken // Log the time taken
console.timeEnd('Module'); console.timeEnd('Packager');
} catch (err) { } catch (err) {
// Handle errors (hopefully not!) // Handle errors (hopefully not!)
console.log(`${chalk.red('ERROR!')} During module creation: ${err}`); console.log(`${chalk.red('ERROR!')} During module creation: ${err}`);

View File

@ -59,7 +59,7 @@ try {
tagDbStats = Object.entries(tagDbData) tagDbStats = Object.entries(tagDbData)
.sort((a, b) => a[1][0].localeCompare(b[1][0])) .sort((a, b) => a[1][0].localeCompare(b[1][0]))
.reduce((acc, val) => { .reduce((acc, val) => {
acc.hasOwnProperty(val[1]) ? acc[val[1]]++ : (acc[val[1]] = 1); val[1].forEach(v => acc.hasOwnProperty(v) ? acc[v]++ : (acc[v] = 1));
return acc; return acc;
}, {}); }, {});
} catch (err) { } catch (err) {

View File

@ -4,7 +4,8 @@
*/ */
// Load modules // Load modules
const fs = require('fs-extra'); const fs = require('fs-extra'), path = require('path');
const child_process = require('child_process');
const chalk = require('chalk'); const chalk = require('chalk');
// Load helper functions (these are from existing snippets in 30 seconds of code!) // Load helper functions (these are from existing snippets in 30 seconds of code!)
const isTravisCI = () => 'TRAVIS' in process.env && 'CI' in process.env; const isTravisCI = () => 'TRAVIS' in process.env && 'CI' in process.env;
@ -29,12 +30,12 @@ snippetFiles.push(...snippetFilesArchive);
// Current Snippet that depend on node_modules // Current Snippet that depend on node_modules
const errSnippets = ['JSONToFile', 'readFileLines', 'UUIDGeneratorNode']; const errSnippets = ['JSONToFile', 'readFileLines', 'UUIDGeneratorNode'];
console.time('Tester');
snippetFiles snippetFiles
.filter(fileName => !errSnippets.includes(fileName)) .filter(fileName => !errSnippets.includes(fileName))
.map(fileName => { .map(fileName => {
// Check if fileName for snippet exist in test/ dir, if doesnt create // Check if fileName for snippet exist in test/ dir, if doesnt create
fs.ensureDirSync(`${TEST_PATH}/${fileName}`); fs.ensureDirSync(path.join(TEST_PATH,fileName));
// return fileName for later use // return fileName for later use
return fileName; return fileName;
@ -42,7 +43,7 @@ snippetFiles
.map(fileName => { .map(fileName => {
const activeOrArchive = snippetFilesActive.includes(fileName) ? SNIPPETS_ACTIVE : SNIPPETS_ARCHIVE; const activeOrArchive = snippetFilesActive.includes(fileName) ? SNIPPETS_ACTIVE : SNIPPETS_ARCHIVE;
// Grab snippetData // Grab snippetData
const fileData = fs.readFileSync(`${activeOrArchive}/${fileName}.md`, 'utf8'); const fileData = fs.readFileSync(path.join(activeOrArchive,`${fileName}.md`), 'utf8');
// Grab snippet Code blocks // Grab snippet Code blocks
const fileCode = fileData.slice(fileData.search(/```\s*js/i), fileData.lastIndexOf('```') + 3); const fileCode = fileData.slice(fileData.search(/```\s*js/i), fileData.lastIndexOf('```') + 3);
// Split code based on code markers // Split code based on code markers
@ -80,9 +81,9 @@ snippetFiles
].join('\n'); ].join('\n');
// Write/Update exportFile which is snippetName.js in respective dir // Write/Update exportFile which is snippetName.js in respective dir
fs.writeFileSync(`${TEST_PATH}/${fileName}/${fileName}.js`, exportFile); fs.writeFileSync(path.join(TEST_PATH,fileName,`${fileName}.js`), exportFile);
if ( !fs.existsSync(`${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 // if snippetName.test.js doesn't exist inrespective dir exportTest
fs.writeFileSync(`${TEST_PATH}/${fileName}/${fileName}.test.js`, exportTest); fs.writeFileSync(`${TEST_PATH}/${fileName}/${fileName}.test.js`, exportTest);
} }
@ -90,4 +91,11 @@ snippetFiles
// return fileName for later use // return fileName for later use
return fileName; return fileName;
}); });
try {
fs.writeFileSync(path.join(TEST_PATH,'testlog'),`Test log for: ${new Date().toString()}\n`);
child_process.execSync(`npm test >> ${TEST_PATH}/testlog`);
}
catch (e) {
fs.appendFileSync(path.join(TEST_PATH,'testlog'));
}
console.timeEnd('Tester');

View File

@ -75,7 +75,7 @@ indexOfAll:array
initial:array initial:array
initialize2DArray:array initialize2DArray:array
initializeArrayWithRange:array,math initializeArrayWithRange:array,math
initializeArrayWithValues:array,amth initializeArrayWithValues:array,math
inRange:math inRange:math
intersection:array,math intersection:array,math
invertKeyValues:object invertKeyValues:object
@ -116,7 +116,7 @@ median:math,array
memoize:function memoize:function
merge:object,array merge:object,array
minBy:math,array,function minBy:math,array,function
minN:array,amth minN:array,math
negate:function negate:function
nthElement:array nthElement:array
objectFromPairs:object,array objectFromPairs:object,array

View File

@ -1,2 +1,2 @@
module.exports = select = (from, selector) => module.exports = select = (from, ...selectors) =>
selector.split('.').reduce((prev, cur) => prev && prev[cur], from); [...selectors].map(s => s.split('.').reduce((prev, cur) => prev && prev[cur], from));

View File

@ -6,7 +6,7 @@ test('Testing select', (t) => {
//Please go to https://github.com/substack/tape //Please go to https://github.com/substack/tape
t.true(typeof select === 'function', 'select is a Function'); t.true(typeof select === 'function', 'select is a Function');
const obj = { selector: { to: { val: 'val to select' } } }; const obj = { selector: { to: { val: 'val to select' } } };
t.equal(select(obj, 'selector.to.val'), 'val to select', "Retrieve a property indicated by the selector from an object."); t.deepEqual(select(obj, 'selector.to.val'), ['val to select'], "Retrieve a property indicated by the selector from an object.");
//t.deepEqual(select(args..), 'Expected'); //t.deepEqual(select(args..), 'Expected');
//t.equal(select(args..), 'Expected'); //t.equal(select(args..), 'Expected');
//t.false(select(args..), 'Expected'); //t.false(select(args..), 'Expected');