niViz

niViz Git Source Tree

Root/build.js

1/*
2 * niViz -- snow profiles visualization
3 * Copyright (C) 2015 WSL/SLF - Fluelastrasse 11 - 7260 Davos Dorf - Switzerland.
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19/*eslint strict: [2, "global"] */
20'use strict';
21
22var fs = require('fs');
23var debug = require('debug')('niviz:build');
24
25var Mincer = require('mincer');
26var pug = require('pug');
27
28var assets = require('./assets.json');
29
30var targets = process.argv.slice(2);
31var dependencies = [];
32
33var options = {
34 compress: true,
35 sourceMaps: true,
36 embedMappingComments: true
37};
38
39var env = new Mincer.Environment('./');
40
41assets.paths.forEach(function (path) {
42 env.appendPath(path);
43});
44
45env.ContextClass.defineAssetPath(function (path, opts) {
46 if (opts.type === 'font') {
47 path = path.replace(/[#?].*$/, '');
48 }
49
50 var asset = env.findAsset(path);
51
52 if (!asset) throw new Error('asset not found: ' + path);
53
54 dependencies.push(path);
55
56 return asset.digestPath;
57});
58
59if (process.env.NODE_ENV === 'development') {
60 debug('compiling assets in development mode...');
61
62} else {
63 debug('compiling assets in production mode...');
64
65 env.enable('source_maps');
66 env.jsCompressor = 'uglify';
67 env.cssCompressor = 'csswring';
68
69 env = env.index;
70}
71
72var manifest = new Mincer.Manifest(env, './dist/assets');
73
74function asset_path(name) {
75 return 'assets/' + manifest.assets[name];
76}
77
78var locals = {
79 js: function (name) {
80 return '<script src="' + asset_path(name + '.js') + '"></script>';
81 },
82
83 css: function (name) {
84 return '<link rel="stylesheet" href="' + asset_path(name + '.css') + '"/>';
85 }
86};
87
88try {
89 manifest.compile(targets, options);
90
91 debug('compiled main targets successfully.');
92
93 if (dependencies.length) {
94 manifest.compile(dependencies, options);
95 debug('compiled dependent assets successfully');
96 }
97
98 var html = pug.compileFile('./ui/index.pug')(locals);
99 fs.writeFileSync('./dist/index.html', html);
100
101 html = pug.compileFile('./ui/index.pug')(locals);
102 fs.writeFileSync('./dist/full.html', html);
103
104 html = pug.compileFile('./ui/simple.pug')(locals);
105 fs.writeFileSync('./dist/simple.html', html);
106
107 fs.createReadStream('./.bower/angular-bootstrap-colorpicker/css/colorpicker.css')
108 .pipe(fs.createWriteStream('./dist/assets/colorpicker.css'));
109
110 debug('compiled index.html successfully');
111
112 fs.mkdirSync('./dist/lib');
113 fs.createReadStream('./dist/assets/' + manifest.assets['niviz.js'])
114 .pipe(fs.createWriteStream('./dist/lib/niviz-latest.js'));
115
116 debug('libaries compiled successfully');
117
118} catch (error) {
119 console.error('Failed to compile assets: %s', error.message);
120 console.error(error.stack);
121}

Archive Download this file

Branches