diff --git a/scripts/dedefine.js b/scripts/dedefine.js index cd21b623c1..e563c629bf 100644 --- a/scripts/dedefine.js +++ b/scripts/dedefine.js @@ -7,10 +7,9 @@ const through = require('through2'); const defineRx = /typeof\s+define\s*===?\s*['"]function['"]\s*&&\s*(?:define\.amd|typeof\s+define\.amd\s*===?\s*['"]object['"]\s*&&\s*define\.amd)/g; -function createStream () { - return through.obj(function (chunk, enc, next) { - this.push(String(chunk) - .replace(defineRx, 'false')); +function createStream() { + return through.obj(function(chunk, enc, next) { + this.push(String(chunk).replace(defineRx, 'false')); next(); }); } diff --git a/scripts/docs-update-toc.js b/scripts/docs-update-toc.js index 93da9aadca..5deef94c19 100755 --- a/scripts/docs-update-toc.js +++ b/scripts/docs-update-toc.js @@ -16,7 +16,8 @@ const docsFilepath = path.join(__dirname, '..', 'docs', 'index.md'); console.log('Updating TOC...'); -fs.createReadStream(docsFilepath) +fs + .createReadStream(docsFilepath) .on('error', err => { console.log(err); process.exit(1); @@ -24,10 +25,14 @@ fs.createReadStream(docsFilepath) .on('close', () => { console.log('Done.'); }) - .pipe(utils.concat(input => { - const output = toc.insert(String(input), { - bullets: '-', - maxdepth: 2 - }).replace(/\n\n$/, '\n'); - return fs.writeFileSync(docsFilepath, output); - })); + .pipe( + utils.concat(input => { + const output = toc + .insert(String(input), { + bullets: '-', + maxdepth: 2 + }) + .replace(/\n\n$/, '\n'); + return fs.writeFileSync(docsFilepath, output); + }) + ); diff --git a/scripts/netlify-headers.js b/scripts/netlify-headers.js index d551b6374c..c99c868bc1 100644 --- a/scripts/netlify-headers.js +++ b/scripts/netlify-headers.js @@ -2,9 +2,7 @@ const AssetGraph = require('assetgraph'); -const headers = [ - 'Content-Security-Policy' -]; +const headers = ['Content-Security-Policy']; const resourceHintTypeMap = { HtmlPreloadLink: 'preload', @@ -13,8 +11,10 @@ const resourceHintTypeMap = { HtmlDnsPrefetchLink: 'dns-prefetch' }; -function getHeaderForRelation (rel) { - let header = `Link: <${rel.href}>; rel=${resourceHintTypeMap[rel.type]}; as=${rel.as}; type=${rel.to.contentType}`; +function getHeaderForRelation(rel) { + let header = `Link: <${rel.href}>; rel=${resourceHintTypeMap[rel.type]}; as=${ + rel.as + }; type=${rel.to.contentType}`; if (rel.as === 'font') { header = `${header}; crossorigin=anonymous`; @@ -23,24 +23,31 @@ function getHeaderForRelation (rel) { return header; } -new AssetGraph({ root: 'docs/_dist' }) +new AssetGraph({root: 'docs/_dist'}) .loadAssets('*.html') .populate({ - followRelations: { type: 'HtmlAnchor', crossorigin: false } + followRelations: {type: 'HtmlAnchor', crossorigin: false} }) - .queue(function (assetGraph) { - const assets = assetGraph.findAssets({ type: 'Html', isInline: false }); + .queue(function(assetGraph) { + const assets = assetGraph.findAssets({type: 'Html', isInline: false}); const headerMap = {}; - assets.forEach(function (asset) { - const url = '/' + asset.url.replace(assetGraph.root, '').replace(/#.*/, '').replace('index.html', ''); + assets.forEach(function(asset) { + const url = + '/' + + asset.url + .replace(assetGraph.root, '') + .replace(/#.*/, '') + .replace('index.html', ''); if (!headerMap[url]) { headerMap[url] = []; } - headers.forEach(function (header) { - const node = asset.parseTree.querySelector('meta[http-equiv=' + header + ']'); + headers.forEach(function(header) { + const node = asset.parseTree.querySelector( + 'meta[http-equiv=' + header + ']' + ); if (node) { headerMap[url].push(`${header}: ${node.getAttribute('content')}`); @@ -51,9 +58,11 @@ new AssetGraph({ root: 'docs/_dist' }) }); const firstCssRel = asset.outgoingRelations.filter(r => { - return r.type === 'HtmlStyle' && - r.crossorigin === false && - r.href !== undefined; + return ( + r.type === 'HtmlStyle' && + r.crossorigin === false && + r.href !== undefined + ); })[0]; if (firstCssRel) { @@ -62,7 +71,9 @@ new AssetGraph({ root: 'docs/_dist' }) headerMap[url].push(header); } - const resourceHintRelations = asset.outgoingRelations.filter(r => ['HtmlPreloadLink', 'HtmlPrefetchLink'].includes(r.type)); + const resourceHintRelations = asset.outgoingRelations.filter(r => + ['HtmlPreloadLink', 'HtmlPrefetchLink'].includes(r.type) + ); resourceHintRelations.forEach(rel => { headerMap[url].push(getHeaderForRelation(rel)); @@ -70,7 +81,9 @@ new AssetGraph({ root: 'docs/_dist' }) rel.detach(); }); - const preconnectRelations = asset.outgoingRelations.filter(r => ['HtmlPreconnectLink'].includes(r.type)); + const preconnectRelations = asset.outgoingRelations.filter(r => + ['HtmlPreconnectLink'].includes(r.type) + ); preconnectRelations.forEach(rel => { let header = `Link: <${rel.href}>; rel=preconnect`; @@ -83,17 +96,17 @@ new AssetGraph({ root: 'docs/_dist' }) console.log('\n## Autogenerated headers:\n'); - Object.keys(headerMap).forEach(function (url) { + Object.keys(headerMap).forEach(function(url) { console.log(url); const httpHeaders = headerMap[url]; - httpHeaders.forEach(function (header) { + httpHeaders.forEach(function(header) { console.log(` ${header}`); }); console.log(''); }); }) - .writeAssetsToDisc({ isLoaded: true }) + .writeAssetsToDisc({isLoaded: true}) .run();