Skip to content

Commit 99f4dad

Browse files
authored
Add web3js-vue-dapp-min Template (#10)
* Add web3js-vue-dapp-min Template * Fix Test Workflow
1 parent 87fd705 commit 99f4dad

26 files changed

+7839
-1
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: web3js-vue-dapp-min Build & Test
2+
on:
3+
push:
4+
branches: [ main ]
5+
pull_request:
6+
branches: [ main ]
7+
types: [ opened, reopened, synchronize ]
8+
jobs:
9+
build:
10+
name: Build & Test
11+
runs-on: ubuntu-latest
12+
defaults:
13+
run:
14+
working-directory: templates/min/web3js-vue-dapp-min
15+
steps:
16+
- uses: actions/checkout@v4
17+
- uses: actions/setup-node@v4
18+
with:
19+
node-version: 20
20+
- run: npm i
21+
- run: npm run build
22+
- run: npm run test:unit

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ for their selection.
1313
Usage: npx create-web3js-dapp [options]
1414

1515
Options:
16-
-f, --framework <name> front-end framework (choices: "angular", "react")
16+
-f, --framework <name> front-end framework (choices: "angular", "react", "vue")
1717
-t, --template <type> template type (choices: "demonstration", "minimal")
1818
-h, --help display help for command
1919
```
@@ -32,3 +32,4 @@ This utility supports the following front-end frameworks:
3232

3333
- [Angular](https://angular.dev/) (only available as a minimal template)
3434
- [React](https://react.dev/)
35+
- [Vue](https://vuejs.org/) (only available as a minimal template)

src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ program
1616
new Option("-f, --framework <name>", "front-end framework").choices([
1717
"angular",
1818
"react",
19+
"vue",
1920
]),
2021
)
2122
.addOption(
@@ -71,6 +72,10 @@ async function inquire(cliOpts: OptionValues): Promise<Options> {
7172
name: "React",
7273
value: Framework.React,
7374
},
75+
{
76+
name: "Vue",
77+
value: Framework.Vue,
78+
},
7479
],
7580
});
7681
}

src/lib.spec.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,49 @@ test("getSelectedOption(react, demonstration)", () => {
111111
"unexpected project location",
112112
);
113113
});
114+
115+
test("getSelectedOption(vue, minimal)", () => {
116+
const opts: Options = {
117+
framework: Framework.Vue,
118+
template: TemplateType.Minimal,
119+
};
120+
const result: SelectedOption = getSelectedOption(opts);
121+
122+
const expectedName: string = "web3js-vue-dapp-min";
123+
assert.strictEqual(
124+
result.projectName,
125+
expectedName,
126+
"unexpected project name",
127+
);
128+
129+
const expectedLocation: string = join(
130+
__dirname,
131+
"..",
132+
"templates",
133+
"min",
134+
expectedName,
135+
);
136+
assert.strictEqual(
137+
result.projectLocation,
138+
expectedLocation,
139+
"unexpected project location",
140+
);
141+
});
142+
143+
test("getSelectedOption(vue, demonstration)", () => {
144+
const opts: Options = {
145+
framework: Framework.Vue,
146+
template: TemplateType.Demonstration,
147+
};
148+
try {
149+
const result: SelectedOption = getSelectedOption(opts);
150+
} catch (e) {
151+
assert.strictEqual(
152+
e.toString(),
153+
"Error: Vue demonstration dApp has not yet been implemented.",
154+
);
155+
return;
156+
}
157+
158+
assert.strictEqual(true, false);
159+
});

src/lib.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,22 @@ export function getSelectedOption(opts: Options): SelectedOption {
4040
);
4141
return { projectName, projectLocation };
4242
}
43+
case Framework.Vue: {
44+
if (opts.template === TemplateType.Demonstration) {
45+
throw new Error(
46+
"Vue demonstration dApp has not yet been implemented.",
47+
);
48+
}
49+
50+
const projectName: string = "web3js-vue-dapp-min";
51+
const projectLocation: string = join(
52+
__dirname,
53+
"..",
54+
"templates",
55+
"min",
56+
projectName,
57+
);
58+
return { projectName, projectLocation };
59+
}
4360
}
4461
}

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export enum Framework {
22
Angular = "angular",
33
React = "react",
4+
Vue = "vue",
45
}
56

67
export enum TemplateType {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/* eslint-env node */
2+
require('@rushstack/eslint-patch/modern-module-resolution')
3+
4+
module.exports = {
5+
root: true,
6+
'extends': [
7+
'plugin:vue/vue3-essential',
8+
'eslint:recommended',
9+
'@vue/eslint-config-typescript',
10+
'@vue/eslint-config-prettier/skip-formatting'
11+
],
12+
parserOptions: {
13+
ecmaVersion: 'latest'
14+
}
15+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
pnpm-debug.log*
8+
lerna-debug.log*
9+
10+
node_modules
11+
.DS_Store
12+
dist
13+
dist-ssr
14+
coverage
15+
*.local
16+
17+
/cypress/videos/
18+
/cypress/screenshots/
19+
20+
# Editor directories and files
21+
.vscode/*
22+
!.vscode/extensions.json
23+
.idea
24+
*.suo
25+
*.ntvs*
26+
*.njsproj
27+
*.sln
28+
*.sw?
29+
30+
*.tsbuildinfo
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"$schema": "https://json.schemastore.org/prettierrc",
3+
"semi": false,
4+
"tabWidth": 2,
5+
"singleQuote": true,
6+
"printWidth": 100,
7+
"trailingComma": "none"
8+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 web3js-react-dapp-min
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Web3.js + Vue Minimal dApp Template
2+
3+
This project is a minimal template for using [Web3.js](https://web3js.org/) with
4+
[Vue](https://vuejs.org/).
5+
6+
- [Web3.js Docs](https://docs.web3js.org/)
7+
- [React Docs](https://vuejs.org/guide/introduction.html)
8+
9+
This project was bootstrapped with
10+
[`create-vue`](https://github.com/vuejs/create-vue).
11+
12+
## Getting Started
13+
14+
Install the project dependencies with a dependency manager like npm or Yarn. Use
15+
`npm run dev` to start a local development server and navigate to
16+
http://localhost:5173/ to view the dApp.
17+
18+
## Project Design
19+
20+
This project defines a service in
21+
[./src/web3/web3-service.ts](./src/web3/web3-service.ts) that exposes an
22+
instance of the [`Web3` class](https://docs.web3js.org/api/web3/class/Web3) and
23+
an [EIP-1193](https://eips.ethereum.org/EIPS/eip-1193) provider, if present. If
24+
the provider is present, it's used by the `Web3` instance to communicate with
25+
the network and the service registers a
26+
[`chainChanged` handler](https://docs.metamask.io/wallet/reference/provider-api/#chainchanged)
27+
that reloads the page. Refer to [./src/App.vue](./src/App.vue) for an example of
28+
using the service.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/// <reference types="vite/client" />
2+
3+
import type { EIP1193Provider, Web3APISpec } from 'web3';
4+
5+
declare global {
6+
interface Window {
7+
ethereum?: EIP1193Provider<Web3APISpec>;
8+
}
9+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<link rel="icon" href="/favicon.ico">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>Web3.js + Vue Minimal dApp Template</title>
8+
</head>
9+
<body>
10+
<div id="app"></div>
11+
<script type="module" src="/src/main.ts"></script>
12+
</body>
13+
</html>

0 commit comments

Comments
 (0)