|
2 | 2 |
|
3 | 3 | Migrates ember-cli projects to the newly proposed module format. |
4 | 4 |
|
5 | | -See [emberjs/rfcs#143](https://github.com/emberjs/rfcs/pull/143) for details. |
| 5 | +This migrator does not leave an application in a bootable state. See "Usage" |
| 6 | +for instructions on how to manually update a migrated app to a bootable |
| 7 | +setup. |
6 | 8 |
|
7 | | -## Examples |
| 9 | +See [emberjs/rfcs#143](https://github.com/emberjs/rfcs/pull/143) for details |
| 10 | +on the design of this app layout. |
| 11 | + |
| 12 | +### Examples |
| 13 | + |
| 14 | +These are examples of the migrator output on various apps: |
8 | 15 |
|
9 | 16 | * [Ghost admin client](https://github.com/rwjblue/--ghost-modules-sample/tree/grouped-collections/src) |
10 | 17 | * [Travis client](https://github.com/rwjblue/--travis-modules-sample/tree/modules/src) |
11 | | -* [`ember new my-app`](https://github.com/rwjblue/--new-app-blueprint/tree/modules/src) |
| 18 | +* [Migration of `ember new my-app`](https://github.com/rwjblue/--new-app-blueprint/tree/modules/src) |
12 | 19 |
|
13 | 20 | ### Usage |
14 | 21 |
|
| 22 | +To run the migrator on your app: |
| 23 | + |
15 | 24 | ```sh |
16 | | -npm install -g ember-module-migrator |
| 25 | +npm install -g ember-module-migrator jscodeshift |
17 | 26 | cd your/project/path |
18 | 27 | ember-module-migrator |
19 | 28 | ``` |
20 | 29 |
|
21 | | -### Important Notes |
| 30 | +After running the migrator itself, you will need to update several files |
| 31 | +to boot an application. The best path forward is to run the |
| 32 | +[ember-module-unification-blueprint](https://github.com/emberjs/ember-module-unification-blueprint) |
| 33 | +on the converted app: |
| 34 | + |
| 35 | +```sh |
| 36 | +# This command will run the blueprint. Important things to note in the |
| 37 | +# package.json and bower.json are these package changes: |
| 38 | +# |
| 39 | +# npm i ember-resolver@^4.2.3 ember-cli@github:ember-cli/ember-cli --save-dev |
| 40 | +# npm uninstall ember-source --save |
| 41 | +# bower install --save components/ember#canary |
| 42 | +# |
| 43 | +ember init -b ember-module-unification-blueprint |
| 44 | +``` |
| 45 | + |
| 46 | +### Running module unification with fallback to classic app layout |
| 47 | + |
| 48 | +If an application cannot be converted all at once, or if your application is |
| 49 | +dependent upon addons that use `app/` to add files, you may want to use |
| 50 | +a setup that falls back to `app/` after checking `src` and honors the `app/` |
| 51 | +directory for some files like initializers. |
22 | 52 |
|
23 | | -Running this migrator on your application will migrate to the new structure being proposed, however at this time that structure is not fully bootable from ember-cli. The goal right now, is for the tool to help guide us in the best module layout and for folks to be able to get a feel for what their projects will look like when things are ready to go. |
| 53 | +To do this use a fallback resolver in `src/resolver.js`: |
| 54 | + |
| 55 | +```js |
| 56 | +import ClassicResolver from 'ember-resolver'; |
| 57 | +import Resolver from 'ember-resolver/resolvers/glimmer-wrapper'; |
| 58 | +import buildResolverConfig from 'ember-resolver/ember-config'; |
| 59 | +import config from '../config/environment'; |
| 60 | + |
| 61 | +export default Resolver.extend({ |
| 62 | + config: buildResolverConfig(config.modulePrefix), |
| 63 | + init(options) { |
| 64 | + this._super(options); |
| 65 | + this._fallback = ClassicResolver.create(Object.assign({ |
| 66 | + namespace: { modulePrefix: config.modulePrefix } |
| 67 | + }, options)); |
| 68 | + }, |
| 69 | + resolve(name, referrer) { |
| 70 | + let result = this._super(name, referrer); |
| 71 | + if (!result) { |
| 72 | + result = this._fallback.resolve(name); |
| 73 | + } |
| 74 | + return result; |
| 75 | + } |
| 76 | +}); |
| 77 | +``` |
| 78 | + |
| 79 | +And in `src/main.js` be sure to load initializers in the `app/` directory |
| 80 | +(possibly added by an addon) via: |
| 81 | + |
| 82 | +```js |
| 83 | +/* |
| 84 | + * This line should be added by the blueprint |
| 85 | + */ |
| 86 | +loadInitializers(App, config.modulePrefix+'/src/init'); |
| 87 | + |
| 88 | +/* |
| 89 | + * This line should be added to support `app/` directories |
| 90 | + */ |
| 91 | +loadInitializers(App, config.modulePrefix); |
| 92 | +``` |
| 93 | + |
| 94 | +### Important Notes |
24 | 95 |
|
25 | 96 | Known caveats: |
26 | 97 |
|
27 | | -* Migrates only "classic" structured ember-cli apps at this point. We are actively working on pods support. |
28 | | -* Leaves the migrated app in a non-bootable state. This is because changes are needed to ember-cli to allow the application to boot, but those changes haven't started yet. |
| 98 | +* Migrates only "classic" structured ember-cli apps at this point. We are |
| 99 | + actively working on pods support. |
0 commit comments