fix: correct path on copy project
This commit is contained in:
parent
79ae49ed57
commit
43b3df453f
@ -65,7 +65,7 @@ apps
|
|||||||
Then run command with project path
|
Then run command with project path
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
dart ./tools/brick_generator/bin/brickgen.dart ./apps/brick_name
|
dart ./tools/brick_generator/bin/brickgen.dart ./apps/brick_name ./bricks/
|
||||||
```
|
```
|
||||||
|
|
||||||
Available options:
|
Available options:
|
||||||
@ -318,7 +318,7 @@ brickgen:
|
|||||||
```
|
```
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
dart ./tools/brick_generator/bin/brickgen.dart ./apps/brick_1
|
dart ./tools/brick_generator/bin/brickgen.dart ./apps/brick_1 ./bricks/
|
||||||
```
|
```
|
||||||
|
|
||||||
Will generate:
|
Will generate:
|
||||||
@ -360,7 +360,7 @@ brickgen:
|
|||||||
```
|
```
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
dart ./tools/brick_generator/bin/brickgen.dart ./apps/brick_2
|
dart ./tools/brick_generator/bin/brickgen.dart ./apps/brick_2 ./bricks/
|
||||||
```
|
```
|
||||||
|
|
||||||
Will generate:
|
Will generate:
|
||||||
|
@ -89,8 +89,10 @@ class Brickgen {
|
|||||||
Logger.debug('Define `targetPath`: $targetPath');
|
Logger.debug('Define `targetPath`: $targetPath');
|
||||||
|
|
||||||
// Check paths
|
// Check paths
|
||||||
if (toBrickifyPath == null || targetPath == null
|
if (toBrickifyPath == null ||
|
||||||
|| masonConfigPath == null || hooksOutputPath == null) {
|
targetPath == null ||
|
||||||
|
masonConfigPath == null ||
|
||||||
|
hooksOutputPath == null) {
|
||||||
throw Exception('An error occures during path definition.');
|
throw Exception('An error occures during path definition.');
|
||||||
}
|
}
|
||||||
Logger.info('Paths defined.');
|
Logger.info('Paths defined.');
|
||||||
@ -126,6 +128,8 @@ class Brickgen {
|
|||||||
FileSystem.renameCompilableFilesInFolder(config, targetPath!);
|
FileSystem.renameCompilableFilesInFolder(config, targetPath!);
|
||||||
Logger.info('Files renamed with variables.');
|
Logger.info('Files renamed with variables.');
|
||||||
|
|
||||||
|
// Clean empty folders created from copy/moves
|
||||||
|
FileSystem.removeEmptyFolders(targetPath!);
|
||||||
|
|
||||||
// Create Mason config
|
// Create Mason config
|
||||||
FileSystem.writeFile(masonConfigPath!, config.toMason());
|
FileSystem.writeFile(masonConfigPath!, config.toMason());
|
||||||
|
@ -53,7 +53,18 @@ abstract class FileSystem {
|
|||||||
throw ArgumentError('Path must be a directory', 'from');
|
throw ArgumentError('Path must be a directory', 'from');
|
||||||
}
|
}
|
||||||
|
|
||||||
final List<String> copiedFolders = [];
|
Future<void> cp(FileSystemEntity entity) async {
|
||||||
|
final absolutPath = entity.path;
|
||||||
|
final relativePath = absolutPath.replaceFirst(from, '');
|
||||||
|
final newPath = ((to + relativePath).split('/')..removeLast()).join('/');
|
||||||
|
|
||||||
|
if (ignoreList != null && ignoreList.contains(from, absolutPath)) {
|
||||||
|
Logger.debug('Ignoring $absolutPath');
|
||||||
|
} else {
|
||||||
|
Logger.debug('cp -Rf $absolutPath $newPath');
|
||||||
|
await Shell.cp(absolutPath, newPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Copy folders
|
// Copy folders
|
||||||
await Future.wait<void>(
|
await Future.wait<void>(
|
||||||
@ -61,38 +72,14 @@ abstract class FileSystem {
|
|||||||
.listSync(recursive: true)
|
.listSync(recursive: true)
|
||||||
.whereType<Directory>()
|
.whereType<Directory>()
|
||||||
.map((directory) async {
|
.map((directory) async {
|
||||||
final absolutPath = directory.path;
|
await cp(directory);
|
||||||
final name = absolutPath.split('/').last;
|
|
||||||
|
|
||||||
if (ignoreList != null && ignoreList.contains(from, absolutPath)) {
|
|
||||||
Logger.debug('Ignoring $absolutPath');
|
|
||||||
} else {
|
|
||||||
Logger.debug('cp -Rf $absolutPath $to/$name');
|
|
||||||
copiedFolders.add(absolutPath);
|
|
||||||
await Shell.cp(absolutPath, '$to/$name');
|
|
||||||
}
|
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Copy files
|
// Copy root files
|
||||||
await Future.wait<void>(
|
await Future.wait<void>(
|
||||||
Directory(from)
|
Directory(from).listSync().whereType<File>().map((file) async {
|
||||||
.listSync(recursive: true)
|
await cp(file);
|
||||||
.whereType<File>()
|
|
||||||
.map((file) async {
|
|
||||||
final absolutPath = file.path;
|
|
||||||
final name = absolutPath.split('/').last;
|
|
||||||
|
|
||||||
if (ignoreList != null && ignoreList.contains(from, absolutPath)) {
|
|
||||||
Logger.debug('Ignoring $absolutPath');
|
|
||||||
} else {
|
|
||||||
if (copiedFolders.any(absolutPath.startsWith)) {
|
|
||||||
Logger.debug('$absolutPath already copied!');
|
|
||||||
} else {
|
|
||||||
Logger.debug('cp -Rf $absolutPath $to/$name');
|
|
||||||
await Shell.cp(absolutPath, '$to/$name');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -259,13 +246,17 @@ abstract class FileSystem {
|
|||||||
for (final syntax in VariableStringSyntax.values) {
|
for (final syntax in VariableStringSyntax.values) {
|
||||||
final toReplace = variable.syntax?[syntax.mapKey];
|
final toReplace = variable.syntax?[syntax.mapKey];
|
||||||
if (toReplace != null) {
|
if (toReplace != null) {
|
||||||
|
if (contents?.contains(toReplace) ?? false) {
|
||||||
contents = contents!.replaceAll(
|
contents = contents!.replaceAll(
|
||||||
toReplace,
|
toReplace,
|
||||||
'{{#${syntax.id}}}{{${variable.name}}}{{/${syntax.id}}}',
|
'{{#${syntax.id}}}{{${variable.name}}}{{/${syntax.id}}}',
|
||||||
);
|
);
|
||||||
|
Logger.debug(
|
||||||
|
'Variable `${variable.name}` replaced in ${file.path}',
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Logger.debug('Variable `${variable.name}` replaced in ${file.path}');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
file.writeAsStringSync(contents!);
|
file.writeAsStringSync(contents!);
|
||||||
@ -289,11 +280,32 @@ abstract class FileSystem {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Removes empty folder dynamically:
|
||||||
|
///
|
||||||
|
/// For example, for this structure:
|
||||||
|
/// ```
|
||||||
|
/// ./brick/__brick__/folder/empty1/
|
||||||
|
/// ./brick/__brick__/folder/empty2/
|
||||||
|
/// ./brick/__brick__/dummy.txt
|
||||||
|
/// ```
|
||||||
|
/// it will delete `empty1` and `empty2`...then it will delete `folder`,
|
||||||
|
/// because by deleting his subfolders he's now empty too.
|
||||||
|
///
|
||||||
static void removeEmptyFolders(String targetPath) {
|
static void removeEmptyFolders(String targetPath) {
|
||||||
if (!FileSystemEntity.isDirectorySync(targetPath)) {
|
if (!FileSystemEntity.isDirectorySync(targetPath)) {
|
||||||
throw ArgumentError('Target must be a directory', 'targetPath');
|
throw ArgumentError('Target must be a directory', 'targetPath');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool containsEmptyFoldersFunction() => Directory(targetPath)
|
||||||
|
.listSync(recursive: true)
|
||||||
|
.whereType<Directory>()
|
||||||
|
.any(
|
||||||
|
(directory) =>
|
||||||
|
directory.existsSync() &&
|
||||||
|
directory.listSync(recursive: true).isEmpty,
|
||||||
|
);
|
||||||
|
|
||||||
|
while (containsEmptyFoldersFunction()) {
|
||||||
Directory(targetPath)
|
Directory(targetPath)
|
||||||
.listSync(recursive: true)
|
.listSync(recursive: true)
|
||||||
.whereType<Directory>()
|
.whereType<Directory>()
|
||||||
@ -305,6 +317,7 @@ abstract class FileSystem {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Transforms compilable file/folder names:
|
/// Transforms compilable file/folder names:
|
||||||
/// For each String `vars` in config, search for compilable in code, then
|
/// For each String `vars` in config, search for compilable in code, then
|
||||||
|
@ -34,12 +34,20 @@ class BooleanFileSystem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final variableName = key;
|
final variableName = key;
|
||||||
final folders = BooleanFileSystemVariable.fromYaml(
|
|
||||||
|
final foldersMap = source.nodes[_foldersKey] as YamlMap?;
|
||||||
|
final folders = (foldersMap != null)
|
||||||
|
? BooleanFileSystemVariable.fromYaml(
|
||||||
source.nodes[_foldersKey] as YamlMap?,
|
source.nodes[_foldersKey] as YamlMap?,
|
||||||
);
|
)
|
||||||
final files = BooleanFileSystemVariable.fromYaml(
|
: BooleanFileSystemVariable.empty();
|
||||||
|
|
||||||
|
final filesMap = source.nodes[_filesKey] as YamlMap?;
|
||||||
|
final files = (filesMap != null)
|
||||||
|
? BooleanFileSystemVariable.fromYaml(
|
||||||
source.nodes[_filesKey] as YamlMap?,
|
source.nodes[_filesKey] as YamlMap?,
|
||||||
);
|
)
|
||||||
|
: BooleanFileSystemVariable.empty();
|
||||||
|
|
||||||
return BooleanFileSystem(
|
return BooleanFileSystem(
|
||||||
booleanName: variableName,
|
booleanName: variableName,
|
||||||
|
@ -43,6 +43,11 @@ class BooleanFileSystemVariable {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
factory BooleanFileSystemVariable.empty() => BooleanFileSystemVariable(
|
||||||
|
onTrueNames: [],
|
||||||
|
onFalseNames: [],
|
||||||
|
);
|
||||||
|
|
||||||
final List<String> onTrueNames;
|
final List<String> onTrueNames;
|
||||||
final List<String> onFalseNames;
|
final List<String> onFalseNames;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user