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

Support for module unification folder #43

Closed
wants to merge 9 commits 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
npm-debug.log*
yarn-error.log
testem.log
jsconfig.json

# ember-try
.node_modules.ember-try/
Expand Down
7 changes: 1 addition & 6 deletions ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@
const EmberAddon = require('ember-cli/lib/broccoli/ember-addon');

module.exports = function(defaults) {
let app = new EmberAddon(defaults, {

'ember-cli-tailwind': {
buildTarget: 'dummy'
}
});
let app = new EmberAddon(defaults, {});

/*
This build file specifies the options for the dummy test app of this
Expand Down
27 changes: 18 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,23 @@ const commonjs = require('rollup-plugin-commonjs');
const buildDestinations = {
dummy: {
path: 'tests/dummy/app',
stylesPath: 'app/styles',
type: 'app'
},
app: {
path: 'app',
stylesPath: 'app/styles',
type: 'app'
},
addon: {
path: 'addon',
stylesPath: 'addon/styles',
type: 'addon'
},
src: {
path: 'src',
stylesPath: 'src/ui/styles',
type: 'app'
}
};

Expand All @@ -42,6 +50,8 @@ module.exports = {
let buildTarget;
if (fs.existsSync(includer.project.root + '/app/tailwind')) {
buildTarget = 'app';
} else if (fs.existsSync(includer.project.root + '/src/tailwind')) {
buildTarget = 'src';
} else if (fs.existsSync(includer.project.root + '/addon/tailwind')) {
buildTarget = 'addon';
} else if (fs.existsSync(includer.project.root + '/tests/dummy/app/tailwind')) {
Expand All @@ -52,24 +62,23 @@ module.exports = {
return;
}

let buildConfig = buildDestinations[buildTarget];
this.buildConfig = buildDestinations[buildTarget];

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

this.projectType = buildConfig.type;
this.tailwindInputPath = this._getInputPath(this.parent.root, buildConfig.path);
this.tailwindInputPath = this._getInputPath(this.parent.root, this.buildConfig.path);
},

treeForStyles() {
if (this.projectType === 'app' && this._hasTailwindConfig()) {
if (this.buildConfig.type === 'app' && this._hasTailwindConfig()) {
return this._buildTailwind();
}
},

treeForAddonStyles() {
if (this.projectType === 'addon' && this._hasTailwindConfig()) {
if (this.buildConfig.type === 'addon' && this._hasTailwindConfig()) {
return this._buildTailwind();
}
},
Expand All @@ -86,21 +95,22 @@ module.exports = {
return appTree;
},

// Private

_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) {
if (typeof inputPath !== 'string') {
this.ui.writeWarnLine('Unable to process Tailwind styles for a non-string tree');
return;
}

let fullPath = path.join(root, inputPath, 'tailwind');

if (fs.existsSync(path.join(fullPath, 'config', 'tailwind.js'))) {
return fullPath;
}
Expand All @@ -111,7 +121,6 @@ module.exports = {
},

_buildTailwind() {
let basePath = this.projectType === 'app' ? 'app/styles' : '';
let tailwindConfig = new Rollup(this.tailwindInputPath, {
rollup: {
input: 'config/tailwind.js',
Expand All @@ -128,7 +137,7 @@ module.exports = {

return new BuildTailwindPlugin([this.tailwindInputPath, tailwindConfig], {
srcFile: path.join('modules.css'),
destFile: path.join(basePath, 'tailwind.css')
destFile: path.join(this.buildConfig.stylesPath, 'tailwind.css')
});
},

Expand Down
16 changes: 16 additions & 0 deletions node-tests/build-target-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,22 @@ describe('build target', function() {
expect(files.assets['tailwind.css']).to.contain('.text-ember-red');
});

if (process.env.EMBER_CLI_MODULE_UNIFICATION) {
it(`builds for applications with module unification layout`, async () => {
loadScenario(input, 'src-with-tailwind');

let app = new EmberApp();

output = createBuilder(app.toTree());
await output.build();

let files = output.read();

expect(files.assets).to.have.property('tailwind.css');
expect(files.assets['tailwind.css']).to.contain('.text-ember-red');
});
}

it(`builds for addons`, async () => {
loadScenario(input, 'addon-with-tailwind');

Expand Down
2 changes: 1 addition & 1 deletion node-tests/fixtures/addon-with-tailwind/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module.exports = function() {
},
'index.html': ''
},
'ember-cli-build.js': 'module.exports = function() { return { "ember-cli-tailwind": { buildTarget: "dummy" } } };',
'ember-cli-build.js': 'module.exports = function() { return { } };',
'package.json': JSON.stringify({
name: 'application',
dependencies: {
Expand Down
5 changes: 4 additions & 1 deletion node-tests/fixtures/app-with-components/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ module.exports = function() {
config: {
'environment.js': "module.exports = function() { return { modulePrefix: 'application' } };"
},
'ember-cli-build.js': 'module.exports = function() { return { "ember-cli-tailwind": { buildTarget: "dummy" } } };',
tests: {
'index.html': ''
},
'ember-cli-build.js': 'module.exports = function() { return { } };',
'package.json': JSON.stringify({
name: 'application',
devDependencies: {
Expand Down
5 changes: 4 additions & 1 deletion node-tests/fixtures/app-with-tailwind/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ module.exports = function() {
config: {
'environment.js': "module.exports = function() { return { modulePrefix: 'application' } };"
},
'ember-cli-build.js': 'module.exports = function() { return { "ember-cli-tailwind": { buildTarget: "dummy" } } };',
tests: {
'index.html': ''
},
'ember-cli-build.js': 'module.exports = function() { return { } };',
'package.json': JSON.stringify({
name: 'application',
devDependencies: {
Expand Down
2 changes: 1 addition & 1 deletion node-tests/fixtures/dummy-app-with-tailwind/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module.exports = function() {
},
'index.html': ''
},
'ember-cli-build.js': 'module.exports = function() { return { "ember-cli-tailwind": { buildTarget: "dummy" } } };',
'ember-cli-build.js': 'module.exports = function() { return { } };',
'package.json': JSON.stringify({
name: 'application',
devDependencies: {
Expand Down
40 changes: 40 additions & 0 deletions node-tests/fixtures/src-with-tailwind/application.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// const fs = require('fs');
const fixturify = require('fixturify')
const path = require('path');

module.exports = function() {
return {
application: {
src: {
ui: {
styles: {
'app.css': ''
},
'index.html': ''
},
tailwind: fixturify.readSync(path.join(__dirname, './tailwind'))
},
tests: {
'index.html': '',
},
config: {
'environment.js': `module.exports = function() {};`
},
'ember-cli-build.js': 'module.exports = function() { return {}};',
'package.json': JSON.stringify({
name: 'application',
devDependencies: {
'ember-cli': '*',
'ember-cli-babel': '*',
'ember-cli-htmlbars': '*',
'ember-engines': '*',
'ember-source': '*',
'loader.js': '*'
},
'ember-addon': {
paths: ['../ember-cli-tailwind']
}
}),
}
}
};
11 changes: 11 additions & 0 deletions node-tests/fixtures/src-with-tailwind/tailwind/config/tailwind.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export default {
textColors: {
'ember-red': '#E04E39'
},

options: {
prefix: '',
important: false,
separator: ':'
}
};
3 changes: 3 additions & 0 deletions node-tests/fixtures/src-with-tailwind/tailwind/modules.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@import "tailwindcss/preflight";
@import "tailwindcss/components";
@import "tailwindcss/utilities";
26 changes: 6 additions & 20 deletions node-tests/import-files-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,10 @@ describe('import files', function() {
['development', 'test'].forEach(environment => {
it(`includes styleguide styles by default in non-production environments (${environment})`, async () => {
process.env.EMBER_ENV = environment;
let addon = new EmberAddon({}, {
'ember-cli-tailwind': {
buildTarget: 'app'
}
});
let addon = new EmberAddon({}, {});
expect(_.values(addon._styleOutputFiles)[0]).to.include('vendor/etw.css');

let output = createBuilder(addon._processedAppTree());
let output = createBuilder(addon.getAppJavascript());
await output.build();
expect(output.read()).to.have.nested.property(
'dummy.instance-initializers.ember-cli-tailwind\\.js'
Expand All @@ -28,14 +24,10 @@ describe('import files', function() {

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

let output = createBuilder(addon._processedAppTree());
let output = createBuilder(addon.getAppJavascript());
await output.build();
expect(output.read()).not.to.have.nested.property(
'dummy.instance-initializers.ember-cli-tailwind\\.js'
Expand All @@ -47,14 +39,11 @@ describe('import files', function() {
it(`includes styleguide styles when enabled (${environment})`, async () => {
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');

let output = createBuilder(addon._processedAppTree());
let output = createBuilder(addon.getAppJavascript());
await output.build();
expect(output.read()).to.have.nested.property(
'dummy.instance-initializers.ember-cli-tailwind\\.js'
Expand All @@ -66,14 +55,11 @@ describe('import files', function() {
it(`excludes styleguide styles when disabled (${environment})`, async () => {
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');

let output = createBuilder(addon._processedAppTree());
let output = createBuilder(addon.getAppJavascript());
await output.build();
expect(output.read()).not.to.have.nested.property(
'dummy.instance-initializers.ember-cli-tailwind\\.js'
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@
},
"devDependencies": {
"broccoli-asset-rev": "^2.4.5",
"broccoli-merge-trees": "^3.0.0",
"broccoli-test-helper": "^1.2.0",
"chai": "^4.1.2",
"ember-ajax": "^3.0.0",
"ember-cli": "~2.18.0",
"ember-cli": "git+https://github.com/ember-cli/ember-cli.git",
"ember-cli-dependency-checker": "^2.0.0",
"ember-cli-eslint": "^4.2.1",
"ember-cli-fastboot": "^1.1.3",
Expand All @@ -60,7 +61,7 @@
"ember-load-initializers": "^1.0.0",
"ember-resolver": "^4.0.0",
"ember-router-service-polyfill": "^1.0.3",
"ember-source": "~2.18.0",
"ember-source": "~3.2.2",
"eslint-plugin-ember": "^5.0.0",
"eslint-plugin-node": "^5.2.1",
"loader.js": "^4.2.3",
Expand Down