1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

Made fs functions work again in cli

This commit is contained in:
Laurent Cozic 2017-07-05 22:52:31 +01:00
parent 8adb5a71c5
commit a81fe24368
5 changed files with 48 additions and 5 deletions

View File

@ -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 }

View File

@ -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;

View File

@ -0,0 +1,9 @@
class FsDriverDummy {
appendFileSync(path, string) {}
writeBinaryFile(path, content) {}
readFile(path) {}
}
export { FsDriverDummy }

View File

@ -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,

View File

@ -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);