2021-08-12 03:11:35 +03:00
|
|
|
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) {
|
2021-08-12 03:11:35 +03:00
|
|
|
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) {
|
2021-08-12 03:11:35 +03:00
|
|
|
const variables = JSON.parse(fs.readFileSync(join(versionPath, './variables.json')))
|
2021-04-01 09:11:55 +03:00
|
|
|
return Object.keys(variables)
|
|
|
|
}
|
|
|
|
|
2021-08-12 03:11:35 +03:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-08-12 03:11:35 +03:00
|
|
|
export function getPackageStats(packageName) {
|
|
|
|
const stats = JSON.parse(fs.readFileSync(join(currentPath, './dist', `./stats/${packageName}.json`)))
|
2021-06-15 21:38:30 +03:00
|
|
|
return stats
|
|
|
|
}
|
|
|
|
|
2021-10-08 19:20:20 +03:00
|
|
|
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'))
|
|
|
|
}
|
|
|
|
|
2021-10-08 19:20:20 +03:00
|
|
|
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'))
|
|
|
|
}
|
|
|
|
|
2021-08-12 03:11:35 +03:00
|
|
|
export function getSelectorDiff() {
|
2021-04-01 09:11:55 +03:00
|
|
|
return diffLists(lastVersionSelectors(), currentVersionSelectors())
|
|
|
|
}
|
2021-04-01 00:53:15 +03:00
|
|
|
|
2021-08-12 03:11:35 +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
|
|
|
}
|