Skip to content

Commit 123cdab

Browse files
author
Chris Garrett
committed
[DOCS] Updates the README
1 parent 4aeee7f commit 123cdab

1 file changed

Lines changed: 44 additions & 66 deletions

File tree

README.md

Lines changed: 44 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -3,71 +3,45 @@
33
[![Build Status](https://travis-ci.org/ember-codemods/ember-native-class-codemod.svg?branch=master)](https://travis-ci.org/ember-codemods/ember-native-class-codemod)
44
[![npm version](https://badge.fury.io/js/ember-native-class-codemod.svg)](https://badge.fury.io/js/ember-native-class-codemod)
55

6-
Codemods for transforming ember app code to native ES6 class syntax with decorators.
6+
A codemod for transforming your ember app code to native JavaScript class syntax
7+
with decorators!
78

89
## Usage
910

10-
The Ember ES6 codemods can be run using the following command:
11+
First, boot up your application. Then, the codemod can be run using the
12+
following command:
1113

1214
```
1315
npx ember-native-class-codemod http://localhost:4200/path/to/server [OPTIONS] path/of/files/ or/some**/*glob.js
1416
```
1517

16-
The codemods accept the following options:
18+
The codemod accepts the following options:
1719

18-
| Option | Value | Default | Details |
19-
| --------------------- | --------- | ------------------------------- | ------------------------------------------------------------------------------------------------------------------ |
20-
| --class-fields | boolean | true | Enable/disable transformation using class fields |
21-
| --decorators | boolean | true | Enable/disable transformation using decorators |
22-
| --type | String | Empty (match all types in path) | Apply transformation to only passed type. The type can be one of `services`, `routes`, `components`, `controllers` |
20+
| Option | Value | Default | Details |
21+
| ------------------- | ------- | ------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
22+
| --class-fields | boolean | true | Enable/disable transformation using class fields |
23+
| --decorators | boolean | true | Enable/disable transformation using decorators |
24+
| --classic-decorator | boolean | true | Enable/disable adding the [`@classic` decorator](https://github.com/pzuraq/ember-classic-decorator), which helps with transitioning Ember Octane |
25+
| --type | String | Empty (match all types in path) | Apply transformation to only passed type. The type can be one of `services`, `routes`, `components`, `controllers` |
26+
| --quote | String | 'single' | Whether to use double or single quotes by default for new statements that are added during the codemod. |
2327

24-
### Class Fields
28+
### Gathering Runtime Data
2529

26-
Class fields are currently defined as a [stage 3 proposal](https://github.com/tc39/proposal-class-fields) in the [ECMA TC39 process](https://tc39.github.io/process-document/). As such, they are added as a configurable option in the transforms, enabled by default. If set to **false**, it will NOT transform the object properties to class fields but instead error out.
30+
The first argument that you must pass to the codemod is the URL of a running
31+
instance of your application. The codemod opens up your application and analyzes
32+
the classes directly, so it can transform them, which is why it needs this URL.
33+
Any classes that were not analyzed will not be transformed. This includes
34+
classes that are private to a module and never exported.
2735

28-
For example, the below declaration
29-
30-
```
31-
const Foo = EmberObject.extend({
32-
prop: "defaultValue",
33-
});
34-
```
35-
36-
Will be transformed to
37-
38-
```
39-
class Foo extends EmberObject {
40-
prop = "defaultValue";
41-
}
42-
```
43-
44-
### Decorators
45-
46-
Decorators are currently a [stage 2 proposal](https://github.com/tc39/proposal-decorators) in the [ECMA TC39 process](https://tc39.github.io/process-document/). They are added as a configurable option in the transforms. If set to true, it will transform the object's properties to decorators wherever required.
47-
48-
For example, the below declaration
49-
50-
```
51-
import { inject as service } from "@ember/service";
52-
const Foo = EmberObject.extend({
53-
store: service(),
54-
});
55-
```
56-
57-
Will be transformed to
58-
59-
```
60-
import { service } from "@ember-decorators/service";
61-
class Foo extends EmberObject {
62-
@service store;
63-
}
64-
```
65-
66-
**Note** The decorators support is built into Ember by way of [email protected] or higher.
36+
If you have any _lazily loaded_ modules, such as modules from Ember Engines,
37+
you'll need to make sure that the URL you provide loads these modules as well.
38+
Otherwise, the codemod will not be able to detect them or analyze them.
6739

6840
### Types
6941

70-
The option `type` can be used to further target transforms to a particular type of ember object within the application or addon. The types can be any of the following:
42+
The `type` option can be used to further transforms to a particular type of
43+
ember object within the application or addon. The types can be any of the
44+
following:
7145

7246
| Type | Option |
7347
| ----------- | ------------------ |
@@ -76,35 +50,39 @@ The option `type` can be used to further target transforms to a particular type
7650
| Components | --type=components |
7751
| Controllers | --type=controllers |
7852

79-
The path of the file being transformed is matched against the glob pattern of the type to determine whether to run the specific transforms.
80-
81-
If a type is not provided, the codemods will run against all the **_types_** in the path provided.
82-
83-
### Runtime Config
53+
The path of the file being transformed is matched against the glob pattern of
54+
the type to determine whether to run the specific transforms.
8455

85-
As per conventional codemods, the code is converted from one API to another by statically analyzing patterns within it. While this works well most of the time, there are cases that can only be analyzed at runtime to determine the full shape of the code to transform. For example, if we need to determine the class hierarchy, it is not possible with static analysis to determine the parent classes and their properties.
86-
87-
The codemods are designed with `runtime data` as input to correctly transform the code. For each file currently being transformed, the codemods need a `configuration file`, which will provide additional metadata about the properties of the ember object.
56+
If a type is not provided, the codemods will run against all the **_types_** in
57+
the path provided.
8858

8959
## Debugging
9060

91-
The codemods log execution information in the `codemods.log` file in the current directory from where the codemods are being executed. Specifically, details such as failures and reasons for failures, are logged. This would be the recommended starting point for debugging issues related to these codemods.
61+
The codemods log execution information in the `codemods.log` file in the current
62+
directory where the codemods are being executed. Specifically, details such as
63+
failures and reasons for failures, are logged. This would be the recommended
64+
starting point for debugging issues related to these codemods.
9265

9366
## Unsupported Types
9467

95-
While the codemods transforms all types of ember objects, it does not support transformation of
68+
While the codemods transforms many types of ember objects, it does not support
69+
transformation of
9670

97-
- `ember-data` entities for example `DS.Model`, `DS.Adapter` etc
71+
- `ember-data` classes such as `DS.Model`, `DS.Adapter` etc
9872
- Mixins
99-
- Ember Object having a property with `ObjectExpression` as value (`actions` and `queryParams` are exception) See `eslint-plugin-ember/avoid-leaking-state-in-ember-objects` for more details.
100-
- Ember object having property with `meta` or `property` modifiers
73+
- Ember Objects with objects or arrays as direct properties (`actions` and
74+
`queryParams` are the exception). See `eslint-plugin-ember/avoid-leaking-state-in-ember-objects`
75+
for more details.
76+
- Ember objects with computed properties that use the `meta` or `property`
77+
modifiers.
10178

10279
## More Transform Examples
10380

10481
<!--TRANSFORMS_START-->
105-
* [ember-object](transforms/ember-object/README.md)
106-
* [helpers](transforms/helpers/README.md)
107-
<!--TRANSFORMS_END-->
82+
83+
- [ember-object](transforms/ember-object/README.md)
84+
- [helpers](transforms/helpers/README.md)
85+
<!--TRANSFORMS_END-->
10886

10987
## Contributing
11088

0 commit comments

Comments
 (0)