官术网_书友最值得收藏!

Using the command-line tools

Some things can be done more easily on the command-line, or are simply not (yet) included in Dart Editor. These tools are found in dart-sdk/bin. They consist of the following:

  • dart: The standalone Dart VM to run Dart command-line apps, such as server-side scripts and server apps
  • dartanalyzer: This is used to check code statically
  • pub: This is the package and repository manager
  • dartfmt: This is the code formatting tool
  • docgen: This is the documentation generator tool

How to do it...

  1. For every tool, it might be useful to know or check its version. This is done with the -- version option such as dart --version with a typical output of Dart VM version: 1.3.0 (Tue Apr 08 09:06:23 2014) on "windows_ia32".
  2. The dart –v –h option lists and discusses all the possible options of the VM. Many tools also take the --package_root=<path> or –p=<path> option to indicate where the packages used in the imports reside on the filesystem.
  3. dartanalyzer is written in Java and works in Dart Editor whenever a project is imported or Dart code is changed; it is started dartanalyzer prorabbits.dart with output:

    Analyzing prorabbits.dart...

    No issues found (or possibly errors and hints to improve the code)

  4. The previous output verifies that the code conforms to the language specification https://www.dartlang.org/docs/spec/, pub functionality is built into Dart Editor, but the tool can also be used from the command line (refer to test_pub). To fetch packages (for example, for the test_pub app), use the following command in the folder where pubspec.yaml lives, pub get, with a typical output as follows:
    Resolving dependencies... (6.6s)
    Got dependencies!
  5. A packages folder is created with symlinks to the central package cache on your machine. The latest versions are downloaded and the package versions are registered in the pubspec.lock file, so that your app can only use these versions.
  6. If you want to get a newer version of a package, use the pub upgrade command. You can use the –v and -- trace options to produce a detailed output to verify its workings.

    Tip

    Always do a pub upgrade if the project you start working on already contains versions of packages!

  7. The dartfmt tool is also a built in Dart Editor. Right-click on any Dart file and choose Format from the context menu. This applies transformations to the code so that it conforms to the Dart Style Guide, which can be seen at then the default operation mode is cleaning up whitespace. Use the –t option to apply code transforms such as dartfmt -t –w bank_terminal.dart.

See also

  • Solving problems when pub get fails
  • Compiling your app to JavaScript (for pub build)
  • Documenting your code from Chapter 2, Structuring, testing, and deploying an application
  • Publishing your app to a pub (for pub publishing)
  • Using snapshotting to start an app in Dart VM
  • For additional information, refer to https://www.dartlang.org/tools/
主站蜘蛛池模板: 花莲县| 冷水江市| 惠来县| 新巴尔虎右旗| 佛教| 高州市| 永德县| 长泰县| 东至县| 普兰店市| 满洲里市| 大宁县| 达孜县| 德清县| 商洛市| 育儿| 随州市| 桃江县| 盐池县| 北票市| 株洲市| 陆川县| 赤峰市| 长泰县| 揭阳市| 获嘉县| 舒兰市| 海阳市| 平度市| 兰溪市| 崇阳县| 衡东县| 津南区| 麻江县| 南投市| 始兴县| 玉门市| 内丘县| 西贡区| 丹阳市| 南华县|