@helloample/netlify-plugin-redirects
Advanced tools
Comparing version 1.0.1 to 1.1.0
@@ -10,4 +10,4 @@ // index.js | ||
const stats = parser.stats(); | ||
console.log(stats.summary); | ||
utils.status.show(stats); | ||
console.log(stats.summary); | ||
} else { | ||
@@ -14,0 +14,0 @@ throw new Error("There was a problem."); |
@@ -30,6 +30,5 @@ const csv = require("csvtojson"); | ||
await this.getRows().then((rows) => { | ||
rows.forEach((row) => { | ||
// TODO: determine context and filter rows accordingly | ||
this.rowsProcessed.push(row); | ||
}); | ||
rows | ||
.filter((row) => row.contextIncluded()) | ||
.forEach((row) => this.rowsProcessed.push(row.toString())); | ||
}); | ||
@@ -66,3 +65,3 @@ await fs.writeFile(this.dest, this.rowsProcessed.join("\n"), (err) => { | ||
this.defaultBranch | ||
).toString(); | ||
); | ||
}); | ||
@@ -69,0 +68,0 @@ }); |
@@ -44,4 +44,4 @@ const branchName = require("current-git-branch"); | ||
contextPresent() { | ||
return this.ctx || this.ctx.split(",").includes(getContext()); | ||
contextIncluded() { | ||
return !this.ctx || this.ctx.split(",").includes(this.getContext()); | ||
} | ||
@@ -48,0 +48,0 @@ |
{ | ||
"name": "@helloample/netlify-plugin-redirects", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "Read a CSV file, parse the rows and write them to `_redirects` _before_ Netlify processes your build.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -30,6 +30,3 @@ "use strict"; | ||
try { | ||
if (fs.existsSync(path)) { | ||
console.log("delete"); | ||
fs.unlinkSync(path); | ||
} | ||
if (fs.existsSync(path)) fs.unlinkSync(path); | ||
} catch (err) { | ||
@@ -42,6 +39,16 @@ console.error(err); | ||
this.parser.perform(); | ||
setTimeout(function() { | ||
setTimeout(function () { | ||
assert.equal(fs.existsSync(path), true); | ||
}, 1); | ||
}); | ||
it("only includes rows that match current context", () => { | ||
process.env["CONTEXT"] = "staging"; | ||
this.parser.rows = [ | ||
new Redirect("/a", "/b", "301"), | ||
new Redirect("/c", "/d", "200", "master"), | ||
]; | ||
this.parser.perform(); | ||
assert.equal(this.parser.rowsProcessed.length, 1); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
13777
288
21