generatePubignore method
void
generatePubignore({})
Generate a .pubignore
file at the package root.
- The
.pubignore
file might be generated from other ignore files, such as.gitignore
files, located inside the package root directory. - When generating from a
.gitignore
file inside a child package, all items inside will be added with the relative path from root to the parent directory where the specifiedbasedOn
file locates. - The specified
additionalIgnores
will be added to the prefix. - It's strongly recommended to use
absolute
d andnormalize
d path.
Implementation
void generatePubignore({
bool basedOnRootGitignore = true,
Iterable<File> basedOn = const [],
List<String> additionalIgnores = const [],
}) {
final buffer = StringBuffer(additionalIgnores.join('\n'));
if (additionalIgnores.isNotEmpty) buffer.writeln();
for (final file in [if (basedOnRootGitignore) rootGitignore, ...basedOn]) {
final basePath = normalize(relative(file.parent.path, from: root.path));
final resolvedBase = basePath == '.' ? '' : '$basePath/';
buffer.writeln('\n# Synced from $basePath');
file
.readAsStringSync()
.split('\n')
.map((line) => line.trim())
.where((line) => line.isNotEmpty && !line.startsWith('#'))
.map((line) => '$resolvedBase$line')
.forEach(buffer.writeln);
}
pubignore.writeAsStringSync('$buffer\n');
}