-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add working code to load the sdk bundle
- Loading branch information
1 parent
e70207d
commit 718acec
Showing
5 changed files
with
99 additions
and
4 deletions.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,78 @@ | ||
const fetch = require('node-fetch'); | ||
const vm = require('vm'); | ||
|
||
const noop = () => {}; | ||
|
||
const BASE_URL = | ||
'https://hypertext-sandbox.nr-assets.net/wanda--wanda-ec-ui--nr1-docs'; | ||
|
||
const getBundle = async (src) => { | ||
const res = await fetch(src); | ||
return res.text(); | ||
}; | ||
|
||
exports.sourceNodes = async ({ actions }, { release }) => { | ||
// const { createNode } = actions; | ||
global.Element = { | ||
prototype: { | ||
setAttribute: noop, | ||
}, | ||
}; | ||
global.CSSStyleDeclaration = { | ||
prototype: { | ||
setAttribute: noop, | ||
}, | ||
}; | ||
global.navigator = { | ||
userAgent: '', | ||
}; | ||
global.removeEventListener = noop; | ||
global.addEventListener = noop; | ||
global.document = { | ||
cookie: '', | ||
getElementsByTagName() { | ||
return []; | ||
}, | ||
body: { | ||
appendChild: noop, | ||
removeChild: noop, | ||
}, | ||
createElement() { | ||
return { | ||
setAttribute: noop, | ||
style: {}, | ||
}; | ||
}, | ||
}; | ||
|
||
global.btoa = noop; | ||
|
||
global.window = { | ||
document: global.document, | ||
history: {}, | ||
navigator: global.navigator, | ||
location: { | ||
hostname: '', | ||
search: '', | ||
}, | ||
}; | ||
|
||
const bundles = await Promise.all([ | ||
getBundle('https://nr1.nr-assets.net/lib/d3/3.5.17/d3.js'), | ||
getBundle( | ||
'https://nr1.nr-assets.net/lib/react/16.6.3/react.development.js' | ||
), | ||
getBundle( | ||
'https://nr1.nr-assets.net/lib/react/16.6.3/react-dom.development.js' | ||
), | ||
getBundle( | ||
'https://nr1.nr-assets.net/lib/react-router-dom/4.2.2/react-router-dom.js' | ||
), | ||
getBundle(`${BASE_URL}-${release}.js`), | ||
'__NR1_SDK__', | ||
]); | ||
|
||
const sdk = vm.runInThisContext(bundles.join('\n')); | ||
|
||
console.log(sdk); | ||
}; |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
const BASE_URL = | ||
'//hypertext-sandbox.nr-assets.net/wanda--wanda-ec-ui--nr1-docs'; | ||
const RELEASE = 'release-1093'; | ||
|
||
export const RELEASE = 'release-1093'; | ||
export const JS_BUNDLE = `${BASE_URL}-${RELEASE}.js`; | ||
export const CSS_BUNDLE = `${BASE_URL}-${RELEASE}.css`; |