Skip to content

Commit

Permalink
Merge pull request #44 from peopledoc/typescript
Browse files Browse the repository at this point in the history
Refactor to Typescript
  • Loading branch information
GreatWizard authored Aug 27, 2020
2 parents 7c1d618 + 9cbd038 commit 098e034
Show file tree
Hide file tree
Showing 36 changed files with 13,116 additions and 23,759 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ module.exports = {
})
}
]
};
}
4 changes: 2 additions & 2 deletions .template-lintrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
'use strict'

module.exports = {
extends: 'recommended'
};
}
26 changes: 17 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@ language: node_js
node_js:
# we recommend testing addons with the same minimum supported node version as Ember CLI
# so that your addon works for all apps
- "8"
- "10"

sudo: false
dist: trusty
dist: xenial

addons:
chrome: stable

cache:
directories:
- $HOME/.npm
yarn: true

env:
global:
Expand All @@ -27,7 +26,7 @@ branches:
- /^v\d+\.\d+\.\d+/

jobs:
fail_fast: true
fast_finish: true
allow_failures:
- env: EMBER_TRY_SCENARIO=ember-canary

Expand All @@ -37,19 +36,28 @@ jobs:
- stage: "Tests"
name: "Tests"
script:
- npm run lint:hbs
- npm run lint:js
- npm test
- yarn lint:hbs
- yarn lint:js
- yarn test

# we recommend new addons test the current and previous LTS
# as well as latest stable release (bonus points to beta/canary)
- stage: "Additional Tests"
env: EMBER_TRY_SCENARIO=ember-lts-3.8
- env: EMBER_TRY_SCENARIO=ember-lts-3.12
- env: EMBER_TRY_SCENARIO=ember-lts-3.16
- env: EMBER_TRY_SCENARIO=ember-release
- env: EMBER_TRY_SCENARIO=ember-beta
- env: EMBER_TRY_SCENARIO=ember-canary
- env: EMBER_TRY_SCENARIO=ember-default-with-jquery
- env: EMBER_TRY_SCENARIO=ember-classic

before_install:
- curl -o- -L https://yarnpkg.com/install.sh | bash
- export PATH=$HOME/.yarn/bin:$PATH

install:
- yarn install --non-interactive

script:
- node_modules/.bin/ember try:one $EMBER_TRY_SCENARIO
- yarn ember try:one $EMBER_TRY_SCENARIO
10 changes: 5 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

* `git clone <repository-url>`
* `cd my-addon`
* `npm install`
* `yarn install`

## Linting

* `npm run lint:hbs`
* `npm run lint:js`
* `npm run lint:js -- --fix`
* `yarn run lint:hbs`
* `yarn run lint:js`
* `yarn run lint:js -- --fix`

## Running tests

Expand All @@ -23,4 +23,4 @@
* `ember serve`
* Visit the dummy application at [http://localhost:4200](http://localhost:4200).

For more information on using ember-cli, visit [https://ember-cli.com/](https://ember-cli.com/).
For more information on using ember-cli, visit [https://ember-cli.com/](https://ember-cli.com/).
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ ember install ember-cli-embedded

## Configuration

This plugin is opt-in; by default, it does nothing to your app unless
This plugin is opt-in by default, it does nothing to your app unless
you configure it.

In your `config/environment.js`, add the following config to the `ENV`:
Expand Down Expand Up @@ -64,17 +64,17 @@ EmberObject.extend({
embedded: service(),
logSomeConfigKey() {
const value = this.get('embedded.myKey');
console.log(value);
const value = this.get('embedded.myKey')
console.log(value)
}
});
})
```

Note: It is sometimes more convenient to access the data from the container directly:

```js
// Returns the raw config
let embeddedConfig = Ember.getOwner(this).lookup('config:embedded');
let embeddedConfig = Ember.getOwner(this).lookup('config:embedded')
```

## Override your APP configuration
Expand All @@ -89,7 +89,7 @@ Make sure that, in your `config/environment.js`, you disable the addon for the
`test` environment, with the following:

```js
ENV.embedded.delegateStart = false;
ENV.embedded.delegateStart = false
```

# Development
Expand All @@ -98,8 +98,7 @@ Installation
------------------------------------------------------------------------------

* `git clone` this repository
* `npm install`
* `bower install`
* `yarn install`

### Linting

Expand Down
Empty file removed addon/.gitkeep
Empty file.
56 changes: 0 additions & 56 deletions addon/initializers/embedded.js

This file was deleted.

81 changes: 81 additions & 0 deletions addon/initializers/embedded.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import EmberApplication from '@ember/application'
import EmberObject from '@ember/object'
import { deprecate } from '@ember/application/deprecations'
import { run } from '@ember/runloop'
import { get } from '@ember/object'

type Application = EmberApplication & EmberObject

interface ObjectConfig {
delegateStart: boolean,
config: any
}

type VoidConfig = null|undefined
type DeprecatedBooleanConfig = boolean

type GivenConfig = VoidConfig
| DeprecatedBooleanConfig
| ObjectConfig

function configIsVoid(config:GivenConfig): config is VoidConfig {
return [null, undefined].includes(config as VoidConfig)
}

function configIsBoolean(config:GivenConfig): config is DeprecatedBooleanConfig {
return typeof config === 'boolean'
}

function normalizeConfig(userConfig:GivenConfig):ObjectConfig {
if (configIsVoid(userConfig)) {
return { delegateStart: false, config: {} }
}

if (configIsBoolean(userConfig)) {
let embeddedConfig = { delegateStart: userConfig, config: {} }
deprecate('The `embedded` config property MUST be undefined or an an object', false, { id: 'bad-object-config', until: '1.0.0' })
return embeddedConfig
}

if (userConfig.delegateStart === undefined) {
deprecate('The config MUST contain a `delegateStart` property. Assuming `true` for backward compatibility. The config must now be defined in a `config` property', false, { id: 'bad-object-config', until: '1.0.0' })
return {
delegateStart: true,
config: userConfig
}
}
return Object.assign({ config: {} }, userConfig)
}

export function initialize():void {
const application:Application = arguments[1] || arguments[0]
const env = application.resolveRegistration('config:environment')

let appConfig:GivenConfig = get(env, 'embedded')

let embeddedConfig:ObjectConfig = normalizeConfig(appConfig)

if (embeddedConfig.delegateStart) {
// @ts-ignore
application.reopen({
start: run.bind(application, function emberCliEmbeddedStart(config = {}) {
const _embeddedConfig = Object.assign(
{},
embeddedConfig.config,
config
)
this.register('config:embedded', _embeddedConfig, { instantiate: false })
this.advanceReadiness()
})
})
application.deferReadiness()
} else {
application.register('config:embedded', embeddedConfig.config)
}
}

export default {
name: 'ember-cli-embedded',
after: 'export-application-global',
initialize
}
14 changes: 7 additions & 7 deletions addon/services/embedded.js → addon/services/embedded.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import ObjectProxy from '@ember/object/proxy';
import { getOwner } from '@ember/application';
import ObjectProxy from '@ember/object/proxy'
import { getOwner } from '@ember/application'

let configService = ObjectProxy.extend({
init() {
this.content = getOwner(this).factoryFor('config:embedded').class;
this._super(...arguments);
this.content = getOwner(this).factoryFor('config:embedded').class
this._super(...arguments)
}
});
})

configService.reopenClass({
isServiceFactory: true
});
})

export default configService;
export default configService
Empty file removed app/.gitkeep
Empty file.
2 changes: 1 addition & 1 deletion app/initializers/embedded.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { default, initialize } from 'ember-cli-embedded/initializers/embedded';
export { default, initialize } from 'ember-cli-embedded/initializers/embedded'
8 changes: 4 additions & 4 deletions app/instance-initializers/embedded.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export function initialize(appInstance) {
const appConf = appInstance.resolveRegistration('config:environment').APP;
const embedConf = appInstance.resolveRegistration('config:embedded');
return Object.assign(appConf, embedConf);
const appConf = appInstance.resolveRegistration('config:environment').APP
const embedConf = appInstance.resolveRegistration('config:embedded')
return Object.assign(appConf, embedConf)
}

export default {
name: 'embedded',
initialize
};
}
2 changes: 1 addition & 1 deletion app/services/embedded.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { default } from 'ember-cli-embedded/services/embedded';
export { default } from 'ember-cli-embedded/services/embedded'
32 changes: 28 additions & 4 deletions config/ember-try.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
'use strict';
'use strict'

const getChannelURL = require('ember-source-channel-url');
const getChannelURL = require('ember-source-channel-url')

module.exports = async function() {
return {
useYarn: true,
scenarios: [
{
name: 'ember-lts-3.8',
Expand All @@ -21,6 +22,14 @@ module.exports = async function() {
}
}
},
{
name: 'ember-lts-3.16',
npm: {
devDependencies: {
'ember-source': '~3.16.0'
}
}
},
{
name: 'ember-release',
npm: {
Expand Down Expand Up @@ -67,7 +76,22 @@ module.exports = async function() {
'@ember/jquery': '^0.5.1'
}
}
},
{
name: 'ember-classic',
env: {
EMBER_OPTIONAL_FEATURES: JSON.stringify({
'application-template-wrapper': true,
'default-async-observers': false,
'template-only-glimmer-components': false
})
},
npm: {
ember: {
edition: 'classic'
}
}
}
]
};
};
}
}
6 changes: 3 additions & 3 deletions config/environment.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
'use strict'

module.exports = function(/* environment, appConfig */) {
return { };
};
return { }
}
Loading

0 comments on commit 098e034

Please sign in to comment.