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

Add shouldIncludeStyleguide option #18

Merged
merged 3 commits into from
May 1, 2018
Merged
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
18 changes: 13 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,19 @@ module.exports = {
this._super.included.apply(this, arguments);

let buildTarget = includer.options &&
includer.options['ember-cli-tailwind'] &&
includer.options['ember-cli-tailwind']['buildTarget'];
includer.options[this.name] &&
includer.options[this.name]['buildTarget'];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updating the reference to keep things consistent.


if (!this._validateBuildTarget(buildTarget, includer)) {
return;
}

let buildConfig = buildDestinations[buildTarget];

this.import('vendor/etw.css');


if (this._shouldIncludeStyleguide()) {
this.import('vendor/etw.css');
}

this.projectType = buildConfig.type;
this.tailwindInputPath = this._getInputPath(this.parent.root, buildConfig.path);
},
Expand All @@ -56,6 +58,12 @@ module.exports = {
}
},

_shouldIncludeStyleguide() {
let envConfig = this.project.config(process.env.EMBER_ENV)[this.name];
let shouldOverrideDefault = envConfig !== undefined && envConfig.shouldIncludeStyleguide !== undefined;
return shouldOverrideDefault ? envConfig.shouldIncludeStyleguide : process.env.EMBER_ENV !== 'production';
},

// Private

_getInputPath(root, inputPath) {
Expand Down
61 changes: 61 additions & 0 deletions node-tests/import-files-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/* eslint-env node */
let expect = require('chai').expect;
let EmberAddon = require('ember-cli/lib/broccoli/ember-addon');
let _ = require('lodash');

describe('import files', function() {
afterEach(() => {
delete process.env.EMBER_ENV;
});

['development', 'test'].forEach(environment => {
it(`includes styleguide styles by default in non-production environments (${environment})`, () => {
process.env.EMBER_ENV = environment;
let addon = new EmberAddon({}, {
'ember-cli-tailwind': {
buildTarget: 'app'
}
});
expect(_.values(addon._styleOutputFiles)[0]).to.include('vendor/etw.css');
});
})

it('excludes styleguide styles by default in the production environment', () => {
process.env.EMBER_ENV = 'production';
let addon = new EmberAddon({}, {
'ember-cli-tailwind': {
buildTarget: 'app'
}
});
expect(_.values(addon._styleOutputFiles)[0]).to.not.include('vendor/etw.css');
});

describe('shouldIncludeStyleguide', function() {
['development', 'test', 'production'].forEach(environment => {
it(`includes styleguide styles when enabled (${environment})`, () => {
process.env.EMBER_ENV = environment
let addon = new EmberAddon({}, {
'ember-cli-tailwind': {
buildTarget: 'app'
},
configPath: 'tests/fixtures/config/environment-styleguide-enabled'
});
expect(_.values(addon._styleOutputFiles)[0]).to.include('vendor/etw.css');
});
});

['development', 'test', 'production'].forEach(environment => {
it(`excludes styleguide styles when disabled (${environment})`, () => {
process.env.EMBER_ENV = environment
let addon = new EmberAddon({}, {
'ember-cli-tailwind': {
buildTarget: 'app'
},
configPath: 'tests/fixtures/config/environment-styleguide-disabled'
});
expect(_.values(addon._styleOutputFiles)[0]).to.not.include('vendor/etw.css');
});
});
});

});
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"start": "ember serve",
"test": "ember try:each",
"test:all": "ember try:each",
"test:fastboot": "qunit fastboot-tests"
"test:fastboot": "qunit fastboot-tests",
"test:node": "mocha node-tests/**/*-test.js"
},
"dependencies": {
"broccoli-plugin": "^1.3.0",
Expand All @@ -38,6 +39,7 @@
},
"devDependencies": {
"broccoli-asset-rev": "^2.4.5",
"chai": "^4.1.2",
"ember-ajax": "^3.0.0",
"ember-cli": "~2.18.0",
"ember-cli-dependency-checker": "^2.0.0",
Expand All @@ -57,7 +59,8 @@
"ember-source": "~2.18.0",
"eslint-plugin-ember": "^5.0.0",
"eslint-plugin-node": "^5.2.1",
"loader.js": "^4.2.3"
"loader.js": "^4.2.3",
"mocha": "^5.1.1"
},
"engines": {
"node": "^4.5 || 6.* || >= 7.*"
Expand Down
54 changes: 54 additions & 0 deletions tests/fixtures/config/environment-styleguide-disabled.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/* eslint-env node */
'use strict';

module.exports = function(environment) {
let ENV = {
modulePrefix: 'scaffold-test',
environment,
rootURL: '/',
locationType: 'auto',
EmberENV: {
FEATURES: {
// Here you can enable experimental features on an ember canary build
// e.g. 'with-controller': true
},
EXTEND_PROTOTYPES: {
// Prevent Ember Data from overriding Date.parse.
Date: false
}
},
APP: {
// Here you can pass flags/options to your application instance
// when it is created
},
'ember-cli-tailwind': {
shouldIncludeStyleguide: false
}
};

if (environment === 'development') {
// ENV.APP.LOG_RESOLVER = true;
// ENV.APP.LOG_ACTIVE_GENERATION = true;
// ENV.APP.LOG_TRANSITIONS = true;
// ENV.APP.LOG_TRANSITIONS_INTERNAL = true;
// ENV.APP.LOG_VIEW_LOOKUPS = true;
}

if (environment === 'test') {
// Testem prefers this...
ENV.locationType = 'none';

// keep test console output quieter
ENV.APP.LOG_ACTIVE_GENERATION = false;
ENV.APP.LOG_VIEW_LOOKUPS = false;

ENV.APP.rootElement = '#ember-testing';
ENV.APP.autoboot = false;
}

if (environment === 'production') {
// here you can enable a production-specific feature
}

return ENV;
};
54 changes: 54 additions & 0 deletions tests/fixtures/config/environment-styleguide-enabled.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/* eslint-env node */
'use strict';

module.exports = function(environment) {
let ENV = {
modulePrefix: 'scaffold-test',
environment,
rootURL: '/',
locationType: 'auto',
EmberENV: {
FEATURES: {
// Here you can enable experimental features on an ember canary build
// e.g. 'with-controller': true
},
EXTEND_PROTOTYPES: {
// Prevent Ember Data from overriding Date.parse.
Date: false
}
},
APP: {
// Here you can pass flags/options to your application instance
// when it is created
},
'ember-cli-tailwind': {
shouldIncludeStyleguide: true
}
};

if (environment === 'development') {
// ENV.APP.LOG_RESOLVER = true;
// ENV.APP.LOG_ACTIVE_GENERATION = true;
// ENV.APP.LOG_TRANSITIONS = true;
// ENV.APP.LOG_TRANSITIONS_INTERNAL = true;
// ENV.APP.LOG_VIEW_LOOKUPS = true;
}

if (environment === 'test') {
// Testem prefers this...
ENV.locationType = 'none';

// keep test console output quieter
ENV.APP.LOG_ACTIVE_GENERATION = false;
ENV.APP.LOG_VIEW_LOOKUPS = false;

ENV.APP.rootElement = '#ember-testing';
ENV.APP.autoboot = false;
}

if (environment === 'production') {
// here you can enable a production-specific feature
}

return ENV;
};
Loading