@tarojs/plugin-inject 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -49,6 +49,7 @@ const config = {
49
49
  | syncApis | array | 新增同步 API |
50
50
  | asyncApis | array | 新增异步 API |
51
51
  | components | object | 修改、新增组件的属性 |
52
+ | componentsMap | object | 新增组件时的名称映射 |
52
53
  | voidComponents | array, function | 设置组件是否可以渲染子元素 |
53
54
  | nestElements | object, function | 设置组件模版的循环次数 |
54
55
 
@@ -120,7 +121,18 @@ const config = {
120
121
  Text: {
121
122
  'x-props': "'hello'",
122
123
  bindYEvent: ''
124
+ },
125
+ // 新增一个组件
126
+ ShareElement: {
127
+ key: "",
128
+ transform: "true",
129
+ duration: "300",
130
+ "easing-function": ""
123
131
  }
132
+ },
133
+ // 新增的组件需要写映射
134
+ componentsMap: {
135
+ ShareElement: 'share-element'
124
136
  }
125
137
  }]
126
138
  ]
@@ -231,22 +243,20 @@ const config = {
231
243
  }
232
244
  }
233
245
 
234
- //global.d.ts
246
+ // global.d.ts
235
247
  declare module '@tarojs/components' {
236
248
  export * from '@tarojs/components/types/index';
237
249
 
238
- ////下面示例是react的定义,vue下可能有所不同,原理是一样的
250
+ // 下面示例是react的定义,vue下可能有所不同,原理是一样的
239
251
  import { ComponentType } from 'react';
240
252
  import { TextProps as OldTextProps } from '@tarojs/components/types/Text';
241
253
 
242
- //修改的Props
254
+ // 修改的Props
243
255
  interface TextProps extends OldTextProps {
244
- xProps?: string;
256
+ xProps?: string;
245
257
  }
246
258
 
247
- declare const Text: ComponentType<TextProps>;
248
-
249
- export { Text, TextProps };
259
+ export const Text: ComponentType<TextProps>;
250
260
  }
251
261
  ```
252
262
 
package/dist/apis-list.js CHANGED
@@ -1,3 +1,6 @@
1
-
2
- export const noPromiseApis = new Set([]);
3
- export const needPromiseApis = new Set(["showShareImageMenu"]);
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.needPromiseApis = exports.noPromiseApis = void 0;
4
+ exports.noPromiseApis = new Set([]);
5
+ exports.needPromiseApis = new Set([]);
6
+ //# sourceMappingURL=apis-list.js.map
@@ -1,2 +1,5 @@
1
-
2
- export const components = {};
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.components = void 0;
4
+ exports.components = {};
5
+ //# sourceMappingURL=components.js.map
package/dist/index.js CHANGED
@@ -7,7 +7,7 @@ exports.default = (ctx, options) => {
7
7
  ctx.registerMethod({
8
8
  name: 'onSetupClose',
9
9
  fn(platform) {
10
- const { voidComponents, nestElements, components, syncApis, asyncApis } = options;
10
+ const { voidComponents, nestElements, components, syncApis, asyncApis, componentsMap } = options;
11
11
  const template = platform.template;
12
12
  if (shared_1.isArray(voidComponents)) {
13
13
  voidComponents.forEach(el => template.voidElements.add(el));
@@ -23,11 +23,15 @@ exports.default = (ctx, options) => {
23
23
  else if (shared_1.isFunction(nestElements)) {
24
24
  template.nestElements = nestElements(template.nestElements);
25
25
  }
26
- if (components || syncApis || asyncApis) {
26
+ if (components || syncApis || asyncApis || componentsMap) {
27
27
  injectRuntimePath(platform);
28
28
  if (components) {
29
29
  template.mergeComponents(ctx, components);
30
30
  }
31
+ if (componentsMap) {
32
+ injectComponentsReact(fs, platform.taroComponentsPath, componentsMap);
33
+ platform.taroComponentsPath = `@tarojs/plugin-inject/dist/components-react`;
34
+ }
31
35
  injectComponents(fs, components);
32
36
  injectApis(fs, syncApis, asyncApis);
33
37
  }
@@ -43,6 +47,12 @@ function injectRuntimePath(platform) {
43
47
  platform.runtimePath = [platform.runtimePath, injectedPath];
44
48
  }
45
49
  }
50
+ function injectComponentsReact(fs, taroComponentsPath, componentsMap) {
51
+ fs.writeFileSync(path.resolve(__dirname, '../dist/components-react.js'), `
52
+ export * from '${taroComponentsPath}'
53
+ ${Object.keys(componentsMap).map((key) => `export const ${key} = '${componentsMap[key]}'`).join('\n')}
54
+ `);
55
+ }
46
56
  function injectComponents(fs, components) {
47
57
  fs.writeFileSync(path.resolve(__dirname, '../dist/components.js'), `
48
58
  export const components = ${components ? JSON.stringify(components) : JSON.stringify({})};
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAEA,2CAAwE;AACxE,6BAA4B;AAa5B,kBAAe,CAAC,GAAmB,EAAE,OAAiB,EAAE,EAAE;IACxD,MAAM,EAAE,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE,CAAA;IAExB,GAAG,CAAC,cAAc,CAAC;QACjB,IAAI,EAAE,cAAc;QACpB,EAAE,CAAE,QAA0B;YAC5B,MAAM,EACJ,cAAc,EACd,YAAY,EACZ,UAAU,EACV,QAAQ,EACR,SAAS,EACV,GAAG,OAAO,CAAA;YAEX,MAAM,QAAQ,GAAG,QAAQ,CAAC,QAAQ,CAAA;YAElC,IAAI,gBAAO,CAAC,cAAc,CAAC,EAAE;gBAC3B,cAAc,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC,QAAQ,CAAC,YAAY,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAA;aAC5D;iBAAM,IAAI,mBAAU,CAAC,cAAc,CAAC,EAAE;gBACrC,QAAQ,CAAC,YAAY,GAAG,cAAc,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAA;aAC9D;YAED,IAAI,iBAAQ,CAAe,YAAY,CAAC,EAAE;gBACxC,KAAK,MAAM,GAAG,IAAI,YAAY,EAAE;oBAC9B,QAAQ,CAAC,YAAY,CAAC,GAAG,CAAC,GAAG,EAAE,YAAY,CAAC,GAAG,CAAC,CAAC,CAAA;iBAClD;aACF;iBAAM,IAAI,mBAAU,CAAC,YAAY,CAAC,EAAE;gBACnC,QAAQ,CAAC,YAAY,GAAG,YAAY,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAA;aAC5D;YAED,IAAI,UAAU,IAAI,QAAQ,IAAI,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AAE,UAAU;IACtC,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,uBAAuB,CAAC,EAAE;4BACzC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;CACvF,CAAC,CAAA;AACF,CAAC;AAED,SAAS,UAAU,CAAC,EAAE,EAAE,QAAQ,EAAE,SAAS;IACzC,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,sBAAsB,CAAC,EAAE;uCAC7B,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;yCACtD,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;CAClG,CAAC,CAAA;AACF,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tarojs/plugin-inject",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Taro 小程序端平台中间层插件",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/src/index.ts CHANGED
@@ -10,6 +10,7 @@ interface IOptions {
10
10
  voidComponents: string[] | ((list: VoidComponents) => VoidComponents)
11
11
  nestElements: Record<string, number> | ((elem: NestElements) => NestElements)
12
12
  components: Record<string, Record<string, any>>
13
+ componentsMap: Record<string, string>
13
14
  syncApis: string[]
14
15
  asyncApis: string[]
15
16
  }
@@ -19,13 +20,14 @@ export default (ctx: IPluginContext, options: IOptions) => {
19
20
 
20
21
  ctx.registerMethod({
21
22
  name: 'onSetupClose',
22
- fn (platform: TaroPlatformBase) {
23
+ fn(platform: TaroPlatformBase) {
23
24
  const {
24
25
  voidComponents,
25
26
  nestElements,
26
27
  components,
27
28
  syncApis,
28
- asyncApis
29
+ asyncApis,
30
+ componentsMap
29
31
  } = options
30
32
 
31
33
  const template = platform.template
@@ -44,13 +46,18 @@ export default (ctx: IPluginContext, options: IOptions) => {
44
46
  template.nestElements = nestElements(template.nestElements)
45
47
  }
46
48
 
47
- if (components || syncApis || asyncApis) {
49
+ if (components || syncApis || asyncApis || componentsMap) {
48
50
  injectRuntimePath(platform)
49
51
 
50
52
  if (components) {
51
53
  template.mergeComponents(ctx, components)
52
54
  }
53
55
 
56
+ if (componentsMap) {
57
+ injectComponentsReact(fs, platform.taroComponentsPath, componentsMap)
58
+ platform.taroComponentsPath = `@tarojs/plugin-inject/dist/components-react`
59
+ }
60
+
54
61
  injectComponents(fs, components)
55
62
  injectApis(fs, syncApis, asyncApis)
56
63
  }
@@ -58,7 +65,7 @@ export default (ctx: IPluginContext, options: IOptions) => {
58
65
  })
59
66
  }
60
67
 
61
- function injectRuntimePath (platform: TaroPlatformBase) {
68
+ function injectRuntimePath(platform: TaroPlatformBase) {
62
69
  const injectedPath = `@tarojs/plugin-inject/dist/runtime`
63
70
  if (isArray(platform.runtimePath)) {
64
71
  platform.runtimePath.push(injectedPath)
@@ -67,15 +74,22 @@ function injectRuntimePath (platform: TaroPlatformBase) {
67
74
  }
68
75
  }
69
76
 
70
- function injectComponents (fs, components) {
77
+ function injectComponentsReact(fs, taroComponentsPath, componentsMap) {
78
+ fs.writeFileSync(path.resolve(__dirname, '../dist/components-react.js'), `
79
+ export * from '${taroComponentsPath}'
80
+ ${Object.keys(componentsMap).map((key) => `export const ${key} = '${componentsMap[key]}'`).join('\n')}
81
+ `)
82
+ }
83
+
84
+ function injectComponents(fs, components) {
71
85
  fs.writeFileSync(path.resolve(__dirname, '../dist/components.js'), `
72
86
  export const components = ${components ? JSON.stringify(components) : JSON.stringify({})};
73
87
  `)
74
88
  }
75
89
 
76
- function injectApis (fs, syncApis, asyncApis) {
90
+ function injectApis(fs, syncApis, asyncApis) {
77
91
  fs.writeFileSync(path.resolve(__dirname, '../dist/apis-list.js'), `
78
- export const noPromiseApis = new Set(${syncApis ? JSON.stringify(syncApis): JSON.stringify([])});
79
- export const needPromiseApis = new Set(${asyncApis ? JSON.stringify(asyncApis): JSON.stringify([])});
92
+ export const noPromiseApis = new Set(${syncApis ? JSON.stringify(syncApis) : JSON.stringify([])});
93
+ export const needPromiseApis = new Set(${asyncApis ? JSON.stringify(asyncApis) : JSON.stringify([])});
80
94
  `)
81
95
  }