Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
changcllong committed Aug 17, 2021
0 parents commit 7363ea6
Show file tree
Hide file tree
Showing 35 changed files with 6,315 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# http://editorconfig.org
root = true

[*]
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules/
dist/
types/
examples/
90 changes: 90 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
module.exports = {
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
'prettier',
],
plugins: ['@typescript-eslint'],
parser: '@typescript-eslint/parser',
env: { es6: true, node: true },
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
project: './tsconfig.json',
ecmaFeatures: {
jsx: true,
},
},
settings: {
'import/resolver': {
typescript: {
directory: './',
},
},
},
ignorePatterns: ['**/*.js'],
rules: {
// ts 2.1
'@typescript-eslint/ban-ts-comment': 'error',
// ts 2.2
'@typescript-eslint/consistent-type-assertions': 'error',
// ts 2.5
'@typescript-eslint/no-parameter-properties': 'error',
// ts 2.7
'@typescript-eslint/no-non-null-assertion': 'warn',
// ts 2.8
'@typescript-eslint/triple-slash-reference': 'error',
// ts 2.9
'@typescript-eslint/unified-signatures': 'warn',
// ts 2.10
'@typescript-eslint/restrict-plus-operands': 'warn',
// ts 2.11
'@typescript-eslint/no-explicit-any': 'warn',
// ts 2.12
'@typescript-eslint/no-inferrable-types': 'warn',
// ts 3.1
'@typescript-eslint/type-annotation-spacing': 'error',
// ts 3.2
'@typescript-eslint/ban-types': [
2,
{
types: {
String: {
message: 'Use string instead',
fixWith: 'string',
},
Number: {
message: 'Use number instead',
fixWith: 'number',
},
Boolean: {
message: 'Use boolean instead',
fixWith: 'boolean',
},
Object: {
message: 'Use object instead',
fixWith: 'object',
},
},
},
],
// ts 3.3
'@typescript-eslint/member-delimiter-style': 'error',
// ts 3.5
'@typescript-eslint/naming-convention': [
'warn',
{
selector: 'variable',
format: ['PascalCase', 'camelCase', 'UPPER_CASE'],
},
],
// ts 3.6
'@typescript-eslint/member-ordering': 'warn',
'no-shadow': 'error',
'lines-between-class-members': 'error',
semi: ['error', 'always'],
'max-lines-per-function': ['warn', { max: 200 }],
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-member-accessibility': 'off',
},
};
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules/
dist/

.vscode
6 changes: 6 additions & 0 deletions .huskyrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"hooks": {
"pre-commit": "lint-staged",
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
}
6 changes: 6 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
tabWidth: 2,
singleQuote: true,
trailingComma: 'all',
semi: true,
};
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Lark Technologies Pte. Ltd.

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.
89 changes: 89 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# @tarojs/plugin-platform-lark

Taro 插件,用于支持编译飞书(Lark)小程序。

## Usage

### 安装

```bash
yarn add @tarojs/plugin-platform-lark
```

### 配置

Taro 项目配置

```javascript
config = {
// ...
plugins: [
[
'@tarojs/plugin-platform-lark',
// 插件选项
{
pc: false
}
]
]
}
```

### 编译命令

package.json 添加命令

```json
{
"scripts": {
"build:lark": "taro build --type lark",
"dev:lark": "npm run build:lark -- --watch"
},
}
```

```bash
# yarn
$ yarn dev:lark
$ yarn build:lark

# npm script
$ npm run dev:lark
$ npm run build:lark

# 仅限全局安装
$ taro build --type lark --watch
$ taro build --type lark

# npx 用户也可以使用
$ npx taro build --type lark --watch
$ npx taro build --type lark

# watch 同时开启压缩
$ set NODE_ENV=production && taro build --type lark --watch # Windows
$ NODE_ENV=production taro build --type lark --watch # Mac
```

### 小程序开发者工具

执行上面的编译命令(根据个人习惯选择一个执行),下载并打开[飞书小程序开发者工具](https://open.feishu.cn/document/uYjL24iN/ucDOzYjL3gzM24yN4MjN?lang=zh-CN),导入项目,选择项目根目录下的 dist 目录(即编译配置 config/index.js 中 outputRoot 设置的目录)打开。

### 类型引入

如果当前 taro 项目使用 typescript 作为开发语言,需要在项目中 global.d.ts 文件头部添加如下一行:

```ts
/// <reference path="./node_modules/@tarojs/plugin-platform-lark/types/shims-lark.d.ts" />
```

## 插件选项

| 选项名 || 默认值 | 是否必填 | 说明 |
| -- | :-: | :-: | :-: | :-: |
| pc | boolean | false || 指定 Lark 小程序是否支持 PC 端的组件属性(注 1) |
| entry | string | <空> || 指定 Lark 小程序编译时的入口文件(注 2) |

注:

1. Lark 小程序支持在 PC 客户端上运行;举个例子,如果此时 view 组件要支持 bindmouseenter / bindmouseleave 这一对属性, 就需要开启这个选项。
2. Taro 的默认小程序编译入口是 src 文件夹下的 app.(ts|js|tsx),可以设置 entry 为另一个文件的路径来修改 Lark 小程序编译入口,这里的路径是相对于项目编译配置的 sourceRoot (一般是 'src')的,且在入口文件的相同文件夹下需要存在同名的 config 文件(默认入口是 app.(ts|js|tsx),且存在 app.config.(ts|js))。
4 changes: 4 additions & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// @ts-nocheck
module.exports = {
extends: ['@commitlint/config-conventional'],
};
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = require('./dist/index.js').default
module.exports.default = module.exports
module.exports.Lark = require('./dist/index.js').Lark
67 changes: 67 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"name": "@tarojs/plugin-platform-lark",
"version": "1.0.0",
"description": "taro platform plugin for lark",
"main": "index.js",
"files": [
"index.js",
"dist",
"types"
],
"types": "types/index.d.ts",
"scripts": {
"build": "rimraf ./dist & rollup -c",
"dev": "rimraf ./dist & rollup -c -w",
"eslint": "eslint --fix .",
"prepublishOnly": "yarn build"
},
"repository": {
"type": "git",
"url": "git+https://github.com/NervJS/taro-plugin-platform-lark.git"
},
"keywords": [
"taro",
"plugin",
"lark"
],
"author": "changcllong",
"homepage": "https://github.com/NervJS/taro-plugin-platform-lark",
"license": "MIT",
"devDependencies": {
"@commitlint/cli": "^12.0.1",
"@commitlint/config-conventional": "^12.0.1",
"@tarojs/components": "^3.3.0",
"@tarojs/service": "^3.3.0",
"@tarojs/shared": "^3.3.0",
"@types/node": "^16.0.1",
"@types/react": "17.0.1",
"@typescript-eslint/eslint-plugin": "^4.16.1",
"@typescript-eslint/parser": "^4.16.1",
"eslint": "^7.30.0",
"eslint-config-prettier": "^8.3.0",
"eslint-config-standard": "^16.0.3",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-promise": "^5.1.0",
"eslint-plugin-standard": "^5.0.0",
"husky": "^5.1.3",
"lint-staged": "^10.5.4",
"prettier": "^2.2.1",
"rollup": "^2.40.0",
"rollup-plugin-typescript2": "^0.30.0",
"typescript": "^4.2.3"
},
"peerDependencies": {
"@tarojs/components": "^3.3.0",
"@tarojs/service": "^3.3.0",
"@tarojs/shared": "^3.3.0"
},
"lint-staged": {
"*.{ts,tsx}": [
"npm run eslint",
"prettier .prettierrc.js --write",
"git add ."
]
}
}
59 changes: 59 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
const { join } = require('path')
const typescript = require('rollup-plugin-typescript2')
const cwd = __dirname

const base = {
external: [
'@tarojs/shared',
'@tarojs/service'
],
plugins: [typescript({
useTsconfigDeclarationDir: true
})]
}

// 供 CLI 编译时使用的 Taro 插件入口
const compileConfig = {
input: join(cwd, 'src/index.ts'),
output: {
file: join(cwd, 'dist/index.js'),
format: 'cjs',
sourcemap: true,
exports: 'named'
},
...base
}

// 供 Loader 使用的运行时入口
const runtimeConfig = {
input: join(cwd, 'src/runtime.ts'),
output: {
file: join(cwd, 'dist/runtime.js'),
format: 'es',
sourcemap: true
},
...base
}

// 供继承的包使用,为了能 tree-shaking
const runtimeUtilsConfig = {
input: join(cwd, 'src/runtime-utils.ts'),
output: {
file: join(cwd, 'dist/runtime-utils.js'),
format: 'es',
sourcemap: true
},
...base
}

const otherConfig = {
input: join(cwd, 'src/components-react.ts'),
output: {
file: join(cwd, 'dist/components-react.js'),
format: 'es',
sourcemap: true
},
...base
}

module.exports = [compileConfig, runtimeConfig, runtimeUtilsConfig, otherConfig]
Loading

0 comments on commit 7363ea6

Please sign in to comment.