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");
|
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)
|
|
|
|
}
|
|
|
|
|
2020-06-11 09:30:00 +03:00
|
|
|
compilefile(relPath('src/plausible.js'), relPath('../priv/tracker/js/plausible.js'))
|
2020-08-25 10:56:36 +03:00
|
|
|
compilefile(relPath('src/plausible.js'), relPath('../priv/tracker/js/plausible.hash.js'), {hashMode: true})
|
2020-06-11 09:30:00 +03:00
|
|
|
compilefile(relPath('src/p.js'), relPath('../priv/tracker/js/p.js'))
|
|
|
|
fs.copyFileSync(relPath('../priv/tracker/js/plausible.js'), relPath('../priv/tracker/js/analytics.js'))
|