1
0
mirror of synced 2025-12-23 11:54:18 -05:00
Files
docs/script/content-migrations/deduplicate-enterprise-assets.js
Mike Surowiec 37f73f0bb3 Heroku dev deps (#19431)
* fix: req.csrfToken doesn't always exist (e.g. 500 page)

* feat: update dockerfile and add nextjs to build

* fix: run linter

* move @babel deps -> dev deps

* move webpack looking things from deps -> dev deps

* move pa11y-ci to optional dep

* explicitly include optional deps for pa11y

* allow heroku dev deps to be installed

* fix: update postcss module

* fix: update dockerfile build

* tmp: disable renderReact

* see if another deploy is slower/faster

* move a few more packages to devDeps

* upgrade to package-lock v2

* use dayjs instead of date-fns

* move cross-env to devDeps

* remove unused 'del' package

* commit husky precommit hooks

* add hrtime to clone-for-build.js

* Revert "add hrtime to clone-for-build.js"

This reverts commit 70ee647bacce833f4ed2f621f62c63c1d85e5413.

* update babel/eslint

* fix: remove unused plugin

* try a .slugignore

* fix: heroku-postbuild to use npm run build

* fix: i cannot spell dereferenced

* add .next/cache to heroku cacheDirectories

* test cached build

* remove aws-sdk, see what breaks

* move jest-puppeteer to optional deps

* fix: update browser-test.yml to use newer node version

* move jimp to optional dependencies

* move puppeteer to optional dependencies

* fix: ci optional include

* fix: bad copy pasta

* remove previous react experiment

* update tests/README.md with note about optional deps

* bump node test version back to 14

* convert package-lock back to v1

* fix: use node 15.x to leverage npm optional deps

* fix: optional dep install

* test: see what happens with heroku/nodejs-typescript buildpack

* back to heroku/nodejs buildpack

* move jest to optional

* revert jest move

* remove .slugignore

* cleanup dockerfile, move xlsx-population to optional, add comment about optional deps

* Update Dockerfile

Co-authored-by: James M. Greene <JamesMGreene@github.com>

Co-authored-by: James M. Greene <JamesMGreene@github.com>
2021-05-24 15:40:50 -07:00

72 lines
2.7 KiB
JavaScript
Executable File

#!/usr/bin/env node
const fs = require('fs')
const path = require('path')
const walk = require('walk-sync')
const jimp = require('jimp') // this is an optional dependency, install with `npm i --include=optional`
// iterate through enterprise images from most recent to oldest
// check if the image in the /assets/enterprise/... directory
// is an exact match to the assets/images in relative path and content
// if exact match, delete the /assets/enterprise/... version
const enterpriseAssetDirectories = [
'/assets/enterprise/3.0',
'/assets/enterprise/github-ae',
'/assets/enterprise/2.22',
'/assets/enterprise/2.21',
'/assets/enterprise/2.20'
]
async function main () {
for (const directory of enterpriseAssetDirectories) {
const fullDirectoryPath = path.join(process.cwd(), directory)
const files = walk(fullDirectoryPath, {
includeBasePath: true,
directories: false
})
for (const file of files) {
// get the /assets/images file that currently exists, which
// would be the equivalent to the enterprise asset
const enterpriseRegex = /\/assets\/enterprise\/(2\.20|2\.21|2\.22|3\.0|github-ae)/
const existingFileToCompare = file.replace(enterpriseRegex, '')
const fileExt = path.extname(file)
// if the file in the enterprise directory is an exact copy of
// the image in the local /assets/images directory, then we can
// delete the enterprise image and the reference in the Markdown
// will just work
if (fs.existsSync(existingFileToCompare)) {
// Buffer.compare and Jimp both return 0 if files match
let compareResult = 1
try {
// Jimp gives slightly better results comparing image files
// over using a buffer compare. Of the assets we have,
// Jimp only supports png and gif
if (fileExt === '.png' || fileExt === '.gif') {
const existingImageToCompare = await jimp.read(existingFileToCompare)
const enterpriseImage = await jimp.read(file)
// if the diff.percent value is 0, images are identical
const diff = await jimp.diff(existingImageToCompare, enterpriseImage)
compareResult = diff.percent
} else {
const existingImageToCompare = await fs.readFileSync(existingFileToCompare)
const enterpriseImage = await fs.readFileSync(file)
compareResult = Buffer.compare(Buffer.from(existingImageToCompare),
Buffer.from(enterpriseImage))
}
} catch (err) {
console.log(file)
console.log(err)
}
if (compareResult === 0) fs.unlinkSync(file)
}
}
}
}
main()
.catch(console.error)
.finally(() => console.log('Done!'))