Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
eleliauk committed Jul 16, 2024
2 parents ca8242b + bffa385 commit edbc100
Show file tree
Hide file tree
Showing 61 changed files with 67,927 additions and 4,045 deletions.
64 changes: 62 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,67 @@
{
"extends": ["taro/react"],
"plugins": ["@typescript-eslint", "simple-import-sort", "unused-imports"],
"extends": [
"taro/react",
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"plugin:react-hooks/recommended",
"prettier",
"plugin:prettier/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module",
"project": true,
"tsconfigRootDir": "__dirname"
},
"rules": {
"react/jsx-uses-react": "off",
"react/react-in-jsx-scope": "off"
"react/react-in-jsx-scope": "off",
"no-unused-vars": "off",
"no-console": "warn",
"@typescript-eslint/explicit-module-boundary-types": "off",
"react/no-unescaped-entities": "off",
"react/display-name": "off",
"react/jsx-curly-brace-presence": ["warn", { "props": "never", "children": "never" }],
"@typescript-eslint/no-unused-vars": "off",
"unused-imports/no-unused-imports": "warn",
"unused-imports/no-unused-vars": [
"warn",
{
"vars": "all",
"varsIgnorePattern": "^_",
"args": "after-used",
"argsIgnorePattern": "^_"
}
],
"simple-import-sort/exports": "warn",
"simple-import-sort/imports": [
"warn",
{
"groups": [
["^@?\\w", "^\\u0000"],
["^.+\\.s?css$"],
["^@/libs", "^@/hooks"],
["^@/data"],
["^@/components", "^@/container"],
["^@/store"],
["^@/"],
[
"^\\./?$",
"^\\.(?!/?$)",
"^\\.\\./?$",
"^\\.\\.(?!/?$)",
"^\\.\\./\\.\\./?$",
"^\\.\\./\\.\\.(?!/?$)",
"^\\.\\./\\.\\./\\.\\./?$",
"^\\.\\./\\.\\./\\.\\.(?!/?$)"
],
["^@/types"],
["^"]
]
}
]
}
}
8 changes: 8 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: 2
updates:
- package-ecosystem: 'npm'
directory: '/'
schedule:
interval: 'daily'
open-pull-requests-limit: 10
versioning-strategy: 'auto'
39 changes: 39 additions & 0 deletions .github/workflows/build_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Build Test

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
lint-and-format:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '18'

- name: Install dependencies
run: yarn install

- name: Run Build
run: yarn build:weapp

- name: Check for merge conflicts
if: github.event_name == 'pull_request'
run: |
git fetch --no-tags --prune origin +refs/heads/*:refs/remotes/origin/*
git checkout -qf ${{ github.event.pull_request.head.sha }}
git merge-base --is-ancestor origin/main ${{ github.event.pull_request.head.sha }} || git merge --no-commit --no-ff origin/main
if [ $? -ne 0 ]; then
echo "Merge conflicts detected. Please resolve them before merging."
exit 1
fi
42 changes: 42 additions & 0 deletions .github/workflows/lint_and_format_check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Lint and Format Check

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
lint-and-format:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '18'

- name: Install dependencies
run: yarn install

- name: Run Prettier
run: npx prettier --check .

- name: Run ESLint
run: npx eslint .

- name: Check for merge conflicts
if: github.event_name == 'pull_request'
run: |
git fetch --no-tags --prune origin +refs/heads/*:refs/remotes/origin/*
git checkout -qf ${{ github.event.pull_request.head.sha }}
git merge-base --is-ancestor origin/main ${{ github.event.pull_request.head.sha }} || git merge --no-commit --no-ff origin/main
if [ $? -ne 0 ]; then
echo "Merge conflicts detected. Please resolve them before merging."
exit 1
fi
8 changes: 8 additions & 0 deletions .husky/common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
command_exists () {
command -v "$1" >/dev/null 2>&1
}

# Workaround for Windows 10, Git Bash, and Yarn
if command_exists winpty && test -t 1; then
exec < /dev/tty
fi
6 changes: 6 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env sh
export GIT_TERMINAL_PROMPT=0
. "$(dirname -- "$0")/_/husky.sh"
. "$(dirname -- "$0")/common.sh"

yarn lint
8 changes: 8 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
node_modules
.DS_Store
dist
dist-ssr
*.local
project.config.json
project.private.config.json
auto-imports.d.ts
18 changes: 18 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"plugins": ["prettier-plugin-organize-imports"],
"trailingComma": "es5",
"semi": true,
"singleQuote": true,
"arrowParens": "always",
"printWidth": 90,
"tabWidth": 2,
"endOfLine": "auto",
"overrides": [
{
"files": ".eslintrc",
"options": {
"trailingComma": "none"
}
}
]
}
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"editor.inlineSuggest.showToolbar": "onHover"
"editor.inlineSuggest.showToolbar": "onHover"
}
16 changes: 7 additions & 9 deletions __tests__/index.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import TestUtils from '@tarojs/test-utils-react'
import TestUtils from '@tarojs/test-utils-react';

describe('Testing', () => {

test('Test', async () => {
const testUtils = new TestUtils()
await testUtils.createApp()
await testUtils.PageLifecycle.onShow('pages/index/index')
expect(testUtils.html()).toMatchSnapshot()
})

})
const testUtils = new TestUtils();
await testUtils.createApp();
await testUtils.PageLifecycle.onShow('pages/index/index');
expect(testUtils.html()).toMatchSnapshot();
});
});
15 changes: 9 additions & 6 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
// https://github.com/NervJS/taro/blob/next/packages/babel-preset-taro/README.md
module.exports = {
presets: [
['taro', {
framework: 'react',
ts: true
}]
]
}
[
'taro',
{
framework: 'react',
ts: true,
},
],
],
};
8 changes: 4 additions & 4 deletions config/dev.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { UserConfigExport } from "@tarojs/cli";
import type { UserConfigExport } from '@tarojs/cli';

export default {
logger: {
quiet: false,
stats: true
stats: true,
},
mini: {},
h5: {}
} satisfies UserConfigExport
h5: {},
} satisfies UserConfigExport;
70 changes: 33 additions & 37 deletions config/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { defineConfig, type UserConfigExport } from '@tarojs/cli'
import TsconfigPathsPlugin from 'tsconfig-paths-webpack-plugin'
import devConfig from './dev'
import prodConfig from './prod'
import { defineConfig, type UserConfigExport } from '@tarojs/cli';
import TsconfigPathsPlugin from 'tsconfig-paths-webpack-plugin';

import devConfig from './dev';
import prodConfig from './prod';

// https://taro-docs.jd.com/docs/next/config#defineconfig-辅助函数
export default defineConfig(async (merge, { command, mode }) => {
Expand All @@ -13,92 +14,87 @@ export default defineConfig(async (merge, { command, mode }) => {
640: 2.34 / 2,
750: 1,
375: 2,
828: 1.81 / 2
828: 1.81 / 2,
},
sourceRoot: 'src',
outputRoot: 'dist',
plugins: [],
defineConstants: {
},
defineConstants: {},
copy: {
patterns: [
],
options: {
}
patterns: [],
options: {},
},
framework: 'react',
compiler: 'webpack5',
cache: {
enable: false // Webpack 持久化缓存配置,建议开启。默认配置请参考:https://docs.taro.zone/docs/config-detail#cache
enable: false, // Webpack 持久化缓存配置,建议开启。默认配置请参考:https://docs.taro.zone/docs/config-detail#cache
},
mini: {
postcss: {
pxtransform: {
enable: true,
config: {

}
config: {},
},
url: {
enable: true,
config: {
limit: 1024 // 设定转换尺寸上限
}
limit: 1024, // 设定转换尺寸上限
},
},
cssModules: {
enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
config: {
namingPattern: 'module', // 转换模式,取值为 global/module
generateScopedName: '[name]__[local]___[hash:base64:5]'
}
}
generateScopedName: '[name]__[local]___[hash:base64:5]',
},
},
},
webpackChain(chain) {
chain.resolve.plugin('tsconfig-paths').use(TsconfigPathsPlugin)
}
chain.resolve.plugin('tsconfig-paths').use(TsconfigPathsPlugin);
},
},
h5: {
publicPath: '/',
staticDirectory: 'static',
output: {
filename: 'js/[name].[hash:8].js',
chunkFilename: 'js/[name].[chunkhash:8].js'
chunkFilename: 'js/[name].[chunkhash:8].js',
},
miniCssExtractPluginOption: {
ignoreOrder: true,
filename: 'css/[name].[hash].css',
chunkFilename: 'css/[name].[chunkhash].css'
chunkFilename: 'css/[name].[chunkhash].css',
},
postcss: {
autoprefixer: {
enable: true,
config: {}
config: {},
},
cssModules: {
enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
config: {
namingPattern: 'module', // 转换模式,取值为 global/module
generateScopedName: '[name]__[local]___[hash:base64:5]'
}
}
generateScopedName: '[name]__[local]___[hash:base64:5]',
},
},
},
webpackChain(chain) {
chain.resolve.plugin('tsconfig-paths').use(TsconfigPathsPlugin)
}
chain.resolve.plugin('tsconfig-paths').use(TsconfigPathsPlugin);
},
},
rn: {
appName: 'taroDemo',
postcss: {
cssModules: {
enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
}
}
}
}
},
},
},
};
if (process.env.NODE_ENV === 'development') {
// 本地开发构建配置(不混淆压缩)
return merge({}, baseConfig, devConfig)
return merge({}, baseConfig, devConfig);
}
// 生产构建配置(默认开启压缩混淆等)
return merge({}, baseConfig, prodConfig)
})
return merge({}, baseConfig, prodConfig);
});
Loading

0 comments on commit edbc100

Please sign in to comment.