2017-10-26 12:43:28 -06:00
|
|
|
import toml from 'toml-j0.4';
|
|
|
|
import tomlify from 'tomlify-j0.4';
|
|
|
|
import moment from 'moment';
|
|
|
|
import AssetProxy from '../valueObjects/AssetProxy';
|
|
|
|
import { sortKeys } from './helpers';
|
|
|
|
|
|
|
|
const outputReplacer = (key, value) => {
|
|
|
|
if (moment.isMoment(value)) {
|
|
|
|
return value.format(value._f);
|
|
|
|
}
|
|
|
|
if (value instanceof AssetProxy) {
|
|
|
|
return `${ value.path }`;
|
|
|
|
}
|
|
|
|
// Return `false` to use default (`undefined` would delete key).
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
2017-10-30 13:48:19 -06:00
|
|
|
export default {
|
2017-10-26 12:43:28 -06:00
|
|
|
fromFile(content) {
|
|
|
|
return toml.parse(content);
|
2017-10-30 13:48:19 -06:00
|
|
|
},
|
2017-10-26 12:43:28 -06:00
|
|
|
|
|
|
|
toFile(data, sortedKeys = []) {
|
|
|
|
return tomlify.toToml(data, { replace: outputReplacer, sort: sortKeys(sortedKeys) });
|
|
|
|
}
|
|
|
|
}
|