First run for Snowplow Vue event dictionary entries
Related to #333993 (closed)
This covers all Snowplow events emitted from frontend using the Vue mixin until date. Any missing event will be added on a follow-up pass.
Generator used
/* eslint-disable import/no-commonjs */
/* eslint-disable no-use-before-define */
/* eslint-disable no-restricted-syntax */
const fs = require('fs');
const csv = require('csv-parser');
const SOURCE_FILE_PATH = './events.csv';
const FOLDER_PATH = './event_dictionary_generator_output';
const ARRAY_SEPARATOR = ';';
// extra_properties
const baseTemplate = `description:
category:
action:
label_description:
property_description:
value_description:
extra_properties:
identifiers:
product_section:
product_stage:
product_group:
product_category:
milestone:
introduced_by_url:
distributions:
tiers:
`;
createFolderIfNeeded();
iterateRows();
function createFolderIfNeeded() {
if (!fs.existsSync(FOLDER_PATH)) {
fs.mkdirSync(FOLDER_PATH);
}
}
function iterateRows() {
fs.createReadStream(SOURCE_FILE_PATH).pipe(csv()).on('data', createFileFromRow);
}
function createFileFromRow(row) {
let template = String(baseTemplate);
for (const [name, rawValue] of Object.entries(row)) {
const label = `${name}:`;
let value = rawValue;
const isArray = value.includes(ARRAY_SEPARATOR) || ['distributions', 'tiers'].includes(name);
if (name === 'category') {
value = value || 'default';
}
if (['description', 'milestone', 'label_description', 'property_description', 'value_description'].includes(name)) {
value = `"${value}"`
}
if (isArray) {
const items = value.split(ARRAY_SEPARATOR).join('\n- ');
template = template.replace(label, `${label}\n- ${items}`);
} else {
const variableValue = value.replace(/^`(.+?)`$/, '"`$1`"');
template = template
.replace(label, `${label} ${variableValue}`);
}
}
// Timestamp
const pad = (number, at = 2) => `0${number}`.slice(at * -1);
const now = new Date;
const timestamp = [
now.getFullYear(),
pad(now.getMonth() + 1),
pad(now.getDate()),
pad(now.getHours()),
pad(now.getMinutes()),
pad(now.getSeconds()),
].join('');
// Custom slug logic attempt
const filename = `${timestamp}_${row.category || 'default'}_${row.label_description}_${row.action}`
.replace(/[`\[\]]/g, '')
.replace(/(?: \| |:)/g, '_')
.replace(/\s+/g, '_')
.toLowerCase()
.trim()
.replace(/_{2,}/, '_');
const path = `${FOLDER_PATH}/${filename}.yml`;
// Create file
fs.writeFileSync(path, template);
console.info(path, 'created');
}
Edited by Axel García