|
| 1 | +// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file |
| 2 | +// for details. All rights reserved. Use of this source code is governed by a |
| 3 | +// BSD-style license that can be found in the LICENSE file. |
| 4 | + |
| 5 | +// INSTRUCTIONS: |
| 6 | + |
| 7 | +// Builds the unminifed dart2js extension (see DDC issue: |
| 8 | +// see DDC issue: https://github.com/dart-lang/sdk/issues/49869). |
| 9 | + |
| 10 | +// Run from the extension root directory: |
| 11 | +// - For dev: dart run tool/build_extension.dart |
| 12 | +// - For prod: dart run tool/build_extension.dart prod |
| 13 | + |
| 14 | +import 'dart:io'; |
| 15 | + |
| 16 | +import 'package:args/args.dart'; |
| 17 | +import 'package:path/path.dart' as p; |
| 18 | + |
| 19 | +const prodFlag = 'prod'; |
| 20 | + |
| 21 | +void main(List<String> arguments) { |
| 22 | + exitCode = 0; // presume success |
| 23 | + final parser = ArgParser() |
| 24 | + ..addFlag(prodFlag, negatable: true, defaultsTo: false); |
| 25 | + final argResults = parser.parse(arguments); |
| 26 | + |
| 27 | + run(isProd: argResults[prodFlag] as bool); |
| 28 | +} |
| 29 | + |
| 30 | +Future<void> run({required bool isProd}) async { |
| 31 | + logInfo('Building extension for ${isProd ? 'prod' : 'dev'}'); |
| 32 | + logInfo('Compiling extension with dart2js to /compiled directory'); |
| 33 | + logOutput( |
| 34 | + await Process.run( |
| 35 | + 'dart', |
| 36 | + ['run', 'build_runner', 'build', 'web', '--output', 'build', '--release'], |
| 37 | + ), |
| 38 | + ); |
| 39 | + logInfo('Updating manifest.json in /compiled directory.'); |
| 40 | + logOutput( |
| 41 | + await Process.run( |
| 42 | + 'dart', |
| 43 | + [p.join('tool', 'update_dev_files.dart')], |
| 44 | + ), |
| 45 | + ); |
| 46 | +} |
| 47 | + |
| 48 | +void logInfo(String message) { |
| 49 | + print('[BUILD STEP] $message'); |
| 50 | +} |
| 51 | + |
| 52 | +void logOutput(ProcessResult result) { |
| 53 | + final output = result.stdout; |
| 54 | + final outputList = output is List ? output : [output ?? '']; |
| 55 | + print(outputList.map((output) => '$output').join('\n')); |
| 56 | +} |
0 commit comments