You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
analytics/tracker/compile.js

24 lines
762 B
JavaScript

const uglify = require("uglify-js");
const fs = require('fs')
const path = require('path')
const scheme = process.env.SCHEME || "http"
const host = process.env.HOST || "localhost"
const baseUrl = scheme + "://" + host
function relPath(segment) {
return path.join(__dirname, segment)
}
function compilefile(input, output) {
const code = fs.readFileSync(input)
.toString()
.replace('BASE_URL', "'" + baseUrl + "'")
const result = uglify.minify(code)
fs.writeFileSync(output, result.code)
}
compilefile(relPath('src/plausible.js'), relPath('../priv/static/js/plausible.js'))
compilefile(relPath('src/p.js'), relPath('../priv/static/js/p.js'))
fs.copyFileSync(relPath('../priv/static/js/plausible.js'), relPath('../priv/static/js/analytics.js'))