2020-05-29 09:51:16 +03:00
|
|
|
const uglify = require("uglify-js");
|
|
|
|
const fs = require('fs')
|
|
|
|
const path = require('path')
|
2020-08-25 10:56:36 +03:00
|
|
|
const Handlebars = require("handlebars");
|
2021-05-18 11:36:12 +03:00
|
|
|
const g = require("generatorics");
|
2020-05-29 09:51:16 +03:00
|
|
|
|
|
|
|
function relPath(segment) {
|
|
|
|
return path.join(__dirname, segment)
|
|
|
|
}
|
|
|
|
|
2020-08-25 10:56:36 +03:00
|
|
|
function compilefile(input, output, templateVars = {}) {
|
2020-06-11 09:30:00 +03:00
|
|
|
const code = fs.readFileSync(input).toString()
|
2020-08-25 10:56:36 +03:00
|
|
|
const template = Handlebars.compile(code)
|
|
|
|
const rendered = template(templateVars)
|
|
|
|
const result = uglify.minify(rendered)
|
2020-05-29 09:51:16 +03:00
|
|
|
fs.writeFileSync(output, result.code)
|
|
|
|
}
|
|
|
|
|
2021-06-17 10:55:45 +03:00
|
|
|
const base_variants = ["hash", "outbound-links", "exclusions", "compat"]
|
2021-05-18 11:36:12 +03:00
|
|
|
const variants = [...g.clone.powerSet(base_variants)].filter(a => a.length > 0).map(a => a.sort());
|
|
|
|
|
2020-06-11 09:30:00 +03:00
|
|
|
compilefile(relPath('src/plausible.js'), relPath('../priv/tracker/js/plausible.js'))
|
2021-05-18 11:36:12 +03:00
|
|
|
compilefile(relPath('src/plausible.js'), relPath('../priv/tracker/js/analytics.js'))
|
2020-06-11 09:30:00 +03:00
|
|
|
compilefile(relPath('src/p.js'), relPath('../priv/tracker/js/p.js'))
|
2021-05-18 11:36:12 +03:00
|
|
|
|
|
|
|
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)
|
|
|
|
})
|