createStructure method
Function to create pj structure
Implementation
Future<int> createStructure({
bool stf = false,
bool withCubit = true,
List<String> libs = const [
'eticon_api',
'get',
'flutter_screenutil',
'flutter_bloc',
'flutter_svg',
'get_storage',
'sentry_flutter',
'intl',
],
}) async {
SgMeta.instance.getL = libs.contains('get');
SgMeta.instance.api = libs.contains('eticon_api');
SgMeta.instance.util = libs.contains('flutter_screenutil');
SgMeta.instance.storage = libs.contains('get_storage');
printYellow('Create Project Utils...');
if (await Directory('${projectDir}lib/project_utils').exists()) {
printRed('Project Utils already exists');
//return 1;
}
Creator curDir = Creator('${projectDir}lib/project_utils');
await curDir.createFile(
fileName: 'pj_colors.dart', templates: Templates.colors);
await curDir.createFile(
fileName: 'pj_icons.dart', templates: Templates.icons);
await curDir.createFile(
fileName: 'pj_utils.dart', templates: Templates.utils);
printYellow('Create Project Widgets...');
if (await Directory('${projectDir}lib/project_widgets').exists()) {
printRed('Project Widgets already exists');
//return 2;
}
curDir.setDir('${projectDir}lib/project_widgets');
await curDir.createFile(
fileName: 'pj_appbar.dart', templates: Templates.appBar);
await curDir.createFile(
fileName: 'pj_text.dart', templates: Templates.text());
// await curDir.createFile(
// fileName: 'pj_widgets.dart', templates: Templates.widgets);
printYellow('Create Models...');
if (await Directory('${projectDir}lib/models').exists()) {
printRed('Models already exists');
//return 3;
}
curDir.setDir('${projectDir}lib/models');
await curDir.createFile(
fileName: 'about_models.txt', templates: Templates.about_models);
printYellow('Create Assets...');
if (await Directory('${projectDir}assets').exists()) {
printRed('Assets already exists');
//return 4;
} else {
curDir.setDir('${projectDir}assets');
await curDir.createFile(fileName: 'icons/empty.png', templates: '');
await curDir.createFile(fileName: 'images/empty.png', templates: '');
await curDir.createFile(fileName: 'fonts/empty.ttf', templates: '');
printYellow('Edit pubspec.yaml...');
String ps = await File('${projectDir}pubspec.yaml').readAsString();
ps = ps.substring(0, ps.lastIndexOf('flutter:'));
ps += Templates.pubspec;
await File('${projectDir}pubspec.yaml').writeAsString(ps);
}
if (!await createScreen('main', stf, withCubit)) {
printRed('main_screen already exists');
//return 5;
} else {
printYellow('Remodel main.dart...');
curDir.setDir('${projectDir}lib');
await curDir.createFile(
fileName: 'main.dart',
templates: Templates.main(withCubit: withCubit),
ignorExistCheck: true);
}
if (SgMetadata.instance.git) {
printYellow('Add to git...');
await Shell(commandVerbose: false, workingDirectory: projectDir)
.run('git add lib');
await Shell(commandVerbose: false, workingDirectory: projectDir)
.run('git add assets');
}
await _addLibrary(libs);
printGreen('Create structure success');
return 0;
}