Automate transpiling entire Dart project into single file? - dart

I'm new to Dart and trying to understand the JavaScript compilation process. After doing to reading, I can't seem to find a way to automatically build an entire project of Dart files at once. Am I missing something?
Thanks

If you run the generate javascript command on any dart project with a main method, all code required by the project in question is automatically compiled to the javascript output file.

Related

dart language: How to get all the classes available to import?

Programmatically I want to get all dart files available to import.
How can I achievement this? (programmatically)
In which environment do you want that?
If it's for a single Pub package, ensure that dart pub get has been run, then parse the .dart_tool/package_config.json file and find the roots of all the packages. Then search through those directories for all dart files that are not part files (does not start with part of ...;). The rest should be Dart library files which can be imported.
If you only want the packages that can be imported from inside lib/, you may want to parse the pubspec.yaml file too, so you can ignore the dev_dependencies.
Then you may also want to list the available dart:... platform libraries. Which are available depends on which platform you compile for. You need to figure that out somehow, then you should just keep a list for each platform.

Run lib build of lib from a project with pub

I'm actually on multiple dart projects which can share code. (based on this exemple)
This common code use a library named json_serializable
I'm using it to generate json serialization et deserialization methods for my user model.
I can use the commande pub run build_runner build to start the build. This way I can generate user_model.g.dart (which contains generated serialization and deserialization methods) from user_model.dart
Back to my project I'm adding my shared code as a dependency.
I'd like to use my user_model.dart but there is an error saying that user_model.g.dart doesn't exist. Indeed I haven't launch the build to generate this file.
I'm trying to find a way to launch this generation of code needed by my library but this must be done from my project.
I think I need to add a build file in my lib but I can't find how to do it :/
Schema :
Project X --using--> Lib Sharing Code --using--> json_serialization
You need to commit generated code.
build_runner can only generate code in the project it is run in, not in dependencies.

Add frameworks to a xcode project using command line

We are creating a framework and want to offer an easy way for a user to add it in their project. Possibly a script which will add framework into the project without any xcode interaction.
mod-pbxproj appears to be an option but also looking for other options, preferably shell script based options.
I looked at .pbxproj file and I think it would be straightforward to copy and add framework files, however, some inputs of structure will be appreciated.
Please do not suggest Cocoapods/Carthage, we are looking for 100% command line option and both these options require some form of xcode interaction.

Dart project structure for apps (not libs)

I am trying to understand Dart's recommended project structure and not seeing the "forest through the trees".
So, if my project is intended to be a reusable library, say, a logging framework of some sort, then if I understand the above link correctly, I want all of my development to be under a lib and lib/src directory.
But what if I am building a web app? Where do my Dart source files go? Under packages? Specifically:
Where do I place Dart source files for a web app (not a lib)?
Are my web app's "packages" just directories that are logically organized similar to Java packages?
Does Dart recommend a 1-class-per-file convention for its source code?
1)
your_app_package/web
your_app_package/web/src/xxx
static content like jpg, css go to
* your_app_package/asset
2) the packages directory is maintained automatically. You configure in the file pubspec.yaml which 3rd party libraries you want to use and then call pub get or pub upgrade and the packages directory is updated automatically (the Darteditor does this automatically when you update pubspec.yaml).
3) not that I know of.
I had some problems putting additional classed in the code file of a Polymer element though. But I guess this is just a temporary limitation of Polymer.

How to generate javascript with Dart editor

When I select Tools > Generate Javascript in Dart editor, I get an error message saying that I need to select a Dart library. I want to convert the entire project into javascript. I can't figure out how to do that.
In the menu,
Tools > Pub build
Then the generated javascript will be created in the /build/web folder.
Source
You need to select a dart file in a project that has a main function. Then you can use Tools > Generate Javascript to generate the Javascript. Dart automatically find all dependencies and compiles them to Javascript. If you have multiple projects that you want to compile, you need to do it for every project.

Resources