You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+60-27Lines changed: 60 additions & 27 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,44 +24,77 @@ Lastly, for **helpers**, the addon consists of
24
24
25
25
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.
26
26
27
-
# Usage
27
+
# What is ember-micro-addon useful for?
28
28
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.
30
30
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.
32
32
33
-
Install it in a working folder
33
+
## How do I turn that component into an Ember addon?
34
34
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.
38
36
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.
40
38
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
51
47
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
53
51
54
-
Install it in a working folder, or, preferably, as a global npm package:
52
+
## What `ember-micro-addon` allows us to do
55
53
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
57
70
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?
59
72
60
-
The command set behaves in the same way as the `embermicro: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.
61
74
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
66
76
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.
67
78
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`
0 commit comments