Files: b24a8c824494555ff39be898c3fde5541e7e8a92 / index.js
1244 bytesRaw
1 | var jetpack = require('fs-jetpack') |
2 | |
3 | var tmpl = jetpack.cwd('tmpl') |
4 | var build = jetpack.cwd('build') |
5 | |
6 | // iterate ./tmpl tree |
7 | // run any template scripts (.html.js and .css.js) |
8 | // and output the result to ./build (.html and .css) |
9 | // ignore any partials (.part.js) |
10 | // copy all other files |
11 | tmpl.find('.', { matching: '*' }, 'inspect') |
12 | .forEach(entry => { |
13 | // console.log(entry) |
14 | if (entry.type == 'dir') { |
15 | // copy folder structure |
16 | // console.log('copying directory') |
17 | build.dir(entry.relativePath) |
18 | } else if (entry.type == 'file') { |
19 | if (/\.(html|css).js$/.test(entry.name)) { |
20 | // build html/css files |
21 | // console.log('building') |
22 | buildTemplate(entry) |
23 | } else if (entry.name.indexOf('.part.js') !== -1) { |
24 | // skip partials |
25 | // console.log('skipping') |
26 | return |
27 | } else { |
28 | // copy all others |
29 | // console.log('copying', entry.absolutePath, entry.relativePath) |
30 | jetpack.copy(entry.absolutePath, build.path(entry.relativePath), { overwrite: true }) |
31 | } |
32 | } |
33 | }) |
34 | |
35 | function buildTemplate (entry) { |
36 | var template = require(entry.absolutePath) |
37 | var path = entry.relativePath.slice(0, -3) // remove the '.js' |
38 | build.write(path, template()) |
39 | } |
Built with git-ssb-web