-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
琼恩
committed
Apr 13, 2022
1 parent
789e873
commit d0415f0
Showing
21 changed files
with
4,047 additions
and
32 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
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,2 @@ | ||
types | ||
!types/shims-tt.d.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 @@ | ||
# `@tarojs/plugin-platform-xhs` | ||
|
||
Taro 插件。用于支持编译为小红书小程序。 |
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 @@ | ||
module.exports = require('./dist/index.js').default | ||
module.exports.default = module.exports | ||
module.exports.XHS = require('./dist/index.js').XHS |
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": "@tarojs/plugin-platform-xhs", | ||
"version": "1.0.0", | ||
"description": "小红书小程序平台插件", | ||
"author": "@xhs", | ||
"homepage": "https://github.com/nervjs/taro/tree/master/packages/taro-xhs#readme", | ||
"license": "MIT", | ||
"main": "index.js", | ||
"keywords": [ | ||
"taro", | ||
"xhs" | ||
], | ||
"files": [ | ||
"index.js", | ||
"dist", | ||
"types" | ||
], | ||
"types": "types/index.d.ts", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/NervJS/taro.git" | ||
}, | ||
"scripts": { | ||
"build": "rollup -c", | ||
"dev": "rollup -c -w" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/NervJS/taro/issues" | ||
}, | ||
"dependencies": { | ||
"@rollup/plugin-json": "^4.1.0", | ||
"@tarojs/service": "3.3.15", | ||
"@tarojs/shared": "3.3.15", | ||
"rollup-plugin-typescript2": "^0.31.1", | ||
"typescript": "^4.5.2" | ||
} | ||
} |
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,49 @@ | ||
import json from '@rollup/plugin-json' | ||
const { join } = require('path') | ||
const typescript = require('rollup-plugin-typescript2') | ||
|
||
const cwd = __dirname | ||
|
||
const base = { | ||
external: ['@tarojs/shared', '@tarojs/service'], | ||
plugins: [typescript({ | ||
useTsconfigDeclarationDir: true | ||
}), | ||
json()] | ||
} | ||
|
||
// 供 CLI 编译时使用的 Taro 插件入口 | ||
const comileConfig = { | ||
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 | ||
} | ||
|
||
module.exports = [comileConfig, runtimeConfig, runtimeUtilsConfig] |
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,11 @@ | ||
export const needPromiseApis = new Set([ | ||
'checkFollowState', | ||
'exitMiniProgram', | ||
'followOfficialAccount', | ||
'getMenuButtonLayout', | ||
'hideInteractionBar', | ||
'pay', | ||
'navigateToVideoView', | ||
'showInteractionBar', | ||
'openEcGood' | ||
]) |
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,10 @@ | ||
import { processApis } from '@tarojs/shared' | ||
// import { needPromiseApis } from './apis-list' | ||
|
||
declare const xhs: any | ||
|
||
export function initNativeApi (taro) { | ||
processApis(taro, xhs, { | ||
|
||
}) | ||
} |
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,40 @@ | ||
import { singleQuote } from '@tarojs/shared' | ||
// singleQuote 给字符串增加一个单引号 | ||
export const components = { | ||
// ======== 调整属性 ======== | ||
Icon: { | ||
size: '23' | ||
}, | ||
Button: { | ||
bindgetphonenumber: '', | ||
'data-channel': '' | ||
}, | ||
Form: { | ||
'report-submit-timeout': '0' | ||
}, | ||
Slider: { | ||
color: singleQuote('#e9e9e9'), | ||
'selected-color': singleQuote('#1aad19') | ||
}, | ||
WebView: { | ||
'progressbar-color': singleQuote('#51a0d8') | ||
}, | ||
Video: { | ||
'play-btn-position': singleQuote('center'), | ||
'pre-roll-unit-id': '', | ||
'post-roll-unit-id': '', | ||
bindAdStart: '', | ||
bindAdEnded: '', | ||
bindAdLoad: '', | ||
bindAdClose: '', | ||
bindAdError: '' | ||
}, | ||
Ad: { | ||
fixed: '', | ||
type: singleQuote('banner'), | ||
scale: '100' | ||
}, | ||
Textarea: { | ||
'disable-default-padding': 'false' | ||
} | ||
} |
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,16 @@ | ||
import XHS from './program' | ||
import type { IPluginContext } from '@tarojs/service' | ||
|
||
// 让其它平台插件可以继承此平台 | ||
export { XHS } | ||
|
||
export default (ctx: IPluginContext) => { | ||
ctx.registerPlatform({ | ||
name: 'xhs', | ||
useConfigName: 'mini', | ||
async fn ({ config }) { | ||
const program = new XHS(ctx, config) | ||
await program.start() | ||
} | ||
}) | ||
} |
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,43 @@ | ||
import { TaroPlatformBase } from '@tarojs/service' | ||
import { Template } from './template' | ||
import { components } from './components' | ||
|
||
const PACKAGE_NAME = '@tarojs/plugin-platform-xhs' | ||
|
||
export default class XHS extends TaroPlatformBase { | ||
platform = 'xhs' | ||
globalObject = 'xhs' | ||
projectConfigJson = 'project.config.json' | ||
runtimePath = `${PACKAGE_NAME}/dist/runtime` | ||
fileType = { | ||
templ: '.xhsml', | ||
style: '.css', | ||
config: '.json', | ||
script: '.js' | ||
} | ||
|
||
template = new Template() | ||
|
||
/** | ||
* 1. setupTransaction - init | ||
* 2. setup | ||
* 3. setupTransaction - close | ||
* 4. buildTransaction - init | ||
* 5. build | ||
* 6. buildTransaction - close | ||
*/ | ||
constructor (ctx, config) { | ||
super(ctx, config) | ||
|
||
this.setupTransaction.addWrapper({ | ||
close: this.modifyTemplate | ||
}) | ||
} | ||
|
||
/** | ||
* 增加组件或修改组件属性 | ||
*/ | ||
modifyTemplate () { | ||
this.template.mergeComponents(this.ctx, components) | ||
} | ||
} |
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 @@ | ||
import { initNativeApi } from './apis' | ||
|
||
export { initNativeApi } | ||
export * from './components' | ||
export * from './apis-list' | ||
export const hostConfig = { | ||
initNativeApi | ||
} |
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 @@ | ||
import { mergeReconciler, mergeInternalComponents } from '@tarojs/shared' | ||
import { hostConfig, components } from './runtime-utils' | ||
|
||
mergeReconciler(hostConfig) | ||
mergeInternalComponents(components) |
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,23 @@ | ||
import { RecursiveTemplate } from '@tarojs/shared/dist/template' | ||
export class Template extends RecursiveTemplate { | ||
supportXS = false | ||
Adapter = { | ||
if: 'xhs:if', | ||
else: 'xhs:else', | ||
elseif: 'xhs:elif', | ||
for: 'xhs:for', | ||
forItem: 'xhs:for-item', | ||
forIndex: 'xhs:for-index', | ||
key: 'xhs:key', | ||
type: 'xhs' | ||
} | ||
|
||
replacePropName (name: string, value: string) { | ||
if (value === 'eh') { | ||
const nameLowerCase = name.toLowerCase() | ||
if (nameLowerCase === 'bindlongtap') return 'bindlongpress' | ||
return nameLowerCase | ||
} | ||
return name | ||
} | ||
} |
Oops, something went wrong.