When you create an ember-cli addon, you are supposed to be able to run a dummy app.
If a component need to access it's vendor folder you access "public/" in production.
While developping the ember app that use the addon you access :
app.options.project.nodeModulesPath + "/"+ this.name+"/vendor/"
However, when you run the ember-cli addon server (the dummy app) you need only "vendor/".
this.getEnv() will return developpement while developping an addon, or an app using the addon.
How can I, in index.js, differentiate app dev from addon dev ?
Suppose we are in the included hook, you can check this.isAddon() to determine where are you now. Say if you are in the consumer ember app now, you can then invoke path.dirname(require.resolve('ADDON_NAME/package.json')) to get the absolute path of your ember add-on.
One thing to notice, this.isAddon() might not a public API (though it's stable enough, it's still not listed in API doc). If you concerned about this, you can use this.parent.name() to achieve the same goal, when you run with the dummy app, this.parent.name() always returns dummy.
BTW, this.parent is the same thing as app.project where app is the first argument of included hook.
Related
I am trying to write an Ember component addon. After complete the template structure I think it would be nice to see the layout inside the dummy application as a sanity test.
Follow the instruction below,
The Ember CLI uses a dummy app in tests/dummy for testing. In tests/dummy/app/templates/application.hbs you can put calls to both the helper and component. Then, with ember serve, you can navigate to localhost:4200 to ensure that everything is working as expected.
http://johnotander.com/ember/2014/12/14/creating-an-emberjs-addon-with-the-ember-cli/
I generate application route using code below,
ember g route application --dummy
However when I use ember s it seems run the addon's app folder instead of tests/dummy. What should I do?
Update
I have also try to start ember s inside dummy app seems no effect. It keep show me the ember-welcome-screen instead.
The solution is simple DELETE ember-welcome-page from package.json file and then run npm install.
The reason is that ember-welcome-page only get disabled when it can find custom route defined inside your app directory.
I'm developing an Ember.js app (using ember-cli) alongside a regular ol' front-end Javascript library, which is included in the Ember project on my local machine via bower link + an import in ember-cli-build.js. Trouble is, I have to restart the local Ember server each time I make a change to the library, which severely slows down development.
The big question: Is there some way to tell ember-cli to watch and reload a bower_components import without restarting the server?
For the record, the JS library is not the sort of thing that would make sense as an Ember addon, and creating a thin-wrapper addon just for the sake of reloading (if that's even possible) seems like overkill.
I am planning to use EmberJS for a small application in my day job. I have used a little ember on my laptop using ember-cli. However at work I don't have access to Github.
I am planning to download the libraries and start using without any tools like npm, bower. I have tried to setup a static web app at https://github.com/mmrath/ember-standalone
There is not much code in there. I have tried to keep the structure as close to ember-cli as possible, os that it will be easier for me to upgrade to ember-cli when access is available. I would like to use ES6 modules like in ember-cli. However the fist step of loading the Ember is not working.
Error I see in chrome console is
Error: http://localhost:4200/vendor/ember/ember.debug.js detected as System.register but didn't execute.
I'm using ember-cli with Firebase for my data. I also have a simple server file I created with http-mock that handles some processes for Twilio. Is there a way to use that http-mock as an actual server on Heroku? I have found an embercli stack for heroku but I'm not sure how to make that use the server file I have:
https://github.com/tonycoco/heroku-buildpack-ember-cli
Thank you in advance for the help.
I believe that build pack just deploys your app's static files to Heroku.
The http-mock file you're working with within Ember CLI is a Node Express app. So, you'd need to host it on a server that can serve node apps somewhere.
In theory you could write a script that does that (deploys it separately) while keeping it within your main repo, but like others have said that's probably not a good idea.
In the future, though, you probably will be able to use http-mocks both for clicking around your app with ember serve, and for use in your tests.
I'm using Ember CLI's http-mock feature to mock REST API endpoints, but I'd like to use it in multiple Ember CLI applications. I thought an addon would be a great solution to this, but I can't seem to get it to work. Does Ember Addon support http-mock?
Here's what I did.
Created an add on
$ ember addon my-http-mock
Then I created a simple test endpoint in the addon
$ ember g http-mock users
After publishing it to my github repository, I imported it into an Ember CLI project like this in package.json
"dependencies": {
"my-http-mock": "git://github.com/git-username/my-http-mock"
}
After npm installing it, I ran my app, but going to http://localhost:4200/api/users doesn't go to the API endpoint, and instead tries to load the Ember app.
Is there any way to use http-mock in multiple applications?
You'll need to have your addon implement the serverMiddleware and you can add middleware, or routes, to the http-mock running in the consuming ember-cli application.
Advanced Addon customization in ember-cli docs
That hook get's passed a config object that has the express app instance on it at config.app. You can then add whatever you'd like to do. If you're using the generated http-mock in the addon, it'd look something like this
{
name: 'my-http-mock',
serverMiddleware: function(config) {
// To require ALL mocks from your addon
var server = require('./server');
server(config.app);
// To require individual mocks
var users = require('./server/mocks/users');
users(config.app);
}
}
This is untested code but should work. The require all mocks one could possibly conflict in a weird way because it adds the bodyparser middleware and connect-restreamer and it probably already has that included if your app already has those from it's local http-mock. Try it out though! :)
note: This answer is in reference to using ember-cli 0.1.2