function loadComponentList() { var p = promise(); fs.readFile('build/components.json', function(err, res) { if (err) { p.reject(err); } else { p.fulfill(JSON.parse(res)); } }); return p; }
function minifyComponent(name) { var p = promise(); console.log(' ' + name); var js = uglifyjs.minify(path.join(name, 'src', name + '.js')); var css = fs.readFileSync(path.join(name, 'src', name + '.css')).toString(); css = cleancss.process(css); p.fulfill({css: css, js: js.code}); return p; }
return function() { var p = promise(); var ret; try { Array.prototype.unshift.apply(arguments, [p.fulfill, p.reject]); ret = fn.apply(this, arguments); } catch (e) { p.reject(e); } if (typeof ret !== 'undefined') { p.fulfill(ret); } return p; };
function minifyComponent(name) { var p = promise(); var distDir = path.join('dist', name); console.log(distDir); // make dist directory if necessary if (!fs.existsSync(distDir)) { fs.mkdirSync(distDir); } var jsPath = path.join(distDir, name + '.min.js'); console.log(jsPath); var srcJsPath; // special case to account for the x-tag core submodule if(name === "core"){ srcJsPath = path.join('component', "core", 'src', "x-tag-core", "dist", "x-tag-core.js"); } else{ srcJsPath = path.join('component', name, 'src', name + '.js'); } try { var js = uglifyjs.minify(srcJsPath); fs.writeFileSync(jsPath, js.code); } catch (e) { p.reject(e); return p; } var cssPath = path.join(distDir, name + '.min.css'); console.log(cssPath); try { var css = fs.readFileSync(path.join('component', name, 'src', name + '.css')).toString(); css = cleancss.process(css); fs.writeFileSync(cssPath, css); } catch (e) { p.reject(e); return p; } if (typeof js !== 'undefined' && typeof css !== 'undefined') { p.fulfill({css: css, js: js.code}); } else { throw "missing resulting source"; } return p; }
function minify(components) { console.log('minifying components'); var p = promise(); var minifiedCSS = ''; var minifiedJS = ''; function processComponent(n) { if (n < components.length) { minifyComponent(components[n]).then(function(result) { minifiedCSS += result.css; minifiedJS += result.js; processComponent(n+1); }, err('Failed to process component ' + components[n] + ': ')) } else { p.fulfill({ css: minifiedCSS, js: minifiedJS }); } } processComponent(0); return p; }