File size: 1,032 Bytes
6778ee0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import fs from 'fs'
import path from 'path'
import { fileURLToPath } from 'url'
import g from 'generatorics'

const __dirname = path.dirname(fileURLToPath(import.meta.url))

function idToGlobal(id) {
  return `COMPILE_${id.replace('-', '_').toUpperCase()}`
}

const LEGACY_VARIANT_NAMES = [
  'hash',
  'outbound-links',
  'exclusions',
  'compat',
  'local',
  'manual',
  'file-downloads',
  'pageview-props',
  'tagged-events',
  'revenue'
]
let legacyVariants = [...g.clone.powerSet(LEGACY_VARIANT_NAMES)]
  .map((a) => a.sort())
  .map((variant) => ({
    name:
      variant.length > 0 ? `plausible.${variant.join('.')}.js` : 'plausible.js',
    globals: {
      ...Object.fromEntries(variant.map((id) => [idToGlobal(id), true])),
      COMPILE_PLAUSIBLE_LEGACY_VARIANT: true
    }
  }))

const variantsFile = path.join(__dirname, 'variants.json')
const existingData = JSON.parse(fs.readFileSync(variantsFile, 'utf8'))

fs.writeFileSync(
  variantsFile,
  JSON.stringify({ ...existingData, legacyVariants }, null, 2) + '\n'
)