-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f1587e8
Showing
17 changed files
with
8,658 additions
and
0 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,51 @@ | ||
module.exports = { | ||
env: { | ||
browser: true, | ||
es2021: true, | ||
}, | ||
parser: '@typescript-eslint/parser', | ||
plugins: ['@typescript-eslint'], | ||
extends: ['airbnb', 'airbnb/hooks'], | ||
globals: { | ||
chrome: true, | ||
window: true, | ||
}, | ||
rules: { | ||
'react/jsx-uses-react': 'off', | ||
'react/react-in-jsx-scope': 'off', | ||
'import/no-mutable-exports': 'off', | ||
'no-nested-ternary': 'warn', | ||
eqeqeq: 'off', | ||
semi: ['error', 'never'], | ||
'class-methods-use-this': 'off', | ||
'react/jsx-props-no-spreading': 'off', | ||
'no-multiple-empty-lines': ['error', { max: 1 }], | ||
'react/jsx-filename-extension': [1, { extensions: ['.tsx', '.jsx'] }], | ||
'no-console': 'off', | ||
'react/self-closing-comp': 'off', | ||
'object-curly-newline': 'off', | ||
'import/no-unresolved': 'off', | ||
'import/extensions': 'off', | ||
'import/no-import-module-exports': 'off', | ||
'global-require': 'off', | ||
'arrow-body-style': 'off', | ||
'react/no-unused-class-component-methods': 'off', | ||
'react/destructuring-assignment': 'off', | ||
'no-plusplus': 'off', | ||
radix: 'off', | ||
'@typescript-eslint/no-unused-vars': 'off', | ||
'import/prefer-default-export': 'off', | ||
'no-param-reassign': 'off', | ||
'react-hooks/exhaustive-deps': 'off', | ||
'no-use-before-define': ['error', { functions: false }], | ||
'react/require-default-props': 'off', | ||
'max-len': ['warn', { code: 150 }], | ||
'default-param-last': 'off', | ||
'react/jsx-one-expression-per-line': 'off', | ||
'lines-between-class-members': 'off', | ||
'import/no-extraneous-dependencies': 'off', | ||
'no-underscore-dangle': 'off', | ||
'consistent-return': 'off', | ||
'no-restricted-syntax': 'off', | ||
}, | ||
} |
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 @@ | ||
import { defineConfig } from 'father'; | ||
|
||
export default defineConfig({ | ||
cjs: {}, | ||
prebundle: {}, | ||
}); |
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 @@ | ||
/node_modules | ||
/dist | ||
.DS_Store |
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,4 @@ | ||
#!/usr/bin/env sh | ||
. "$(dirname -- "$0")/_/husky.sh" | ||
|
||
npx --no -- commitlint --edit ${1} |
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,4 @@ | ||
#!/usr/bin/env sh | ||
. "$(dirname -- "$0")/_/husky.sh" | ||
|
||
npx lint-staged |
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,19 @@ | ||
{ | ||
"git": { | ||
"commitMessage": "chore: release v${version}" | ||
}, | ||
"github": { | ||
"release": true, | ||
"releaseName": "v${version}" | ||
}, | ||
"npm": { | ||
"publish": false | ||
}, | ||
"plugins": { | ||
"@release-it/conventional-changelog": { | ||
"preset": "angular", | ||
"infile": "CHANGELOG.md", | ||
"ignoreRecommendedBump": true | ||
} | ||
} | ||
} |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 dingff | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,132 @@ | ||
# tarojs-react-generator | ||
|
||
> Taro 页面/组件创建工具,支持 Taro 3 + React | ||
## 安装 | ||
|
||
|
||
```bash | ||
npm install tarojs-react-generator --save-dev | ||
``` | ||
|
||
## 使用 | ||
|
||
|
||
修改项目 `config/index.js` 中的 plugins 配置 | ||
|
||
```js | ||
const config = { | ||
... | ||
plugins: [ | ||
... | ||
['tarojs-react-generator', { | ||
css: 'sass', | ||
cssModules: true | ||
}] | ||
] | ||
... | ||
} | ||
``` | ||
|
||
### 插件配置 | ||
|
||
| 参数项 | 类型 | 说明 | 默认值 | | ||
| :-----| :---- | :---- | :---- | | ||
| css | string | 指定 css 预处理器,可选 ```none```, ```sass```, ```less```, ```stylus``` | ```sass```| | ||
| cssModules | boolean | 是否开启 cssModules,可选 ```true```, ```false``` | ```true``` | | ||
| typescript | boolean | 是否使用 typescript,可选 ```true```, ```false``` | ```false``` | | ||
| hooks | boolean | 是否使用 hooks,可选 ```true```, ```false``` | ```false``` | | ||
| createConfigFile | boolean | 是否单独创建页面配置文件,可选 ```true```, ```false``` | ```true``` | | ||
| updateRouter | object | 创建页面后更新路由配置 | | | ||
| pageTpl | string | 自定义页面模板的路径,如'src/tpl/page.ejs',注入变量有 ```name```, ```upperFirst```, ```lowerFirst``` | 默认为'',不使用自定义模板 | | ||
| componentTpl | string | 自定义组件模板的路径,注入变量有 ```name```, ```upperFirst```, ```lowerFirst``` | 默认为'',不使用自定义模板 | | ||
| configTpl | string | 自定义配置模板的路径,注入变量有 ```name```, ```upperFirst```, ```lowerFirst``` | 默认为'',不使用自定义模板 | | ||
| styleTpl | string | 自定义样式模板的路径,注入变量有 ```name```, ```isPage```, ```upperFirst```, ```lowerFirst``` | 默认为'',不使用自定义模板 | | ||
|
||
### updateRouter 参数 | ||
|
||
| 参数项 | 类型 | 说明 | 默认值 | | ||
| :-----| :---- | :---- | :---- | | ||
| enable | boolean | 是否开启,可选 ```true```, ```false``` | ```true``` | | ||
| space | number | 插入位置缩进空格数 | ```4``` | | ||
|
||
##### 模板示例 | ||
src/tpl/page.ejs | ||
```js | ||
/** | ||
* 模板注入变量 | ||
* @param name: string 文件名 | ||
* @param upperFirst: function 将首字母大写的函数 | ||
* @param lowerFirst: function 将首字母小写的函数 | ||
*/ | ||
import { useEffect } from 'react' | ||
import { View } from '@tarojs/components' | ||
import styles from './index.module.scss' | ||
|
||
function <%= upperFirst(name) %>() { | ||
|
||
return ( | ||
<View className={styles.<%= name %>Page}> | ||
hello | ||
</View> | ||
) | ||
} | ||
|
||
export default <%= upperFirst(name) %> | ||
``` | ||
src/tpl/style.ejs | ||
```js | ||
<% if (isPage) { %>.<%= name %>Page { | ||
|
||
} | ||
<% } else { %>.<%= lowerFirst(name) %>Com { | ||
|
||
} | ||
<% } %> | ||
``` | ||
|
||
### 命令行参数 | ||
|
||
| 参数项 | 类型 | 说明 | | ||
| :-----| :---- | :---- | | ||
| --com | string | 创建一个公共组件/页面组件 | | ||
| --page | string | 创建一个页面 | | ||
|
||
|
||
### 示例 | ||
|
||
##### 创建公共组件 | ||
```bash | ||
taro g --com Button | ||
``` | ||
|
||
|
||
##### 创建页面组件(index为页面文件夹名称) | ||
```bash | ||
taro g --com index/Button | ||
``` | ||
|
||
|
||
##### 创建页面 | ||
```bash | ||
taro g --page mine | ||
``` | ||
|
||
``` | ||
-- 页面:pages/mine/index.tsx | ||
-- 配置:pages/mine/index.config.tsx | ||
-- 样式:pages/mine/index.module.scss | ||
``` | ||
|
||
|
||
|
||
##### 创建页面(指定路径) | ||
```bash | ||
taro g --page index/bannerDetail | ||
``` | ||
|
||
``` | ||
-- 页面:pages/index/bannerDetail/index.tsx | ||
-- 配置:pages/index/bannerDetail/index.config.tsx | ||
-- 样式:pages/index/bannerDetail/index.module.scss | ||
``` |
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 @@ | ||
module.exports = { extends: ['@commitlint/config-conventional'] } |
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,67 @@ | ||
{ | ||
"name": "tarojs-react-generator", | ||
"version": "1.4.0", | ||
"description": "Taro 页面/组件创建工具,支持 Taro 3 + React", | ||
"main": "dist/cjs/index.js", | ||
"types": "dist/cjs/index.d.ts", | ||
"scripts": { | ||
"dev": "father dev", | ||
"build": "father build", | ||
"build:deps": "father prebundle", | ||
"prepare": "husky install", | ||
"prepublishOnly": "father doctor && npm run build", | ||
"release": "npm run build && release-it --only-version" | ||
}, | ||
"keywords": [ | ||
"Taro", | ||
"React" | ||
], | ||
"repository": "dingff/tarojs-react-generator", | ||
"authors": [ | ||
"dingff0923@foxmail.com" | ||
], | ||
"license": "MIT", | ||
"files": [ | ||
"dist", | ||
"compiled" | ||
], | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"lint-staged": { | ||
"*.{js,jsx,ts,tsx}": [ | ||
"eslint --fix" | ||
] | ||
}, | ||
"devDependencies": { | ||
"@commitlint/cli": "^17.4.4", | ||
"@commitlint/config-conventional": "^17.4.4", | ||
"@release-it/conventional-changelog": "^5.1.1", | ||
"@types/babel__generator": "^7.6.4", | ||
"@types/babel__traverse": "^7.18.3", | ||
"@types/ejs": "^3.1.2", | ||
"@types/node": "^18.15.11", | ||
"@types/react": "^18.0.0", | ||
"@types/react-dom": "^18.0.0", | ||
"@typescript-eslint/eslint-plugin": "^5.55.0", | ||
"@typescript-eslint/parser": "^5.55.0", | ||
"eslint": "^8.2.0", | ||
"eslint-config-airbnb": "19.0.4", | ||
"eslint-plugin-import": "^2.25.3", | ||
"eslint-plugin-jsx-a11y": "^6.5.1", | ||
"eslint-plugin-react": "^7.28.0", | ||
"eslint-plugin-react-hooks": "^4.3.0", | ||
"father": "^4.1.7", | ||
"husky": "^8.0.3", | ||
"lint-staged": "^13.2.0", | ||
"release-it": "^15.7.0" | ||
}, | ||
"dependencies": { | ||
"@babel/generator": "^7.21.4", | ||
"@babel/parser": "^7.21.4", | ||
"@babel/traverse": "^7.21.4", | ||
"@babel/types": "^7.21.4", | ||
"ejs": "^3.1.9", | ||
"fs-extra": "^11.1.0" | ||
} | ||
} |
Oops, something went wrong.