-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
441 additions
and
368 deletions.
There are no files selected for viewing
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import prettierConfig from "eslint-config-prettier"; | ||
import prettierPlugin from "eslint-plugin-prettier/recommended"; | ||
import globals from "globals"; | ||
import js from "@eslint/js"; | ||
|
||
export default [ | ||
js.configs.recommended, | ||
prettierConfig, | ||
prettierPlugin, | ||
{ | ||
languageOptions: { | ||
globals: { | ||
...globals.node, | ||
...globals.browser, | ||
global: true, | ||
}, | ||
}, | ||
}, | ||
{ | ||
ignores: [ | ||
"tap-snapshots/*", | ||
"node_modules/*", | ||
"modules/*", | ||
"utils/*", | ||
"dist/*", | ||
"tmp/*", | ||
], | ||
}, | ||
]; |
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 @@ | ||
import { html } from 'lit-element'; | ||
import { html } from "lit-element"; | ||
|
||
const render = (world) => { | ||
return html`<p>Hello ${world}!</p>`; | ||
return html`<p>Hello ${world}!</p>`; | ||
}; | ||
render(); |
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,13 +1,19 @@ | ||
import { html } from 'lit-html/lit-html'; | ||
import { css } from 'lit-html'; | ||
import { LitElement } from 'lit-element'; | ||
import { html } from "lit-html/lit-html"; | ||
import { css } from "lit-html"; | ||
import { LitElement } from "lit-element"; | ||
|
||
export default class Inner extends LitElement { | ||
static get styles() { | ||
return [css`:host { color: red; }`]; | ||
} | ||
static get styles() { | ||
return [ | ||
css` | ||
:host { | ||
color: red; | ||
} | ||
`, | ||
]; | ||
} | ||
|
||
render(world) { | ||
return html`<p>Hello ${world}!</p>`; | ||
} | ||
render(world) { | ||
return html`<p>Hello ${world}!</p>`; | ||
} | ||
} |
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,21 +1,21 @@ | ||
import { replaceElement } from '../utils/dom.js'; | ||
import view from './views.js'; | ||
import data from '../data/data.js'; | ||
import { replaceElement } from "../utils/dom.js"; | ||
import view from "./views.js"; | ||
import data from "../data/data.js"; | ||
|
||
export default class App { | ||
constructor(root) { | ||
this.root = root; | ||
} | ||
constructor(root) { | ||
this.root = root; | ||
} | ||
|
||
render() { | ||
const items = data(); | ||
const el = view(items); | ||
this.root = replaceElement(this.root, el); | ||
} | ||
render() { | ||
const items = data(); | ||
const el = view(items); | ||
this.root = replaceElement(this.root, el); | ||
} | ||
|
||
update() { | ||
setInterval(() => { | ||
this.render(); | ||
}, 1000); | ||
} | ||
update() { | ||
setInterval(() => { | ||
this.render(); | ||
}, 1000); | ||
} | ||
} |
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,5 +1,5 @@ | ||
import { html, css } from 'lit-element'; | ||
import { html } from "lit-element"; | ||
|
||
export default function view(items) { | ||
return html`<p>Hello ${items[0]}!</p>`; | ||
return html`<p>Hello ${items[0]}!</p>`; | ||
} |
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,13 +1,13 @@ | ||
function random(min, max) { | ||
return Math.floor(min + Math.random() * (max + 1 - min)); | ||
return Math.floor(min + Math.random() * (max + 1 - min)); | ||
} | ||
|
||
export default function data() { | ||
return [ | ||
random(0, 20), | ||
random(20, 40), | ||
random(40, 60), | ||
random(60, 80), | ||
random(80, 100), | ||
]; | ||
return [ | ||
random(0, 20), | ||
random(20, 40), | ||
random(40, 60), | ||
random(60, 80), | ||
random(80, 100), | ||
]; | ||
} |
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,19 +1,19 @@ | ||
import { firstElement } from './utils/dom.js'; | ||
import App from './app/app.js'; | ||
import { firstElement } from "./utils/dom.js"; | ||
import App from "./app/app.js"; | ||
|
||
const ready = () => { | ||
return new Promise((resolve) => { | ||
document.addEventListener('DOMContentLoaded', () => { | ||
const el = document.getElementById('app'); | ||
resolve(firstElement(el)); | ||
}); | ||
return new Promise((resolve) => { | ||
document.addEventListener("DOMContentLoaded", () => { | ||
const el = document.getElementById("app"); | ||
resolve(firstElement(el)); | ||
}); | ||
}); | ||
}; | ||
|
||
const start = async () => { | ||
const el = await ready(); | ||
const app = new App(el); | ||
app.render(); | ||
app.update(); | ||
const el = await ready(); | ||
const app = new App(el); | ||
app.render(); | ||
app.update(); | ||
}; | ||
start(); |
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,8 +1,8 @@ | ||
export function replaceElement(target, element) { | ||
target.replaceWith(element); | ||
return element; | ||
target.replaceWith(element); | ||
return element; | ||
} | ||
|
||
export function firstElement(element) { | ||
return element.firstElementChild; | ||
return element.firstElementChild; | ||
} |
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 |
---|---|---|
@@ -1,13 +1,5 @@ | ||
export default { | ||
input: 'src/plugin.js', | ||
external: [ | ||
'rollup-plugin-import-map', | ||
'undici', | ||
'path', | ||
'url', | ||
'fs', | ||
], | ||
output: [ | ||
{ file: 'dist/plugin.cjs', format: 'cjs' }, | ||
], | ||
input: "src/plugin.js", | ||
external: ["rollup-plugin-import-map", "undici", "path", "url", "fs"], | ||
output: [{ file: "dist/plugin.cjs", format: "cjs" }], | ||
}; |
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,70 +1,67 @@ | ||
/* eslint-disable no-restricted-syntax */ | ||
|
||
import { rollupImportMapPlugin as importMapPlugin } from 'rollup-plugin-import-map'; | ||
import { helpers } from '@eik/common'; | ||
import { request } from 'undici'; | ||
import { rollupImportMapPlugin as importMapPlugin } from "rollup-plugin-import-map"; | ||
import { helpers } from "@eik/common"; | ||
import { request } from "undici"; | ||
|
||
const fetchImportMaps = async (urls = []) => { | ||
try { | ||
const maps = urls.map(async (map) => { | ||
const { | ||
statusCode, | ||
body, | ||
} = await request(map, { maxRedirections: 2 }); | ||
try { | ||
const maps = urls.map(async (map) => { | ||
const { statusCode, body } = await request(map, { | ||
maxRedirections: 2, | ||
}); | ||
|
||
if (statusCode === 404) { | ||
throw new Error('Import map could not be found on server'); | ||
} else if (statusCode >= 400 && statusCode < 500) { | ||
throw new Error('Server rejected client request'); | ||
} else if (statusCode >= 500) { | ||
throw new Error('Server error'); | ||
} | ||
return body.json(); | ||
}); | ||
return await Promise.all(maps); | ||
} catch (err) { | ||
throw new Error( | ||
`Unable to load import map file from server: ${err.message}`, | ||
); | ||
} | ||
if (statusCode === 404) { | ||
throw new Error("Import map could not be found on server"); | ||
} else if (statusCode >= 400 && statusCode < 500) { | ||
throw new Error("Server rejected client request"); | ||
} else if (statusCode >= 500) { | ||
throw new Error("Server error"); | ||
} | ||
return body.json(); | ||
}); | ||
return await Promise.all(maps); | ||
} catch (err) { | ||
throw new Error( | ||
`Unable to load import map file from server: ${err.message}`, | ||
); | ||
} | ||
}; | ||
|
||
export default function esmImportToUrl({ | ||
path = process.cwd(), | ||
maps = [], | ||
urls = [], | ||
path = process.cwd(), | ||
maps = [], | ||
urls = [], | ||
} = {}) { | ||
const pMaps = Array.isArray(maps) ? maps : [maps]; | ||
const pUrls = Array.isArray(urls) ? urls : [urls]; | ||
let plugin; | ||
const pMaps = Array.isArray(maps) ? maps : [maps]; | ||
const pUrls = Array.isArray(urls) ? urls : [urls]; | ||
let plugin; | ||
|
||
return { | ||
name: 'eik-rollup-plugin', | ||
return { | ||
name: "eik-rollup-plugin", | ||
|
||
async buildStart(options) { | ||
// Load eik config from eik.json or package.json | ||
const config = await helpers.getDefaults(path); | ||
this.debug(`Loaded eik config ${JSON.stringify(config, null, 2)}`); | ||
async buildStart(options) { | ||
// Load eik config from eik.json or package.json | ||
const config = await helpers.getDefaults(path); | ||
this.debug(`Loaded eik config ${JSON.stringify(config, null, 2)}`); | ||
|
||
// Fetch import maps from the server | ||
try { | ||
const fetched = await fetchImportMaps([...config.map, ...pUrls]); | ||
for (const map of fetched) { | ||
this.debug(`Fetched import map ${JSON.stringify(map, null, 2)}`); | ||
} | ||
plugin = importMapPlugin([...fetched, ...pMaps]); | ||
await plugin.buildStart(options); | ||
} catch (err) { | ||
this.error(err.message); | ||
} | ||
}, | ||
// Fetch import maps from the server | ||
try { | ||
const fetched = await fetchImportMaps([...config.map, ...pUrls]); | ||
for (const map of fetched) { | ||
this.debug(`Fetched import map ${JSON.stringify(map, null, 2)}`); | ||
} | ||
plugin = importMapPlugin([...fetched, ...pMaps]); | ||
await plugin.buildStart(options); | ||
} catch (err) { | ||
this.error(err.message); | ||
} | ||
}, | ||
|
||
resolveId(importee) { | ||
const resolved = plugin.resolveId(importee); | ||
if (resolved) { | ||
this.debug(`Resolved ${importee} to ${resolved.id}`); | ||
} | ||
return resolved; | ||
}, | ||
}; | ||
resolveId(importee) { | ||
const resolved = plugin.resolveId(importee); | ||
if (resolved) { | ||
this.debug(`Resolved ${importee} to ${resolved.id}`); | ||
} | ||
return resolved; | ||
}, | ||
}; | ||
} |
Oops, something went wrong.