Skip to content

Commit

Permalink
feat: 🎸 update
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] authored and [email protected] committed Oct 18, 2024
1 parent e57a52c commit f6936a4
Show file tree
Hide file tree
Showing 97 changed files with 1,736 additions and 1,029 deletions.
5 changes: 5 additions & 0 deletions apps/create-aelf-dapp/lib/generator/templates/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
dist
.git
Dockerfile
.dockerignore
36 changes: 35 additions & 1 deletion apps/create-aelf-dapp/lib/generator/templates/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,40 @@
{
"plugins": ["tailwindcss"],
"extends": [
"next/core-web-vitals",
"plugin:@typescript-eslint/recommended",
"plugin:tailwindcss/recommended",
"plugin:prettier/recommended",
"plugin:@tanstack/eslint-plugin-query/recommended"
]
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 11,
"sourceType": "module"
},
"ignorePatterns": [],
"rules": {
"quotes": [
"error",
"single",
{
"avoidEscape": true,
"allowTemplateLiterals": true
}
],
"@typescript-eslint/no-explicit-any": "off",
"tailwindcss/classnames-order": "off",
"tailwindcss/no-custom-classname": "off",
"tailwindcss/no-contradicting-classname": "error",
"@typescript-eslint/no-unused-vars": "warn",
"@typescript-eslint/ban-ts-comment": [
"error",
{
"ts-ignore": false
}
]
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: Test by jest

on: [push, pull_request]
on: [pull_request]

jobs:
lint:
test:
runs-on: ubuntu-latest

steps:
Expand All @@ -13,8 +13,23 @@ jobs:
with:
node-version: '20' # Your node version, default 20 in 2024

- name: Cache node modules
uses: actions/cache@v4
env:
cache-name: cache-node-modules
with:
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Install pnpm
run: npm install -g pnpm

- name: Install Dependencies
run: yarn
run: pnpm install

- name: Run Test
run: yarn test
- name: Run Jest Test
run: pnpm test
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Next Build

on: [pull_request]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20' # Your node version, default 20 in 2024

- name: Cache node modules
uses: actions/cache@v4
env:
cache-name: cache-node-modules
with:
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Install pnpm
run: npm install -g pnpm

- name: Install Dependencies
run: pnpm install

- name: Run Next Build
run: pnpm build
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Next Lint

on: [push, pull_request]
on: [pull_request]

jobs:
lint:
Expand All @@ -19,14 +19,17 @@ jobs:
cache-name: cache-node-modules
with:
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/yarn-lock.json') }}
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Install pnpm
run: npm install -g pnpm

- name: Install Dependencies
run: yarn
run: pnpm install

- name: Run ESLint
run: yarn lint
run: pnpm lint
2 changes: 2 additions & 0 deletions apps/create-aelf-dapp/lib/generator/templates/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,5 @@ package

# git ls-files > filelist.txt
filelist.txt

.eslintcache
3 changes: 2 additions & 1 deletion apps/create-aelf-dapp/lib/generator/templates/.prettierrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"plugins": ["prettier-plugin-tailwindcss"]
"plugins": ["prettier-plugin-tailwindcss"],
"singleQuote": true
}
37 changes: 37 additions & 0 deletions apps/create-aelf-dapp/lib/generator/templates/.stylelintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"extends": [
"stylelint-config-standard",
"stylelint-config-css-modules",
"stylelint-prettier/recommended"
],
"plugins": [
"stylelint-order"
],
"rules": {
"at-rule-no-unknown": [
true,
{
"ignoreAtRules": [
"tailwind",
"apply",
"variants",
"responsive",
"screen"
]
}
],
"order/order": [
"custom-properties",
"declarations"
],
"order/properties-alphabetical-order": true,
"selector-class-pattern": null,
"prettier/prettier": true
},
"ignoreFiles": [
"**/node_modules/**",
"**/dist/**",
"**/build/**",
"**/.next/**"
]
}
81 changes: 81 additions & 0 deletions apps/create-aelf-dapp/lib/generator/templates/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
FROM node:20-alpine AS base

# Install dependencies only when needed
FROM base AS deps
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat
WORKDIR /app

# Install dependencies based on the preferred package manager
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
RUN \
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
elif [ -f package-lock.json ]; then npm ci; \
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \
else echo "Lockfile not found." && exit 1; \
fi


# Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .

# Next.js collects completely anonymous telemetry data about general usage.
# Learn more here: https://nextjs.org/telemetry
# Uncomment the following line in case you want to disable telemetry during the build.
# ENV NEXT_TELEMETRY_DISABLED 1

RUN \
if [ -f yarn.lock ]; then yarn run build; \
elif [ -f package-lock.json ]; then npm run build; \
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm run build; \
else echo "Lockfile not found." && exit 1; \
fi

# Setup Nginx and serve the built application with PM2
FROM node:20-alpine AS app

WORKDIR /app

# Install PM2 globally
RUN npm install -g pm2

# Set environment variables
ENV NODE_ENV=production
# Uncomment the following line in case you want to disable telemetry during runtime.
# ENV NEXT_TELEMETRY_DISABLED 1

# Create a system user and group
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs

# Install Nginx
RUN apk update && apk add --no-cache nginx

# Copy the Nginx configuration file
COPY nginx-template.conf /etc/nginx/http.d/default.conf

# Copy the PM2 config file
COPY pm2.config.js /app/pm2.config.js

# Copy the built Next.js app from the builder stage
COPY --from=builder /app/public ./public
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static

# Set the correct permission for prerender cache
# RUN mkdir -p .next && chown nextjs:nodejs .next

# Copy the .env.production file
COPY .env.production /app/.env.production

# Switch to the non-root user
# USER nextjs

# Expose the port
EXPOSE 3005

# Start Nginx and the Next.js app with PM2
CMD ["sh", "-c", "nginx && pm2-runtime start pm2.config.js"]
10 changes: 10 additions & 0 deletions apps/create-aelf-dapp/lib/generator/templates/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,13 @@ You can check out [the Next.js GitHub repository](https://github.com/vercel/next
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.

Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.

## Docker Build & Use

```bash
# Dockerfile
# build
docker build -t create-aelf-dapp .
# run
docker run -p 3006:3005 create-aelf-dapp
```
5 changes: 4 additions & 1 deletion apps/create-aelf-dapp/lib/generator/templates/appsettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ export const APP_SETTINGS: IAppSettings = {
],
propagateTraceHeaderCorsUrls: [
// /.*/,
"https://httpbin.org"
/gcptest-indexer-api\.aefinder\.io/,
// "https://httpbin.org",
// "https://otel.aelf.com/v1/traces",
// "gcptest-indexer-api.aefinder.io/*"
],
},
"chainGPT": {
Expand Down
28 changes: 28 additions & 0 deletions apps/create-aelf-dapp/lib/generator/templates/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
version: '1.0'

services:
create-aelf-dapp.nginx:
container_name: create-aelf-dapp.nginx
image: nginx:1.27.1
ports:
- "3006:3006"
volumes:
- ./create-aelf-dapp.conf:/etc/nginx/conf.d/default.conf
networks:
- create-aelf-dapp_network
restart: unless-stopped

create-aelf-dapp.interface:
container_name: create-aelf-dapp.interface
build:
context: .
dockerfile: Dockerfile
ports:
- "3005:3005"
networks:
- create-aelf-dapp_network
restart: unless-stopped

networks:
create-aelf-dapp_network:
external: true
18 changes: 0 additions & 18 deletions apps/create-aelf-dapp/lib/generator/templates/jest.config.js

This file was deleted.

35 changes: 35 additions & 0 deletions apps/create-aelf-dapp/lib/generator/templates/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
// const nextJest = require('next/jest');
import nextJest from 'next/jest';
import type { Config } from 'jest';

/** @type {import('jest').Config} */
const createJestConfig = nextJest({
// Provide the path to your Next.js app to load next.config.js and .env files in your test environment
dir: './',
});

// Add any custom config to be passed to Jest
const config: Config = {
coverageProvider: 'v8',
collectCoverage: true,
coverageDirectory: 'coverage',
coverageReporters: ['json-summary', 'text'],
testEnvironment: 'jsdom',
// Add more setup options before each test is run
setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'],
moduleNameMapper: {
// '^@/(.*)$': '<rootDir>/src/$1',
'^@/(.*)$': '<rootDir>/src/$1',
'^lodash-es$': 'lodash',
'^swiper$': '<rootDir>/._tests__/__mocks__/swiper.js',
},
transformIgnorePatterns: [
'node_modules/(?!(swiper)/)',
'node_modules/.pnpm/(?!(swiper)/)',
],
};

// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async
// module.exports = createJestConfig(config);
export default createJestConfig(config);
Loading

0 comments on commit f6936a4

Please sign in to comment.