-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rfc/issue 185 Transforms API (pt. 1) #422
Merged
Merged
Changes from 81 commits
Commits
Show all changes
82 commits
Select commit
Hold shift + click to select a range
46f048a
basic unbundled rendering of home page
thescientist13 f0804fe
got livereload working for all files
thescientist13 2e9456e
JSON support
thescientist13 aaa25a6
import CSS support
thescientist13 d2fbece
disable eslint complexity
thescientist13 10fcc2b
header working
thescientist13 4e9b020
ading banner and stylinh and fixed binary image loading
thescientist13 1e29db9
integrated evergreen deps
thescientist13 3631d06
fully restored the home page in develop mode
thescientist13 8a18552
wip getting serialization working
thescientist13 770178b
wip getting serialization working
thescientist13 af86832
clean up and refactor, serialize WIP
thescientist13 1beeb5f
upgrade puppeteer to latest
thescientist13 6930472
a bit hacky but home page is now being built for production
thescientist13 4702f6d
render header navigation from graph
thescientist13 6bd752a
page template working for site in development
thescientist13 a6bda80
all pages working in develop
thescientist13 c67559b
all pages serializing for prod
thescientist13 25c8392
sort header and shelf
thescientist13 d7dba58
shelf expansion and table of contents
thescientist13 4c743fc
label fallback handling
thescientist13 db2f97c
fix index page rendering
thescientist13 f27b3bd
clean up logging
thescientist13 f605dda
favicon support
thescientist13 61dd7eb
refactor server lifecycle to use compilation and expose devServer
thescientist13 b879792
built in serve command
thescientist13 396ca5c
serve docs
thescientist13 59b0b72
add support for app templates
thescientist13 bdc68de
pretty URLs
thescientist13 0b588a1
shelf working WIP
thescientist13 adbcffb
quick styling tweak for side nav
thescientist13 44a5451
copy assets and graph.json in copy lifecycle
thescientist13 698988a
basic support for css files
thescientist13 e7f12a6
fix copy error for nested folders
thescientist13 1729b94
call rollup from JS API
thescientist13 7b65990
rollup configuration sourced from compilation
thescientist13 f2ad06e
make sure to await Promise.all
thescientist13 f8a159b
Rfc/issue 355 organize serve lifecycle (#419)
hutchgrant 4cf32de
linting
thescientist13 dd3cfa4
renable default tests and limited smoke tests
thescientist13 d9e92a2
disable all tests enable subset of tests
thescientist13 2219c6b
task: add custom transforms API from koa context
hutchgrant 0ad031e
fix: remove redundant line
hutchgrant 8c0c784
fix: more descriptive var
hutchgrant b59b6dc
meta specs
thescientist13 1d60732
Merge branch 'rfc/issue-355-no-bundle-development' of github.com:Proj…
hutchgrant c11cf17
fix: merge conflict
hutchgrant 0cf35cb
enable custom title case
thescientist13 b7a1812
enable custom workspace spec
thescientist13 8c972da
track missing dev dep
thescientist13 c186ced
enabled workspace assets test case
thescientist13 5129a2f
fix link closing slash
thescientist13 d00edd9
content-outlet refactor
thescientist13 bbf1293
enabled getting started test case
thescientist13 6b58605
enable nested directory test case
thescientist13 e6851c5
enable app template case
thescientist13 cbe7bff
enable page template spec
thescientist13 c16e0cf
enable user directory mapping case
thescientist13 1280a34
update comments
thescientist13 ef55f9a
task: standardize transforms
hutchgrant 3ed28e3
fix: prod render
hutchgrant 6849dd9
task: adding disabled markdown transform
hutchgrant fc6f47b
fix: cleanup class names
hutchgrant fd0a571
fix: cleanup class names
hutchgrant 02ce6ac
got code markdown rendering and added support for custom plugins from…
thescientist13 71e325d
markdown plugins working including prism
thescientist13 0d64e43
default markdown specs
thescientist13 e5683d1
enable all tests
thescientist13 fbfa261
rename markdown case
thescientist13 a28de1f
syntax highlighting markdown spec
thescientist13 c73ab95
fix: transform fixes
hutchgrant d4bd739
task: add markdown and json transforms
hutchgrant f7af5d1
fix: header rendering, comment out eve-container temp
hutchgrant de040a6
fix: cleanup
hutchgrant a9b4788
Merge branch 'rfc/issue-355-no-bundle-development' of github.com:Proj…
hutchgrant 6fdf53d
fix: remove node_module seperate transform, instead use js/css with p…
hutchgrant 5f9aba3
task: remove old transforms
hutchgrant cc61085
fix: immutability of compilation object
hutchgrant 080cae1
fix: tests, page-templates, defaults
hutchgrant 9b2eeec
fix: cleanup
hutchgrant a610b43
Merge branch 'release/0.10.0' of github.com:ProjectEvergreen/greenwoo…
hutchgrant 210568f
fix: remove outdated transforms
hutchgrant File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<!DOCTYPE html> | ||
<html lang="en" prefix="og:http://ogp.me/ns#"> | ||
<head> | ||
<title></title> | ||
<meta charset='utf-8'> | ||
<meta name='viewport' content='width=device-width, initial-scale=1'/> | ||
<meta-outlet></meta-outlet> | ||
</head> | ||
<body> | ||
<section> | ||
<h1>Welcome to my website!</h1> | ||
<content-outlet></content-outlet> | ||
</section> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
const path = require('path'); | ||
const { promises: fsp } = require('fs'); | ||
const TransformInterface = require('./transform.interface'); | ||
|
||
class AssetTransform extends TransformInterface { | ||
|
||
constructor(req) { | ||
super(req, ['.woff2', '.woff', '.ttf', '.jpg', '.png', '.gif', '.svg']); | ||
} | ||
|
||
shouldTransform() { | ||
const { url } = this.request; | ||
|
||
return url.indexOf('assets/') >= 0 && url.indexOf('.css') < 0; | ||
} | ||
|
||
async applyTransform() { | ||
return new Promise(async (resolve, reject) => { | ||
try { | ||
|
||
let body = '', contentType = ''; | ||
const assetPath = path.join(this.workspace, this.request.url); | ||
const ext = path.extname(assetPath); | ||
const type = ext === '.svg' | ||
? `${ext.replace('.', '')}+xml` | ||
: ext.replace('.', ''); | ||
|
||
if (['.jpg', '.png', '.gif', '.svg'].includes(ext)) { | ||
contentType = `image/${type}`; | ||
|
||
if (ext === '.svg') { | ||
body = await fsp.readFile(assetPath, 'utf-8'); | ||
} else { | ||
body = await fsp.readFile(assetPath); | ||
} | ||
} else if (['.woff2', '.woff', '.ttf'].includes(ext)) { | ||
contentType = `font/${type}`; | ||
body = await fsp.readFile(assetPath); | ||
} else if (['.ico'].includes(ext)) { | ||
contentType = 'image/x-icon'; | ||
body = await fsp.readFile(assetPath); | ||
} else { | ||
contentType = `text/${type}`; | ||
body = await fsp.readFile(assetPath, 'utf-8'); | ||
} | ||
|
||
resolve({ | ||
body, | ||
contentType, | ||
extension: this.extensions | ||
}); | ||
} catch (e) { | ||
reject(e); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
module.exports = AssetTransform; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
const path = require('path'); | ||
const { promises: fsp } = require('fs'); | ||
const TransformInterface = require('./transform.interface'); | ||
|
||
class CSSTransform extends TransformInterface { | ||
|
||
constructor(req) { | ||
super(req, ['.css'], 'text/css'); | ||
} | ||
|
||
async applyTransform() { | ||
// do stuff with path | ||
return new Promise(async (resolve, reject) => { | ||
try { | ||
const { url, header } = this.request; | ||
const destHeader = header['sec-fetch-dest']; | ||
const cssPath = url.indexOf('/node_modules') >= 0 | ||
? path.join(process.cwd(), url) | ||
: path.join(this.workspace, url); | ||
|
||
const css = await fsp.readFile(cssPath, 'utf-8'); | ||
let body = '', contentType = ''; | ||
|
||
// <style> tag used | ||
if (destHeader === 'style') { | ||
contentType = 'text/css'; | ||
body = css; | ||
} else if (destHeader === 'empty') { | ||
// assume JS import being being used | ||
contentType = 'text/javascript'; | ||
// TODO line breaks are bad for fetch, need to return CSS string all on one line | ||
body = `const css = "${css.replace(/\r?\n|\r/g, ' ')}";\nexport default css;`; | ||
} | ||
|
||
resolve({ | ||
body, | ||
contentType, | ||
extension: this.extentsions | ||
}); | ||
} catch (e) { | ||
reject(e); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
module.exports = CSSTransform; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const TransformInterface = require('./transform.interface'); | ||
const { getAppTemplate, getAppTemplateScripts, getUserScripts, getMetaContent } = require('./transform.tools'); | ||
|
||
class HTMLTransform extends TransformInterface { | ||
|
||
constructor(req) { | ||
super(req, ['.html'], 'text/html'); | ||
} | ||
|
||
shouldTransform() { | ||
const { url } = this.request; | ||
const barePath = url.endsWith('/') | ||
? `${this.workspace}/pages${url}index` | ||
: `${this.workspace}/pages${url.replace('.html', '')}`; | ||
|
||
return (this.extensions.indexOf(path.extname(url)) >= 0 || path.extname(url) === '') && | ||
(fs.existsSync(`${barePath}.html`) || barePath.substring(barePath.length - 5, barePath.length) === 'index'); | ||
} | ||
|
||
async applyTransform() { | ||
// do stuff with path | ||
let { url } = this.request; | ||
|
||
return new Promise(async (resolve, reject) => { | ||
try { | ||
// do something with markdown or html | ||
const barePath = url[url.length - 1] === '/' | ||
? `${this.workspace}/pages${url}index` | ||
: `${this.workspace}/pages${url.replace('.html', '')}`; | ||
|
||
let body = await getAppTemplate(barePath, this.workspace); | ||
body = await getAppTemplateScripts(body, this.workspace); | ||
body = getUserScripts(body, this.workspace); | ||
body = getMetaContent(url, this.config, body); | ||
|
||
resolve({ | ||
body, | ||
contentType: this.contentType, | ||
extension: this.extensions | ||
}); | ||
} catch (e) { | ||
reject(e); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
module.exports = HTMLTransform; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* eslint-disable no-unused-vars */ | ||
const path = require('path'); | ||
|
||
// tranform.interface.js | ||
module.exports = class TransformInterface { | ||
|
||
constructor(request, extensions, contentType = '') { | ||
const { context, config } = request.compilation; | ||
this.extensions = extensions; // ['.foo', '.bar'] | ||
this.workspace = context.userWorkspace; // greenwood | ||
this.scratchDir = context.scratchDir; | ||
this.request = request; | ||
this.config = config; | ||
this.contentType = contentType; | ||
} | ||
|
||
shouldTransform() { | ||
return this.extensions.indexOf(path.extname(this.request.url)) >= 0; | ||
} | ||
|
||
applyTransform() { | ||
// do stuff with path | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
const path = require('path'); | ||
const { promises: fsp } = require('fs'); | ||
const TransformInterface = require('./transform.interface'); | ||
|
||
class JSTransform extends TransformInterface { | ||
|
||
constructor(req) { | ||
super(req, ['.js'], 'text/javascript'); | ||
} | ||
|
||
shouldTransform() { | ||
const { url } = this.request; | ||
|
||
return this.extensions.indexOf(path.extname(url)) >= 0 && url.indexOf('.json') < 0; | ||
} | ||
|
||
async applyTransform() { | ||
return new Promise(async (resolve, reject) => { | ||
try { | ||
const { url } = this.request; | ||
const jsPath = url.indexOf('/node_modules') >= 0 | ||
? path.join(process.cwd(), url) | ||
: path.join(this.workspace, this.request.url); | ||
|
||
const body = await fsp.readFile(jsPath, 'utf-8'); | ||
resolve({ | ||
body, | ||
contentType: this.contentType, | ||
extension: this.extensions | ||
}); | ||
} catch (e) { | ||
reject(e); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
module.exports = JSTransform; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
const path = require('path'); | ||
const { promises: fsp } = require('fs'); | ||
const TransformInterface = require('./transform.interface'); | ||
|
||
class TransformJSON extends TransformInterface { | ||
|
||
constructor(req) { | ||
super(req, ['.json']); | ||
} | ||
|
||
async applyTransform() { | ||
return new Promise(async (resolve, reject) => { | ||
try { | ||
|
||
// TODO This is here because of ordering, should make JS / JSON matching less greedy | ||
// handle things outside if workspace, like a root directory resolver plugin? | ||
// console.debug('JSON file request!', ctx.url);' | ||
let body = '', contentType = ''; | ||
const { url } = this.request; | ||
|
||
if (url.indexOf('graph.json') >= 0) { | ||
const json = await fsp.readFile(path.join(this.scratchDir, 'graph.json'), 'utf-8'); | ||
|
||
contentType = 'application/json'; | ||
body = JSON.parse(json); | ||
} else { | ||
const json = await fsp.readFile(path.join(this.workspace, url), 'utf-8'); | ||
|
||
contentType = 'text/javascript'; | ||
body = `export default ${json}`; | ||
} | ||
|
||
resolve({ | ||
body, | ||
contentType, | ||
extension: this.extensions | ||
}); | ||
} catch (e) { | ||
reject(e); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
module.exports = TransformJSON; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should probably be called transform image instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it also does fonts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
then we should probably have two then (fonts and images) :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not a big deal for now, will add it as a follow up, but in my mind, I could even see some of these transforms getting more granular, e.g.
but again, one step at a time. I had some ideas on how to scale this out a bit so will take a stab at this API myself to help contribute to the design instead of just pontificating. 😄