md-curcuma
Version:
A Typescript library for transporting and converting markdown and other data.
82 lines (81 loc) • 2.91 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Markdown_IO_Writer = exports.Markdown_IO_Reader = void 0;
const observer_1 = require("../core/observer");
const types_1 = require("./types");
const filesystem_1 = require("../core/filesystem");
class Markdown_IO_Reader {
constructor(props) {
this.observer_subject = new observer_1.Observer_Subject();
this.props = null;
this.props = props;
}
add_observer(observer, id) {
this.observer_subject.add_observer(observer, id);
}
notify_all(props) {
this.observer_subject.notify_all(props);
}
notify(props) {
this.observer_subject.notify(props);
}
read() {
var file_list = [];
if (filesystem_1.Filesystem.isFolder(this.props.path)) {
file_list = filesystem_1.Filesystem.get_files_list(this.props.path);
}
else if (filesystem_1.Filesystem.isFile(this.props.path)) {
file_list.push(this.props.path);
}
else {
console.log(`not supported: '${this.props.path}'`);
}
console.log("Markdown_IO.read: ", file_list);
file_list.forEach((file) => {
let o_props = new types_1.IO_Observer_Props();
o_props.from = "markdown-io";
o_props.to = "runner";
o_props.command = "perform-tasks";
let dao_string = filesystem_1.Filesystem.read_file_txt(file);
let io_meta = new types_1.IO_Meta();
io_meta.file_list_reader = file_list;
io_meta.file_name_reader = file;
let the_dao = {
data: dao_string,
io_meta: io_meta,
};
o_props.dao = the_dao;
console.log("markdown-io.do_command: perform tasks for", file);
this.notify_all(o_props);
});
let m_props = new types_1.IO_Observer_Props();
m_props.from = "markdown-io";
m_props.to = "runner";
m_props.command = "tasks-finished";
this.notify_all(m_props);
}
}
exports.Markdown_IO_Reader = Markdown_IO_Reader;
class Markdown_IO_Writer {
constructor(write_props) {
this.observer_subject = new observer_1.Observer_Subject();
this.write_props = null;
this.write_props = write_props;
}
write(data) {
let source_file = this.write_props.path;
filesystem_1.Filesystem.write_my_file(source_file, this.write_props, data.data, false, (filename, data) => {
filesystem_1.Filesystem.write_file_txt(filename, data);
});
}
add_observer(observer, id) {
this.observer_subject.add_observer(observer, id);
}
notify_all(props) {
this.observer_subject.notify_all(props);
}
notify(props) {
this.observer_subject.notify(props);
}
}
exports.Markdown_IO_Writer = Markdown_IO_Writer;