Skip to content

Commit

Permalink
Add node-tests and custom options for css-imports (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
onechiporenko committed Aug 9, 2022
1 parent 22c9769 commit 69ffa1a
Show file tree
Hide file tree
Showing 11 changed files with 691 additions and 144 deletions.
8 changes: 8 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ module.exports = {
'@typescript-eslint/no-var-requires': 2,
},
},
// node tests
{
files: ['./node-tests/**'],
env: {
mocha: true,
},
},
// node files
{
files: [
Expand All @@ -66,6 +73,7 @@ module.exports = {
'./blueprints/*/index.js',
'./config/**/*.js',
'./tests/dummy/config/**/*.js',
'./node-tests/**/*.js',
],
excludedFiles: [
'addon/**',
Expand Down
16 changes: 16 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,22 @@ jobs:
- name: Run Tests
run: yarn test:ember

node-tests:
name: "Node Tests"
runs-on: ubuntu-latest
timeout-minutes: 10

steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 14.x
cache: yarn
- name: Install Dependencies
run: yarn install --frozen-lockfile
- name: Run Node Tests
run: yarn run nodetest

try-scenarios:
name: ${{ matrix.try-scenario }}
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,4 @@
/gh-pages-docs.sh
/coverage
/yuidoc.json
/node-tests
65 changes: 64 additions & 1 deletion blueprints/ember-models-table-floating-filter/index.js
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,
});
}
},
};
4 changes: 3 additions & 1 deletion ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ module.exports = function (defaults) {
This build file does *not* influence how the addon or the app using it
behave. You most likely want to be modifying `./index.js` or app's build file
*/

if (process.env.EMT_UI === 'plain-html') {
app.import('vendor/ember-models-table-floating-filter/plain-html.css');
}
const { maybeEmbroider } = require('@embroider/test-setup');
return maybeEmbroider(app, {
skipBabel: [
Expand Down
19 changes: 19 additions & 0 deletions index.js
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 node-tests/blueprints/ember-models-table-floating-filter-test.js
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'
);
})
);
});
});
18 changes: 12 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "ember-models-table-floating-filter",
"version": "0.0.0",
"version": "1.0.0",
"description": "The default blueprint for ember-cli addons.",
"keywords": [
"ember-addon"
],
"repository": "",
"repository": "https://github.com/onechiporenko/ember-models-table-floating-filter.git",
"license": "MIT",
"author": "",
"author": "Oleg Nechiporenko",
"directories": {
"doc": "doc",
"test": "tests"
Expand All @@ -30,16 +30,20 @@
"test:cov:bs5": "COVERAGE=true ember try:one ember-default-with-ember-bootstrap-v5 --- ember test",
"test:cov:plain-html": "COVERAGE=true ember try:one ember-default-with-plain-html --- ember test",
"prepack": "ember ts:precompile",
"postpack": "ember ts:clean"
"postpack": "ember ts:clean",
"nodetest": "mocha node-tests --recursive"
},
"dependencies": {
"@ember/render-modifiers": "^2.0.4",
"@embroider/macros": "^1.2.0",
"@embroider/util": "^1.2.0",
"chalk": "^4.1.1",
"ember-cli-babel": "^7.26.11",
"ember-cli-build-config-editor": "0.5.1",
"ember-cli-htmlbars": "^6.1.0",
"ember-cli-typescript": "^5.1.0",
"ember-truth-helpers": "^3.0.0"
"ember-truth-helpers": "^3.0.0",
"fs-extra": "^10.0.0"
},
"devDependencies": {
"@ember/optional-features": "^2.0.0",
Expand Down Expand Up @@ -75,6 +79,7 @@
"broccoli-asset-rev": "^3.0.0",
"ember-auto-import": "^2.4.2",
"ember-cli": "~4.6.0",
"ember-cli-blueprint-test-helpers": "^0.19.2",
"ember-cli-code-coverage": "^1.0.3",
"ember-cli-dependency-checker": "^3.3.1",
"ember-cli-inject-live-reload": "^2.1.0",
Expand All @@ -84,7 +89,7 @@
"ember-cli-terser": "^4.0.2",
"ember-disable-prototype-extensions": "^1.1.3",
"ember-load-initializers": "^2.1.2",
"ember-models-table": "^4.3.0",
"ember-models-table": "^4.4.0",
"ember-page-title": "^7.0.0",
"ember-qunit": "^5.1.5",
"ember-resolver": "^8.0.3",
Expand All @@ -100,6 +105,7 @@
"eslint-plugin-qunit": "^7.3.1",
"lcov-result-merger": "^3.1.0",
"loader.js": "^4.7.0",
"mocha": "^10.0.0",
"npm-run-all": "^4.1.5",
"prettier": "^2.7.1",
"qunit": "^2.19.1",
Expand Down
Loading

0 comments on commit 69ffa1a

Please sign in to comment.