-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add node-tests and custom options for css-imports (#4)
- Loading branch information
1 parent
22c9769
commit 69ffa1a
Showing
11 changed files
with
691 additions
and
144 deletions.
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
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
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 |
---|---|---|
|
@@ -47,3 +47,4 @@ | |
/gh-pages-docs.sh | ||
/coverage | ||
/yuidoc.json | ||
/node-tests |
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,20 +1,83 @@ | ||
/* eslint-env node */ | ||
|
||
const fs = require('fs-extra'); | ||
const chalk = require('chalk'); | ||
const BuildConfigEditor = require('ember-cli-build-config-editor'); | ||
|
||
const { | ||
prototype: { hasOwnProperty }, | ||
} = Object; | ||
|
||
module.exports = { | ||
name: 'ember-models-table-floating-filter', | ||
description: 'Configure ember-models-table-floating-filter', | ||
|
||
availableOptions: [ | ||
{ | ||
name: 'include-plain-html-theme-css', | ||
type: Boolean, | ||
default: false, | ||
aliases: ['iphtc'], | ||
}, | ||
], | ||
|
||
normalizeEntityName: function () { | ||
// do nothing | ||
}, | ||
|
||
beforeInstall(options) { | ||
this.includePlainHtmlThemeCss = hasOwnProperty.call( | ||
options, | ||
'includePlainHtmlThemeCss' | ||
) | ||
? options.includePlainHtmlThemeCss | ||
: false; | ||
}, | ||
|
||
afterInstall() { | ||
this.addBuildConfiguration(); | ||
return this.addEmberModelsTable(); | ||
}, | ||
|
||
addBuildConfiguration() { | ||
const file = 'ember-cli-build.js'; | ||
const settings = {}; | ||
|
||
if (this.includePlainHtmlThemeCss) { | ||
settings.includePlainHtmlThemeCss = this.includePlainHtmlThemeCss; | ||
} | ||
|
||
if (!fs.existsSync(file)) { | ||
this.ui.writeLine(chalk.red(`Could not find ${file} to modify.`)); | ||
return; | ||
} | ||
|
||
const source = fs.readFileSync(file, 'utf-8'); | ||
const build = new BuildConfigEditor(source); | ||
|
||
try { | ||
const newBuild = build.edit(this.name, settings); | ||
fs.writeFileSync(file, newBuild.code()); | ||
this.ui.writeLine( | ||
chalk.green( | ||
`Added ember-models-table-floating-filter configuration to ${file}.` | ||
) | ||
); | ||
} catch (error) { | ||
const settingsString = JSON.stringify(settings); | ||
this.ui.writeLine( | ||
chalk.red( | ||
`Configuration file could not be edited. Manually update your ${file} to include '${this.name}': ${settingsString}.` | ||
) | ||
); | ||
} | ||
}, | ||
|
||
addEmberModelsTable() { | ||
if (!('ember-models-table' in this.project.dependencies())) { | ||
return this.addAddonToProject('ember-models-table'); | ||
return this.addAddonToProject('ember-models-table', { | ||
iphtc: this.includePlainHtmlThemeCss, | ||
}); | ||
} | ||
}, | ||
}; |
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
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,5 +1,24 @@ | ||
'use strict'; | ||
|
||
const path = require('path'); | ||
const defaultOptions = { | ||
includePlainHtmlThemeCss: false, | ||
}; | ||
|
||
module.exports = { | ||
name: require('./package').name, | ||
|
||
included: function () { | ||
const app = this._findHost.call(this); | ||
this._super.included.apply(this, arguments); | ||
const options = Object.assign( | ||
{}, | ||
defaultOptions, | ||
app.options['ember-models-table-floating-filter'] | ||
); | ||
let vendorPath = path.join('vendor', 'ember-models-table-floating-filter'); | ||
if (options.includePlainHtmlThemeCss) { | ||
app.import(path.join(vendorPath, 'plain-html.css')); | ||
} | ||
}, | ||
}; |
52 changes: 52 additions & 0 deletions
52
node-tests/blueprints/ember-models-table-floating-filter-test.js
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
'use strict'; | ||
|
||
const { | ||
setupTestHooks, | ||
emberNew, | ||
emberGenerate, | ||
} = require('ember-cli-blueprint-test-helpers/helpers'); | ||
|
||
const { expect } = require('ember-cli-blueprint-test-helpers/chai'); | ||
|
||
describe('Acceptance: ember generate ember-models-table-floating-filter (ember-cli-build.js)', function () { | ||
setupTestHooks(this); | ||
|
||
it('ember-models-table-floating-filter', function () { | ||
const args = ['ember-models-table-floating-filter']; | ||
|
||
return emberNew().then(() => | ||
emberGenerate(args, (file) => { | ||
expect(file('ember-cli-build.js')).to.not.contain( | ||
'includePlainHtmlThemeCss' | ||
); | ||
}) | ||
); | ||
}); | ||
|
||
it('ember-models-table-floating-filter --iphtc', function () { | ||
const args = ['ember-models-table-floating-filter', '--iphtc']; | ||
|
||
return emberNew().then(() => | ||
emberGenerate(args, (file) => { | ||
expect(file('ember-cli-build.js')).to.contain( | ||
'includePlainHtmlThemeCss: true' | ||
); | ||
}) | ||
); | ||
}); | ||
|
||
it('ember-models-table-floating-filter --include-plain-html-theme-css=true', function () { | ||
const args = [ | ||
'ember-models-table-floating-filter', | ||
'--include-plain-html-theme-css=true', | ||
]; | ||
|
||
return emberNew().then(() => | ||
emberGenerate(args, (file) => { | ||
expect(file('ember-cli-build.js')).to.contain( | ||
'includePlainHtmlThemeCss: true' | ||
); | ||
}) | ||
); | ||
}); | ||
}); |
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
Oops, something went wrong.