Skip to content

Commit d0990c2

Browse files
committed
Update to faucet-pipeline 1.0.0-beta.0
1 parent 2f98328 commit d0990c2

File tree

17 files changed

+107
-207
lines changed

17 files changed

+107
-207
lines changed

lib/build-bundler.js

Lines changed: 0 additions & 53 deletions
This file was deleted.

lib/build-config.js

Lines changed: 0 additions & 49 deletions
This file was deleted.

lib/build-manifest-writer.js

Lines changed: 0 additions & 34 deletions
This file was deleted.

lib/build-reporter.js

Lines changed: 0 additions & 12 deletions
This file was deleted.

lib/index.js

Lines changed: 58 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,72 @@
1-
let buildConfig = require("./build-config");
2-
let buildBundler = require("./build-bundler");
3-
let buildReporter = require("./build-reporter");
4-
let buildManifestWriter = require("./build-manifest-writer");
1+
let path = require("path");
2+
let { readFile } = require("./promisified-fs");
3+
let tree = require("./tree");
54

6-
module.exports = (rawConfig, configDir, { watcher, fingerprint }) => {
7-
let config = buildConfig(rawConfig, configDir, fingerprint);
8-
let bundleAll = buildBundleAll(config);
5+
module.exports = (pluginConfig, assetManager, { watcher }) => {
6+
let copyAll = buildCopyAll(pluginConfig, assetManager);
97

108
// Run once for all files
11-
bundleAll();
9+
copyAll();
1210

1311
if(watcher) {
14-
watcher.on("edit", bundleAll);
12+
watcher.on("edit", copyAll);
1513
}
1614
};
1715

18-
function buildBundleAll(config) {
19-
let bundlers = config.bundles.map(bundleConfig => buildBundler(bundleConfig));
20-
let report = buildReporter();
21-
let writeManifest = buildManifestWriter(config.manifest);
16+
function buildCopyAll(copyConfigs, assetManager) {
17+
let copiers = copyConfigs.map(copyConfig =>
18+
buildCopier(copyConfig, assetManager));
19+
20+
return files => copiers.forEach(copier => copier(files));
21+
}
22+
23+
function buildCopier(copyConfig, assetManager) {
24+
let source = assetManager.resolvePath(copyConfig.source, {
25+
enforceRelative: true
26+
});
27+
let target = assetManager.resolvePath(copyConfig.target, {
28+
enforceRelative: true
29+
});
2230

2331
return files => {
24-
Promise.all(bundlers.map(bundler => bundler(files))).
25-
then(flatten).
26-
then(writeManifest).
27-
then(report);
32+
return determineFilesToProcess(source, files).
33+
then(filterInvisibleFiles).
34+
then(fileNames => processFiles(fileNames, {
35+
assetManager, source, target
36+
}));
2837
};
2938
}
3039

31-
function flatten(arr) {
32-
return arr.reduce((acc, cur) => acc.concat(cur));
40+
function processFiles(fileNames, config) {
41+
return Promise.all(fileNames.map(fileName => processFile(fileName, config)));
42+
}
43+
44+
function processFile(fileName, { source, target, assetManager }) {
45+
let sourcePath = path.join(source, fileName);
46+
let targetPath = path.join(target, fileName);
47+
48+
return readFile(sourcePath).
49+
then(content => assetManager.writeFile(targetPath, content, {
50+
targetDir: target
51+
}));
52+
}
53+
54+
function determineFilesToProcess(source, files) {
55+
if(files) {
56+
return filesWithinDirectory(source, files);
57+
} else {
58+
return tree(source);
59+
}
60+
}
61+
62+
function filterInvisibleFiles(files) {
63+
return files.filter(file => !file.startsWith("."));
64+
}
65+
66+
function filesWithinDirectory(directory, files) {
67+
return new Promise(resolve => {
68+
resolve(files.
69+
map(file => path.relative(directory, file)).
70+
filter(file => !file.startsWith("..")));
71+
});
3372
}

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
},
1818
"homepage": "https://github.com/faucet-pipeline/faucet-pipeline-static#readme",
1919
"dependencies": {
20-
"faucet-pipeline": "^0.14.0",
21-
"faucet-pipeline-util": "^0.10.3"
20+
"faucet-pipeline": "1.0.0-beta.0"
2221
},
2322
"devDependencies": {
2423
"eslint": "^4.4.1",

test/hooks.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ let path = require("path");
77
let faucetStatic = path.resolve(__dirname, "..");
88

99
hook.hook(".js", (src, name) => {
10-
if(/\/faucet-pipeline\/index.js$/.test(name)) {
10+
if(/\/faucet-pipeline\/lib\/index.js$/.test(name)) {
1111
return src.replace("faucet-pipeline-static", faucetStatic);
1212
}
1313

test/run

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,24 +61,28 @@ function fail {
6161
cd "$root/test"
6262

6363
begin "./test_basic"
64-
faucet --no-fingerprint
64+
faucet
6565
assert_identical "./dist/test.txt" "./src/test.txt"
6666
assert_identical "./dist/inner/test2.txt" "./src/inner/test2.txt"
6767
end
6868

6969
begin "./test_fingerprint"
70-
faucet
70+
faucet --fingerprint
7171
assert_identical "./dist/test-e59ff97941044f85df5297e1c302d260.txt" "./src/test.txt"
7272
assert_identical_json "./dist/manifest.json" "./expected.json"
7373
end
7474

7575
begin "./test_manifest_base_uri"
76-
faucet
76+
faucet --fingerprint
7777
assert_identical_json "./dist/manifest.json" "./expected.json"
7878
end
7979

8080
begin "./test_single"
81-
faucet --no-fingerprint
81+
faucet
8282
assert_identical "./dist/dist.txt" "./src.txt"
8383
end
8484

85+
begin "./test_key_config"
86+
faucet --fingerprint
87+
assert_identical_json "./dist/manifest.json" "./expected.json"
88+
end

test/test_basic/faucet.config.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
"use strict";
22

33
module.exports = {
4-
static: {
5-
manifest: false,
6-
bundles: [{
7-
source: "src",
8-
target: "dist"
9-
}]
10-
}
4+
static: [{
5+
source: "./src",
6+
target: "./dist"
7+
}]
118
};
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"dist/inner/test2.txt":"/assets/dist/inner/test2-e59ff97941044f85df5297e1c302d260.txt","dist/test.txt":"/assets/dist/test-e59ff97941044f85df5297e1c302d260.txt"}
1+
{"dist/inner/test2.txt":"/dist/inner/test2-e59ff97941044f85df5297e1c302d260.txt","dist/test.txt":"/dist/test-e59ff97941044f85df5297e1c302d260.txt"}

0 commit comments

Comments
 (0)