UNPKG

1.08 kBJavaScriptView Raw
1var fs = require('fs');
2
3module.exports = function makeLayout(opts) {
4 var base = '';
5
6 // add hostname/port if needed
7 if (opts.hostname || opts.port) {
8 var hostname = opts.hostname || 'localhost';
9 base = 'http://' + hostname + ':' + opts.port + '/';
10 }
11
12 if (opts.debug)
13 console.log('Copying layout %s', opts.template);
14
15 // read layout
16 try {
17 var layout = fs.readFileSync(opts.template).toString();
18 }
19 catch (e) {
20 console.error("Couldn't find your template file".red, "\n");
21 console.log(e.join("\n"));
22 process.exit(1);
23 }
24
25 if (opts.debug)
26 console.log('Making layout with scripts: ', opts.scripts);
27
28 var scripts = opts.scripts.map(function(key) {
29 return '<script src="' + base + key + '.js"></script>';
30 });
31
32 var styles = (opts.styles || []).map(function(key) {
33 return '<link rel="stylesheet" type="text/css" href="' + base + key + '" />';
34 });
35
36 var newLine = "\n";
37 var result = layout
38 .replace('<!-- SCRIPTS -->', scripts.join(newLine))
39 .replace('<!-- STYLES -->', styles.join(newLine));
40
41 return result;
42}
\No newline at end of file