Fix File.toJson() not serializing correctly

This commit is contained in:
Jocelyn Badgley (Twipped) 2020-02-27 20:41:51 -08:00
parent 4751c8f215
commit 0179aa10f0

View File

@ -29,10 +29,7 @@ module.exports = exports = class File {
} }
// remove the public root and any _images segment from the dir // remove the public root and any _images segment from the dir
const dir = file.dir.split('/'); const dir = this._dir(file.dir);
if (dir[0] === 'public') dir.shift();
const i = dir.indexOf('_images');
if (i > -1) dir.splice(i, 1);
this.kind = kind(filepath); this.kind = kind(filepath);
this.type = type(filepath); this.type = type(filepath);
@ -51,6 +48,7 @@ module.exports = exports = class File {
this.serializable = [ this.serializable = [
'kind', 'kind',
'type', 'type',
'cwd',
'ext', 'ext',
'input', 'input',
'base', 'base',
@ -63,6 +61,14 @@ module.exports = exports = class File {
]; ];
} }
_dir (dir) {
dir = dir.split('/');
if (dir[0] === 'public') dir.shift();
const i = dir.indexOf('_images');
if (i > -1) dir.splice(i, 1);
return dir;
}
load () {} load () {}
tasks () { tasks () {
@ -75,18 +81,7 @@ module.exports = exports = class File {
} }
toJson () { toJson () {
return pick(this.serializable, [ return pick(this, this.serializable);
'preprocessed',
'type',
'kind',
'input',
'base',
'dir',
'name',
'basename',
'ext',
'dimensions',
]);
} }
}; };