Skip to content

Commit

Permalink
WORKING build and serve
Browse files Browse the repository at this point in the history
  • Loading branch information
lunelson committed Feb 15, 2018
1 parent dbd5f3e commit 9555bbd
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 32 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,4 @@ Icon
Network Trash Folder
Temporary Items
.apdisk
/test-build
Expand Down
23 changes: 23 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@
"<node_internals>/**/*.js"
]
},
{
"type": "node",
"request": "launch",
"name": "Build Test",
"program": "${workspaceFolder}/bin/cli.js",
"args": [
"build",
"/Users/lunelson/Git/packages/penny/test",
"/Users/lunelson/Git/packages/penny/test-build",
],
"skipFiles": [
"${workspaceRoot}/node_modules/**/*.js",
"<node_internals>/**/*.js"
]
},
{
"type": "node",
"request": "launch",
Expand All @@ -26,6 +41,10 @@
"args": [
"serve",
"/Users/lunelson/Git/projects/nova-bps-proto/src"
],
"skipFiles": [
"/Users/lunelson/Git/projects/nova-bps-proto/node_modules/**/*.js",
"<node_internals>/**/*.js"
]
},
{
Expand All @@ -37,6 +56,10 @@
"build",
"/Users/lunelson/Git/projects/nova-bps-proto/src",
"/Users/lunelson/Git/projects/nova-bps-proto/out"
],
"skipFiles": [
"/Users/lunelson/Git/projects/nova-bps-proto/node_modules/**/*.js",
"<node_internals>/**/*.js"
]
}
]
Expand Down
2 changes: 1 addition & 1 deletion index-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ module.exports = function pennyServe(baseDir, isDev = true) {
}
}
)
.on('ready', () => (watcherReady = true));
.on('ready', () => watcherReady = true);
});
} else {

Expand Down
68 changes: 40 additions & 28 deletions lib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@ const chalk = require('chalk');
const write = require('write');
const del = require('delete');
const _ = require('lodash');
const rr = require('recursive-readdir');
const mm = require('micromatch'); // https://github.com/micromatch/micromatch
const rrddir = require('recursive-readdir');
const mmatch = require('micromatch'); // https://github.com/micromatch/micromatch
const cp = require('cp-file');



const ignoreGlobs = [
'!**/_*/**/*.*', // ignore _folder
'!**/_*.*', // ignore _file
Expand All @@ -35,45 +33,59 @@ module.exports = function (srcDir, outDir, options) {
const { reqSrcExt } = options;
const srcOutExt = _.invert(reqSrcExt);
const srcExts = Object.keys(srcOutExt);
const srcRenderFns = _.mapValues(srcOutExt, (out, src) => require(`./render-${src.slice(1)}`)(srcDir, false, options));
// const changeTimes = _.mapValues(srcOutExt, Date.now);
// const sourceWares = _.mapValues(srcOutExt, (outExt, srcExt) => {
// return require(`./lib/serve-${srcExt.slice(1)}.js`)(srcDir, isDev, changeTimes, options);
// });
const srcRenderFns = _.mapValues(srcOutExt, (outExt, srcExt) => require(`./render-${srcExt.slice(1)}`)({srcDir, options}));
const srcOutReplacers = _.mapValues(srcOutExt, (outExt, srcExt) => {
return function(str) { return str.replace(new RegExp(`\\${srcExt}$`), outExt); };
});

/*
TODO
- render to a temp directory; move everything in to place, only if it all worked
console.log(`
BUILDING
from: ${srcDir}
to: ${outDir}
`);
*/

rr(srcDir).then(files => {
rrddir(srcDir).then(files => {

// FILTERING
/**
* FILTERING
*/

const filesBySrc = mm(files, ['**/*'].concat(ignoreGlobs))
const filesBySrc = mmatch(files, ['**/*'].concat(ignoreGlobs))
.reduce((obj, file) => {
const srcExt = srcExts.find(ext => mm(file, extGlobs[ext]).length);
const srcExt = srcExts.find(ext => mmatch(file, extGlobs[ext]).length);
obj[srcExt||'other'] = obj[srcExt||'other'] || [];
obj[srcExt||'other'].push(path.relative(srcDir, file));
return obj;
}, {});

console.log(JSON.stringify(filesBySrc, null, 2));
/**
* PROCESSING
*/

// PROCESSING
const srcRenders = [].concat(...srcExts.map((ext) => {
return filesBySrc[ext]
.map((file) => srcRenderFns[ext](path.join(srcDir, file))
.then((str) => write(path.join(outDir, srcOutReplacers[ext](file)), str))
.catch((err) => {

const scssRenders = filesBySrc['.scss']
.map((file) => srcRenderFns['.scss'](file)
.then((str) => write(path.join(outDir, file.replace(/\.scss$/, '.css')), str))
);
/**
* ERRORS
*/

Promise.all(scssRenders).then((results) => {
console.log(err);
})
);
}));

});
// const copies = filtered.other.map((file) => cp(path.join(srcDir, file), path.join(outDir, file)));
// Promise.all([...copies]).then(([...processed]) => console.log(`processed ${processed.length} files`));
const copies = filesBySrc['other'].map((file) => cp(path.join(srcDir, file), path.join(outDir, file)));

Promise.all([...copies, ...srcRenders]).then(([...processed]) => {

/**
* SUCCESS
*/

console.log(`processed ${processed.length} files`);
});
});
};
5 changes: 2 additions & 3 deletions lib/render-pug.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@ module.exports = function({srcDir, renderTimes, loggerFn, options}) {
// RENDER
Pug.renderFile(
srcFile,
Object.assign({}, pugLocals, {
Object.assign(pugLocals(), {
pretty: isDev,
basedir: srcDir,
pathname: relative(srcDir, srcFile)
basedir: srcDir
}),
(err, data) => {
if (err) reject(err);
Expand Down
36 changes: 36 additions & 0 deletions src/ascii-logo.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
XXXXXXX XXXXXXX
X X X X
X X X X
XXXXXXXX XXXXXXXX XXXXXXX
XXXX X
XX X
XX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
X XX
X X
X XX
XX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XX X
XXXX X
XXXXXXXX XXXXXXXX XXXXXXX
X X X X
X X X X
XXXXXXX XXXXXXX


XXXXXXXX XXXXXXXX
X X X X
X X X X
XXXXXXXX XXXXXXXXX XXXXXXXX
XXXX X
XX X
XX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
X XX
X X
X XX
XX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XX X
XXXX X
XXXXXXXX XXXXXXXXX XXXXXXXX
X X X X
X X X X
XXXXXXXX XXXXXXXX

0 comments on commit 9555bbd

Please sign in to comment.