// 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:meta/meta.dart'; import 'package:package_config/package_config.dart'; import 'package:package_config/package_config_types.dart'; import 'base/common.dart'; import 'base/file_system.dart'; import 'cache.dart'; import 'dart/package_map.dart'; import 'dart/pub.dart'; import 'globals.dart' as globals hide fs; /// Expands templates in a directory to a destination. All files that must /// undergo template expansion should end with the '.tmpl' extension. All files /// that should be replaced with the corresponding image from /// flutter_template_images should end with the '.img.tmpl' extension. All other /// files are ignored. In case the contents of entire directories must be copied /// as is, the directory itself can end with '.tmpl' extension. Files within /// such a directory may also contain the '.tmpl' or '.img.tmpl' extensions and /// will be considered for expansion. In case certain files need to be copied /// but without template expansion (data files, etc.), the '.copy.tmpl' /// extension may be used. /// /// Folders with platform/language-specific content must be named /// '-.tmpl'. /// /// Files in the destination will contain none of the '.tmpl', '.copy.tmpl', /// 'img.tmpl', or '-.tmpl' extensions. class Template { Template(Directory templateSource, Directory baseDir, this.imageSourceDir, { @required FileSystem fileSystem, }) : _fileSystem = fileSystem { _templateFilePaths = {}; if (!templateSource.existsSync()) { return; } final List templateFiles = templateSource.listSync(recursive: true); for (final FileSystemEntity entity in templateFiles) { if (entity is! File) { // We are only interesting in template *file* URIs. continue; } final String relativePath = fileSystem.path.relative(entity.path, from: baseDir.absolute.path); if (relativePath.contains(templateExtension)) { // If '.tmpl' appears anywhere within the path of this entity, it is // is a candidate for rendering. This catches cases where the folder // itself is a template. _templateFilePaths[relativePath] = fileSystem.path.absolute(entity.path); } } } static Future