diff --git a/CliClient/app/fs-driver-node.js b/CliClient/app/fs-driver-node.js new file mode 100644 index 000000000..6053ae6bb --- /dev/null +++ b/CliClient/app/fs-driver-node.js @@ -0,0 +1,20 @@ +import fs from 'fs-extra'; + +class FsDriverNode { + + appendFileSync(path, string) { + return fs.appendFileSync(path, string); + } + + writeBinaryFile(path, content) { + let buffer = new Buffer(content); + return fs.writeFile(path, buffer); + } + + readFile(path) { + return fs.readFile(path); + } + +} + +export { FsDriverNode } \ No newline at end of file diff --git a/CliClient/app/main.js b/CliClient/app/main.js index 55dc4bdf9..33aa335b9 100644 --- a/CliClient/app/main.js +++ b/CliClient/app/main.js @@ -22,6 +22,7 @@ import { uuid } from 'lib/uuid.js'; import { sprintf } from 'sprintf-js'; import { importEnex } from 'import-enex'; import { vorpalUtils } from 'vorpal-utils.js'; +import { FsDriverNode } from './fs-driver-node.js'; import { filename, basename } from 'lib/path-utils.js'; import { _ } from 'lib/locale.js'; import os from 'os'; @@ -37,6 +38,10 @@ let initArgs = { profileDir: null, } +const fsDriver = new FsDriverNode(); +Logger.fsDriver_ = fsDriver; +Resource.fsDriver_ = fsDriver; + Setting.setConstant('appId', 'net.cozic.joplin-cli'); let currentFolder = null; diff --git a/ReactNativeClient/lib/fs-driver-dummy.js b/ReactNativeClient/lib/fs-driver-dummy.js new file mode 100644 index 000000000..9bc341316 --- /dev/null +++ b/ReactNativeClient/lib/fs-driver-dummy.js @@ -0,0 +1,9 @@ +class FsDriverDummy { + + appendFileSync(path, string) {} + writeBinaryFile(path, content) {} + readFile(path) {} + +} + +export { FsDriverDummy } \ No newline at end of file diff --git a/ReactNativeClient/lib/logger.js b/ReactNativeClient/lib/logger.js index a1f6c2115..de3aaaf4e 100644 --- a/ReactNativeClient/lib/logger.js +++ b/ReactNativeClient/lib/logger.js @@ -1,6 +1,6 @@ import moment from 'moment'; -// import fs from 'fs-extra'; import { _ } from 'lib/locale.js'; +import FsDriverDummy from 'lib/fs-driver-dummy.js'; class Logger { @@ -10,6 +10,11 @@ class Logger { this.fileAppendQueue_ = [] } + static fsDriver() { + if (!Logger.fsDriver_) Logger.fsDriver_ = new FsDriverDummy(); + return Logger.fsDriver_; + } + setLevel(level) { this.level_ = level; } @@ -67,8 +72,7 @@ class Logger { serializedObject = object; } - // RNFIX: Temporary disabled for React Native - // fs.appendFileSync(t.path, line + serializedObject + "\n"); + Logger.fsDriver().appendFileSync(t.path, line + serializedObject + "\n"); // this.fileAppendQueue_.push({ // path: t.path, diff --git a/ReactNativeClient/lib/models/resource.js b/ReactNativeClient/lib/models/resource.js index e61434b53..d6bb7c88d 100644 --- a/ReactNativeClient/lib/models/resource.js +++ b/ReactNativeClient/lib/models/resource.js @@ -15,6 +15,11 @@ class Resource extends BaseItem { return BaseModel.TYPE_RESOURCE; } + static fsDriver() { + if (!Resource.fsDriver_) Resource.fsDriver_ = new FsDriverDummy(); + return Resource.fsDriver_; + } + static async serialize(item, type = null, shownKeys = null) { let fieldNames = this.fieldNames(); fieldNames.push('type_'); @@ -32,15 +37,15 @@ class Resource extends BaseItem { return filename(path); } - // RNFIX: Temporary disabled for React Native - static content(resource) { + return this.fsDriver().readFile(this.fullPath(resource)); // // TODO: node-only, and should probably be done with streams // const fs = require('fs-extra'); // return fs.readFile(this.fullPath(resource)); } static setContent(resource, content) { + return this.fsDriver().writeBinaryFile(this.fullPath(resource), content); // // TODO: node-only, and should probably be done with streams // const fs = require('fs-extra'); // let buffer = new Buffer(content);