You've already forked joplin
							
							
				mirror of
				https://github.com/laurent22/joplin.git
				synced 2025-10-31 00:07:48 +02:00 
			
		
		
		
	Made fs functions work again in cli
This commit is contained in:
		
							
								
								
									
										20
									
								
								CliClient/app/fs-driver-node.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								CliClient/app/fs-driver-node.js
									
									
									
									
									
										Normal 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 } | ||||||
| @@ -22,6 +22,7 @@ import { uuid } from 'lib/uuid.js'; | |||||||
| import { sprintf } from 'sprintf-js'; | import { sprintf } from 'sprintf-js'; | ||||||
| import { importEnex } from 'import-enex'; | import { importEnex } from 'import-enex'; | ||||||
| import { vorpalUtils } from 'vorpal-utils.js'; | import { vorpalUtils } from 'vorpal-utils.js'; | ||||||
|  | import { FsDriverNode } from './fs-driver-node.js'; | ||||||
| import { filename, basename } from 'lib/path-utils.js'; | import { filename, basename } from 'lib/path-utils.js'; | ||||||
| import { _ } from 'lib/locale.js'; | import { _ } from 'lib/locale.js'; | ||||||
| import os from 'os'; | import os from 'os'; | ||||||
| @@ -37,6 +38,10 @@ let initArgs = { | |||||||
| 	profileDir: null, | 	profileDir: null, | ||||||
| } | } | ||||||
|  |  | ||||||
|  | const fsDriver = new FsDriverNode(); | ||||||
|  | Logger.fsDriver_ = fsDriver; | ||||||
|  | Resource.fsDriver_ = fsDriver; | ||||||
|  |  | ||||||
| Setting.setConstant('appId', 'net.cozic.joplin-cli'); | Setting.setConstant('appId', 'net.cozic.joplin-cli'); | ||||||
|  |  | ||||||
| let currentFolder = null; | let currentFolder = null; | ||||||
|   | |||||||
							
								
								
									
										9
									
								
								ReactNativeClient/lib/fs-driver-dummy.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								ReactNativeClient/lib/fs-driver-dummy.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,9 @@ | |||||||
|  | class FsDriverDummy { | ||||||
|  |  | ||||||
|  | 	appendFileSync(path, string) {} | ||||||
|  | 	writeBinaryFile(path, content) {} | ||||||
|  | 	readFile(path) {} | ||||||
|  |  | ||||||
|  | } | ||||||
|  |  | ||||||
|  | export { FsDriverDummy } | ||||||
| @@ -1,6 +1,6 @@ | |||||||
| import moment from 'moment'; | import moment from 'moment'; | ||||||
| // import fs from 'fs-extra'; |  | ||||||
| import { _ } from 'lib/locale.js'; | import { _ } from 'lib/locale.js'; | ||||||
|  | import FsDriverDummy from 'lib/fs-driver-dummy.js'; | ||||||
|  |  | ||||||
| class Logger { | class Logger { | ||||||
|  |  | ||||||
| @@ -10,6 +10,11 @@ class Logger { | |||||||
| 		this.fileAppendQueue_ = [] | 		this.fileAppendQueue_ = [] | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	static fsDriver() { | ||||||
|  | 		if (!Logger.fsDriver_) Logger.fsDriver_ = new FsDriverDummy(); | ||||||
|  | 		return Logger.fsDriver_; | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	setLevel(level) { | 	setLevel(level) { | ||||||
| 		this.level_ = level; | 		this.level_ = level; | ||||||
| 	} | 	} | ||||||
| @@ -67,8 +72,7 @@ class Logger { | |||||||
| 					serializedObject = object; | 					serializedObject = object; | ||||||
| 				} | 				} | ||||||
|  |  | ||||||
| 				// RNFIX: Temporary disabled for React Native | 				Logger.fsDriver().appendFileSync(t.path, line + serializedObject + "\n"); | ||||||
| 				// fs.appendFileSync(t.path, line + serializedObject + "\n"); |  | ||||||
|  |  | ||||||
| 				// this.fileAppendQueue_.push({ | 				// this.fileAppendQueue_.push({ | ||||||
| 				// 	path: t.path, | 				// 	path: t.path, | ||||||
|   | |||||||
| @@ -15,6 +15,11 @@ class Resource extends BaseItem { | |||||||
| 		return BaseModel.TYPE_RESOURCE; | 		return BaseModel.TYPE_RESOURCE; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	static fsDriver() { | ||||||
|  | 		if (!Resource.fsDriver_) Resource.fsDriver_ = new FsDriverDummy(); | ||||||
|  | 		return Resource.fsDriver_; | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	static async serialize(item, type = null, shownKeys = null) { | 	static async serialize(item, type = null, shownKeys = null) { | ||||||
| 		let fieldNames = this.fieldNames(); | 		let fieldNames = this.fieldNames(); | ||||||
| 		fieldNames.push('type_'); | 		fieldNames.push('type_'); | ||||||
| @@ -32,15 +37,15 @@ class Resource extends BaseItem { | |||||||
| 		return filename(path); | 		return filename(path); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	// RNFIX: Temporary disabled for React Native |  | ||||||
|  |  | ||||||
| 	static content(resource) { | 	static content(resource) { | ||||||
|  | 		return this.fsDriver().readFile(this.fullPath(resource)); | ||||||
| 		// // TODO: node-only, and should probably be done with streams | 		// // TODO: node-only, and should probably be done with streams | ||||||
| 		// const fs = require('fs-extra'); | 		// const fs = require('fs-extra'); | ||||||
| 		// return fs.readFile(this.fullPath(resource)); | 		// return fs.readFile(this.fullPath(resource)); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	static setContent(resource, content) { | 	static setContent(resource, content) { | ||||||
|  | 		return this.fsDriver().writeBinaryFile(this.fullPath(resource), content); | ||||||
| 		// // TODO: node-only, and should probably be done with streams | 		// // TODO: node-only, and should probably be done with streams | ||||||
| 		// const fs = require('fs-extra'); | 		// const fs = require('fs-extra'); | ||||||
| 		// let buffer = new Buffer(content); | 		// let buffer = new Buffer(content); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user