2016-05-01 22:52:51 +00:00
|
|
|
// Copyright 2016 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';
|
|
|
|
import 'dart:convert';
|
|
|
|
import 'dart:io';
|
|
|
|
|
2018-02-05 17:31:18 +00:00
|
|
|
import 'package:args/args.dart';
|
2017-02-10 17:55:58 +00:00
|
|
|
import 'package:intl/intl.dart';
|
2016-05-01 22:52:51 +00:00
|
|
|
import 'package:path/path.dart' as path;
|
2018-11-10 01:51:25 +00:00
|
|
|
import 'package:process/process.dart';
|
2016-05-01 22:52:51 +00:00
|
|
|
|
2018-10-23 20:50:24 +00:00
|
|
|
const String kDocsRoot = 'dev/docs';
|
|
|
|
const String kPublishRoot = '$kDocsRoot/doc';
|
2018-11-10 01:51:25 +00:00
|
|
|
const String kSnippetsRoot = 'dev/snippets';
|
2016-05-16 15:28:58 +00:00
|
|
|
|
2016-05-01 22:52:51 +00:00
|
|
|
/// This script expects to run with the cwd as the root of the flutter repo. It
|
|
|
|
/// will generate documentation for the packages in `//packages/` and write the
|
|
|
|
/// documentation to `//dev/docs/doc/api/`.
|
2016-08-29 23:20:18 +00:00
|
|
|
///
|
2016-05-16 15:28:58 +00:00
|
|
|
/// This script also updates the index.html file so that it can be placed
|
|
|
|
/// at the root of docs.flutter.io. We are keeping the files inside of
|
|
|
|
/// docs.flutter.io/flutter for now, so we need to manipulate paths
|
|
|
|
/// a bit. See https://github.com/flutter/flutter/issues/3900 for more info.
|
2017-05-11 16:42:08 +00:00
|
|
|
///
|
|
|
|
/// This will only work on UNIX systems, not Windows. It requires that 'git' be
|
|
|
|
/// in your path. It requires that 'flutter' has been run previously. It uses
|
|
|
|
/// the version of Dart downloaded by the 'flutter' tool in this repository and
|
|
|
|
/// will crash if that is absent.
|
2018-10-04 16:44:23 +00:00
|
|
|
Future<void> main(List<String> arguments) async {
|
2018-02-05 17:31:18 +00:00
|
|
|
final ArgParser argParser = _createArgsParser();
|
|
|
|
final ArgResults args = argParser.parse(arguments);
|
|
|
|
if (args['help']) {
|
|
|
|
print ('Usage:');
|
|
|
|
print (argParser.usage);
|
|
|
|
exit(0);
|
|
|
|
}
|
2016-05-01 22:52:51 +00:00
|
|
|
// If we're run from the `tools` dir, set the cwd to the repo root.
|
|
|
|
if (path.basename(Directory.current.path) == 'tools')
|
|
|
|
Directory.current = Directory.current.parent.parent;
|
|
|
|
|
2018-01-18 15:59:06 +00:00
|
|
|
final ProcessResult flutter = Process.runSync('flutter', <String>[]);
|
2018-09-12 06:29:29 +00:00
|
|
|
final File versionFile = File('version');
|
2018-01-18 15:59:06 +00:00
|
|
|
if (flutter.exitCode != 0 || !versionFile.existsSync())
|
2018-09-12 06:29:29 +00:00
|
|
|
throw Exception('Failed to determine Flutter version.');
|
2018-01-18 15:59:06 +00:00
|
|
|
final String version = versionFile.readAsStringSync();
|
2017-06-20 18:27:37 +00:00
|
|
|
|
2016-05-01 22:52:51 +00:00
|
|
|
// Create the pubspec.yaml file.
|
2018-09-12 06:29:29 +00:00
|
|
|
final StringBuffer buf = StringBuffer();
|
2018-01-18 15:59:06 +00:00
|
|
|
buf.writeln('name: Flutter');
|
|
|
|
buf.writeln('homepage: https://flutter.io');
|
|
|
|
buf.writeln('version: $version');
|
|
|
|
buf.writeln('dependencies:');
|
2016-05-16 15:28:58 +00:00
|
|
|
for (String package in findPackageNames()) {
|
2016-05-01 22:52:51 +00:00
|
|
|
buf.writeln(' $package:');
|
2016-09-23 03:39:35 +00:00
|
|
|
buf.writeln(' sdk: flutter');
|
2016-05-01 22:52:51 +00:00
|
|
|
}
|
2017-02-10 00:12:09 +00:00
|
|
|
buf.writeln(' platform_integration: 0.0.1');
|
|
|
|
buf.writeln('dependency_overrides:');
|
|
|
|
buf.writeln(' platform_integration:');
|
|
|
|
buf.writeln(' path: platform_integration');
|
2018-10-23 20:50:24 +00:00
|
|
|
File('$kDocsRoot/pubspec.yaml').writeAsStringSync(buf.toString());
|
2016-05-01 22:52:51 +00:00
|
|
|
|
|
|
|
// Create the library file.
|
2018-10-23 20:50:24 +00:00
|
|
|
final Directory libDir = Directory('$kDocsRoot/lib');
|
2016-05-01 22:52:51 +00:00
|
|
|
libDir.createSync();
|
|
|
|
|
2018-09-12 06:29:29 +00:00
|
|
|
final StringBuffer contents = StringBuffer('library temp_doc;\n\n');
|
2016-05-16 15:28:58 +00:00
|
|
|
for (String libraryRef in libraryRefs()) {
|
2016-05-01 22:52:51 +00:00
|
|
|
contents.writeln('import \'package:$libraryRef\';');
|
|
|
|
}
|
2018-10-23 20:50:24 +00:00
|
|
|
File('$kDocsRoot/lib/temp_doc.dart').writeAsStringSync(contents.toString());
|
2016-05-01 22:52:51 +00:00
|
|
|
|
2017-12-05 22:46:39 +00:00
|
|
|
final String flutterRoot = Directory.current.path;
|
|
|
|
final Map<String, String> pubEnvironment = <String, String>{
|
|
|
|
'FLUTTER_ROOT': flutterRoot,
|
|
|
|
};
|
|
|
|
|
|
|
|
// If there's a .pub-cache dir in the flutter root, use that.
|
|
|
|
final String pubCachePath = '$flutterRoot/.pub-cache';
|
2018-09-12 06:29:29 +00:00
|
|
|
if (Directory(pubCachePath).existsSync()) {
|
2017-12-05 22:46:39 +00:00
|
|
|
pubEnvironment['PUB_CACHE'] = pubCachePath;
|
|
|
|
}
|
|
|
|
|
|
|
|
final String pubExecutable = '$flutterRoot/bin/cache/dart-sdk/bin/pub';
|
|
|
|
|
2016-05-01 22:52:51 +00:00
|
|
|
// Run pub.
|
2018-11-10 01:51:25 +00:00
|
|
|
ProcessWrapper process = ProcessWrapper(await Process.start(
|
2017-12-05 22:46:39 +00:00
|
|
|
pubExecutable,
|
2017-05-11 16:42:08 +00:00
|
|
|
<String>['get'],
|
2018-10-23 20:50:24 +00:00
|
|
|
workingDirectory: kDocsRoot,
|
2017-12-05 22:46:39 +00:00
|
|
|
environment: pubEnvironment,
|
2018-11-10 01:51:25 +00:00
|
|
|
));
|
2017-07-28 22:44:38 +00:00
|
|
|
printStream(process.stdout, prefix: 'pub:stdout: ');
|
|
|
|
printStream(process.stderr, prefix: 'pub:stderr: ');
|
2018-11-10 01:51:25 +00:00
|
|
|
final int code = await process.done;
|
2016-05-01 22:52:51 +00:00
|
|
|
if (code != 0)
|
|
|
|
exit(code);
|
|
|
|
|
2018-10-23 20:50:24 +00:00
|
|
|
createFooter('$kDocsRoot/lib/footer.html');
|
|
|
|
copyAssets();
|
|
|
|
cleanOutSnippets();
|
2017-02-10 17:55:58 +00:00
|
|
|
|
2018-02-05 17:31:18 +00:00
|
|
|
final List<String> dartdocBaseArgs = <String>['global', 'run'];
|
|
|
|
if (args['checked']) {
|
|
|
|
dartdocBaseArgs.add('-c');
|
|
|
|
}
|
|
|
|
dartdocBaseArgs.add('dartdoc');
|
|
|
|
|
2017-04-19 17:00:18 +00:00
|
|
|
// Verify which version of dartdoc we're using.
|
2017-05-11 16:42:08 +00:00
|
|
|
final ProcessResult result = Process.runSync(
|
2017-12-05 22:46:39 +00:00
|
|
|
pubExecutable,
|
2018-02-05 17:31:18 +00:00
|
|
|
<String>[]..addAll(dartdocBaseArgs)..add('--version'),
|
2018-10-23 20:50:24 +00:00
|
|
|
workingDirectory: kDocsRoot,
|
2017-12-05 22:46:39 +00:00
|
|
|
environment: pubEnvironment,
|
2017-05-11 16:42:08 +00:00
|
|
|
);
|
2018-01-18 15:59:06 +00:00
|
|
|
print('\n${result.stdout}flutter version: $version\n');
|
2017-04-19 17:00:18 +00:00
|
|
|
|
2018-02-05 17:31:18 +00:00
|
|
|
if (args['json']) {
|
|
|
|
dartdocBaseArgs.add('--json');
|
|
|
|
}
|
2018-02-27 22:39:42 +00:00
|
|
|
if (args['validate-links']) {
|
|
|
|
dartdocBaseArgs.add('--validate-links');
|
|
|
|
} else {
|
|
|
|
dartdocBaseArgs.add('--no-validate-links');
|
|
|
|
}
|
2016-08-29 23:20:18 +00:00
|
|
|
// Generate the documentation.
|
2018-05-04 00:47:50 +00:00
|
|
|
// We don't need to exclude flutter_tools in this list because it's not in the
|
|
|
|
// recursive dependencies of the package defined at dev/docs/pubspec.yaml
|
2018-02-05 17:31:18 +00:00
|
|
|
final List<String> dartdocArgs = <String>[]..addAll(dartdocBaseArgs)..addAll(<String>[
|
2018-10-23 20:50:24 +00:00
|
|
|
'--inject-html',
|
2016-05-01 22:52:51 +00:00
|
|
|
'--header', 'styles.html',
|
|
|
|
'--header', 'analytics.html',
|
2017-11-29 17:07:04 +00:00
|
|
|
'--header', 'survey.html',
|
2018-10-23 20:50:24 +00:00
|
|
|
'--header', 'snippets.html',
|
2017-05-25 16:42:55 +00:00
|
|
|
'--footer-text', 'lib/footer.html',
|
2017-12-08 16:08:49 +00:00
|
|
|
'--exclude-packages',
|
2018-10-23 20:50:24 +00:00
|
|
|
<String>[
|
|
|
|
'analyzer',
|
|
|
|
'args',
|
|
|
|
'barback',
|
|
|
|
'cli_util',
|
|
|
|
'csslib',
|
|
|
|
'flutter_goldens',
|
2018-11-10 01:51:25 +00:00
|
|
|
'flutter_goldens_client',
|
2018-10-23 20:50:24 +00:00
|
|
|
'front_end',
|
|
|
|
'fuchsia_remote_debug_protocol',
|
|
|
|
'glob',
|
|
|
|
'html',
|
|
|
|
'http_multi_server',
|
|
|
|
'io',
|
|
|
|
'isolate',
|
|
|
|
'js',
|
|
|
|
'kernel',
|
|
|
|
'logging',
|
|
|
|
'mime',
|
|
|
|
'mockito',
|
|
|
|
'node_preamble',
|
|
|
|
'plugin',
|
|
|
|
'shelf',
|
|
|
|
'shelf_packages_handler',
|
|
|
|
'shelf_static',
|
|
|
|
'shelf_web_socket',
|
|
|
|
'utf',
|
|
|
|
'watcher',
|
|
|
|
'yaml',
|
|
|
|
].join(','),
|
2017-12-08 16:08:49 +00:00
|
|
|
'--exclude',
|
2018-10-23 20:50:24 +00:00
|
|
|
<String>[
|
|
|
|
'package:Flutter/temp_doc.dart',
|
|
|
|
'package:http/browser_client.dart',
|
|
|
|
'package:intl/intl_browser.dart',
|
|
|
|
'package:matcher/mirror_matchers.dart',
|
|
|
|
'package:quiver/io.dart',
|
|
|
|
'package:quiver/mirrors.dart',
|
|
|
|
'package:vm_service_client/vm_service_client.dart',
|
|
|
|
'package:web_socket_channel/html.dart',
|
|
|
|
].join(','),
|
2016-05-01 22:52:51 +00:00
|
|
|
'--favicon=favicon.ico',
|
2018-11-10 01:51:25 +00:00
|
|
|
'--package-order', 'flutter,Dart,platform_integration,flutter_test,flutter_driver',
|
2017-07-28 22:44:38 +00:00
|
|
|
'--auto-include-dependencies',
|
2018-02-05 17:31:18 +00:00
|
|
|
]);
|
2016-05-01 22:52:51 +00:00
|
|
|
|
2018-03-30 19:19:44 +00:00
|
|
|
String quote(String arg) => arg.contains(' ') ? "'$arg'" : arg;
|
2018-10-23 20:50:24 +00:00
|
|
|
print('Executing: (cd $kDocsRoot ; $pubExecutable ${dartdocArgs.map<String>(quote).join(' ')})');
|
2018-03-30 19:19:44 +00:00
|
|
|
|
2018-11-10 01:51:25 +00:00
|
|
|
process = ProcessWrapper(await Process.start(
|
2017-12-05 22:46:39 +00:00
|
|
|
pubExecutable,
|
2018-02-05 17:31:18 +00:00
|
|
|
dartdocArgs,
|
2018-10-23 20:50:24 +00:00
|
|
|
workingDirectory: kDocsRoot,
|
2017-12-05 22:46:39 +00:00
|
|
|
environment: pubEnvironment,
|
2018-11-10 01:51:25 +00:00
|
|
|
));
|
2018-02-05 17:31:18 +00:00
|
|
|
printStream(process.stdout, prefix: args['json'] ? '' : 'dartdoc:stdout: ',
|
|
|
|
filter: args['verbose'] ? const <Pattern>[] : <Pattern>[
|
2018-09-12 06:29:29 +00:00
|
|
|
RegExp(r'^generating docs for library '), // unnecessary verbosity
|
|
|
|
RegExp(r'^pars'), // unnecessary verbosity
|
2017-07-28 22:44:38 +00:00
|
|
|
],
|
|
|
|
);
|
2018-02-05 17:31:18 +00:00
|
|
|
printStream(process.stderr, prefix: args['json'] ? '' : 'dartdoc:stderr: ',
|
|
|
|
filter: args['verbose'] ? const <Pattern>[] : <Pattern>[
|
2018-09-12 06:29:29 +00:00
|
|
|
RegExp(r'^ warning: .+: \(.+/\.pub-cache/hosted/pub.dartlang.org/.+\)'), // packages outside our control
|
2017-07-28 22:44:38 +00:00
|
|
|
],
|
|
|
|
);
|
2018-11-10 01:51:25 +00:00
|
|
|
final int exitCode = await process.done;
|
2016-05-16 15:28:58 +00:00
|
|
|
|
|
|
|
if (exitCode != 0)
|
|
|
|
exit(exitCode);
|
|
|
|
|
2016-11-09 23:16:13 +00:00
|
|
|
sanityCheckDocs();
|
|
|
|
|
2016-05-16 15:28:58 +00:00
|
|
|
createIndexAndCleanup();
|
|
|
|
}
|
|
|
|
|
2018-02-05 17:31:18 +00:00
|
|
|
ArgParser _createArgsParser() {
|
2018-09-12 06:29:29 +00:00
|
|
|
final ArgParser parser = ArgParser();
|
2018-02-05 17:31:18 +00:00
|
|
|
parser.addFlag('help', abbr: 'h', negatable: false,
|
|
|
|
help: 'Show command help.');
|
|
|
|
parser.addFlag('verbose', negatable: true, defaultsTo: true,
|
|
|
|
help: 'Whether to report all error messages (on) or attempt to '
|
|
|
|
'filter out some known false positives (off). Shut this off '
|
|
|
|
'locally if you want to address Flutter-specific issues.');
|
|
|
|
parser.addFlag('checked', abbr: 'c', negatable: true,
|
|
|
|
help: 'Run dartdoc in checked mode.');
|
|
|
|
parser.addFlag('json', negatable: true,
|
|
|
|
help: 'Display json-formatted output from dartdoc and skip stdout/stderr prefixing.');
|
2018-02-27 22:39:42 +00:00
|
|
|
parser.addFlag('validate-links', negatable: true,
|
|
|
|
help: 'Display warnings for broken links generated by dartdoc (slow)');
|
2018-02-05 17:31:18 +00:00
|
|
|
return parser;
|
|
|
|
}
|
|
|
|
|
2018-09-12 06:29:29 +00:00
|
|
|
final RegExp gitBranchRegexp = RegExp(r'^## (.*)');
|
2018-08-17 21:10:33 +00:00
|
|
|
|
2017-02-10 17:55:58 +00:00
|
|
|
void createFooter(String footerPath) {
|
2017-10-13 20:31:32 +00:00
|
|
|
const int kGitRevisionLength = 10;
|
|
|
|
|
2018-08-17 21:10:33 +00:00
|
|
|
ProcessResult gitResult = Process.runSync('git', <String>['rev-parse', 'HEAD']);
|
2018-01-18 15:59:06 +00:00
|
|
|
if (gitResult.exitCode != 0)
|
2018-08-17 21:10:33 +00:00
|
|
|
throw 'git rev-parse exit with non-zero exit code: ${gitResult.exitCode}';
|
2018-01-18 15:59:06 +00:00
|
|
|
String gitRevision = gitResult.stdout.trim();
|
|
|
|
|
2018-08-17 21:10:33 +00:00
|
|
|
gitResult = Process.runSync('git', <String>['status', '-b', '--porcelain']);
|
|
|
|
if (gitResult.exitCode != 0)
|
|
|
|
throw 'git status exit with non-zero exit code: ${gitResult.exitCode}';
|
|
|
|
final Match gitBranchMatch = gitBranchRegexp.firstMatch(
|
|
|
|
gitResult.stdout.trim().split('\n').first);
|
2018-08-23 17:25:15 +00:00
|
|
|
final String gitBranchOut = gitBranchMatch == null ? '' : '• </span class="no-break">${gitBranchMatch.group(1).split('...').first}</span>';
|
2018-08-17 21:10:33 +00:00
|
|
|
|
2017-10-13 20:31:32 +00:00
|
|
|
gitRevision = gitRevision.length > kGitRevisionLength ? gitRevision.substring(0, kGitRevisionLength) : gitRevision;
|
2017-02-10 17:55:58 +00:00
|
|
|
|
2018-09-12 06:29:29 +00:00
|
|
|
final String timestamp = DateFormat('yyyy-MM-dd HH:mm').format(DateTime.now());
|
2017-02-10 17:55:58 +00:00
|
|
|
|
2018-09-12 06:29:29 +00:00
|
|
|
File(footerPath).writeAsStringSync(<String>[
|
2018-08-17 21:10:33 +00:00
|
|
|
'• </span class="no-break">$timestamp<span>',
|
|
|
|
'• </span class="no-break">$gitRevision</span>',
|
|
|
|
gitBranchOut].join(' '));
|
2017-02-10 17:55:58 +00:00
|
|
|
}
|
|
|
|
|
2018-10-23 20:50:24 +00:00
|
|
|
/// Recursively copies `srcDir` to `destDir`, invoking [onFileCopied], if
|
|
|
|
/// specified, for each source/destination file pair.
|
|
|
|
///
|
|
|
|
/// Creates `destDir` if needed.
|
|
|
|
void copyDirectorySync(Directory srcDir, Directory destDir, [void onFileCopied(File srcFile, File destFile)]) {
|
|
|
|
if (!srcDir.existsSync())
|
|
|
|
throw Exception('Source directory "${srcDir.path}" does not exist, nothing to copy');
|
|
|
|
|
|
|
|
if (!destDir.existsSync())
|
|
|
|
destDir.createSync(recursive: true);
|
|
|
|
|
|
|
|
for (FileSystemEntity entity in srcDir.listSync()) {
|
|
|
|
final String newPath = path.join(destDir.path, path.basename(entity.path));
|
|
|
|
if (entity is File) {
|
|
|
|
final File newFile = File(newPath);
|
|
|
|
entity.copySync(newPath);
|
|
|
|
onFileCopied?.call(entity, newFile);
|
|
|
|
} else if (entity is Directory) {
|
|
|
|
copyDirectorySync(entity, Directory(newPath));
|
|
|
|
} else {
|
|
|
|
throw Exception('${entity.path} is neither File nor Directory');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void copyAssets() {
|
|
|
|
final Directory assetsDir = Directory(path.join(kPublishRoot, 'assets'));
|
|
|
|
if (assetsDir.existsSync()) {
|
|
|
|
assetsDir.deleteSync(recursive: true);
|
|
|
|
}
|
|
|
|
copyDirectorySync(
|
|
|
|
Directory(path.join(kDocsRoot, 'assets')),
|
|
|
|
Directory(path.join(kPublishRoot, 'assets')),
|
|
|
|
(File src, File dest) => print('Copied ${src.path} to ${dest.path}'));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void cleanOutSnippets() {
|
|
|
|
final Directory snippetsDir = Directory(path.join(kPublishRoot, 'snippets'));
|
|
|
|
if (snippetsDir.existsSync()) {
|
|
|
|
snippetsDir
|
|
|
|
..deleteSync(recursive: true)
|
|
|
|
..createSync(recursive: true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-09 23:16:13 +00:00
|
|
|
void sanityCheckDocs() {
|
2018-03-30 19:19:44 +00:00
|
|
|
final List<String> canaries = <String>[
|
2018-10-23 20:50:24 +00:00
|
|
|
'$kPublishRoot/assets/overrides.css',
|
|
|
|
'$kPublishRoot/api/dart-io/File-class.html',
|
|
|
|
'$kPublishRoot/api/dart-ui/Canvas-class.html',
|
|
|
|
'$kPublishRoot/api/dart-ui/Canvas/drawRect.html',
|
|
|
|
'$kPublishRoot/api/flutter_driver/FlutterDriver/FlutterDriver.connectedTo.html',
|
|
|
|
'$kPublishRoot/api/flutter_test/WidgetTester/pumpWidget.html',
|
|
|
|
'$kPublishRoot/api/material/Material-class.html',
|
|
|
|
'$kPublishRoot/api/material/Tooltip-class.html',
|
|
|
|
'$kPublishRoot/api/widgets/Widget-class.html',
|
2016-11-09 23:16:13 +00:00
|
|
|
];
|
|
|
|
for (String canary in canaries) {
|
2018-09-12 06:29:29 +00:00
|
|
|
if (!File(canary).existsSync())
|
|
|
|
throw Exception('Missing "$canary", which probably means the documentation failed to build correctly.');
|
2016-11-09 23:16:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-16 15:28:58 +00:00
|
|
|
/// Creates a custom index.html because we try to maintain old
|
|
|
|
/// paths. Cleanup unused index.html files no longer needed.
|
|
|
|
void createIndexAndCleanup() {
|
2018-10-23 20:50:24 +00:00
|
|
|
print('\nCreating a custom index.html in $kPublishRoot/index.html');
|
2016-05-16 20:05:13 +00:00
|
|
|
removeOldFlutterDocsDir();
|
2016-05-16 15:28:58 +00:00
|
|
|
renameApiDir();
|
|
|
|
copyIndexToRootOfDocs();
|
|
|
|
addHtmlBaseToIndex();
|
2018-03-30 19:19:44 +00:00
|
|
|
changePackageToSdkInTitlebar();
|
2016-05-16 15:28:58 +00:00
|
|
|
putRedirectInOldIndexLocation();
|
|
|
|
print('\nDocs ready to go!');
|
|
|
|
}
|
|
|
|
|
2016-05-16 20:05:13 +00:00
|
|
|
void removeOldFlutterDocsDir() {
|
|
|
|
try {
|
2018-10-23 20:50:24 +00:00
|
|
|
Directory('$kPublishRoot/flutter').deleteSync(recursive: true);
|
2018-08-17 20:17:23 +00:00
|
|
|
} on FileSystemException {
|
2016-05-16 20:05:13 +00:00
|
|
|
// If the directory does not exist, that's OK.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-16 15:28:58 +00:00
|
|
|
void renameApiDir() {
|
2018-10-23 20:50:24 +00:00
|
|
|
Directory('$kPublishRoot/api').renameSync('$kPublishRoot/flutter');
|
2016-05-16 15:28:58 +00:00
|
|
|
}
|
|
|
|
|
2016-07-23 05:21:04 +00:00
|
|
|
void copyIndexToRootOfDocs() {
|
2018-10-23 20:50:24 +00:00
|
|
|
File('$kPublishRoot/flutter/index.html').copySync('$kPublishRoot/index.html');
|
2016-05-16 15:28:58 +00:00
|
|
|
}
|
|
|
|
|
2018-03-30 19:19:44 +00:00
|
|
|
void changePackageToSdkInTitlebar() {
|
2018-10-23 20:50:24 +00:00
|
|
|
final File indexFile = File('$kPublishRoot/index.html');
|
2018-03-30 19:19:44 +00:00
|
|
|
String indexContents = indexFile.readAsStringSync();
|
|
|
|
indexContents = indexContents.replaceFirst(
|
|
|
|
'<li><a href="https://flutter.io">Flutter package</a></li>',
|
|
|
|
'<li><a href="https://flutter.io">Flutter SDK</a></li>',
|
|
|
|
);
|
|
|
|
|
|
|
|
indexFile.writeAsStringSync(indexContents);
|
|
|
|
}
|
|
|
|
|
2016-05-16 15:28:58 +00:00
|
|
|
void addHtmlBaseToIndex() {
|
2018-10-23 20:50:24 +00:00
|
|
|
final File indexFile = File('$kPublishRoot/index.html');
|
2016-05-16 15:28:58 +00:00
|
|
|
String indexContents = indexFile.readAsStringSync();
|
2017-07-28 22:44:38 +00:00
|
|
|
indexContents = indexContents.replaceFirst(
|
|
|
|
'</title>\n',
|
|
|
|
'</title>\n <base href="./flutter/">\n',
|
|
|
|
);
|
2017-02-10 00:12:09 +00:00
|
|
|
indexContents = indexContents.replaceAll(
|
|
|
|
'href="Android/Android-library.html"',
|
2017-07-28 22:44:38 +00:00
|
|
|
'href="/javadoc/"',
|
2017-02-10 00:12:09 +00:00
|
|
|
);
|
2017-06-26 10:15:24 +00:00
|
|
|
indexContents = indexContents.replaceAll(
|
|
|
|
'href="iOS/iOS-library.html"',
|
2017-07-28 22:44:38 +00:00
|
|
|
'href="/objcdoc/"',
|
2017-06-26 10:15:24 +00:00
|
|
|
);
|
|
|
|
|
2016-05-16 15:28:58 +00:00
|
|
|
indexFile.writeAsStringSync(indexContents);
|
|
|
|
}
|
|
|
|
|
|
|
|
void putRedirectInOldIndexLocation() {
|
2018-02-01 06:51:26 +00:00
|
|
|
const String metaTag = '<meta http-equiv="refresh" content="0;URL=../index.html">';
|
2018-10-23 20:50:24 +00:00
|
|
|
File('$kPublishRoot/flutter/index.html').writeAsStringSync(metaTag);
|
2016-05-01 22:52:51 +00:00
|
|
|
}
|
|
|
|
|
2016-05-16 15:28:58 +00:00
|
|
|
List<String> findPackageNames() {
|
2018-10-01 19:29:08 +00:00
|
|
|
return findPackages().map<String>((FileSystemEntity file) => path.basename(file.path)).toList();
|
2016-05-01 22:52:51 +00:00
|
|
|
}
|
|
|
|
|
2017-01-11 17:00:10 +00:00
|
|
|
/// Finds all packages in the Flutter SDK
|
2018-07-12 21:59:22 +00:00
|
|
|
List<FileSystemEntity> findPackages() {
|
2018-09-12 06:29:29 +00:00
|
|
|
return Directory('packages')
|
2016-05-01 22:52:51 +00:00
|
|
|
.listSync()
|
2016-11-15 20:35:50 +00:00
|
|
|
.where((FileSystemEntity entity) {
|
|
|
|
if (entity is! Directory)
|
|
|
|
return false;
|
2018-09-12 06:29:29 +00:00
|
|
|
final File pubspec = File('${entity.path}/pubspec.yaml');
|
2016-11-15 20:35:50 +00:00
|
|
|
// TODO(ianh): Use a real YAML parser here
|
|
|
|
return !pubspec.readAsStringSync().contains('nodoc: true');
|
2016-05-01 22:52:51 +00:00
|
|
|
})
|
2018-07-13 17:35:23 +00:00
|
|
|
.cast<Directory>()
|
2016-05-01 22:52:51 +00:00
|
|
|
.toList();
|
|
|
|
}
|
|
|
|
|
2017-01-11 17:00:10 +00:00
|
|
|
/// Returns import or on-disk paths for all libraries in the Flutter SDK.
|
2018-10-11 20:27:43 +00:00
|
|
|
Iterable<String> libraryRefs() sync* {
|
2016-05-16 15:28:58 +00:00
|
|
|
for (Directory dir in findPackages()) {
|
2017-03-04 02:06:08 +00:00
|
|
|
final String dirName = path.basename(dir.path);
|
2018-09-12 06:29:29 +00:00
|
|
|
for (FileSystemEntity file in Directory('${dir.path}/lib').listSync()) {
|
2017-01-11 17:00:10 +00:00
|
|
|
if (file is File && file.path.endsWith('.dart')) {
|
2018-10-11 20:27:43 +00:00
|
|
|
yield '$dirName/${path.basename(file.path)}';
|
|
|
|
}
|
2016-05-01 22:52:51 +00:00
|
|
|
}
|
|
|
|
}
|
2017-02-10 00:12:09 +00:00
|
|
|
|
|
|
|
// Add a fake package for platform integration APIs.
|
2018-10-11 20:27:43 +00:00
|
|
|
yield 'platform_integration/android.dart';
|
|
|
|
yield 'platform_integration/ios.dart';
|
2016-05-01 22:52:51 +00:00
|
|
|
}
|
|
|
|
|
2018-06-05 06:50:40 +00:00
|
|
|
void printStream(Stream<List<int>> stream, { String prefix = '', List<Pattern> filter = const <Pattern>[] }) {
|
2017-07-28 22:44:38 +00:00
|
|
|
assert(prefix != null);
|
|
|
|
assert(filter != null);
|
2016-05-01 22:52:51 +00:00
|
|
|
stream
|
2018-10-01 19:29:08 +00:00
|
|
|
.transform<String>(utf8.decoder)
|
|
|
|
.transform<String>(const LineSplitter())
|
2017-07-28 22:44:38 +00:00
|
|
|
.listen((String line) {
|
|
|
|
if (!filter.any((Pattern pattern) => line.contains(pattern)))
|
|
|
|
print('$prefix$line'.trim());
|
|
|
|
});
|
2016-05-01 22:52:51 +00:00
|
|
|
}
|