Permalink
Browse files

build: Support for LESS files in packages via metadata

Built automatically via `grunt packages` task. Inclusion paths included
is core stylesheet path and theme stylesheet path. Sourcemap is also
generated.

Example:
```
{
  "build": {
    "less": {
      "src.less": "dest.css"
     }
   }
}
```
  • Loading branch information...
andersevenrud committed Jun 15, 2016
1 parent b916649 commit d118cfde7791b2e51e685c411311d7106a9c8029
Showing with 74 additions and 8 deletions.
  1. +2 −1 Gruntfile.js
  2. +72 −7 src/build.js
@@ -254,7 +254,8 @@
return;
}
_build.buildPackages(grunt, arg);
var done = this.async();
_build.buildPackages(grunt, done, arg);
});
grunt.registerTask('themes', 'Build theme files (arguments: resources, fonts. Or a single theme, ex: grunt themes:MyThemename)', function(arg) {
@@ -246,6 +246,18 @@
}
}
function aQueue(queue, every, done) {
(function _next(index) {
if ( index >= queue.length ) {
return done();
}
every(queue[index], function() {
_next(index + 1);
});
})(0);
}
/////////////////////////////////////////////////////////////////////////////
// HELPERS
/////////////////////////////////////////////////////////////////////////////
@@ -1389,7 +1401,7 @@
/**
* Builds packages
*/
function buildPackages(grunt, arg) {
function buildPackages(grunt, onfinished, arg) {
function copyFiles(src, dst, p, list) {
list = list || [];
@@ -1465,24 +1477,77 @@
});
}
function compileLess(root, files, done) {
files = files || {};
var additions = [];
aQueue(Object.keys(files), function(ln, next) {
var dest = _path.join(root, files[ln]);
var src = _path.join(root, ln);
console.log('CSS', src.replace(ROOT, ''), '=>', dest.replace(ROOT, ''));
try {
var data = readFile(src).toString();
_less.render(data, {
sourceMap: {},
paths: ['.', PATHS.themes, PATHS.stylesheets]
}).then(function(result) {
writeFile(dest, result.css);
writeFile(dest + '.map', result.map);
additions.push(files[ln]);
additions.push(files[ln] + '.map');
next();
}, function(error) {
console.warn(error);
next();
});
} catch ( e ) {
console.warn(error, error.stack);
next();
}
}, function() {
done(additions);
});
}
var packages = readPackageMetadata(grunt);
Object.keys(packages).forEach(function(p) {
aQueue(Object.keys(packages), function(p, next) {
if ( arg && arg !== p ) {
return;
return next();
}
grunt.log.subhead(p);
var iter = packages[p];
var src = _path.join(PATHS.packages, p);
var dst = _path.join(PATHS.out_client_packages, p);
var copy = iter.build.copy || [];
copyFiles(src, dst, p, iter.build.copy);
function _proceed(additions) {
additions = additions.filter(function(iter) {
return copy.indexOf(iter) < 0;
});
if ( additions.length ) {
copy = copy.concat(additions);
}
copyFiles(src, dst, p, copy);
if ( iter.type !== 'extension' ) {
combineFiles(src, dst, p, iter);
}
if ( iter.type === 'extension' ) {
return;
return next();
}
combineFiles(src, dst, p, iter);
compileLess(src, iter.build.less, _proceed);
}, function() {
onfinished();
});
}

0 comments on commit d118cfd

Please sign in to comment.