Skip to content

Commit

Permalink
use TemplatePath.normalize rather than path.normalize
Browse files Browse the repository at this point in the history
  • Loading branch information
MadeByMike committed Jun 16, 2019
1 parent 4c3f89f commit 0608138
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
Empty file modified package.json
100644 → 100755
Empty file.
11 changes: 6 additions & 5 deletions src/TemplatePassthrough.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const copy = require("recursive-copy");
const fs = require("fs");
const path = require("path");
const TemplatePath = require("./TemplatePath");
const debug = require("debug")("Eleventy:TemplatePassthrough");
const fastglob = require("fast-glob");
Expand All @@ -20,12 +19,14 @@ class TemplatePassthrough {
getOutputPath() {
const { inputDir, outputDir, outputPath, inputPath } = this;
if (outputPath === true) {
return TemplatePath.join(
outputDir,
TemplatePath.stripLeadingSubPath(inputPath, inputDir)
return TemplatePath.normalize(
TemplatePath.join(
outputDir,
TemplatePath.stripLeadingSubPath(inputPath, inputDir)
)
);
}
return path.normalize(TemplatePath.join(outputDir, outputPath));
return TemplatePath.normalize(TemplatePath.join(outputDir, outputPath));
}

getOutputPathForGlobFile(globFile) {
Expand Down
30 changes: 19 additions & 11 deletions test/TemplatePassthroughTest.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import test from "ava";
import path from "path";
const normalize = require("normalize-path");
import TemplatePassthrough from "../src/TemplatePassthrough";

const getTemplatePassthrough = (path, outputDir, inputDir) => {
Expand All @@ -17,7 +15,7 @@ const getTemplatePassthrough = (path, outputDir, inputDir) => {
test("Constructor", t => {
let pass = getTemplatePassthrough("avatar.png", "_site", ".");
t.truthy(pass);
t.is(pass.getOutputPath(), normalize(path.join("_site/avatar.png")));
t.is(pass.getOutputPath(), "_site/avatar.png");
});

test("Constructor Dry Run", t => {
Expand All @@ -29,19 +27,19 @@ test("Constructor Dry Run", t => {
test("Origin path isn’t included in output when targeting a directory", t => {
let pass = getTemplatePassthrough("img", "_site", "_src");
t.truthy(pass);
t.is(pass.getOutputPath(), normalize(path.join("_site/img")));
t.is(pass.getOutputPath(), "_site/img");
});

test("Origin path isn’t included in output when targeting a directory several levels deep", t => {
let pass = getTemplatePassthrough("img", "_site", "_src/subdir");
t.truthy(pass);
t.is(pass.getOutputPath(), normalize(path.join("_site/img")));
t.is(pass.getOutputPath(), "_site/img");
});

test("Target directory’s subdirectory structure is retained", t => {
let pass = getTemplatePassthrough("subdir/img", "_site", "_src");
t.truthy(pass);
t.is(pass.getOutputPath(), normalize(path.join("_site/subdir/img")));
t.is(pass.getOutputPath(), "_site/subdir/img");
});

test("Origin path isn’t included in output when targeting a file", t => {
Expand All @@ -53,7 +51,7 @@ test("Origin path isn’t included in output when targeting a file", t => {
test("Origin path isn’t included in output when targeting a file several levels deep", t => {
let pass = getTemplatePassthrough("avatar.png", "_site", "_src/subdir/img");
t.truthy(pass);
t.is(pass.getOutputPath(), normalize(path.join("_site/avatar.png")));
t.is(pass.getOutputPath(), "_site/avatar.png");
});

test("Full input file path and deep input path", t => {
Expand All @@ -63,15 +61,15 @@ test("Full input file path and deep input path", t => {
"_site",
"src/views/"
).getOutputPath(),
normalize(path.join("_site/avatar.png"))
"_site/avatar.png"
);
t.is(
getTemplatePassthrough(
"src/views/avatar.png",
"_site",
"src/views"
).getOutputPath(),
normalize(path.join("_site/avatar.png"))
"_site/avatar.png"
);
t.is(
getTemplatePassthrough(
Expand Down Expand Up @@ -172,7 +170,7 @@ test("Directory where outputPath is true", async t => {
"_src"
);
t.truthy(pass);
t.is(pass.getOutputPath(), normalize(path.join("_site/static")));
t.is(pass.getOutputPath(), "_site/static");
});

test("Nested directory where outputPath is remapped", async t => {
Expand All @@ -182,7 +180,7 @@ test("Nested directory where outputPath is remapped", async t => {
"_src"
);
t.truthy(pass);
t.is(pass.getOutputPath(), normalize(path.join("_site/test")));
t.is(pass.getOutputPath(), "_site/test");
});

test("Glob pattern", async t => {
Expand All @@ -202,6 +200,16 @@ test("Glob pattern", async t => {
);
});

test("Output paths match with different templatePassthrough methods", async t => {
let pass1 = getTemplatePassthrough(
{ inputPath: "./static/nested", outputPath: "./test" },
"_site",
"_src"
);
let pass2 = getTemplatePassthrough("avatar.png", "_site/test", ".");
t.is(pass1.getOutputPathForGlobFile("avatar.png"), pass2.getOutputPath());
});

// ToDo: Currently can't do :(
// test("File renamed", async t => {
// let pass = getTemplatePassthrough(
Expand Down

0 comments on commit 0608138

Please sign in to comment.