build_web.dart 1.8 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
    usesDartDefines();
22 23 24 25 26 27
    argParser.addFlag('web-initialize-platform',
        defaultsTo: true,
        negatable: true,
        hide: true,
        help: 'Whether to automatically invoke webOnlyInitializePlatform.',
    );
28 29
  }

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

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

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

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

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