-
-
Save jdlrobson/ccb9ec74eaa59cd05f5ff000cb084999 to your computer and use it in GitHub Desktop.
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
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