-
Notifications
You must be signed in to change notification settings - Fork 257
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #864 from MoralisWeb3/beta-create-moralis-dapp
Beta create-moralis-dapp
- Loading branch information
Showing
75 changed files
with
1,725 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"create-moralis-dapp": patch | ||
"demo-nextjs": patch | ||
--- | ||
|
||
Beta version of the create-moralis-dapp CLI too to quickstart a new project |
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
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,5 @@ | ||
module.exports = { | ||
extends: ['@moralisweb3'], | ||
plugins: ['jest'], | ||
ignorePatterns: ['**/lib/**/*', '**/*.test.ts', '**/dist/**/*', '**/build/**/*', '**/generated/**/*'], | ||
}; |
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 @@ | ||
Run `create-moralis-dapp` in directory where you want to setup dApp |
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,37 @@ | ||
{ | ||
"name": "create-moralis-dapp", | ||
"author": "Moralis", | ||
"version": "2.7.4", | ||
"license": "MIT", | ||
"private": false, | ||
"main": "./lib/index.js", | ||
"types": "./lib/index.d.ts", | ||
"sideEffects": false, | ||
"type": "commonjs", | ||
"files": [ | ||
"lib/*" | ||
], | ||
"bin": { | ||
"create-moralis-dapp": "./lib/index.js" | ||
}, | ||
"scripts": { | ||
"lint": "eslint . --ext .js,.ts,.tsx,jsx", | ||
"format": "prettier --write 'src/**/*.{js,ts}'", | ||
"clean": "rm -rf lib && rm -rf tsconfig.tsbuildinfo && rm -rf ./node_modules/.cache/nx", | ||
"build": "tsc", | ||
"postbuild": "npm run copy-files", | ||
"copy-files": "copyfiles -u 1 -a src/generators/*/template/** lib", | ||
"dev": "ts-node-dev src/index.ts" | ||
}, | ||
"devDependencies": { | ||
"ejs": "^3.1.8", | ||
"@types/ejs": "3.1.1", | ||
"ora": "^5.4.1", | ||
"chalk": "^5.0.1", | ||
"fs-extra": "^10.1.0", | ||
"inquirer": "^8.0.0", | ||
"axios": "^1.2.0", | ||
"lodash": "^4.17.21", | ||
"copyfiles": "2.4.1" | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
packages/create-moralis-dapp/src/generators/next/actions/askWeb3Lib/index.ts
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,27 @@ | ||
import { prompt } from 'inquirer'; | ||
import { getVersionByName } from '../../utils'; | ||
import { Web3LibSchema, web3LibSchema } from './web3LibSchema'; | ||
|
||
export const askWeb3Lib = async (_destination: string) => { | ||
const { web3Lib } = await prompt<Web3LibSchema>({ | ||
type: 'list', | ||
name: 'web3Lib', | ||
message: '🧙 : Select a Web3 library ...', | ||
choices: [ | ||
{ name: 'wagmi', value: web3LibSchema.wagmi }, | ||
{ name: 'useDapp', value: web3LibSchema.useDapp }, | ||
{ name: 'web3-react', value: web3LibSchema.web3React }, | ||
], | ||
}); | ||
|
||
return { | ||
web3Lib, | ||
dependencies: [ | ||
{ | ||
name: web3Lib.name, | ||
version: getVersionByName(web3Lib.name), | ||
}, | ||
{ name: 'ethers', version: getVersionByName('ethers') }, | ||
], | ||
}; | ||
}; |
52 changes: 52 additions & 0 deletions
52
packages/create-moralis-dapp/src/generators/next/actions/askWeb3Lib/web3LibSchema.ts
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,52 @@ | ||
import { DependencyName } from '../../utils'; | ||
|
||
export type Web3LibSchema = Record< | ||
string, | ||
{ name: DependencyName; imports: string; config: string; wrappers: string[] } | ||
>; | ||
|
||
export const web3LibSchema: Web3LibSchema = { | ||
wagmi: { | ||
name: 'wagmi', | ||
imports: ` | ||
import { createClient, configureChains, defaultChains, WagmiConfig } from 'wagmi'; | ||
import { publicProvider } from 'wagmi/providers/public';`, | ||
config: ` | ||
const { provider, webSocketProvider } = configureChains(defaultChains, [publicProvider()]); | ||
const client = createClient({ | ||
provider, | ||
webSocketProvider, | ||
autoConnect: true, | ||
});`, | ||
wrappers: [`<WagmiConfig client={client}>`, `</WagmiConfig>`], | ||
}, | ||
useDapp: { | ||
name: '@usedapp/core', | ||
imports: ` | ||
import { Mainnet, DAppProvider, Config } from '@usedapp/core'; | ||
import { getDefaultProvider } from 'ethers';`, | ||
config: ` | ||
const config: Config = { | ||
readOnlyChainId: Mainnet.chainId, | ||
readOnlyUrls: { | ||
[Mainnet.chainId]: getDefaultProvider('mainnet'), | ||
}, | ||
autoConnect: true, | ||
};`, | ||
wrappers: [`<DAppProvider config={config}>`, `</DAppProvider>`], | ||
}, | ||
web3React: { | ||
name: '@web3-react/core', | ||
imports: ` | ||
import { ethers } from 'ethers'; | ||
import { Web3ReactProvider } from '@web3-react/core';`, | ||
config: ` | ||
const getLibrary = (wrappers: any) => { | ||
const library = new ethers.providers.Web3Provider(provider); | ||
library.pollingInterval = 8000; // frequency provider is polling | ||
return library; | ||
};`, | ||
wrappers: [`<Web3ReactProvider getLibrary={getLibrary}>`, `</Web3ReactProvider>`], | ||
}, | ||
}; |
1 change: 1 addition & 0 deletions
1
packages/create-moralis-dapp/src/generators/next/actions/index.ts
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 @@ | ||
export * from './askWeb3Lib'; |
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,37 @@ | ||
import { Question, prompt } from 'inquirer'; | ||
import { join } from 'path'; | ||
import { addDependenciesToPackageJson, generateWithTemplate } from '../../utils'; | ||
import { askWeb3Lib } from './actions'; | ||
import axios from 'axios'; | ||
|
||
export const nextGenerator = async (name: string, destination: string) => { | ||
try { | ||
const { web3Lib, dependencies } = await askWeb3Lib(destination); | ||
|
||
const templateDir = join(__dirname, './template'); | ||
|
||
const envQuestions: Question[] = [ | ||
{ | ||
name: 'MORALIS_API_KEY', | ||
message: '🧙 : Input your Moralis Api key. You can find it on https://admin.moralis.io/web3apis', | ||
type: 'password', | ||
}, | ||
{ | ||
name: 'NEXTAUTH_URL', | ||
message: | ||
'🧙 : Input your NextJS app URL. You can use "http://localhost:3000" for development. Change it before go production!', | ||
default: 'http://localhost:3000', | ||
}, | ||
]; | ||
|
||
const envVars = await prompt(envQuestions); | ||
|
||
const { data: NEXTAUTH_SECRET } = await axios.get<string>('https://generate-secret.now.sh/32'); | ||
|
||
await generateWithTemplate(templateDir, destination, { web3Lib, name, envVars: { ...envVars, NEXTAUTH_SECRET } }); | ||
|
||
await addDependenciesToPackageJson(destination, [...dependencies]); | ||
} catch (e) { | ||
throw new Error(e); | ||
} | ||
}; |
8 changes: 8 additions & 0 deletions
8
packages/create-moralis-dapp/src/generators/next/template/.env.local.example
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,8 @@ | ||
# Your Moralis Api key, that can be found in the dashboard. Keep this secret! | ||
MORALIS_API_KEY = ''; | ||
|
||
# Linux: `openssl rand -hex 32` or go to https://generate-secret.now.sh/32 | ||
NEXTAUTH_SECRET = ''; | ||
|
||
# Your App URL for Next-Auth | ||
NEXTAUTH_URL = ''; |
8 changes: 8 additions & 0 deletions
8
packages/create-moralis-dapp/src/generators/next/template/.env.local.tmpl
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,8 @@ | ||
# Your Moralis Api key, that can be found in the dashboard. Keep this secret! | ||
MORALIS_API_KEY = <%- envVars.MORALIS_API_KEY %> | ||
|
||
# Linux: `openssl rand -hex 32` or go to https://generate-secret.now.sh/32 | ||
NEXTAUTH_SECRET = <%- envVars.NEXTAUTH_SECRET %> | ||
|
||
# Your App URL for Next-Auth | ||
NEXTAUTH_URL = <%- envVars.NEXTAUTH_URL %> |
7 changes: 7 additions & 0 deletions
7
packages/create-moralis-dapp/src/generators/next/template/.eslintrc.js
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,7 @@ | ||
module.exports = { | ||
extends: ['@moralisweb3', 'plugin:@next/next/recommended'], | ||
ignorePatterns: ['**/build/**/*'], | ||
env: { | ||
browser: true, | ||
}, | ||
}; |
35 changes: 35 additions & 0 deletions
35
packages/create-moralis-dapp/src/generators/next/template/.gitignore
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,35 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
/.pnp | ||
.pnp.js | ||
|
||
# testing | ||
/coverage | ||
|
||
# next.js | ||
/.next/ | ||
/out/ | ||
|
||
# production | ||
/build | ||
|
||
# misc | ||
.DS_Store | ||
*.pem | ||
|
||
# debug | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
.pnpm-debug.log* | ||
|
||
# local env files | ||
.env*.local | ||
|
||
# vercel | ||
.vercel | ||
|
||
# typescript | ||
*.tsbuildinfo |
7 changes: 7 additions & 0 deletions
7
packages/create-moralis-dapp/src/generators/next/template/README.md
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,7 @@ | ||
# Demo NextJS Wagmi Auth | ||
|
||
## Run locally | ||
|
||
1. Copy `.env.local.example` to `.env.local` and fill in the values | ||
2. Install all dependencies `yarn` or `npm install` | ||
3. Run `yarn dev` to start the Next.js application |
13 changes: 13 additions & 0 deletions
13
...eate-moralis-dapp/src/generators/next/template/app/components/elements/Meta/Meta.tsx.tmpl
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,13 @@ | ||
import Head from 'next/head'; | ||
|
||
const Meta = () => { | ||
return ( | ||
<Head> | ||
<title><%- name %></title> | ||
<meta name="description" content="<%- name %>" /> | ||
<link rel="icon" href="/favicon.ico" /> | ||
</Head> | ||
); | ||
}; | ||
|
||
export default Meta; |
1 change: 1 addition & 0 deletions
1
...es/create-moralis-dapp/src/generators/next/template/app/components/elements/Meta/index.ts
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 @@ | ||
export { default as Meta } from './Meta'; |
17 changes: 17 additions & 0 deletions
17
...oralis-dapp/src/generators/next/template/app/components/elements/Navbar/Navbar.module.css
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,17 @@ | ||
.nav { | ||
display: flex; | ||
gap: 38px; | ||
margin-right: auto; | ||
} | ||
|
||
.tab { | ||
font-weight: 500; | ||
font-size: 16px; | ||
line-height: 17px; | ||
text-decoration: none; | ||
} | ||
|
||
.tab:hover, | ||
.active { | ||
color: #2e7daf; | ||
} |
31 changes: 31 additions & 0 deletions
31
...reate-moralis-dapp/src/generators/next/template/app/components/elements/Navbar/Navbar.tsx
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,31 @@ | ||
import Link from 'next/link'; | ||
import { useRouter } from 'next/router'; | ||
import { FC } from 'react'; | ||
import styles from './Navbar.module.css'; | ||
|
||
const pages = [ | ||
{ | ||
href: '/', | ||
name: 'User', | ||
}, | ||
{ | ||
href: '/private', | ||
name: 'Private Page', | ||
}, | ||
]; | ||
|
||
const Navbar: FC = () => { | ||
const { pathname } = useRouter(); | ||
|
||
return ( | ||
<div className={styles.nav}> | ||
{pages.map(({ href, name }) => ( | ||
<Link href={href} key={name}> | ||
<a className={`${styles.tab} ${href === pathname ? styles.active : null}`}> {name}</a> | ||
</Link> | ||
))} | ||
</div> | ||
); | ||
}; | ||
|
||
export default Navbar; |
1 change: 1 addition & 0 deletions
1
.../create-moralis-dapp/src/generators/next/template/app/components/elements/Navbar/index.ts
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 @@ | ||
export { default as Navbar } from './Navbar'; |
28 changes: 28 additions & 0 deletions
28
...app/src/generators/next/template/app/components/elements/buttons/Option/Option.module.css
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,28 @@ | ||
.option { | ||
border-radius: 12px; | ||
cursor: pointer; | ||
display: flex; | ||
justify-content: space-between; | ||
padding: 6px; | ||
width: 100%; | ||
} | ||
|
||
.disabled { | ||
opacity: 0.4; | ||
} | ||
|
||
.option:hover { | ||
background: #ebeff9; | ||
} | ||
|
||
.info { | ||
display: flex; | ||
gap: 12px; | ||
align-items: center; | ||
} | ||
|
||
.name { | ||
color: #68738d; | ||
font-size: 14px; | ||
font-weight: 500; | ||
} |
24 changes: 24 additions & 0 deletions
24
...ralis-dapp/src/generators/next/template/app/components/elements/buttons/Option/Option.tsx
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 @@ | ||
import Image from 'next/image'; | ||
import { FC } from 'react'; | ||
import styles from './Option.module.css'; | ||
|
||
export interface IOption { | ||
name: string; | ||
logoPath: string; | ||
onClick: React.MouseEventHandler<HTMLDivElement>; | ||
disabled?: boolean; | ||
} | ||
|
||
const Option: FC<IOption> = ({ name, logoPath, onClick, disabled }) => { | ||
return ( | ||
<div className={`${styles.option} ${disabled && styles.disabled}`} onClick={onClick}> | ||
<div className={styles.info}> | ||
<Image src={logoPath} alt={name} width={40} height={40} /> | ||
<span className={styles.name}>{name}</span> | ||
</div> | ||
<Image src="/assets/chevronRight.svg" alt="chevronRight" width={24} height={24} /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Option; |
1 change: 1 addition & 0 deletions
1
...moralis-dapp/src/generators/next/template/app/components/elements/buttons/Option/index.ts
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 @@ | ||
export { default as Option } from './Option'; |
1 change: 1 addition & 0 deletions
1
...create-moralis-dapp/src/generators/next/template/app/components/elements/buttons/index.ts
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 @@ | ||
export * from './Option'; |
3 changes: 3 additions & 0 deletions
3
packages/create-moralis-dapp/src/generators/next/template/app/components/elements/index.ts
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,3 @@ | ||
export * from './buttons'; | ||
export * from './Meta'; | ||
export * from './Navbar'; |
Oops, something went wrong.
ecff08e
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.
Test coverage