How to change the name of the pub packages folder? - dart

I have a little problem with developing. For my projects I use the IDE, which has some folder layout conventions. Now I started to work with dart, but the Pub Package Layout Conventions seems not to allow me to change the name of the "packages" folder to "applications".
Is there any way, how to change the Pub Package Layout Conventions in the settings file in sdk? My goal is, that running "pub get" downloads dependencies to another folder than packages folder.

You can't rename the packages folder.

Related

How can I configure pub to copy a file from the root directory of my project to build/web?

As part of the pub build process, I would like pub to copy a file from $PROJECT_ROOT/third_party/foo/foo.png to $PROJECT_ROOT/build/web/foo.png to make it accessible to my code at runtime. How can I configure pub to copy the file for me using pubspec.yaml?
You can't.
You can use for example Grinder and automate your build tasks with it. It makes it easy to invoke pub build and copying files with a few lines of Dart code.
You can use symlink for that. It will be automatically copied during pub build to your build directory and will always be the same file as in your root directory during debug.
You may symlink the whole folder or single file to your web folder.
pub does exactly the same with packages folder. In linux or macosx its quite easy using ln -s command. In windows, here is good explanation how to do that.

Dart pub get generates link to packages in each folder and subfolders

I try to avoid Dart to generate symbolic links (to packages) in each folder/sub-folder. For example, in pubspec.yaml I add polymer package and run pub get. After that I got:
Now each folder has packages symbolic link! As I understand it's because to ensure that we can use package:.. statement in any Dart file in any subdirectory.
I've already read the following topic (Why is dart pub suddenly trying to install packages in my css folder?), but it was created 2 years ago. Maybe something new here? How can I specify folders to exclude generating links by pub?
These symlinks are necessary for many tools. You can use the experimental command line option --no-package-symlinks for pub get/pub upgrade to disable symlink creation. I tried this a while ago but the DartEditor debugger stopped working (see http://dartbug.com/21749).
There are plans to get rid of symlinks entirely. A proposal exists and I assume it will be implemented within a few months (no promises).
Update
No packages directory and no symlinks might become default with Dart 1.13.

Dart Package Management via dart2js

I'm learning Dart and its dependency manager pub and am having a tough time seeing the "forest through the trees" here.
Say I want to use Polymer.dart in my project. So, in my project root, I create the following pubspec.yaml:
name: test_dart
description: A sample web application
dependencies:
browser: any
polymer: ">=0.9.0 <0.10.0"
I then run pub get, which goes to the pub repo and fetches the browser and polymer dependencies that I've specified. It then creates a packages directory in my project root, which now means I have a project that looks like:
MyDartProject/
pubspec.yaml
myapp.dart
packages/
browser/
...
...all the packages that ship with Polymer
Now I start coding my Dart web app (myapp.dart), which will references various Polymer and browser types/functions/etc. in its source code.
When I'm all done, I want to create a JavaScript file called myapp.js.
According to the dart2js docs, I need to run something like:
dart2js --out=myapp.js --package-root=??? myapp.dart
How do I include all the browser & polymer packages on the buildpath?
There is a "pub build" option now.
http://pub.dartlang.org/doc/pub-build.html
Use pub build when you’re ready to deploy your web app. When you run
pub build, it generates the assets for the current package and all of
its dependencies, putting them into a new directory named build.
$ cd ~/dart/helloworld
$ pub build
Building helloworld......
Built 5 files!
If the build directory already exists, pub build deletes it and then creates it again.
That should do everything you are after here. You can also launch it from the IDE by right clicking on the pubspec.yaml file and choose "pub build"
EDIT: You should also see the links in zoechi's answer.
If you run dart2js from your MyDartProject directory you don't have to provide --package-root parameter.
An alternative way is running pub build. If you use Polymer you need to add a transformers section.
see also
How to deploy a Dart Polymer app to Javascript using dart2js
How do I pass multiple entry_points to polymer transformer in pubspec.yaml?

Add package link in a custom folder

I have create a folder (named webapp) in a Dart project where I put some server side classes. When I run pub install ( or pub update ), to import the libraries that I use in the project, the dependencies are correctly download and some link to this folder are created in some default folders ( eg: web, out ecc ).
there is a way to generate automatically a link to the package folder in my webapp ( or any custom folder ) folder?
I don't think it is possible to make pub generate packages in a not standard directory.
In pub install documentation you can read the section Linked packages directories :
It assumes your package is laid out according to the package layout guide, and creates a linked packages directory in bin/, test/, and example/, as well as their subdirectories.

Pub install fail, Package "html5lib" doesn't have a pubspec.yaml file

I've created a simple project. This is my pubspec.yaml
name: testapp
description: test application
dependencies:
html5lib: 0.0.12
And now i get this error
Pub install fail, Resolving dependencies...
Package "html5lib" doesn't have a pubspec.yaml file.
I'm guessing you are on windows? Dart seems to setup shortcuts (hard dir links?) between the packages folder in a project and where the packages are stored. So if you delete your packages dir from within Eclipse, it will trash the folder that stores the actual package.
On Windows 7, the folder is:
C:\Users\[user]\AppData\Roaming\Pub\
Go ahead and delete its contents and run pub install again.
If you start getting errors about UnitTest or other core libraries, you may need to re-download the Dark-SDK (or dart editor) and replace it.

Resources