@tarojs/binding 3.7.0-canary.6 → 3.8.0-canary.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/Cargo.toml ADDED
@@ -0,0 +1,22 @@
1
+ [package]
2
+ name = "taro_binding"
3
+ version = "0.1.0"
4
+ edition = "2021"
5
+
6
+ # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7
+
8
+ [lib]
9
+ crate-type = ["cdylib"]
10
+
11
+ [dependencies]
12
+ napi = { version = "=2.15.2", features = ["napi4", "tokio_rt"] }
13
+ napi-derive = { version = "=2.15.3" }
14
+ tokio = { version = "=1.36.0" }
15
+ serde_json = { version = "=1.0.114" }
16
+ serde = { version = "=1.0.197", features = ["serde_derive"] }
17
+ anyhow = { version = "=1.0.80" }
18
+
19
+ taro_init = { version = "0.0.1" }
20
+
21
+ [build-dependencies]
22
+ napi-build = { version = "=2.1.2" }
package/LICENSE CHANGED
@@ -158,3 +158,17 @@ MIT (stencil-vue2-output-target):
158
158
  The following files embed [stencil-vue2-output-target](https://github.com/diondree/stencil-vue2-output-target) MIT:
159
159
  `/packages/taro-components-library-vue2/src/vue-component-lib/utils.ts`
160
160
  See `/LICENSE` for details of the license.
161
+
162
+ ==================
163
+
164
+ MIT (weui):
165
+ The following files embed [stencil-vue2-output-target](https://github.com/Tencent/weui) MIT:
166
+ `/packages/taro-components/src/components/*.scss`
167
+ See `/LICENSE.txt` for details of the license.
168
+
169
+ ==================
170
+
171
+ Apache-2.0 (intersection-observer):
172
+ The following files embed [intersection-observer](https://github.com/GoogleChromeLabs/intersection-observer) Apache-2.0:
173
+ `/packages/taro-api/src/polyfill/intersection-observer.ts`
174
+ See `/LICENSE.txt` for details of the license.
package/binding.d.ts CHANGED
@@ -27,19 +27,16 @@ export interface CreateOptions {
27
27
  pageName?: string
28
28
  compiler?: CompilerType
29
29
  setPageName?: string
30
- subPkg?: string
31
- pageDir?: string
32
- setSubPkgPageName?: string
33
30
  changeExt?: boolean
34
31
  isCustomTemplate?: boolean
35
32
  pluginType?: string
36
33
  }
37
34
 
38
- export function createPage(conf: Page, handlers: Record<string, (err: Error | null, value: CreateOptions) => any>): Promise<void>
35
+ export function createPage(conf: Page, handlers: Record<string, (err: Error | null, arg: CreateOptions) => any>): Promise<void>
39
36
 
40
37
  export function createPlugin(conf: Plugin): Promise<void>
41
38
 
42
- export function createProject(conf: Project, handlers: Record<string, (err: Error | null, value: CreateOptions) => any>): Promise<void>
39
+ export function createProject(conf: Project, handlers: Record<string, (err: Error | null, arg: CreateOptions) => any>): Promise<void>
43
40
 
44
41
  export const enum CSSType {
45
42
  None = 'None',
@@ -79,8 +76,6 @@ export interface Page {
79
76
  customTemplatePath?: string
80
77
  basePageFiles: Array<string>
81
78
  period: PeriodType
82
- subPkg?: string
83
- pageDir?: string
84
79
  }
85
80
 
86
81
  export const enum PeriodType {
package/build.rs ADDED
@@ -0,0 +1,5 @@
1
+ extern crate napi_build;
2
+
3
+ fn main() {
4
+ napi_build::setup();
5
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tarojs/binding",
3
- "version": "3.7.0-canary.6",
3
+ "version": "3.8.0-canary.1",
4
4
  "description": "Node binding for taro",
5
5
  "main": "binding.js",
6
6
  "typings": "binding.d.ts",
@@ -9,13 +9,18 @@
9
9
  "triples": {
10
10
  "default": true,
11
11
  "additional": [
12
- "aarch64-apple-darwin"
12
+ "aarch64-apple-darwin",
13
+ "x86_64-unknown-linux-musl"
13
14
  ]
14
15
  }
15
16
  },
16
17
  "files": [
17
18
  "binding.js",
18
- "binding.d.ts"
19
+ "binding.d.ts",
20
+ "src/**",
21
+ "build.rs",
22
+ "Cargo.toml",
23
+ "postinstall.js"
19
24
  ],
20
25
  "repository": {
21
26
  "type": "git",
@@ -30,15 +35,18 @@
30
35
  "@napi-rs/cli": "3.0.0-alpha.5",
31
36
  "ava": "5.3.1"
32
37
  },
38
+ "dependencies": {
39
+ "@napi-rs/triples": "1.2.0"
40
+ },
33
41
  "bugs": {
34
42
  "url": "https://github.com/NervJS/taro/issues"
35
43
  },
36
44
  "homepage": "https://github.com/NervJS/taro#readme",
37
45
  "optionalDependencies": {
38
- "@tarojs/binding-darwin-arm64": "3.7.0-canary.6",
39
- "@tarojs/binding-darwin-x64": "3.7.0-canary.6",
40
- "@tarojs/binding-win32-x64-msvc": "3.7.0-canary.6",
41
- "@tarojs/binding-linux-x64-gnu": "3.7.0-canary.6"
46
+ "@tarojs/binding-darwin-arm64": "3.8.0-canary.1",
47
+ "@tarojs/binding-darwin-x64": "3.8.0-canary.1",
48
+ "@tarojs/binding-linux-x64-gnu": "3.8.0-canary.1",
49
+ "@tarojs/binding-win32-x64-msvc": "3.8.0-canary.1"
42
50
  },
43
51
  "scripts": {
44
52
  "artifacts": "napi artifacts --npm-dir ../../npm --cwd ./",
@@ -47,6 +55,7 @@
47
55
  "format": "run-p format:source format:rs",
48
56
  "format:rs": "cargo fmt",
49
57
  "format:source": "prettier . -w",
50
- "test": "ava"
58
+ "test": "ava",
59
+ "postinstall": "node postinstall.js"
51
60
  }
52
61
  }
package/postinstall.js ADDED
@@ -0,0 +1,45 @@
1
+ const { execSync } = require('child_process')
2
+ const { readFileSync, writeFileSync, existsSync } = require('fs')
3
+ const { join, resolve } = require('path')
4
+ const { platform, arch } = require('os')
5
+
6
+ const { platformArchTriples } = require('@napi-rs/triples')
7
+
8
+ const PLATFORM_NAME = platform()
9
+ const ARCH_NAME = arch()
10
+
11
+ if (process.env.npm_config_build_from_source || process.env.BUILD_TARO_FROM_SOURCE) {
12
+ let libExt
13
+ let dylibName = 'taro_binding'
14
+ switch (PLATFORM_NAME) {
15
+ case 'darwin':
16
+ libExt = '.dylib'
17
+ dylibName = `lib${dylibName}`
18
+ break
19
+ case 'win32':
20
+ libExt = '.dll'
21
+ break
22
+ case 'linux':
23
+ case 'freebsd':
24
+ case 'openbsd':
25
+ case 'android':
26
+ case 'sunos':
27
+ dylibName = `lib${dylibName}`
28
+ libExt = '.so'
29
+ break
30
+ default:
31
+ throw new TypeError('Operating system not currently supported or recognized by the build script')
32
+ }
33
+ execSync('cargo build --release', {
34
+ stdio: 'inherit',
35
+ env: process.env,
36
+ })
37
+ let dylibPath = join(__dirname, 'target', 'release', `${dylibName}${libExt}`)
38
+ if (!existsSync(dylibPath)) {
39
+ dylibPath = join(resolve(__dirname, '..', '..'), 'target', 'release', `${dylibName}${libExt}`)
40
+ }
41
+ const dylibContent = readFileSync(dylibPath)
42
+ const triples = platformArchTriples[PLATFORM_NAME][ARCH_NAME]
43
+ const tripe = triples[0]
44
+ writeFileSync(join(__dirname, `taro.${tripe.platformArchABI}.node`), dylibContent)
45
+ }
package/src/lib.rs ADDED
@@ -0,0 +1,95 @@
1
+ #![deny(clippy::all)]
2
+ #[macro_use]
3
+ extern crate napi_derive;
4
+
5
+ use std::collections::HashMap;
6
+
7
+ use napi::{threadsafe_function::ThreadsafeFunction, Result};
8
+ use taro_init::{creator::CreateOptions, page::Page, plugin::Plugin, project::Project};
9
+
10
+ #[napi]
11
+ pub async fn create_project(
12
+ conf: Project,
13
+ handlers: HashMap<String, ThreadsafeFunction<CreateOptions>>,
14
+ ) -> Result<()> {
15
+ let project: Project = Project::new(
16
+ conf.project_root,
17
+ conf.project_name,
18
+ conf.npm,
19
+ conf.description,
20
+ conf.typescript,
21
+ conf.template,
22
+ conf.css,
23
+ conf.framework,
24
+ conf.auto_install,
25
+ conf.template_root,
26
+ conf.version,
27
+ conf.date,
28
+ conf.compiler,
29
+ conf.period,
30
+ );
31
+ let mut thread_safe_functions = HashMap::new();
32
+ for (key, callback) in handlers {
33
+ thread_safe_functions.insert(key, callback);
34
+ }
35
+ if let Err(e) = project.create(thread_safe_functions).await {
36
+ println!("创建项目错误,原因如下:");
37
+ println!("{:?}", e);
38
+ return Err(napi::Error::from_reason(format!("{:?}", e)));
39
+ }
40
+ Ok(())
41
+ }
42
+
43
+ #[napi]
44
+ pub async fn create_page(
45
+ conf: Page,
46
+ handlers: HashMap<String, ThreadsafeFunction<CreateOptions>>,
47
+ ) -> Result<()> {
48
+ let page = Page::new(
49
+ conf.project_dir,
50
+ conf.project_name,
51
+ conf.template,
52
+ conf.template_root,
53
+ conf.description,
54
+ conf.page_name,
55
+ conf.date,
56
+ conf.framework,
57
+ conf.css,
58
+ conf.typescript,
59
+ conf.compiler,
60
+ conf.version,
61
+ conf.is_custom_template,
62
+ conf.custom_template_path,
63
+ conf.base_page_files,
64
+ conf.period,
65
+ );
66
+ let mut thread_safe_functions = HashMap::new();
67
+ for (key, callback) in handlers {
68
+ thread_safe_functions.insert(key, callback);
69
+ }
70
+ if let Err(e) = page.create(thread_safe_functions).await {
71
+ println!("创建页面错误,原因如下:");
72
+ println!("{:?}", e);
73
+ return Err(napi::Error::from_reason(format!("{:?}", e)));
74
+ }
75
+ Ok(())
76
+ }
77
+
78
+ #[napi]
79
+ pub async fn create_plugin(conf: Plugin) -> Result<()> {
80
+ let plugin = Plugin::new(
81
+ conf.project_root,
82
+ conf.project_name,
83
+ conf.description,
84
+ conf.plugin_type,
85
+ conf.template_root,
86
+ conf.version,
87
+ conf.template,
88
+ );
89
+ if let Err(e) = plugin.create().await {
90
+ println!("创建插件错误,原因如下:");
91
+ println!("{:?}", e);
92
+ return Err(napi::Error::from_reason(format!("{:?}", e)));
93
+ }
94
+ Ok(())
95
+ }