build.dart 1.79 KB
Newer Older
1 2 3 4 5 6
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:async';

7
import '../base/context.dart';
8
import '../flx.dart';
9
import '../runner/flutter_command.dart';
10
import '../toolchain.dart';
11

12 13
class BuildCommand extends FlutterCommand {
  final String name = 'build';
14
  final String description = 'Packages your Flutter app into an FLX.';
15

16
  BuildCommand() {
17
    argParser.addFlag('precompiled', negatable: false);
18
    argParser.addOption('asset-base', defaultsTo: defaultAssetBase);
19
    argParser.addOption('compiler');
20 21 22 23 24
    argParser.addOption('main', defaultsTo: defaultMainPath);
    argParser.addOption('manifest', defaultsTo: defaultManifestPath);
    argParser.addOption('private-key', defaultsTo: defaultPrivateKeyPath);
    argParser.addOption('output-file', abbr: 'o', defaultsTo: defaultFlxOutputPath);
    argParser.addOption('snapshot', defaultsTo: defaultSnapshotPath);
25 26
  }

27
  Future<int> runInProject() async {
28 29 30 31 32 33 34
    String compilerPath = argResults['compiler'];

    if (compilerPath == null)
      await downloadToolchain();
    else
      toolchain = new Toolchain(compiler: new Compiler(compilerPath));

35 36
    String outputPath = argResults['output-file'];

37
    return await build(
38
      toolchain,
39 40 41
      assetBase: argResults['asset-base'],
      mainPath: argResults['main'],
      manifestPath: argResults['manifest'],
42
      outputPath: outputPath,
43
      snapshotPath: argResults['snapshot'],
44 45
      privateKeyPath: argResults['private-key'],
      precompiledSnapshot: argResults['precompiled']
46
    ).then((int result) {
47
      if (result == 0)
48
        printStatus('Built $outputPath.');
49
      else
50
        printError('Error building $outputPath: $result.');
51 52
      return result;
    });
53 54
  }
}