How do I change source directory in Dart/Pub config? - dart

I couldn't find answer to this in Dart documentation.
My application's server-side is driven by Spray and by convention static files are stored in /webapp folder. When I try to build Dart project I get following error
C:\work\externals\dart-sdk\bin\pub.bat build --mode=release
Your package must have a "web" directory, or you must specify the source directories.
How can I change it from web to webapp ? My pubspec.yaml looks like this
name: dart_spray_example
description: A sample Dart/Spray application
dependencies:
browser: any
Here is layout of my application right now

You just pass it as an additional argument.
pub build --mode=release webapp
but I would expect troubles doing it this way because only some top-level directory names are compliant with the pub package layout convention.
pub build --mode=release example
would be fine.
It might be easier to just use web as the source directory and move the generated output to webapp. I'm aware that this can cause problems during development but I would expect it to be easier to fix the development setup instead of the build setup.
Using frameworks like Angular and Polymer which make heavy use of transformers have a strong dependency on the package layout convention.

Related

How to transpiling dart to javascript in Phpstorm

I installed dart-sdk and downloaded dart plugin to Phpstorm 8.0.3, but I cant figure out how to transpile dart to js. When I am trying to make file watcher I dont have any Dart2Js predefined template in settings.
Thank you
I know only WebStorm 9 and 10. Maybe you can still derive how it might work in PHPStorm.
Usually you don't want to build to JavaScript on each file change because this would slow your machine down.
During development you use pub serve which is automatically launched by WS 9 and 10 and which transpiles Dart files to JavaScript only on demand (when requested by a browser) and only compiles what it didn't compile previously.
For deployment WebStorm can use the Pub: build ... context menu of the pubspec.yaml file in the project view.
See #Günter Zöchbauer answer.
Using dart2js is not the recommended approach, as it runs on file level instead of project, creates output in the src folder, etc. - but the main reason is that it is not clear when/why to use it. If you need to build your project, use 'pub build' (available in pubspec.yaml right-click menu). When debugging in browser, 'pub serve' is always used implicitly - it performs all needed transformations...
But, if you still need this watcher, you can easily configure it yourself by adding a watcher of 'custom' type.
Program: path/to/dart2js
Arguments: --out=$FilePath$.js $FilePath$
Working directory: $FileDir$
Output paths: $FileName$.js:$FileName$.js.map:$FileName$.js.deps

Dart app with bin, web and libs

I want to make Dart app that has flexible deployment. It can be started as a web server or standalone app in browser as well. My directory structure:
bin
- httpserver.dart
lib
- commonlib.dart
web
- web.html
- web.dart
pubspec.yaml
I wanto start either httpserver.dart providing web's content or web.html directly in Chromium. I have troubles with the lib visibility from bin/httpserver.dart. using the "import 'package:prj/commonlib.dart'" does not work. But from the web.dart is works fine.
Please advice how to share libs among bin's and web's code. Or I should I make structure of dirs somehow different?
Note: there is no packages sub-dir in the bin directory created by pub get. I am using dart sdk 1.7.2.
Thank you, Ladislav.
In the bin directory there should be a packages symlink created automatically but it is not in subdirectories of prj/bin. If the symlink isn't created just create it manually.

How to integrate Dart into a Rails app

How should I go about integrating my Dart application, into my rails application.
I'm having a hard time with the whole, 'packages' structure that has to exist on every directory.
Because the subdirectories reference the root using an alias, rails is not serving them even though all of this is in the 'public' folder
Excuse me for reviving, but you may try https://github.com/m0gg/dart-rails
It's targeting to simplifiy usage of Dart in Rails applications with automatic dart2js and pulling in dependencies by pub with a rake-task.
If you run pub build --mode=debug the build directory contains the application without symlinks.
The Dart code should be retained when --mode=debug is used.
Here is some discussion going on about this topic too Dart and it's place in Rails Assets Pipeline

Usage of local dart library

I have created some local libraries in my dart lib directory.
These libraries are visible in dart packages for each newly created folder in the web directory. However, when I attempt to access them using the dart's package nomenclature eg package:reg/name.dart, the system always generates an error.
I think I am missing something.
I have read http://pub.dartlang.org/doc/package-layout.html but this did not help me either.
You need to ensure that the name you're using as the package matches that in pubspec.yaml.
Eg. if in pubspec.yaml you havename: my_app and your file is at lib\my_library.dart then you need to use import 'package:my_app/my_library.dart';.

"Bundling" external libraries in Erlang?

I have an erlang application I have been writing which uses the erldis library for communicating with redis.
Being a bit of a newbie with actually deploying erlang applications to production, I wanted to know if there was anyway to 'bundle' these external libraries with the application rather than installing into my system wide /usr/lib/erlang/lib/ folder.
Currently my directory structure looks like...
\
--\conf
--\ebin
--\src
I have a basic Makefile that I stole from a friend's project, but I am unsure how to write them properly.
I suspect this answer could involve telling me how to write my Makefile properly rather than just which directory to plonk some external library code into.
You should really try to avoid project nesting whenever possible. It can lead to all sorts of problems because of how module/application version is structured within Erlang.
In my development environment, I do a few things to simplify dependancies and multiple developed projects. Specifically, I keep most of my projects sourced in a dev directory and create symlinks into an elibs dir that is set in the ERL_LIBS environmental variables.
~/dev/ngerakines-etap
~/dev/jacobvorreuter-log_roller
~/dev/elib/etap -> ~/dev/ngerakines-etap
~/dev/elib/log_roller -> ~/dev/jacobvorreuter-log_roller
For projects that are deployed, I've either had package-rpm or package-apt make targets that create individual packages per project. Applications get boot scripts and init.d scripts for easy start/stop controls but libraries and dependancy projects just get listed as package dependencies.
I use mochiweb-inspired style. To see example of this get your copy of mochiweb:
svn checkout http://mochiweb.googlecode.com/svn/trunk/ mochiweb
and use
path/to/mochiweb/scripts/new_mochiweb.erl new_project_name
to create sample project of the structure (feel free to delete everything inside src afterwards and use it for your project).
It looks like this:
/
/ebin/
/deps/
/src/
/include/
/support/
/support/include.mk
Makefile
start.sh
ebin contains *.beam files
src contains ***.erl files and local *.hrl files
include contains global *.hrl files
deps contains symlinks to root directories of dependencies
Makefile and include.mk takes care of including appropriate paths when project is built.
start.sh takes care of including appropriate paths when project is run.
So using symlinks in deps directory you are able to fine tune the versions of libraries you use for every project. It is advised to use relative paths, so afterwards it is enough to rsync this structure to the production server and run it.
On more global scale I use the following structure:
~/code/erlang/libs/*/
~/code/category/project/*/
~/code/category/project/*/deps/*/
Where every symlink in deps points to the library in ~/code/erlang/libs/ or to another project in the same category.
The simplest way to do this would be to just create a folder named erldir and put the beams you need into it and then in your start script just use the -pa flag to the erlang runtime to point out where it should fetch the beams.
The correct way (at least if you buy into the OTP distribution model) would be to create a release using reltool (http://www.erlang.org/doc/man/reltool.html) or systools (http://www.erlang.org/doc/man/systools.html) which includes both your application and erldis.
Add the external libraries that you need, anywhere you want them, and add them to your ERL_LIBS environment variable. Separate the paths with colon in unix or semicolon in dos.
Erlang will add the "ebin"-named subdirs to its code loading path.
Have your *.app file point out the other applications it depends on.
This is a good halfway-there approach for setting up larger applications.
Another way is put your lib path in ~/.erlang.
code:add_pathz("/Users/brucexin/sources/mochiweb/ebin").
code:add_pathz("/Users/brucexin/sources/webnesia/ebin").
code:add_pathz("./ebin").
code:add_pathz("/Users/brucexin/sources/erlang-history/ebin/2.15.2").

Resources