Skip to content

Commit 94f5a44

Browse files
committed
Moved documentation to README.md
1 parent 78a810a commit 94f5a44

File tree

2 files changed

+60
-78
lines changed

2 files changed

+60
-78
lines changed

README.md

Lines changed: 60 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -24,44 +24,77 @@ Lastly, for **helpers**, the addon consists of
2424

2525
Thanks to the contents of `index.js` this addon can be installed and used from an ember app. To follow convention, it is also possible to "build" the addon so it gets a proper, conventional ember-addon file structure by running a single command.
2626

27-
# Usage
27+
# What is ember-micro-addon useful for?
2828

29-
Currently, ember-micro-addon can be used as a locally installed ember-addon, or as a locally and/or globally installed plain npm package.
29+
Let's say I'm writing an Ember-CLI application.
3030

31-
## Usage as ember addon
31+
I made a component and it turned out pretty ok. It also turned out to be something other people might want to use. It's not completely done yet, but I can see the potential.
3232

33-
Install it in a working folder
33+
## How do I turn that component into an Ember addon?
3434

35-
* `mkdir working_folder`
36-
* `cd working_folder`
37-
* `npm install --save-dev ember-micro-addon
35+
Usually, we would do a couple of things.
3836

39-
Once these 3 steps are done, the `ember micro:x` command set is available. There are several commands it supports:
37+
First, we create a new ember addon in some folder somewhere, using the `ember addon` command provided by Ember-CLI.
4038

41-
* `ember micro:component addon-name` creates a component micro-addon folder containing files listed in the previous section
42-
* `ember micro:library addon-name` creates a library micro-addon
43-
* `ember micro:helper addon-name` creates a helper micro-addon
44-
* `ember micro:build addon-name` copies files from the `addon-name` folder into the folder `addon-name/dist`. Files are copied in a way that complies with the default ember-addon filestructure:
45-
* `index.js` and `package.json` go to the root,
46-
* `component.js` goes to `app/components`,
47-
* `template.hbs` goes to `app/templates/components`,
48-
* `style.css` goes to `addon/styles` so it gets merged into `vendor.css`
49-
* `helper.js` goes to `app/helpers
50-
* `library.js` goes to `app/lib`
39+
Then, we copy the existing component code into a proper addon structure.
40+
* `my-app/app/components/my-component.js` goes to `my-component/addon/components/my-component.js`
41+
* `my-component/app/components/my-component.js` needs to be created and needs to import-export the component from the addon folder
42+
* `my-app/app/templates/components/my-component.hbs` needs to go to `my-component/app/templates/components/my-component.js
43+
* We need to link the addon with the addon to the app to continue using it
44+
*We can use `npm link` to link it symbolically
45+
*We can publish the addon and link it from a repo
46+
*We can install the addon from a local folder
5147

52-
## Usage as a plain npm package (preferred)
48+
Couple of possible issues with all of this
49+
* It's complicated and takes a while
50+
* The structure we need to create, while being the convention, seems a bit complex for just a tiny component
5351

54-
Install it in a working folder, or, preferably, as a global npm package:
52+
## What `ember-micro-addon` allows us to do
5553

56-
* `npm install -g ember-micro-addon`
54+
### Extract a component, library or helper out of an application into a separate addon
55+
56+
Let's say we have our app in `~/git/my-app` and we're currently in that folder.
57+
58+
We type in `ember-micro:extract component my-component`. In about a second, there's a new folder `~/git/my-component` and it has a fully working ember addon containing our component. We can also do the same with a library or a helper.
59+
60+
### Use a simplified, flat file structure
61+
62+
Additionally, the structure of the addon folder is simplified:
63+
* For components, we have `package.json`, `index.js`, `component.js`, `style.css` and `template.hbs` all in the root of the addon folder.
64+
* For libraries, we just have `package.json`, `index.js` and `library.json`
65+
* For helpers, we just have `package.json`, `index.js` and `helper.json`
66+
67+
The structure is not conventional but it _just works_ out of the box.
68+
69+
### Publish the micro-addon as a git repository on GitHub
5770

58-
Once the package is installed globally, the `ember-micro:x` command set is available **from any location**. Note the added dash compared to the case of using it as an `ember-addon`
71+
What if we want to quickly make our addon availabe online somewhere?
5972

60-
The command set behaves in the same way as the `ember micro:x` command set. The available commands are:
73+
We position ourselves to `~/git/` and run `ember-micro:publish my-component`. We will get prompted for our GitHub credentials and within seconds, our addon will become a proper local git repository and then get pushed to a remote repository of the same name on our GitHub account. It is now available for everyone to use.
6174

62-
* `ember-micro:component addon-name`
63-
* `ember-micro:library addon-name`
64-
* `ember-micro:helper addon-name`
65-
* `ember-micro:build addon-name`
75+
### Convert the flat file structure into a fully-fledged ember addon structure
6676

77+
If we ever want to convert our addon to a proper ember-addon structure, we can still do it. We simply move to `~/git` where our addon folder currently is and we run `ember-micro:build my-component`. A new folder will be created, `~git/my-component/dist` containing our addon in the conventional ember addon format, with all files in their proper place.
6778

79+
80+
# Usage
81+
82+
Install it in a working folder, or, preferably, as a global npm package:
83+
84+
* `npm install -g ember-micro-addon`
85+
86+
Once the package is installed globally, the `ember-micro:x` command set is available **from any location**.
87+
88+
The available commands are:
89+
90+
* `ember-micro:extract <component|library|helper> addonName` - extract a component, helper or library from an existing Ember app into a stand-alone micro-addon
91+
* `ember-micro:component addon-name` creates a component micro-addon folder containing files listed in the previous section
92+
* `ember-micro:library addon-name` creates a library micro-addon
93+
* `ember-micro:helper addon-name` creates a helper micro-addon
94+
* `ember-micro:build addon-name` copies files from the `addon-name` folder into the folder `addon-name/dist`. Files are copied in a way that complies with the default ember-addon filestructure:
95+
* `index.js` and `package.json` go to the root,
96+
* `component.js` goes to `app/components`,
97+
* `template.hbs` goes to `app/templates/components`,
98+
* `style.css` goes to `addon/styles` so it gets merged into `vendor.css`
99+
* `helper.js` goes to `app/helpers
100+
* `library.js` goes to `app/lib`

USE-CASE.md

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)