createProjectAdditionalFiles function
Future<bool>
createProjectAdditionalFiles(
- PostgreSQLConnection connection, {
- required String path,
- required String name,
- bool schemaInName = false,
})
Implementation
Future<bool> createProjectAdditionalFiles(PostgreSQLConnection connection,
{required String path,
required String name,
bool schemaInName = false}) async {
print('Creating additional project files. . .');
json.addAll({
'name': name,
'version': 1,
'port_number': 8080,
'docker_tag': camelize(name).toLowerCase(),
'gcloud_project': name.toLowerCase(),
'gcloud_name': camelize(name).toLowerCase(),
'gcr_host': 'gcr.io',
'gcr_memory': 256,
'gcr_timeout': 300,
'gcr_allow_unauthenticated': true,
});
return getTables(connection).then((dataset) async {
if (dataset.isNotempty) {
var result;
for (var record in dataset.records) {
var fullpath =
'$path/$name/lib/services/${getServicePath(record, schemaInName)}';
services.add({
'name': getTableName(record).capitalize(),
'version': 1,
'table_name': getTableName(record),
'path': 'lib/services/${getServicePath(record, schemaInName)}',
'server_file_name': '${getServerFileName(record, schemaInName)}',
'service_file_name': '${getServiceFileName(record, schemaInName)}',
'service_class_name': '${getServiceClassName(record, schemaInName)}',
'proto_name': '${getTableName(record).toLowerCase()}.proto',
'proto_path':
'lib/services/${getServicePath(record, schemaInName)}/lib/proto_generated',
'docker_tag': (getTableName(record)).toLowerCase(),
'gcloud_name':
'${camelize(name).toLowerCase()}-${(camelize(getTableName(record))).toLowerCase()}',
'gcr_memory': 50,
});
result = await createAdditionalFiles(
connection,
record,
path: fullpath,
packageName: name,
schemaInName: schemaInName,
);
if (!result) {
return false;
}
await executeCommand(
verbose: true,
command: '''
protoc --dart_out=grpc:lib/services/${getServicePath(record, schemaInName)}/lib/proto_generated -Iprotos protos/${getProtoFileName(record, schemaInName)}
''',
workingDirectory: '$path/$name',
throwOnError: false);
}
json.addAll({'services': services});
await writeInFile(
'$path/$name/',
'upper.json',
prettyJson(json, indent: 2),
);
await executeCommand(
verbose: true,
command: 'pub get',
workingDirectory: '$path/$name',
);
await writeInFile(
'$path/$name/lib/src',
'service_list.dart',
getServiceList(),
);
return true;
} else {
return false;
}
});
}