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

convert to v2 addon #598

Merged
merged 3 commits into from
Feb 11, 2022
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
5 changes: 1 addition & 4 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,4 @@ engines:
enabled: true
ratings:
paths:
- "**.js"
exclude_paths:
- config/**/*
- vendor/**/*
- "addon/src/**/*.js"
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobs:
test:
name: "Tests"
runs-on: ubuntu-latest
timeout-minutes: 20

steps:
- uses: actions/checkout@v2
Expand All @@ -38,6 +39,7 @@ jobs:
floating:
name: "Floating Dependencies"
runs-on: ubuntu-latest
timeout-minutes: 20

steps:
- uses: actions/checkout@v2
Expand All @@ -54,6 +56,7 @@ jobs:
try-scenarios:
name: ${{ matrix.try-scenario }}
runs-on: ubuntu-latest
timeout-minutes: 20
needs: 'test'

strategy:
Expand Down
19 changes: 13 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# How To Contribute

This repo is divided into multiple packages using Yarn workspaces:

- `addon` is the actual ember-keyboard addon
- `test-app` is its test suite

## Installation

* `git clone https://github.com/adopted-ember-addons/ember-keyboard.git`
Expand All @@ -8,18 +13,20 @@

## Linting

Inside any of the packages you can run:

* `yarn run lint`
* `yarn run lint:fix`

## Running tests

* `ember test` – Runs the test suite on the current Ember version
* `ember test --server` – Runs the test suite in "watch mode"
* `ember try:each` – Runs the test suite against multiple Ember versions
* `cd test-app && ember test` – Runs the test suite on the current Ember version
* `cd test-app && ember test --server` – Runs the test suite in "watch mode"
* `cd test-app && ember try:each` – Runs the test suite against multiple Ember versions

## Running the dummy application
## Running the test application

* `ember serve`
* Visit the dummy application at [http://localhost:4200](http://localhost:4200).
* `cd test-app && ember serve`
* Visit the test application at [http://localhost:4200](http://localhost:4200).

For more information on using ember-cli, visit [https://ember-cli.com/](https://ember-cli.com/).
12 changes: 0 additions & 12 deletions addon/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,23 +1,11 @@
# unconventional js
/blueprints/*/files/
/vendor/

# compiled output
/dist/
/tmp/

# dependencies
/bower_components/
/node_modules/

# misc
/coverage/
!.*
.*/
.eslintcache

# ember-try
/.node_modules.ember-try/
/bower.json.ember-try
/package.json.ember-try
/yarn.lock.ember-try
12 changes: 1 addition & 11 deletions addon/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,8 @@ module.exports = {
files: [
'./.eslintrc.js',
'./.prettierrc.js',
'./.template-lintrc.js',
'./ember-cli-build.js',
'./index.js',
'./testem.js',
'./blueprints/*/index.js',
'./addon-main.js',
'./config/**/*.js',
'./tests/dummy/config/**/*.js',
],
parserOptions: {
sourceType: 'script',
Expand All @@ -44,10 +39,5 @@ module.exports = {
plugins: ['node'],
extends: ['plugin:node/recommended'],
},
{
// Test files:
files: ['tests/**/*-test.{js,ts}'],
extends: ['plugin:qunit/recommended'],
},
],
};
3 changes: 3 additions & 0 deletions addon/addon-main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const { addonV1Shim } = require('@embroider/addon-shim');

module.exports = addonV1Shim(__dirname);
1 change: 0 additions & 1 deletion addon/app/helpers/if-key.js

This file was deleted.

1 change: 0 additions & 1 deletion addon/app/helpers/on-key.js

This file was deleted.

1 change: 0 additions & 1 deletion addon/app/modifiers/on-key.js

This file was deleted.

1 change: 0 additions & 1 deletion addon/app/services/keyboard.js

This file was deleted.

7 changes: 7 additions & 0 deletions addon/babel.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"plugins": [
"@embroider/addon-dev/template-colocation-plugin",
["@babel/plugin-proposal-decorators", { "legacy": true }],
"@babel/plugin-proposal-class-properties"
]
}
36 changes: 0 additions & 36 deletions addon/index.js

This file was deleted.

59 changes: 49 additions & 10 deletions addon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,54 @@
"doc": "doc",
"test": "tests"
},
"exports": {
".": "./dist/index.js",
"./*": "./dist/*",
"./test-support/key-event": "./dist/test-support/key-event.js",
"./test-support/test-helpers": "./dist/test-support/test-helpers.js",
"./addon-main.js": "./addon-main.js"
},
"files": [
"addon-main.js",
"dist"
],
"scripts": {
"lint": "npm-run-all --aggregate-output --continue-on-error --parallel \"lint:!(fix)\"",
"lint:fix": "npm-run-all --aggregate-output --continue-on-error --parallel lint:*:fix",
"build": "rollup --config",
"lint": "eslint . --cache",
"lint:fix": "eslint . --fix",
"lint:js": "eslint . --cache",
"lint:js:fix": "eslint . --fix"
"lint:js:fix": "eslint . --fix",
"prepublishOnly": "rollup --config",
"start": "rollup --config --watch"
},
"dependencies": {
"ember-cli-babel": "^7.26.6",
"ember-modifier": "^2.1.2 || ^3.0.0",
"@embroider/addon-shim": "^1.2.0",
"ember-modifier": "^2.1.2 || ^3.1.0",
"ember-modifier-manager-polyfill": "^1.2.0"
},
"devDependencies": {
"@babel/core": "^7.17.2",
"@babel/plugin-proposal-class-properties": "^7.16.7",
"@babel/plugin-proposal-decorators": "^7.17.2",
"@embroider/addon-dev": "^1.2.0",
"@rollup/plugin-babel": "^5.3.0",
"ember-template-lint": "^4.0.0",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-ember": "^10.5.7",
"eslint-plugin-ember": "^10.5.8",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-qunit": "^7.0.0",
"npm-run-all": "^4.1.5",
"prettier": "^2.4.1"
"eslint-plugin-qunit": "^7.2.0",
"prettier": "^2.5.1",
"rollup": "^2.67.2"
},
"peerDependencies": {
"@ember/test-helpers": "^2.6.0"
},
"peerDependenciesMeta": {
"@ember/test-helpers": {
"optional": true
}
},
"engines": {
"node": "12.* || 14.* || >= 16"
Expand All @@ -41,7 +68,19 @@
"edition": "octane"
},
"ember-addon": {
"demoURL": "https://adopted-ember-addons.github.io/ember-keyboard/"
"demoURL": "https://adopted-ember-addons.github.io/ember-keyboard/",
"main": "addon-main.js",
"type": "addon",
"version": 2,
"versionCompatibility": {
"ember": "3.8 || 3.12 || 3.16 || 3.20 || 3.24 || 3.28 || >=4.0"
},
"app-js": {
"./helpers/if-key.js": "./dist/_app_/helpers/if-key.js",
"./helpers/on-key.js": "./dist/_app_/helpers/on-key.js",
"./modifiers/on-key.js": "./dist/_app_/modifiers/on-key.js",
"./services/keyboard.js": "./dist/_app_/services/keyboard.js"
}
},
"release-it": {
"plugins": {
Expand Down
64 changes: 64 additions & 0 deletions addon/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import babel from '@rollup/plugin-babel';
import { Addon } from '@embroider/addon-dev/rollup';

const addon = new Addon({
srcDir: 'src',
destDir: 'dist',
});

export default {
// This provides defaults that work well alongside `publicEntrypoints` below.
// You can augment this if you need to.
output: addon.output(),

plugins: [
// These are the modules that users should be able to import from your
// addon. Anything not listed here may get optimized away.
addon.publicEntrypoints([
'decorators/**/*.js',
'fixtures/**/*.js',
'helpers/**/*.js',
'listeners/**/*.js',
'modifiers/**/*.js',
'services/**/*.js',
'test-support/key-event.js',
'test-support/test-helpers.js',
'utils/**/*.js',
'index.js',
]),

// These are the modules that should get reexported into the traditional
// "app" tree. Things in here should also be in publicEntrypoints above, but
// not everything in publicEntrypoints necessarily needs to go here.
addon.appReexports([
'helpers/**/*.js',
'modifiers/**/*.js',
'services/**/*.js',
]),

// This babel config should *not* apply presets or compile away ES modules.
// It exists only to provide development niceties for you, like automatic
// template colocation.
//
// By default, this will load the actual babel config from the file
// babel.config.json.
babel({
babelHelpers: 'bundled',
}),

// Follow the V2 Addon rules about dependencies. Your code can import from
// `dependencies` and `peerDependencies` as well as standard Ember-provided
// package names.
addon.dependencies(),

// Ensure that standalone .hbs files are properly integrated as Javascript.
addon.hbs(),

// addons are allowed to contain imports of .css files, which we want rollup
// to leave alone and keep in the published output.
addon.keepAssets(['**/*.css']),

// Remove leftover build artifacts when starting a new build.
addon.clean(),
],
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import listenerName from 'ember-keyboard/utils/listener-name';
import listenerName from '../utils/listener-name';
const DEFAULT_EVENT_NAME = 'keydown';

export default function onKey(keyCombo, opts = {}) {
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions addon/addon/helpers/if-key.js → addon/src/helpers/if-key.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { helper } from '@ember/component/helper';
import isKey from 'ember-keyboard/utils/is-key';
import listenerName from 'ember-keyboard/utils/listener-name';
import { assert } from '@ember/debug';
import isKey from '../utils/is-key';
import listenerName from '../utils/listener-name';

export default helper(function ifKey([keyCombo, callback] /*, named*/) {
return function (event) {
Expand Down
4 changes: 2 additions & 2 deletions addon/addon/helpers/on-key.js → addon/src/helpers/on-key.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Helper from '@ember/component/helper';
import { inject as service } from '@ember/service';
import listenerName from 'ember-keyboard/utils/listener-name';
import { assert } from '@ember/debug';
import { inject as service } from '@ember/service';
import listenerName from '../utils/listener-name';

export default class extends Helper {
@service keyboard;
Expand Down
18 changes: 7 additions & 11 deletions addon/addon/index.js → addon/src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import getMouseCode from 'ember-keyboard/utils/get-mouse-code';
import { default as keyResponder } from 'ember-keyboard/decorators/key-responder';
import { default as onKey } from 'ember-keyboard/decorators/on-key';
import getMouseCode from './utils/get-mouse-code';
import { default as keyResponder } from './decorators/key-responder';
import { default as onKey } from './decorators/on-key';

function getCode() {
throw new Error(
Expand All @@ -16,15 +16,11 @@ function getKeyCode() {

export { getCode, getKeyCode, getMouseCode, keyResponder, onKey };

export { keyDown, keyUp, keyPress } from 'ember-keyboard/listeners/key-events';
export {
click,
mouseDown,
mouseUp,
} from 'ember-keyboard/listeners/mouse-events';
export { touchStart, touchEnd } from 'ember-keyboard/listeners/touch-events';
export { keyDown, keyUp, keyPress } from './listeners/key-events';
export { click, mouseDown, mouseUp } from './listeners/mouse-events';
export { touchStart, touchEnd } from './listeners/touch-events';
export {
triggerKeyDown,
triggerKeyPress,
triggerKeyUp,
} from 'ember-keyboard/utils/trigger-event';
} from './utils/trigger-event';
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import listenerName from 'ember-keyboard/utils/listener-name';
import listenerName from '../utils/listener-name';

export function keyDown(keyCombo) {
return listenerName('keydown', keyCombo);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import listenerName from 'ember-keyboard/utils/listener-name';
import validMouseButtons from 'ember-keyboard/fixtures/mouse-buttons-array';
import validModifiers from 'ember-keyboard/fixtures/modifiers-array';
import listenerName from '../utils/listener-name';
import validMouseButtons from '../fixtures/mouse-buttons-array';
import validModifiers from '../fixtures/modifiers-array';

const validKeys = validMouseButtons.concat(validModifiers);

Expand Down
Loading