Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions src/lib/blueprinters.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import path from 'path'
import fs from 'fs'
import R from 'ramda'

export const defaultBlueprint = {
const defaultBlueprint = {
name: null,
sheet: {
name: null,
Expand All @@ -11,11 +11,11 @@ export const defaultBlueprint = {
resources: {}
}

export const defaultResource = {
const defaultResource = {
data: []
}

export function buildDesaturated (sheetId, sheetName, tab, resources) {
function buildDesaturated (sheetId, sheetName, tab, resources) {
const bp = R.clone(defaultBlueprint)
bp.sheet.name = sheetName
bp.sheet.id = sheetId
Expand Down Expand Up @@ -50,10 +50,25 @@ fs.readdirSync(normalizedPath).forEach(file => {
allBps[bpName] = buildBlueprinter(bpName, datafier)
})

function deeprowsWithSchema (datafierName, schema) {
const datafier = data => {
const transformedData = allBps.deeprows('', '', '', data).resources.deeprows.data
return transformedData.map(row => {
Object.keys(schema).forEach(key => {
row[key] = schema[key](row[key])
})
return row
})
}

return buildBlueprinter(`deeprows_${datafierName}`, datafier)
}

// NB: revert to ES5 'module.exports' required to make blueprinters from
// each file in blueprinters folder available for granular import from here.
module.exports = Object.assign({
defaultBlueprint,
defaultResource,
buildDesaturated
buildDesaturated,
deeprowsWithSchema
}, allBps)
Loading