-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add migrate-goldens script (#21)
* Add migrate-goldens script * Add Windows support * Cleanup * Fix lint * Proper plural support because why not * move/rename files individually into new directory struture * Update target directory path * Add .vdiff/ to .gitignore on migrate * Use path constants; Re-add .vdiff/ to .gitignore * Fix package-lock * Fix Windows
- Loading branch information
1 parent
0d1e0aa
commit 2ab2f14
Showing
3 changed files
with
48 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/usr/bin/env node | ||
import { appendFile, mkdir, readFile, rename, rm } from 'node:fs/promises'; | ||
import { join, normalize, parse } from 'node:path'; | ||
import commandLineArgs from 'command-line-args'; | ||
import { glob } from 'glob'; | ||
import { PATHS } from '../src/server/visual-diff-plugin.js'; | ||
import { stdout } from 'node:process'; | ||
|
||
const { pattern = './test/**' } = commandLineArgs({ name: 'pattern', type: String, defaultOption: true }, { partial: true }); | ||
const oldSuffix = 'screenshots/ci/golden'; | ||
const newSuffix = `${PATHS.GOLDEN}/chromium`; | ||
const dirs = await glob(`${pattern}/${oldSuffix}`, { ignore: 'node_modules/**', posix: true }); | ||
let fileCount = 0; | ||
|
||
const gitignore = await readFile('.gitignore', { encoding: 'UTF8' }).catch(() => ''); | ||
if (!new RegExp(`${PATHS.VDIFF_ROOT}/(\n|$)`).test(gitignore)) { | ||
const newline = gitignore.endsWith('\n') ? '' : '\n'; | ||
await appendFile('.gitignore', `${newline}${PATHS.VDIFF_ROOT}/\n`); | ||
} | ||
|
||
await Promise.all(dirs.map(async dir => { | ||
const files = await glob(`${dir}/*/*.png`, { posix: true }); | ||
const base = dir.replace(normalize(oldSuffix), ''); | ||
|
||
await mkdir(join(base, normalize(newSuffix)), { recursive: true }); | ||
|
||
await Promise.all(files.map(async file => { | ||
fileCount += 1; | ||
const { base: name, dir } = parse(file); | ||
const dirName = parse(dir).name; | ||
|
||
const newName = name | ||
.replace(/^d2l-/, '') | ||
.replace(new RegExp(`^${dirName}-`), ''); | ||
|
||
const newDir = join(dir.replace(oldSuffix, newSuffix)); | ||
|
||
await mkdir(newDir, { recursive: true }); | ||
return rename(file, join(newDir, newName)); | ||
})); | ||
return rm(normalize(join(dir, '..', '..')), { recursive: true }); | ||
})); | ||
|
||
stdout.write(`\nMigrated ${fileCount} ${fileCount === 1 ? 'golden' : 'goldens'} found in ${dirs.length} test ${dirs.length === 1 ? 'directory' : 'directories'}\n`); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters