Skip to content

Instantly share code, notes, and snippets.

@jdlrobson
Created March 13, 2024 00:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdlrobson/ccb9ec74eaa59cd05f5ff000cb084999 to your computer and use it in GitHub Desktop.
Save jdlrobson/ccb9ec74eaa59cd05f5ff000cb084999 to your computer and use it in GitHub Desktop.
const fs = require( 'fs' );
const pixel = `/srv/pixel`;
const outputDir = `/var/www/html`;
const ctx = () => {
try {
return JSON.parse( fs.readFileSync( `${pixel}/context.json` ) );
} catch ( e ) {
return {};
}
};
const json = ctx();
if ( Object.keys(json).length === 0 ) {
console.warn( `Could not read Pixel directory: ${pixel}` );
}
const ref = Object.keys(json).map( ( build ) => {
let ref = json[build].reference;
if ( !ref ) {
return;
}
ref = ref.replace( /\/g/, '_' );
const archivePath = `${outputDir}/archive/${ref}`;
const masterPath = `${outputDir}/reports`;
// If the archive folder hasn't been created make it from the current copy.
if ( !fs.existsSync( archivePath ) ) {
console.log( `Creating ${archivePath}` );
fs.mkdirSync( archivePath, { recursive: true } );
fs.cpSync( masterPath, archivePath, { recursive: true } );
}
// Once that's done, check the individual build
// and create new copy
[
`${build}`,
`reference-screenshots-${build}`,
`test-screenshots-${build}`
].forEach( ( subfolder ) => {
const archiveSubFolder = `${archivePath}/${subfolder}`;
const currentSubFolder = `${masterPath}/${subfolder}`;
if ( !fs.existsSync( currentSubFolder ) ) {
console.warn( `Skipping as directory ${currentSubFolder} does not exist.` );
return;
}
// If an existing version exists delete it.
if ( fs.existsSync( archiveSubFolder ) ) {
console.log(`Replacing archive ${archiveSubFolder}`)
fs.rmSync( archiveSubFolder, { recursive: true } );
} else {
console.log(`Creating archive ${archiveSubFolder}`)
}
fs.cpSync( currentSubFolder, archiveSubFolder, { recursive: true } );
} );
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment