-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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([ | ||
|
@@ -21,27 +23,52 @@ module.exports = function(defaults) { | |
}; | ||
|
||
|
||
/** Generate RTL CSS files along side regular CSS. */ | ||
class BroccoliSassWithRtl extends BroccoliSass { | ||
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. */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move the |
||
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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)?