build_web.dart 1.73 KB
Newer Older
1 2 3 4 5 6
// Copyright 2019 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/common.dart';
8
import '../build_info.dart';
9
import '../features.dart';
10
import '../project.dart';
11 12
import '../runner/flutter_command.dart'
    show DevelopmentArtifact, FlutterCommandResult;
13 14 15 16 17 18 19
import '../web/compile.dart';
import 'build.dart';

class BuildWebCommand extends BuildSubCommand {
  BuildWebCommand() {
    usesTargetOption();
    usesPubOption();
20
    addBuildModeFlags(excludeDebug: true);
21 22 23 24 25 26
    argParser.addFlag('web-initialize-platform',
        defaultsTo: true,
        negatable: true,
        hide: true,
        help: 'Whether to automatically invoke webOnlyInitializePlatform.',
    );
27 28
  }

29
  @override
30 31 32 33 34
  Future<Set<DevelopmentArtifact>> get requiredArtifacts async =>
      const <DevelopmentArtifact>{
        DevelopmentArtifact.universal,
        DevelopmentArtifact.web,
      };
35

36 37 38 39
  @override
  final String name = 'web';

  @override
40
  bool get hidden => !featureFlags.isWebEnabled;
41

42
  @override
43
  final String description = 'build a web application bundle.';
44 45 46

  @override
  Future<FlutterCommandResult> runCommand() async {
47 48 49
    if (!featureFlags.isWebEnabled) {
      throwToolExit('"build web" is not currently supported.');
    }
50
    final FlutterProject flutterProject = FlutterProject.current();
51
    final String target = argResults['target'];
52
    final BuildInfo buildInfo = getBuildInfo();
53 54 55
    if (buildInfo.isDebug) {
      throwToolExit('debug builds cannot be built directly for the web. Try using "flutter run"');
    }
56
    await buildWeb(flutterProject, target, buildInfo, argResults['web-initialize-platform']);
57
    return null;
58 59
  }
}