Unverified Commit a9cf41fa authored by Renée Kooi's avatar Renée Kooi Committed by GitHub
Browse files

Expose mime types on graph nodes, fixes #402 (#443)

* Add mime type metadata.

* Stick the dynamic bundles list on scripts:bundle metadata

* Stick manifest description and color data on metadata

* force latest buffer graph to beat caches
parent beed8c08
......@@ -92,7 +92,7 @@ function Bankai (entry, opts) {
// Insert nodes into the graph.
this.graph.node('assets', assetsNode)
this.graph.node('documents', [ 'assets:list', 'manifest:color', 'manifest:description', 'styles:bundle', 'scripts:list', 'reload:bundle' ], documentNode)
this.graph.node('documents', [ 'assets:list', 'manifest:bundle', 'styles:bundle', 'scripts:bundle', 'reload:bundle' ], documentNode)
this.graph.node('manifest', manifestNode)
this.graph.node('scripts', scriptNode)
this.graph.node('reload', reloadNode)
......
......@@ -63,7 +63,9 @@ function node (state, createEdge) {
var name = route
if (name === '/') name = 'index'
name = name + '.html'
createEdge(name, buf)
createEdge(name, buf, {
mime: 'text/html'
})
done(null, buf)
}
}
......@@ -76,7 +78,7 @@ function node (state, createEdge) {
var body = content.body
var selector = content.selector
var hasDynamicScripts = state.scripts.list.buffer.length > 0
var hasDynamicScripts = state.scripts.bundle.dynamicBundles.length > 0
var html = head(language)
var d = documentify(entry, html)
......@@ -84,15 +86,15 @@ function node (state, createEdge) {
viewportTag(),
scriptTag({ hash: state.scripts.bundle.hash, base: base }),
hasDynamicScripts && dynamicScriptsTag({
bundleNames: String(state.scripts.list.buffer).split(','),
bundleNames: state.scripts.bundle.dynamicBundles,
scripts: state.scripts,
base: base
}),
preloadTag(),
loadFontsTag({ fonts: fonts, base: base }),
manifestTag({ base: base }),
descriptionTag({ description: String(state.manifest.description.buffer) }),
themeColorTag({ color: String(state.manifest.color.buffer) }),
descriptionTag({ description: state.manifest.bundle.description }),
themeColorTag({ color: state.manifest.bundle.color }),
titleTag({ title: title })
].filter(Boolean)
// TODO: twitter
......
......@@ -4,15 +4,15 @@ var fs = require('fs')
var utils = require('./utils')
var DEFAULT_COLOR = Buffer.from('#fff')
var DEFAULT_DESCRIPTION = Buffer.from('')
var DEFAULT_COLOR = '#fff'
var DEFAULT_DESCRIPTION = ''
var DEFAULT_MANIFEST = Buffer.from(JSON.stringify({
name: '',
short_name: '',
start_url: '/',
display: 'minimal-ui',
background_color: '#fff',
theme_color: '#fff'
theme_color: DEFAULT_COLOR
}))
var filenames = [
......@@ -41,9 +41,11 @@ function node (state, createEdge, emit) {
debug('parsing')
utils.find(basedir, filenames, function (err, filename) {
if (err) {
createEdge('color', DEFAULT_COLOR)
createEdge('description', DEFAULT_DESCRIPTION)
createEdge('bundle', DEFAULT_MANIFEST)
createEdge('bundle', DEFAULT_MANIFEST, {
color: DEFAULT_COLOR,
description: DEFAULT_DESCRIPTION,
mime: 'application/json'
})
return
}
......@@ -54,9 +56,11 @@ function node (state, createEdge, emit) {
if (res.err) return self.emit('error', 'manifest', 'JSON.parse', res.err)
debug('creating edges')
createEdge('description', Buffer.from(res.value.description || ''))
createEdge('color', Buffer.from(res.value.theme_color || '#fff'))
createEdge('bundle', Buffer.from(JSON.stringify(res.value)))
createEdge('bundle', Buffer.from(JSON.stringify(res.value)), {
color: res.value.theme_color || DEFAULT_COLOR,
description: res.value.description || DEFAULT_DESCRIPTION,
mime: 'application/json'
})
})
})
}
......
......@@ -15,8 +15,12 @@ function node (state, createEdge) {
var mapName = 'bankai-reload.js.map'
exorcise(bundle, mapName, function (err, bundle, map) {
if (err) return self.emit('error', 'reload', 'exorcise', err)
createEdge(mapName, map)
createEdge('bundle', bundle)
createEdge(mapName, map, {
mime: 'application/json'
})
createEdge('bundle', bundle, {
mime: 'application/javascript'
})
})
})
}
......@@ -129,9 +129,13 @@ function node (state, createEdge) {
var mapName = 'bundle.js.map'
exorcise(bundle, mapName, function (err, bundle, map) {
if (err) return self.emit('error', 'scripts', 'exorcise', err)
createEdge(mapName, Buffer.from(map))
createEdge('bundle', bundle)
createEdge('list', Buffer.from(dynamicBundles.join(',')))
createEdge(mapName, Buffer.from(map), {
mime: 'application/json'
})
createEdge('bundle', bundle, {
mime: 'application/javascript',
dynamicBundles: dynamicBundles
})
self.emit('progress', 'scripts', 100)
})
})
......@@ -140,7 +144,9 @@ function node (state, createEdge) {
function exorciseDynamicBundle (bundleName) {
var mapName = bundleName + '.map'
return exorcist(concat({ encoding: 'buffer' }, function (map) {
createEdge(mapName, map)
createEdge(mapName, map, {
mime: 'application/json'
})
}), mapName)
}
......@@ -148,7 +154,9 @@ function node (state, createEdge) {
var edgeName = bundleName.replace(/\.js$/, '')
var stream = concat({ encoding: 'buffer' }, function (bundle) {
dynamicBundles.push(bundleName)
createEdge(edgeName, bundle)
createEdge(edgeName, bundle, {
mime: 'application/javascript'
})
// Inform the main bundle about this file's full name.
stream.emit('name', state.scripts[edgeName].hash.toString('hex').slice(0, 16) + '/' + bundleName)
......@@ -158,7 +166,9 @@ function node (state, createEdge) {
function bundleStyles () {
return concat({ encoding: 'buffer' }, function (buf) {
createEdge('style', buf)
createEdge('style', buf, {
mime: 'text/css'
})
})
}
}
......
......@@ -44,7 +44,9 @@ function node (state, createEdge) {
find(basedir, filenames, function (err, filename) {
if (err) {
state.metadata.serviceWorker = 'service-worker.js'
return createEdge('bundle', Buffer.from(''))
return createEdge('bundle', Buffer.from(''), {
mime: 'application/javascript'
})
}
// Expose what the original file name of the service worker was
......@@ -83,8 +85,12 @@ function node (state, createEdge) {
var mapName = 'bankai-service-worker.js.map'
exorcise(bundle, mapName, function (err, bundle, map) {
if (err) return self.emit('error', 'service-worker', 'exorcise', err)
createEdge(mapName, map)
createEdge('bundle', bundle)
createEdge(mapName, map, {
mime: 'application/json'
})
createEdge('bundle', bundle, {
mime: 'application/javascript'
})
})
})
}
......
......@@ -28,7 +28,9 @@ function node (state, createEdge) {
this.emit('error', 'styles', 'clean-css', e)
}
createEdge('bundle', Buffer.from(bundle))
createEdge('bundle', Buffer.from(bundle), {
mime: 'text/css'
})
}
function createCleanCssOptions () {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment