mirror of
https://github.com/plausible/analytics.git
synced 2024-12-22 17:11:36 +03:00
11654ddc07
* added data-include attribute to plausible.exclusions.js * reorder extensions in filename when serving the plausible script * fix formatting * tweaks after review * changelog update
29 lines
1.1 KiB
JavaScript
29 lines
1.1 KiB
JavaScript
const uglify = require("uglify-js");
|
|
const fs = require('fs')
|
|
const path = require('path')
|
|
const Handlebars = require("handlebars");
|
|
const g = require("generatorics");
|
|
|
|
function relPath(segment) {
|
|
return path.join(__dirname, segment)
|
|
}
|
|
|
|
function compilefile(input, output, templateVars = {}) {
|
|
const code = fs.readFileSync(input).toString()
|
|
const template = Handlebars.compile(code)
|
|
const rendered = template(templateVars)
|
|
const result = uglify.minify(rendered)
|
|
fs.writeFileSync(output, result.code)
|
|
}
|
|
|
|
const base_variants = ["hash", "outbound-links", "exclusions", "compat", "local", "manual", "file-downloads", "dimensions"]
|
|
const variants = [...g.clone.powerSet(base_variants)].filter(a => a.length > 0).map(a => a.sort());
|
|
|
|
compilefile(relPath('src/plausible.js'), relPath('../priv/tracker/js/plausible.js'))
|
|
compilefile(relPath('src/p.js'), relPath('../priv/tracker/js/p.js'))
|
|
|
|
variants.map(variant => {
|
|
const options = variant.map(variant => variant.replace('-', '_')).reduce((acc, curr) => (acc[curr] = true, acc), {})
|
|
compilefile(relPath('src/plausible.js'), relPath(`../priv/tracker/js/plausible.${variant.join('.')}.js`), options)
|
|
})
|