Ember server does not serve dummy app while creating an addon - ember.js

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.

Related

Ember-cli addon dev, how to differentiate addon dev from application dev

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.

Using test support code from an ember addon

I have several ember apps which use a common shared ember-cli addon. This addon has common code like models, navigation etc. I also want this addon to provide common test support code like test helpers, factories to the ember apps. However if I remove tests from .npmignore in the addon, then the test resources gets built with the ember app.
Is there a way to use the addon in an ember app, but strip the addon's tests folder on build? Or perhaps there is a better way of achieving this?
Common code can go to the addon's test-support folder. That folder would automatically get merged into the app's tests folder.
This is mentioned here - https://ember-cli.com/extending/#addon-project-structure

Use ember cli mock server as actual server

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.

Ember CLI http-mock as Addon

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

Deploy Ember Application

I have created an ember application (prior to the arrival of Ember CLI) which follows a file hierarchy as given below:
Modules
Controllers
Views
Models
Routes
App.js
I would like to know that is there any way to deploy these files by compiling as a single javascript and html file, like now we are doing in ember cli. Since my application is using offline APP Cache, I terribly need this feature to avoid save numberous files and downloading it from cache manifest file.
After some research I have decided to update application with Ember CLI. This seems to be the best option to build and deploy Ember Application.