-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from ARK4579/develop
v0.0.12
- Loading branch information
Showing
12 changed files
with
294 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import 'package:dj/dj.dart'; | ||
|
||
/// IO Wrapper for BaseDJ from 'dj' library. | ||
class BaseDjIo { | ||
final Map<String, dynamic> baseDjMap; | ||
|
||
BaseDjIo({ | ||
required this.baseDjMap, | ||
}); | ||
|
||
void write() { | ||
print('Writing to Disk...'); | ||
var baseDj = BaseDj.fromJson(baseDjMap); | ||
|
||
var directoryDjIo = DirectoryDjIo(directoryDj: baseDj.node); | ||
directoryDjIo.create(baseDj.path); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import 'package:universal_io/io.dart'; | ||
|
||
import 'package:dj/main/main.dart'; | ||
import 'package:path/path.dart' as p; | ||
|
||
import 'node_dj_io.dart'; | ||
import 'file_dj_io.dart'; | ||
|
||
class DirectoryDjIo extends NodeDjIo { | ||
final DirectoryDj directoryDj; | ||
final bool shouldFormat; | ||
|
||
DirectoryDjIo({ | ||
required this.directoryDj, | ||
this.shouldFormat = true, | ||
}); | ||
|
||
@override | ||
void create(String basePath) { | ||
super.create(basePath); | ||
|
||
var dirPath = p.join(basePath, directoryDj.name); | ||
|
||
var directory = Directory(dirPath); | ||
|
||
directory.createSync(); | ||
|
||
directoryDj.nodes?.forEach((node) { | ||
var nodeDjIo = getNodeDj(node, shouldFormat); | ||
if (nodeDjIo != null) { | ||
nodeDjIo.create(dirPath); | ||
nodeDjIo.write(); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
NodeDjIo? getNodeDj(NodeDj? node, bool shouldFormat) { | ||
if (node == null) return null; | ||
|
||
NodeDjIo? nodeDjIo; | ||
if (node.type == StructureType.Directory) { | ||
nodeDjIo = DirectoryDjIo( | ||
directoryDj: DirectoryDj.fromJson(node.toJson()), | ||
shouldFormat: shouldFormat, | ||
); | ||
} else if (node.type == StructureType.File) { | ||
nodeDjIo = FileDjIo( | ||
fileDj: FileDj.fromJson(node.toJson()), | ||
shouldFormat: shouldFormat, | ||
); | ||
} else { | ||
print('${node.runtimeType} Not Handeled'); | ||
} | ||
|
||
return nodeDjIo; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export 'node_dj_io.dart'; | ||
export 'file_dj_io.dart'; | ||
export 'directory_dj_io.dart'; | ||
export 'base_dj_io.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import 'package:universal_io/io.dart'; | ||
import 'package:dart_style/dart_style.dart'; | ||
import 'package:path/path.dart' as p; | ||
|
||
import 'package:dj/main/main.dart'; | ||
|
||
import 'node_dj_io.dart'; | ||
|
||
class FileDjIo extends NodeDjIo { | ||
final FileDj fileDj; | ||
final bool shouldFormat; | ||
|
||
FileDjIo({ | ||
required this.fileDj, | ||
this.shouldFormat = true, | ||
}); | ||
|
||
File? _handler; | ||
|
||
@override | ||
void create(String basePath) { | ||
if (_handler == null) { | ||
super.create(basePath); | ||
|
||
var fullFileName = '${fileDj.name}.${fileDj.fileExtension}'; | ||
var fileAbsolutePath = p.join(basePath, fullFileName); | ||
|
||
_handler = File(fileAbsolutePath); | ||
} | ||
|
||
_handler!.createSync(); | ||
} | ||
|
||
@override | ||
void write() { | ||
if (_handler != null) { | ||
var codeLines = <String>[]; | ||
|
||
fileDj.codeParts?.forEach((codePart) { | ||
codePart.toCode().forEach((codePartLine) { | ||
codeLines.add(codePartLine); | ||
}); | ||
}); | ||
|
||
var singleCodeLine = codeLines.join('\n'); | ||
|
||
if (shouldFormat) { | ||
try { | ||
singleCodeLine = DartFormatter().format(singleCodeLine); | ||
} catch (e) { | ||
print(e); | ||
} | ||
} | ||
|
||
var fileWriter = _handler!.openWrite(); | ||
fileWriter.writeln(singleCodeLine); | ||
fileWriter.close(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import 'package:universal_io/io.dart'; | ||
|
||
abstract class NodeDjIo { | ||
void create(String basePath) { | ||
Directory(basePath).createSync(recursive: true); | ||
} | ||
|
||
void write() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.