Skip to content

Commit

Permalink
structure
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobrosenberg committed Apr 5, 2020
1 parent 03b42b0 commit b7d310f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 20 deletions.
12 changes: 11 additions & 1 deletion lib/services/flow/assignMeta.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ function applyMetaToTree({tree, defaultMeta}) {
}(tree, defaultMeta)
}

function defineDefaultMeta(payload){
payload.defaultMeta = {
bundle: false,
recursive: true,
'precache-order': false,
'precache-proximity': true,
preload: false,
}
}

/**
* mergeMeta
* @param {Object} meta
Expand Down Expand Up @@ -62,4 +72,4 @@ function mergeMeta({ meta = {}, filepath, isLayout, dir }, { ...dirMeta }) {
return meta
}

module.exports = { applyMetaToFiles, applyMetaToTree }
module.exports = { applyMetaToFiles, applyMetaToTree, defineDefaultMeta }
6 changes: 5 additions & 1 deletion lib/services/flow/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,9 @@ const removeNonSvelteFiles = payload => walkAsyncTree(payload, file => {
return isPage || isNormalDir || file.isLayout || file.isFallback
})

function normalizeOptions({ options }) {
const { extensions } = options
options.extensions = Array.isArray(extensions) ? extensions : extensions.split(',')
}

module.exports = { addPath, addId, removeUnderscoredDirs, removeNonSvelteFiles, defineFiles }
module.exports = { addPath, addId, removeUnderscoredDirs, removeNonSvelteFiles, defineFiles, normalizeOptions }
21 changes: 3 additions & 18 deletions lib/services/scanner.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,23 @@
const { attachComponent } = require('./flow/attachComponent')
const { applyMetaToFiles, applyMetaToTree } = require('./flow/assignMeta')
const { applyMetaToFiles, applyMetaToTree, defineDefaultMeta } = require('./flow/assignMeta')
const { generateFileTree } = require('./flow/generateFileTree')
const { addPath, addId, removeUnderscoredDirs, removeNonSvelteFiles, defineFiles } = require('./flow/misc')
const { addPath, addId, removeUnderscoredDirs, removeNonSvelteFiles, defineFiles, normalizeOptions } = require('./flow/misc')
const template = require('./flow/createTemplate')

const { pipeAsync } = require('../utils/fp')


const defaultMeta = {
bundle: false,
recursive: true,
'precache-order': false,
'precache-proximity': true,
preload: false,
}

function normalizeOptions({ options }) {
const { extensions } = options
options.extensions = Array.isArray(extensions) ? extensions : extensions.split(',')
}

module.exports = async function scanner(options, metaParser) {
return await pipeAsync(
x => {
x.options = options;
x.metaParser = metaParser;
x.defaultMeta = defaultMeta;
x.tree = { meta: { untouched: true }, root: true, dir: [] }
},
normalizeOptions,
generateFileTree, // => dir
removeUnderscoredDirs, // _private => false
defineFiles, // file => ({ isLayout, isReset, isIndex, isFallback })
removeNonSvelteFiles, // remove _file.svelte, keep dirs, layouts & resets
defineDefaultMeta,
applyMetaToFiles,
applyMetaToTree,
addPath, // ... => ({ path, ... })
Expand Down

0 comments on commit b7d310f

Please sign in to comment.