Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build(): build a -rtl.css file along the css, and compile _every_ sass files #25

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 50 additions & 23 deletions ember-cli-build.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
'use strict';
var fs = require('fs');
var path = require('path');

var mergeTrees = require('broccoli-merge-trees');
var Angular2App = require('angular-cli/lib/broccoli/angular2-app');
var BroccoliSass = require('broccoli-sass');
var broccoliAutoprefixer = require('broccoli-autoprefixer');
var cssjanus = require('cssjanus');

var autoprefixerOptions = require('./build/autoprefixer-options');

module.exports = function(defaults) {
var demoAppCssTree = new BroccoliSass(['src/demo-app'], './demo-app.scss', 'demo-app/demo-app.css');
var componentCssTree = getComponentsCssTree();
var componentCssTree = getCssTree('src/components/', 'components/');
var angularAppTree = new Angular2App(defaults);

return mergeTrees([
Expand All @@ -21,27 +23,52 @@ module.exports = function(defaults) {
};


/** Generate RTL CSS files along side regular CSS. */
class BroccoliSassWithRtl extends BroccoliSass {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better to make a standalone broccoli-cssjanus plugin (similar to how autoprefixer is implemented)?

build() {
// This will output the regular CSS.
super.build();

// We then read that file and output the RTL CSS.
const cssOutputPath = path.join(this.outputPath, this.outputFile);
const cssRtlOutputPath = path.join(this.outputPath,
path.dirname(this.outputFile),
path.basename(this.outputFile, '.css') + '-rtl.css');
fs.writeFileSync(cssRtlOutputPath, cssjanus.transform(fs.readFileSync(cssOutputPath).toString()));
}
}



/** Gets the tree for all of the components' CSS. */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update function comment

function getComponentsCssTree() {
// Assume that the list of components is all directories in `src/components/`
var componentsSrc = 'src/components/';
var components = fs.readdirSync(componentsSrc)
.filter(file => fs.statSync(path.join(componentsSrc, file)).isDirectory());

var componentCssTrees = components.reduce((trees, component) => {
// We want each individual scss file to be compiled into a corresponding css file
// so that they can be individually included in styleUrls.
var scssFiles = fs.readdirSync(path.join(componentsSrc, component))
.filter(file => path.extname(file) === '.scss')
.map(file => path.basename(file, '.scss'));

return scssFiles.map(fileName => {
return BroccoliSass(
[`src/components/${component}`, 'src/core/style'], // Directories w/ scss sources
`./${fileName}.scss`, // Root scss input file
`components/${component}/${fileName}.css`); // Css output file
}).concat(trees);
}, []);

return broccoliAutoprefixer(mergeTrees(componentCssTrees), autoprefixerOptions);
function getCssTree(source, destination) {
function walk(dir) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move the walk function out of the function body of getCssTree and add a description.

const dirs = fs.readdirSync(dir)
.filter(file => fs.statSync(path.join(dir, file)).isDirectory());
if (!dirs.length) {
return [dir];
}

return dirs.reduce((previous, current) => {
return previous.concat(walk(path.join(dir, current)));
}, [dir]);
}

const trees = walk(source)
.reduce((previous, current) => {
const dir = path.join(destination, current.substr(source.length));
const scssFiles = fs.readdirSync(current)
.filter(file => path.extname(file) === '.scss')
.map(file => path.basename(file, '.scss'));

return scssFiles.map(filename => {
return new BroccoliSassWithRtl(
[current, 'src/core/style'],
path.join('.', filename + '.scss'),
path.join(dir, filename + '.css')
);
}).concat(previous);
}, []);

return broccoliAutoprefixer(mergeTrees(trees), autoprefixerOptions);
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
},
"dependencies": {
"angular2": "2.0.0-beta.0",
"cssjanus": "^1.1.2",
"es6-promise": "^3.0.2",
"es6-shim": "^0.33.3",
"reflect-metadata": "0.1.2",
Expand Down