Skip to content

Commit

Permalink
Set default value to stable,output and current folder.
Browse files Browse the repository at this point in the history
Make configurable stable,output and current.
  • Loading branch information
Zura024 committed Dec 26, 2018
1 parent 223c5af commit 71a56ad
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ let siteMapIndex = 0;
class Generator {
constructor(params) {
this.url = params.url;
this.outputFolder = params.outputFolder || 'output';
this.currentFolder = params.currentFolder || 'current';
this.stableFolder = params.stableFolder || 'stable';
this.generateSitemap = params.generateSitemap;
this.urls = [];
this.resolutionName = params.resolutionName;
Expand All @@ -38,7 +41,7 @@ class Generator {
this.FILE_MAX_LENGTH = 214;

fs.ensureDirSync(this.sitesFolder);
this.outputPath = this.sitesFolder + '/output/' + this.resolutionName;
this.outputPath = this.sitesFolder + `/${this.outputFolder}/` + this.resolutionName;
winston.configure({
transports: [
new (winston.transports.File)({filename: `${this.RUNTIME}/output.log`})
Expand All @@ -55,7 +58,7 @@ class Generator {
if (typeof this.resolutionName === 'string') {
if (this.resolutionName === 'all') {
for (let resolution in conf.SCREEN_RESOLUTIONS) {
imageFolder = `${this.sitesFolder}/current/${resolution}`;
imageFolder = `${this.sitesFolder}/${this.currentFolder}/${resolution}`;
fs.emptyDirSync(imageFolder);
if (this.includeThumbnails) {
fs.emptyDirSync(`${imageFolder}-thumbnails`)
Expand All @@ -65,7 +68,7 @@ class Generator {
}));
}
} else {
imageFolder = `${this.sitesFolder}/current/${this.resolutionName}`;
imageFolder = `${this.sitesFolder}/${this.currentFolder}/${this.resolutionName}`;
fs.emptyDirSync(imageFolder);
if (this.includeThumbnails) {
fs.emptyDirSync(`${imageFolder}-thumbnails`)
Expand All @@ -77,7 +80,7 @@ class Generator {
} else if (typeof this.resolutionName === 'object') {
if (this.resolutionName.includes('all')) {
for (let resolution in conf.SCREEN_RESOLUTIONS) {
imageFolder = `${this.sitesFolder}/current/${resolution}`;
imageFolder = `${this.sitesFolder}/${this.currentFolder}/${resolution}`;
fs.emptyDirSync(imageFolder);
if (this.includeThumbnails) {
fs.emptyDirSync(`${imageFolder}-thumbnails`)
Expand All @@ -88,7 +91,7 @@ class Generator {
}
} else {
for (let i in this.resolutionName) {
imageFolder = `${this.sitesFolder}/current/${this.resolutionName[i]}`;
imageFolder = `${this.sitesFolder}/${this.currentFolder}/${this.resolutionName[i]}`;
fs.emptyDirSync(imageFolder);
if (this.includeThumbnails) {
fs.emptyDirSync(`${imageFolder}-thumbnails`)
Expand Down Expand Up @@ -200,9 +203,9 @@ class Generator {
}

//Compare images if stable folder exist
let stableFile = newFile.replace('/current/', '/stable/');
let stableFile = newFile.replace(`/${this.currentFolder}/`, `/${this.stableFolder}/`);
if (fs.existsSync(stableFile)) {
let output = newFile.replace('/current/', '/output/');
let output = newFile.replace(`/${this.currentFolder}/`, `/${this.outputFolder}/`);
await compareImage.isTheSame(stableFile, newFile, path.dirname(output)).then((result) => {
winston.info(result.stdout);
});
Expand Down

0 comments on commit 71a56ad

Please sign in to comment.