run method
Runs this command.
The return value is wrapped in a Future
if necessary and returned by
CommandRunner.runCommand.
Implementation
@override
void run() async {
final appsName = argResults?['apps-name']?.toString().snakeCase;
final featureName = argResults?['feature-name']?.toString().snakeCase ?? '';
final pageName = argResults?['page-name']?.toString().snakeCase ?? '';
if (!exists(
join(
current,
'features',
featureName,
'lib',
pageName,
),
)) {
StatusHelper.failed(
'Feature or page not found, please check your feature or page name',
);
return;
}
final searchFileJson2Dart = appsName?.isNotEmpty ?? false
? '${appsName}_json2dart.yaml'
: 'json2dart.yaml';
final workingDirectory = find(
searchFileJson2Dart,
workingDirectory: join(current, 'json2dart'),
).toList();
for (var pathJson2Dart in workingDirectory) {
final yml = YamlHelper.loadFileYaml(pathJson2Dart);
final json2DartMap = Map.from(yml);
String pathTestPage = join(
current,
'features',
featureName,
'test',
'${pageName}_test',
);
if (appsName?.toString().isNotEmpty ?? false) {
pathTestPage = join(
current,
'apps',
appsName,
'features',
featureName,
'test',
'${pageName}_test',
);
}
Map map = json2DartMap[featureName] ?? {};
if (map.isNotEmpty) {
map = map[pageName] ?? {};
}
createDataTest(pathTestPage, featureName, pageName);
createDomainTest(pathTestPage, featureName, pageName);
createPresentationTest(pathTestPage, featureName, pageName, map);
await ModularHelper.format([pathTestPage]);
}
StatusHelper.success('Generate template test code');
}