custom_devices_common.dart 2.18 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
// Copyright 2014 The Flutter 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 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/convert.dart';
import 'package:flutter_tools/src/custom_devices/custom_device_config.dart';

void writeCustomDevicesConfigFile(
  Directory dir, {
11
  List<CustomDeviceConfig>? configs,
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
  dynamic json
}) {
  dir.createSync(recursive: true);

  final File file = dir.childFile('.flutter_custom_devices.json');
  file.writeAsStringSync(jsonEncode(
    <String, dynamic>{
      'custom-devices': configs != null ?
        configs.map<dynamic>((CustomDeviceConfig c) => c.toJson()).toList() :
        json
    },
  ));
}

final CustomDeviceConfig testConfig = CustomDeviceConfig(
  id: 'testid',
  label: 'testlabel',
  sdkNameAndVersion: 'testsdknameandversion',
  enabled: true,
  pingCommand: const <String>['testping'],
  pingSuccessRegex: RegExp('testpingsuccess'),
  postBuildCommand: const <String>['testpostbuild'],
  installCommand: const <String>['testinstall'],
  uninstallCommand: const <String>['testuninstall'],
  runDebugCommand: const <String>['testrundebug'],
  forwardPortCommand: const <String>['testforwardport'],
  forwardPortSuccessRegex: RegExp('testforwardportsuccess')
);

const String testConfigPingSuccessOutput = 'testpingsuccess\n';
const String testConfigForwardPortSuccessOutput = 'testforwardportsuccess\n';
final CustomDeviceConfig disabledTestConfig = testConfig.copyWith(enabled: false);
final CustomDeviceConfig testConfigNonForwarding = testConfig.copyWith(
  explicitForwardPortCommand: true,
  explicitForwardPortSuccessRegex: true,
);

const Map<String, dynamic> testConfigJson = <String, dynamic>{
  'id': 'testid',
  'label': 'testlabel',
  'sdkNameAndVersion': 'testsdknameandversion',
  'enabled': true,
  'ping': <String>['testping'],
  'pingSuccessRegex': 'testpingsuccess',
  'postBuild': <String>['testpostbuild'],
  'install': <String>['testinstall'],
  'uninstall': <String>['testuninstall'],
  'runDebug': <String>['testrundebug'],
  'forwardPort': <String>['testforwardport'],
  'forwardPortSuccessRegex': 'testforwardportsuccess'
};