2020-11-05 18:58:23 +02:00
|
|
|
const InteropService_Exporter_Base = require('./InteropService_Exporter_Base').default;
|
|
|
|
const BaseItem = require('../../models/BaseItem.js');
|
|
|
|
const { basename } = require('../../path-utils');
|
|
|
|
const shim = require('../../shim').default;
|
2018-02-26 21:25:54 +02:00
|
|
|
|
2020-10-09 19:35:46 +02:00
|
|
|
export default class InteropService_Exporter_Raw extends InteropService_Exporter_Base {
|
2020-11-12 21:13:28 +02:00
|
|
|
async init(destDir: string) {
|
2018-02-26 21:25:54 +02:00
|
|
|
this.destDir_ = destDir;
|
2019-09-19 23:51:18 +02:00
|
|
|
this.resourceDir_ = destDir ? `${destDir}/resources` : null;
|
2018-02-26 21:25:54 +02:00
|
|
|
|
|
|
|
await shim.fsDriver().mkdir(this.destDir_);
|
|
|
|
await shim.fsDriver().mkdir(this.resourceDir_);
|
|
|
|
}
|
|
|
|
|
2020-11-12 21:13:28 +02:00
|
|
|
async processItem(itemType: number, item: any) {
|
2020-10-09 19:35:46 +02:00
|
|
|
const ItemClass = BaseItem.getClassByItemType(itemType);
|
2018-02-26 21:25:54 +02:00
|
|
|
const serialized = await ItemClass.serialize(item);
|
2019-09-19 23:51:18 +02:00
|
|
|
const filePath = `${this.destDir_}/${ItemClass.systemPath(item)}`;
|
2018-02-26 21:25:54 +02:00
|
|
|
await shim.fsDriver().writeFile(filePath, serialized, 'utf-8');
|
|
|
|
}
|
|
|
|
|
2020-11-12 21:13:28 +02:00
|
|
|
async processResource(_resource: any, filePath: string) {
|
2019-09-19 23:51:18 +02:00
|
|
|
const destResourcePath = `${this.resourceDir_}/${basename(filePath)}`;
|
2018-02-26 21:25:54 +02:00
|
|
|
await shim.fsDriver().copy(filePath, destResourcePath);
|
|
|
|
}
|
|
|
|
|
|
|
|
async close() {}
|
|
|
|
}
|