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

the ability to import paths relative to app root #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Preprocess your CSS using Myth.
## Installation

```
npm install --save-dev ember-myth
ember install ember-myth
```

## Usage
Expand All @@ -18,11 +18,16 @@ By default, this addon will compile `app/styles/<app-name>.css` into `dist/asset
Options can be configured within your `Brocfile.js` or from within `config/environment.js`:

```javascript
// Brocfile.js
var app = new EmberApp({
mythOptions: {...}
...
});
// ember-cli-build.js
var EmberApp = require('ember-cli/lib/broccoli/ember-app');

module.exports = function(defaults) {
var app = new EmberApp(defaults, {
mythOptions: {...}
});

return app.toTree();
};
```

```javascript
Expand Down
44 changes: 22 additions & 22 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,37 @@
var defaults = require('lodash.defaults');
var checker = require('ember-cli-version-checker');
var path = require('path');

var BroccoliMyth = require('./lib/broccoli-myth');
var MythCompiler = require('./lib/broccoli-myth');

module.exports = EmberMyth;

function MythPlugin (mythOptions) {
function MythPlugin(options) {
this.name = 'ember-myth';
this.ext = 'css';
this.mythOptions = defaults({}, mythOptions);
this.options = defaults({}, options);
}

MythPlugin.prototype = {
constructor: MythPlugin,

toTree: function (tree, inputPath, outputPath) {
var options = this.options;
var trees = [];

if (tree) {
trees.push(tree);
}

// todo: look into this `paths`
if (this.mythOptions.paths) {
trees = trees.concat(this.mythOptions.paths);
}

inputPath += '/' + this.mythOptions.inputFile;
outputPath += '/' + this.mythOptions.outputFile;
inputPath = path.join(inputPath, options.inputFile);
outputPath = path.join(outputPath, options.outputFile);

return new BroccoliMyth(trees, inputPath, outputPath, this.mythOptions);
return new MythCompiler(trees, inputPath, outputPath, options);
}
};

function EmberMyth (project) {
this.project = project;
this.name = 'Ember CLI Myth';
this.name = 'Ember CLI Myth';
}

EmberMyth.prototype = {
Expand All @@ -51,18 +46,18 @@ EmberMyth.prototype = {

options: function(app) {
var config = this.project.config(app.env) || {};
var stylesDir;
var root = app.project.root;

var mythOptions = defaults({}, app.options.mythOptions, config.mythOptions, {
paths: 'app/styles',
paths: [root],
inputFile: 'app.css',
outputFile: 'app.css',
outputFile: this.project.name() + '.css',
compress: app.env === 'production'
});

if (!mythOptions.source) {
stylesDir = app.options.trees.styles.dir || app.options.trees.styles
mythOptions.source = path.join(app.project.root, stylesDir, mythOptions.inputFile);
var styles = app.options.trees.styles.dir || app.options.trees.styles
mythOptions.source = path.join(root, styles, mythOptions.inputFile);
}

return mythOptions;
Expand All @@ -72,15 +67,20 @@ EmberMyth.prototype = {
var app = registry.app;
var mythOptions = this.options(app);
registry.add('css', new MythPlugin(mythOptions));
},

included: function (app) {
this.app = app;
// prevent conflict with broccoli-myth if it's installed
if (registry.remove) {
registry.remove('css', 'broccoli-myth');
}
},

if (this._super) {
included: function(app) {
if (this._super && this._super.included) {
this._super.included.apply(this, arguments);
}

this.app = app;

if (this.shouldSetupRegistryInIncluded()) {
this.setupPreprocessorRegistry('parent', app.registry);
}
Expand Down
16 changes: 8 additions & 8 deletions lib/broccoli-myth.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,21 @@ function MythCompiler (sourceTrees, inputFile, outputFile, options) {
}

this.sourceTrees = sourceTrees;
this.outputFile = outputFile;
this.inputFile = inputFile;
this.mythOptions = options;
this.outputFile = outputFile;
this.inputFile = inputFile;
this.options = options;
}

MythCompiler.prototype.updateCache = function (srcDir, destDir) {
var destFile = destDir + '/' + this.outputFile;
var destFile = path.join(destDir, this.outputFile);

var mythOptions = defaults({}, this.mythOptions, {
filename: pathSearcher.findFileSync(this.inputFile, srcDir)
var options = defaults({}, this.options, {
filename: pathSearcher.findFileSync(this.inputFile, srcDir)
});

mkdirp.sync(path.dirname(destFile));

return readFile(mythOptions.filename, { encoding: 'utf8' }).then(function (input) {
return writeFile(destFile, myth(input, mythOptions).trim(), { encoding: 'utf8' });
return readFile(options.filename, { encoding: 'utf8' }).then(function (input) {
return writeFile(destFile, myth(input, options).trim(), { encoding: 'utf8' });
});
}
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ember-myth",
"version": "0.1.1",
"version": "0.2.0",
"description": "Myth for ember-cli - css the way it was imagined",
"repository": {
"type": "git",
Expand All @@ -20,12 +20,12 @@
"ember"
],
"dependencies": {
"broccoli-caching-writer": "^0.5.5",
"broccoli-caching-writer": "^1.0.0",
"ember-cli-version-checker": "^1.0.2",
"include-path-searcher": "^0.1.0",
"lodash.defaults": "^3.1.1",
"mkdirp": "^0.5.1",
"myth": "^1.4.0",
"myth": "jasonmit/myth#92753f767f162a2e59627a5ea23a4053cdd20782",
"rsvp": "^3.0.18"
}
}