summaryrefslogtreecommitdiff
path: root/scripts/frontend/check_page_bundle_mixins_css_for_sideeffects.js
blob: 34e939e3cebe8c9b4d34c34256a781387ffa4ca7 (plain)
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
#!/usr/bin/env node

if (process.env.RAILS_ENV !== 'production') {
  console.log(
    `RAILS_ENV is not set to 'production': ${process.env.RAILS_ENV} - Not executing check`,
  );
  process.exit(0);
}

const path = require('path');
const fs = require('fs');
const glob = require('glob');
const pjs = require('postcss');

const paths = glob.sync('public/assets/page_bundles/_mixins_and_variables_and_functions*.css', {
  cwd: path.join(__dirname, '..', '..'),
});

if (!paths[0]) {
  console.log('Could not find mixins test file');
  process.exit(1);
}

console.log(`Checking ${paths[0]} for side effects`);

const file = fs.readFileSync(paths[0], 'utf-8');

const parsed = pjs.parse(file);

if (parsed.nodes.every((node) => ['comment', 'atrule'].includes(node.type))) {
  console.log('The file does not introduce any side effects, we are all good.');
  process.exit(0);
}

console.log(`At least one unwanted style was introduced.`);
process.exit(1);