How do you add a new folder to app/ in ember-cli? - ember.js

I want to add an SDK type to ember-cli to wrap up complex ajax calls into a simple javascript wrapper returning a known format of POJO that can be tested.
I added an app/sdk/login.js and exported a simple empty class there. When I import it elsewhere I get a broccoli error:
ENOENT, no such file or directory 'F:\Projects\insm-ui\tmp\tree_merger-tmp_dest_
dir-JOQL1Mli.tmp\sdk\login.js'
Standard ember-cli way:
// sdk/login.js
import Ember from 'ember';
export function initialize(container, application) {
container.register('sdk:login', LoginSdk);
}
export default Ember.Object.extend({
});
// somewhere else
import LoginSdk from 'sdk/login'; // this line errors as above in broccoli
What's the correct way to do this?

You need to use relative paths for local files in your import statement. You didn't give the path to the "somewhere else" file. But let's say it's a controller at app/controllers/my-controller.js and your sdk is at app/sdk/login.js.
You could import it in the controller like:
import LoginSdk from '../sdk/login';

Related

Ember js import a UMD node module

I have to import this library and have the "ZeroEx" variable global across all ember files.
i tried to add this line in ember-cli-build.js but I got no such file or directory
app.import('node_modules/0x.js');
https://0xproject.com/docs/0x.js#installation
There is a new ember add-on that should make this easy for you: ember-auto-import https://github.com/ef4/ember-auto-import

Custom import package Python

I am making a import package and I keep running into a problem when I try and import and use the package. Primarily when I try to run it.
import mypackage
once I import it I can use it I dont get any errors upon importing it, however when I go to use it I get an error that says
TypeError: 'module' object is not callable
In a folder that I have named myfolder which is located in my current working directory i have a empty init.py file as well as two other .py files which contain the functions i have one called test.py and another called testing.py.... my problem isnt importing them but when I go to use them I get the TypeError.
the folders structure is as follows,
current working directory
-Mypackage
-__init__.py
-test.py
-testing.py
I import it like this,
from Mypackage import test
I use it like this,
test(stuff)
You have to learn how to use modules in python. When you import mypackage into your script it imports a module which has two scripts in it. Let's say they are first.py and second.py . Now if you use something like
from mypackage import first
And then you use a function named func like this
first.func()
Then it should work.
In short either import all the functions from your module or use dot notation to reference these functions. More on module can be read here

Where is my test helper for ember-power-select?

I am reading the docs for ember-power-select testings here.
On the setup, it says:
import registerPowerSelectHelpers from '../../tests/helpers/ember-power-select';
registerPowerSelectHelpers();
...
I do not see ember-power-select in my tests/helpers/ directory. Am I supposed to install it separately, or was it supposed to come by default?
I installed ember-power-select by running the command suggested: ember install ember-power-select.
How can I use some of the power-select helpers like selectChoose(), selectSearch(), &c. like prescribed on the docs?
If you look ember-cli explanation about addons; there says "test-support/ - merged with the application’s tests/" and if you look at source code of ember-power-select there is a helper directory under test-support directory. This means when you install ember-power-select; this directory behaves like it is merged with your application's tests directory. It does not matter whether you see the tests/helpers/ember-power-select.js under your project. You can access it like this. Let's assume your project is named sample-project; then you can just import relevant function as follows:
import registerPowerSelectHelpers from 'sample-project/tests/helpers/ember-power-select';
from within your acceptance-test and call it before your test begin registerPowerSelectHelpers(); and you are able to use selectChoose(), selectSearch() as you wish.
Similarly you can just import integration test helpers as follows:
import { typeInSearch, clickTrigger } from 'sample-project/tests/helpers/ember-power-select'

ES6 lib with named exports in ./vendor dir

Ember 2.0 / ember-cli 1.13.8
I couldn't find a way to import names export from ES6 module located in ./vendor dir in my Ember 2.0 project.
simple
import {Socket} from 'vendor/phoenix' in my Controller does not transpile the lib into ES5
app.import('vendor/phoenix.js', {exports: {phoenix: ['Socket']}}) in my ember-cli-build.js does not transpile the lib into ES5 either.
I have also tried
https://stackoverflow.com/a/29659509/255633 --
could not make it work due to named exports. (Error: Entry module can only have named exports in strict mode (pass ``strict: true``)
When I just modify the library to use default export the error went away but the library was not available for import. Looks like Broccoli didn't merge the lib into the tree.
here is my ember-cli-build.js :
var tree = './vendor';
var amdFiles = new ES6Modules(tree, {
format: 'amd',
bundleOptions: {
entry: 'phoenix.js',
name: 'phoenix'
}
});
return mergeTrees([app.toTree(), amdFiles]);
When you import an ES6 file into an ember app you need to have ember run the file through the transpiler so to do this you can simply do the import in your controller. The issue is that ember needs to have the file in the app folder in order to be able to import it.
So place the JavaScript file inside the app folder under say:
app/phoenixjs
then in your controller:
import phoenix from 'PROJECTNAME/phoenixjs/phoenix
then you can use the phoenix object anywhere in that file.
working Proof:
EDIT
being able to use a named import by
import {Socket} from 'import-test-app/extends/phoenix';
import Ember from 'ember';
export default Ember.Controller.extend({
test:Socket.name
});
in the template test is "Socket"

How do I locate vendor files to 'import' using Ember-cli

So this is a really basic question. In all my blueprinted files, I see import statements such as:
import DS from 'ember-data';
Now I know that the build process is finding these in the vendor directory where bower installed them. Recently, I added moment.js, and I'd like to create a helper using it. However, there must be an additional naming convention that's being used because I can't simply
import moment from 'moment';
-- it claims it cannot find it in the tree merger. What is the right way to tell Broccoli where to find things when I want to import them?
Here is how I got things to work.
Install moment.js using bower install
Add the following line in Brocfile.js
app.import('vendor/moment/min/moment.min.js');
In your code, you do NOT have to import moment as it is NOT a ES6 module. You can call moment directly. For example,
var currDate = moment();
In the files where you use moment, don't forget to add the below comment as the first line of your file. You need to do this to avoid the jshint errors shown by ember-cli when you build the code
/* global moment:true */
Hope this helps!