Skip to content

Commit

Permalink
feat: vanilla boilerplate (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidecarpini authored Oct 29, 2023
1 parent fc03020 commit 3feb784
Show file tree
Hide file tree
Showing 46 changed files with 5,121 additions and 128 deletions.
19 changes: 19 additions & 0 deletions apps/sample-vanilla-app/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>

<html>
<head>
<meta charset="utf-8" />
<script crossorigin type="module" src="index.js"></script>
<style>
p {
border: solid 1px blue;
padding: 8px;
}
</style>
</head>
<body>
<connect-button>
<p>This is child content</p>
</connect-button>
</body>
</html>
1 change: 1 addition & 0 deletions apps/sample-vanilla-app/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import '@vechain/vanilla-wallet-kit';
17 changes: 17 additions & 0 deletions apps/sample-vanilla-app/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "sample-vanilla-app",
"version": "1.0.0",
"description": "",
"license": "ISC",
"author": "",
"type": "module",
"scripts": {
"dev": "wds --watch",
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
"@vechain/vanilla-wallet-kit": "*",
"@web/dev-server": "^0.1.31",
"@web/dev-server-legacy": "^1.0.0"
}
}
26 changes: 26 additions & 0 deletions apps/sample-vanilla-app/web-dev-server.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* @license
* Copyright 2021 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/

import { legacyPlugin } from '@web/dev-server-legacy';

const mode = process.env.MODE || 'dev';
if (!['dev', 'prod'].includes(mode)) {
throw new Error(`MODE must be "dev" or "prod", was "${mode}"`);
}

// eslint-disable-next-line import/no-default-export
export default {
nodeResolve: { exportConditions: mode === 'dev' ? ['development'] : [] },
preserveSymlinks: true,
plugins: [
legacyPlugin({
polyfills: {
// Manually imported in index.html file
webcomponents: false,
},
}),
],
};
21 changes: 21 additions & 0 deletions packages/vanilla-wallet-kit/.eleventy.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const syntaxHighlight = require('@11ty/eleventy-plugin-syntaxhighlight');

module.exports = function (eleventyConfig) {
eleventyConfig.addPlugin(syntaxHighlight);
eleventyConfig.addPassthroughCopy('docs-src/docs.css');
eleventyConfig.addPassthroughCopy('docs-src/.nojekyll');
eleventyConfig.addPassthroughCopy(
'node_modules/@webcomponents/webcomponentsjs'
);
eleventyConfig.addPassthroughCopy('node_modules/lit/polyfill-support.js');
return {
dir: {
input: 'docs-src',
output: 'docs',
},
templateExtensionAliases: {
'11ty.cjs': '11ty.js',
'11tydata.cjs': '11tydata.js',
},
};
};
6 changes: 6 additions & 0 deletions packages/vanilla-wallet-kit/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules/*
docs/*
docs-src/*
rollup-config.js
custom-elements.json
web-dev-server.config.js
51 changes: 51 additions & 0 deletions packages/vanilla-wallet-kit/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"root": true,
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2020,
"sourceType": "module"
},
"plugins": ["@typescript-eslint"],
"env": {
"browser": true
},
"rules": {
"no-prototype-builtins": "off",
"@typescript-eslint/ban-types": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-unused-vars": [
"warn",
{
"argsIgnorePattern": "^_"
}
]
},
"overrides": [
{
"files": ["rollup.config.js", "web-test-runner.config.js"],
"env": {
"node": true
}
},
{
"files": [
"*_test.ts",
"**/custom_typings/*.ts",
"packages/labs/ssr/src/test/integration/tests/**",
"packages/labs/ssr/src/lib/util/parse5-utils.ts"
],
"rules": {
"@typescript-eslint/no-explicit-any": "off"
}
}
]
}
11 changes: 11 additions & 0 deletions packages/vanilla-wallet-kit/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/node_modules/
/lib/
/test/
custom-elements.json
# top level source
my-element.js
my-element.js.map
my-element.d.ts
my-element.d.ts.map
# only generated for size check
my-element.bundled.js
7 changes: 7 additions & 0 deletions packages/vanilla-wallet-kit/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"trailingComma": "es5",
"tabWidth": 2,
"singleQuote": true,
"bracketSpacing": false,
"arrowParens": "always"
}
28 changes: 28 additions & 0 deletions packages/vanilla-wallet-kit/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
BSD 3-Clause License

Copyright (c) 2019 Google LLC. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2 changes: 2 additions & 0 deletions packages/vanilla-wallet-kit/docs-src/.eleventyignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Ignore files with a leading underscore; useful for e.g. readmes in source documentation
_*.md
Empty file.
7 changes: 7 additions & 0 deletions packages/vanilla-wallet-kit/docs-src/_README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
This directory contains the sources for the static site contained in the /docs/ directory. The site is based on the [eleventy](11ty.dev) static site generator.

The site is intended to be used with GitHub pages. To enable the site go to the GitHub settings and change the GitHub Pages "Source" setting to "master branch /docs folder".

To view the site locally, run `npm run docs:serve`.

To edit the site, add to or edit the files in this directory then run `npm run docs` to build the site. The built files must be checked in and pushed to GitHub to appear on GitHub pages.
18 changes: 18 additions & 0 deletions packages/vanilla-wallet-kit/docs-src/_data/api.11tydata.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* @license
* Copyright 2021 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/

// eslint-disable-next-line @typescript-eslint/no-var-requires, no-undef
const fs = require('fs');

// eslint-disable-next-line no-undef
module.exports = () => {
const customElements = JSON.parse(
fs.readFileSync('custom-elements.json', 'utf-8')
);
return {
customElements,
};
};
43 changes: 43 additions & 0 deletions packages/vanilla-wallet-kit/docs-src/_includes/example.11ty.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const page = require('./page.11ty.cjs');
const relative = require('./relative-path.cjs');

/**
* This template extends the page template and adds an examples list.
*/
module.exports = function (data) {
return page({
...data,
content: renderExample(data),
});
};

const renderExample = ({name, content, collections, page}) => {
return `
<h1>Example: ${name}</h1>
<section class="examples">
<nav class="collection">
<ul>
${
collections.example === undefined
? ''
: collections.example
.map(
(post) => `
<li class=${post.url === page.url ? 'selected' : ''}>
<a href="${relative(
page.url,
post.url
)}">${post.data.description.replace('<', '&lt;')}</a>
</li>
`
)
.join('')
}
</ul>
</nav>
<div>
${content}
</div>
</section>
`;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = function (data) {
return `
<footer>
<p>
Made with
<a href="https://github.com/lit/lit-element-starter-ts">lit-starter-ts</a>
</p>
</footer>`;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = function (data) {
return `
<header>
<h1>&lt;my-element></h1>
<h2>A web component just for me.</h2>
</header>`;
};
11 changes: 11 additions & 0 deletions packages/vanilla-wallet-kit/docs-src/_includes/nav.11ty.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const relative = require('./relative-path.cjs');

module.exports = function ({page}) {
return `
<nav>
<a href="${relative(page.url, '/')}">Home</a>
<a href="${relative(page.url, '/examples/')}">Examples</a>
<a href="${relative(page.url, '/api/')}">API</a>
<a href="${relative(page.url, '/install/')}">Install</a>
</nav>`;
};
37 changes: 37 additions & 0 deletions packages/vanilla-wallet-kit/docs-src/_includes/page.11ty.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const header = require('./header.11ty.cjs');
const footer = require('./footer.11ty.cjs');
const nav = require('./nav.11ty.cjs');
const relative = require('./relative-path.cjs');

module.exports = function (data) {
const {title, page, content} = data;
return `
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>${title}</title>
<link rel="stylesheet" href="${relative(page.url, '/docs.css')}">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,600|Roboto+Mono">
<link href="${relative(page.url, '/prism-okaidia.css')}" rel="stylesheet" />
<script src="/node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js"></script>
<script src="/node_modules/lit/polyfill-support.js"></script>
<script type="module" src="${relative(
page.url,
'/my-element.bundled.js'
)}"></script>
</head>
<body>
${header()}
${nav(data)}
<div id="main-wrapper">
<main>
${content}
</main>
</div>
${footer()}
</body>
</html>`;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const path = require('path').posix;

module.exports = (base, p) => {
const relativePath = path.relative(base, p);
if (p.endsWith('/') && !relativePath.endsWith('/') && relativePath !== '') {
return relativePath + '/';
}
return relativePath;
};
Loading

0 comments on commit 3feb784

Please sign in to comment.