@tarojs/binding 4.0.0-beta.61 → 4.0.0-beta.62
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 +22 -0
- package/binding.d.ts +2 -2
- package/build.rs +5 -0
- package/package.json +17 -8
- package/postinstall.js +45 -0
- package/src/lib.rs +97 -0
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/binding.d.ts
CHANGED
|
@@ -35,11 +35,11 @@ export interface CreateOptions {
|
|
|
35
35
|
pluginType?: string
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
export function createPage(conf: Page, handlers: Record<string, (err: Error | null,
|
|
38
|
+
export function createPage(conf: Page, handlers: Record<string, (err: Error | null, arg: CreateOptions) => any>): Promise<void>
|
|
39
39
|
|
|
40
40
|
export function createPlugin(conf: Plugin): Promise<void>
|
|
41
41
|
|
|
42
|
-
export function createProject(conf: Project, handlers: Record<string, (err: Error | null,
|
|
42
|
+
export function createProject(conf: Project, handlers: Record<string, (err: Error | null, arg: CreateOptions) => any>): Promise<void>
|
|
43
43
|
|
|
44
44
|
export const enum CSSType {
|
|
45
45
|
None = 'None',
|
package/build.rs
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tarojs/binding",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.62",
|
|
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-
|
|
39
|
-
"@tarojs/binding-
|
|
40
|
-
"@tarojs/binding-
|
|
41
|
-
"@tarojs/binding-
|
|
46
|
+
"@tarojs/binding-linux-x64-gnu": "4.0.0-beta.62",
|
|
47
|
+
"@tarojs/binding-win32-x64-msvc": "4.0.0-beta.62",
|
|
48
|
+
"@tarojs/binding-darwin-x64": "4.0.0-beta.62",
|
|
49
|
+
"@tarojs/binding-darwin-arm64": "4.0.0-beta.62"
|
|
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,97 @@
|
|
|
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
|
+
conf.sub_pkg,
|
|
66
|
+
conf.page_dir,
|
|
67
|
+
);
|
|
68
|
+
let mut thread_safe_functions = HashMap::new();
|
|
69
|
+
for (key, callback) in handlers {
|
|
70
|
+
thread_safe_functions.insert(key, callback);
|
|
71
|
+
}
|
|
72
|
+
if let Err(e) = page.create(thread_safe_functions).await {
|
|
73
|
+
println!("创建页面错误,原因如下:");
|
|
74
|
+
println!("{:?}", e);
|
|
75
|
+
return Err(napi::Error::from_reason(format!("{:?}", e)));
|
|
76
|
+
}
|
|
77
|
+
Ok(())
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
#[napi]
|
|
81
|
+
pub async fn create_plugin(conf: Plugin) -> Result<()> {
|
|
82
|
+
let plugin = Plugin::new(
|
|
83
|
+
conf.project_root,
|
|
84
|
+
conf.project_name,
|
|
85
|
+
conf.description,
|
|
86
|
+
conf.plugin_type,
|
|
87
|
+
conf.template_root,
|
|
88
|
+
conf.version,
|
|
89
|
+
conf.template,
|
|
90
|
+
);
|
|
91
|
+
if let Err(e) = plugin.create().await {
|
|
92
|
+
println!("创建插件错误,原因如下:");
|
|
93
|
+
println!("{:?}", e);
|
|
94
|
+
return Err(napi::Error::from_reason(format!("{:?}", e)));
|
|
95
|
+
}
|
|
96
|
+
Ok(())
|
|
97
|
+
}
|