Created
April 17, 2019 21:32
-
-
Save oligriffiths/ebff4a6947259e69aa970a6ac010acb2 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
class Plugin | |
{ | |
shouldBuild() { | |
return this.inputs.hasChanges(); | |
} | |
build() { | |
for (let input of this.inputs) { | |
input.readFileSync('path/to/file'); | |
} | |
this.output.writeFileSync('path/to/file', 'content'); // here we know about changes | |
} | |
} | |
class DirectoryArray { | |
construct(directories) { | |
this.directories = directories; | |
} | |
hasChanges() { | |
for (let directory of this.directories) { | |
if (directory.hasChanges()) { | |
return true; | |
} | |
} | |
return false; | |
} | |
} | |
// brocfile.js | |
const source = 'src'; | |
const funnel1 = funnel(source, {files: ['index.html', 'index.js']}); | |
// funnel1.outputPath == '/tmp/assdasdas/funnel-1-out' | |
const funnel2 = funnel('public', {files: ['index.css']}); | |
// funnel2.outputPath == '/tmp/assdasdas/funnel-2-out' | |
const funnel3 = funnel(funnel1, {files: ['index.html']}); | |
// funnel3.inputPaths[0] = /tmp/assdasdas/funnel-1-out | |
// funnel3.outputPath == '/tmp/assdasdas/funnel-3-out' | |
const funnel4 = merge([funnel1, funnel2, funnel3]); | |
// funnel4.inputPaths[0] = /tmp/assdasdas/funnel-1-out | |
return funnel3; | |
class DirectoryRevision | |
{ | |
construct(directory) { | |
this.directory = directory; | |
this.revision = 0; | |
} | |
hasChanges() { | |
return patch.length > 0; | |
} | |
getChanges() { | |
const current = FSTree.fromEntries(walkSync.entries(inputPath)); | |
return current.calculatePatch(this.previous); | |
} | |
settleState() { | |
const changes = this.getChanges(); | |
if (changes.length > 0) { | |
this.previous = changes; | |
this.revision++; | |
return true; | |
} | |
return false; | |
} | |
getRevision() { | |
return this.revision; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment