|
| 1 | +// Copyright (c) 2024, 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 | +import 'package:pub_dev/package/api_export/api_exporter.dart'; |
| 6 | + |
| 7 | +import 'actions.dart'; |
| 8 | + |
| 9 | +final exportedApiSync = AdminAction( |
| 10 | + name: 'exported-api-sync', |
| 11 | + summary: 'Synchronize exported API bucket', |
| 12 | + description: ''' |
| 13 | +This command will trigger synchronization of exported API bucket. |
| 14 | +
|
| 15 | +This is the bucket from which API responses are served. |
| 16 | +
|
| 17 | +This synchronize packages specified with: |
| 18 | + --packages="foo bar" |
| 19 | +
|
| 20 | +Synchronize all packages with: |
| 21 | + --packages=ALL |
| 22 | +
|
| 23 | +Optionally, write rewrite of all files using: |
| 24 | + --force-write=true |
| 25 | +''', |
| 26 | + options: { |
| 27 | + 'packages': 'Space separated list of packages, use "ALL" for all!', |
| 28 | + 'force-write': 'true/false if writes should be forced (default: false)', |
| 29 | + }, |
| 30 | + invoke: (options) async { |
| 31 | + final forceWriteString = options['force-write'] ?? 'false'; |
| 32 | + InvalidInputException.checkAnyOf( |
| 33 | + forceWriteString, |
| 34 | + 'force-write', |
| 35 | + ['true', 'false'], |
| 36 | + ); |
| 37 | + final forceWrite = forceWriteString == 'true'; |
| 38 | + |
| 39 | + final packagesOpt = options['packages'] ?? ''; |
| 40 | + final syncAll = packagesOpt == 'ALL'; |
| 41 | + if (syncAll) { |
| 42 | + await apiExporter!.synchronizeExportedApi(forceWrite: forceWrite); |
| 43 | + return { |
| 44 | + 'packages': 'ALL', |
| 45 | + 'forceWrite': forceWrite, |
| 46 | + }; |
| 47 | + } else { |
| 48 | + final packages = packagesOpt.split(' ').map((p) => p.trim()).toList(); |
| 49 | + for (final p in packages) { |
| 50 | + InvalidInputException.checkPackageName(p); |
| 51 | + } |
| 52 | + for (final p in packages) { |
| 53 | + await apiExporter!.synchronizePackage(p, forceWrite: forceWrite); |
| 54 | + } |
| 55 | + return { |
| 56 | + 'packages': packages, |
| 57 | + 'forceWrite': forceWrite, |
| 58 | + }; |
| 59 | + } |
| 60 | + }, |
| 61 | +); |
0 commit comments