Snippet format update
To match the starter (for the migration)
This commit is contained in:
@ -1,66 +0,0 @@
|
||||
/*
|
||||
This is the tagger script that updates the tag_databse file and logs stats for snippet tags.
|
||||
Run using `npm run tagger`.
|
||||
*/
|
||||
// Load modules
|
||||
const fs = require('fs-extra'),
|
||||
{ black, blue, green, yellow, red, bgWhite } = require('kleur');
|
||||
const util = require('./util');
|
||||
if (util.isTravisCI() && /^Travis build: \d+/g.test(process.env['TRAVIS_COMMIT_MESSAGE'])) {
|
||||
console.log(`${green('NOBUILD')} Tagging terminated, parent commit is a Travis build!`);
|
||||
process.exit(0);
|
||||
}
|
||||
// Set variables for paths
|
||||
const snippetsPath = './snippets';
|
||||
// Set variables for script
|
||||
let snippets = {},
|
||||
output = '',
|
||||
tagDbData = {},
|
||||
missingTags = 0,
|
||||
tagDbStats = {};
|
||||
// Start the timer of the script
|
||||
console.time('Tagger');
|
||||
// Synchronously read all snippets and sort them as necessary (case-insensitive)
|
||||
snippets = util.readSnippets(snippetsPath);
|
||||
// Load tag data from the database
|
||||
tagDbData = util.readTags();
|
||||
tagDbStats = Object.entries(tagDbData).reduce((acc, val) => {
|
||||
val[1].forEach(v => (acc.hasOwnProperty(v) ? acc[v]++ : (acc[v] = 1)));
|
||||
return acc;
|
||||
}, {});
|
||||
// Update the listing of snippets in tag_database and log the statistics, along with missing scripts
|
||||
try {
|
||||
for (let snippet of Object.entries(snippets)) {
|
||||
if (
|
||||
tagDbData.hasOwnProperty(snippet[0].slice(0, -3)) &&
|
||||
tagDbData[snippet[0].slice(0, -3)].join(',').trim()
|
||||
) {
|
||||
output += `${snippet[0].slice(0, -3)}:${tagDbData[snippet[0].slice(0, -3)]
|
||||
.join(',')
|
||||
.trim()}\n`;
|
||||
} else {
|
||||
output += `${snippet[0].slice(0, -3)}:uncategorized\n`;
|
||||
missingTags++;
|
||||
console.log(`${yellow('Tagged uncategorized:')} ${snippet[0].slice(0, -3)}`);
|
||||
}
|
||||
}
|
||||
// Write to tag_database
|
||||
fs.writeFileSync('tag_database', output);
|
||||
} catch (err) {
|
||||
// Handle errors (hopefully not!)
|
||||
console.log(`${red('ERROR!')} During tag_database generation: ${err}`);
|
||||
process.exit(1);
|
||||
}
|
||||
// Log statistics for the tag_database file
|
||||
console.log(`\n${bgWhite(black('=== TAG STATS ==='))}`);
|
||||
for (let tagData of Object.entries(tagDbStats)
|
||||
.filter(v => v[0] !== 'undefined')
|
||||
.sort((a, b) => a[0].localeCompare(b[0])))
|
||||
console.log(`${green(tagData[0])}: ${tagData[1]} snippets`);
|
||||
console.log(
|
||||
`${blue("New untagged snippets (will be tagged as 'uncategorized'):")} ${missingTags}\n`
|
||||
);
|
||||
// Log a success message
|
||||
console.log(`${green('SUCCESS!')} tag_database file updated!`);
|
||||
// Log the time taken
|
||||
console.timeEnd('Tagger');
|
||||
Reference in New Issue
Block a user