1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-03 08:35:29 +02:00
joplin/ReactNativeClient/lib/services/InteropService_Exporter_Json.js

30 lines
974 B
JavaScript
Raw Normal View History

const InteropService_Exporter_Base = require('lib/services/InteropService_Exporter_Base');
2019-07-29 15:58:33 +02:00
const { basename } = require('lib/path-utils.js');
const { shim } = require('lib/shim');
class InteropService_Exporter_Json extends InteropService_Exporter_Base {
async init(destDir) {
this.destDir_ = destDir;
this.resourceDir_ = destDir ? destDir + '/resources' : null;
await shim.fsDriver().mkdir(this.destDir_);
await shim.fsDriver().mkdir(this.resourceDir_);
}
async processItem(ItemClass, item) {
2019-07-29 15:43:53 +02:00
const fileName = ItemClass.systemPath(item, 'json');
const filePath = this.destDir_ + '/' + fileName;
const serialized = JSON.stringify(item);
await shim.fsDriver().writeFile(filePath, serialized, 'utf-8');
}
async processResource(resource, filePath) {
const destResourcePath = this.resourceDir_ + '/' + basename(filePath);
await shim.fsDriver().copy(filePath, destResourcePath);
}
async close() {}
}
2019-07-29 15:43:53 +02:00
module.exports = InteropService_Exporter_Json;