1
1
mirror of https://github.com/primer/css.git synced 2024-11-29 14:14:26 +03:00
css/__tests__/utils/css.js

73 lines
2.0 KiB
JavaScript
Raw Normal View History

import {join, dirname} from 'path'
import semver from 'semver'
import { fileURLToPath } from 'url'
import fs from 'fs'
const __dirname = dirname(fileURLToPath(import.meta.url))
2021-04-01 09:11:55 +03:00
const currentPath = join(__dirname, '../../')
const lastPath = join(__dirname, '../../tmp/node_modules/@primer/css')
2021-04-01 00:53:15 +03:00
2021-04-01 09:11:55 +03:00
function diffLists(before, after) {
2021-05-06 00:10:15 +03:00
const added = [...new Set(after.filter(value => !before.includes(value)))]
const removed = [...new Set(before.filter(value => !after.includes(value)))]
2021-04-01 09:11:55 +03:00
return {
changed: added.length + removed.length,
added,
removed
}
}
function getSelectors(versionPath) {
const stats = JSON.parse(fs.readFileSync(join(versionPath, './stats/primer.json')))
2021-04-01 09:11:55 +03:00
return stats.selectors.values
}
function getVariables(versionPath) {
const variables = JSON.parse(fs.readFileSync(join(versionPath, './variables.json')))
2021-04-01 09:11:55 +03:00
return Object.keys(variables)
}
export function getCurrentVersion() {
const pkg = JSON.parse(fs.readFileSync(join(currentPath, './package.json')))
2021-05-06 00:10:15 +03:00
return semver.parse(pkg.version)
2021-04-01 09:11:55 +03:00
}
export function getPackageStats(packageName) {
const stats = JSON.parse(fs.readFileSync(join(currentPath, './dist', `./stats/${packageName}.json`)))
return stats
}
function getDeprecations(versionPath) {
const deprecations = JSON.parse(fs.readFileSync(join(versionPath, './deprecations.json')))
return deprecations
}
2021-04-01 09:11:55 +03:00
function currentVersionSelectors() {
return getSelectors(join(currentPath, './dist'))
}
function currentVersionVariables() {
return getVariables(join(currentPath, './dist'))
}
export function currentVersionDeprecations() {
return getDeprecations(join(currentPath, './dist'))
}
2021-04-01 09:11:55 +03:00
function lastVersionSelectors() {
return getSelectors(join(lastPath, './dist'))
}
function lastVersionVariables() {
return getVariables(join(lastPath, './dist'))
}
export function getSelectorDiff() {
2021-04-01 09:11:55 +03:00
return diffLists(lastVersionSelectors(), currentVersionSelectors())
}
2021-04-01 00:53:15 +03:00
export function getVariableDiff() {
2021-04-01 09:11:55 +03:00
return diffLists(lastVersionVariables(), currentVersionVariables())
2021-04-01 00:53:15 +03:00
}