mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00

* Update project.pbxproj files to say Flutter rather than Chromium Also, the templates now have an empty organization so that we don't cause people to give their apps a Flutter copyright. * Update the copyright notice checker to require a standard notice on all files * Update copyrights on Dart files. (This was a mechanical commit.) * Fix weird license headers on Dart files that deviate from our conventions; relicense Shrine. Some were already marked "The Flutter Authors", not clear why. Their dates have been normalized. Some were missing the blank line after the license. Some were randomly different in trivial ways for no apparent reason (e.g. missing the trailing period). * Clean up the copyrights in non-Dart files. (Manual edits.) Also, make sure templates don't have copyrights. * Fix some more ORGANIZATIONNAMEs
79 lines
2.7 KiB
Dart
79 lines
2.7 KiB
Dart
// 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 'dart:io' hide Platform;
|
|
|
|
import 'package:meta/meta.dart';
|
|
import 'package:path/path.dart' as path;
|
|
|
|
/// What type of snippet to produce.
|
|
enum SnippetType {
|
|
/// Produces a snippet that includes the code interpolated into an application
|
|
/// template.
|
|
application,
|
|
|
|
/// Produces a nicely formatted sample code, but no application.
|
|
sample,
|
|
}
|
|
|
|
/// Return the name of an enum item.
|
|
String getEnumName(dynamic enumItem) {
|
|
final String name = '$enumItem';
|
|
final int index = name.indexOf('.');
|
|
return index == -1 ? name : name.substring(index + 1);
|
|
}
|
|
|
|
/// A class to compute the configuration of the snippets input and output
|
|
/// locations based in the current location of the snippets main.dart.
|
|
class Configuration {
|
|
Configuration({@required this.flutterRoot}) : assert(flutterRoot != null);
|
|
|
|
final Directory flutterRoot;
|
|
|
|
/// This is the configuration directory for the snippets system, containing
|
|
/// the skeletons and templates.
|
|
@visibleForTesting
|
|
Directory get configDirectory {
|
|
_configPath ??= Directory(
|
|
path.canonicalize(path.join(flutterRoot.absolute.path, 'dev', 'snippets', 'config')));
|
|
return _configPath;
|
|
}
|
|
|
|
Directory _configPath;
|
|
|
|
/// This is where the snippets themselves will be written, in order to be
|
|
/// uploaded to the docs site.
|
|
Directory get outputDirectory {
|
|
_docsDirectory ??= Directory(
|
|
path.canonicalize(path.join(flutterRoot.absolute.path, 'dev', 'docs', 'doc', 'snippets')));
|
|
return _docsDirectory;
|
|
}
|
|
|
|
Directory _docsDirectory;
|
|
|
|
/// This makes sure that the output directory exists.
|
|
void createOutputDirectory() {
|
|
if (!outputDirectory.existsSync()) {
|
|
outputDirectory.createSync(recursive: true);
|
|
}
|
|
}
|
|
|
|
/// The directory containing the HTML skeletons to be filled out with metadata
|
|
/// and returned to dartdoc for insertion in the output.
|
|
Directory get skeletonsDirectory => Directory(path.join(configDirectory.path,'skeletons'));
|
|
|
|
/// The directory containing the code templates that can be referenced by the
|
|
/// dartdoc.
|
|
Directory get templatesDirectory => Directory(path.join(configDirectory.path, 'templates'));
|
|
|
|
/// Gets the skeleton file to use for the given [SnippetType] and DartPad preference.
|
|
File getHtmlSkeletonFile(SnippetType type, {bool showDartPad = false}) {
|
|
assert(!showDartPad || type == SnippetType.application,
|
|
'Only application snippets work with dartpad.');
|
|
final String filename =
|
|
'${showDartPad ? 'dartpad-' : ''}${getEnumName(type)}.html';
|
|
return File(path.join(skeletonsDirectory.path, filename));
|
|
}
|
|
}
|