gemercheung преди 1 година
родител
ревизия
ea75cb0071

+ 2 - 2
.github/workflows/CI.yml

@@ -1,7 +1,7 @@
 name: CI
 env:
   DEBUG: napi:*
-  APP_NAME: package-template
+  APP_NAME: laster-tool
   MACOSX_DEPLOYMENT_TARGET: '10.13'
 permissions:
   contents: write
@@ -157,7 +157,7 @@ jobs:
           version: '13.2'
           memory: 8G
           cpu_count: 3
-          environment_variables: 'DEBUG RUSTUP_IO_THREADS'
+          environment_variables: DEBUG RUSTUP_IO_THREADS
           shell: bash
           run: |
             sudo pkg install -y -f curl node libnghttp2 npm

+ 4 - 1
Cargo.toml

@@ -12,9 +12,12 @@ crate-type = ["cdylib"]
 [dependencies]
 napi        = "2"
 napi-derive = "2"
-
+sysinfo = "0.30.12"
 [build-dependencies]
 napi-build = "2"
 
+
+
+
 [profile.release]
 lto = true

+ 1 - 0
index.d.ts

@@ -4,3 +4,4 @@
 /* auto-generated by NAPI-RS */
 
 export function plus100(input: number): number
+export function stop(): void

+ 2 - 1
index.js

@@ -234,6 +234,7 @@ if (!nativeBinding) {
   throw new Error(`Failed to load native binding`)
 }
 
-const { plus100 } = nativeBinding
+const { plus100, stop } = nativeBinding
 
 module.exports.plus100 = plus100
+module.exports.stop = stop

+ 2 - 2
npm/android-arm-eabi/README.md

@@ -1,3 +1,3 @@
-# `@napi-rs/package-template-android-arm-eabi`
+# `laster-tool-android-arm-eabi`
 
-This is the **armv7-linux-androideabi** binary for `@napi-rs/package-template`
+This is the **armv7-linux-androideabi** binary for `laster-tool`

+ 4 - 4
npm/android-arm-eabi/package.json

@@ -1,5 +1,5 @@
 {
-  "name": "@napi-rs/package-template-android-arm-eabi",
+  "name": "laster-tool-android-arm-eabi",
   "version": "1.0.0",
   "os": [
     "android"
@@ -7,9 +7,9 @@
   "cpu": [
     "arm"
   ],
-  "main": "package-template.android-arm-eabi.node",
+  "main": "laster-tool.android-arm-eabi.node",
   "files": [
-    "package-template.android-arm-eabi.node"
+    "laster-tool.android-arm-eabi.node"
   ],
   "description": "Template project for writing node package with napi-rs",
   "keywords": [
@@ -29,4 +29,4 @@
     "access": "public"
   },
   "repository": "git@github.com:napi-rs/package-template.git"
-}
+}

+ 2 - 2
npm/android-arm64/README.md

@@ -1,3 +1,3 @@
-# `@napi-rs/package-template-android-arm64`
+# `laster-tool-android-arm64`
 
-This is the **aarch64-linux-android** binary for `@napi-rs/package-template`
+This is the **aarch64-linux-android** binary for `laster-tool`

+ 4 - 4
npm/android-arm64/package.json

@@ -1,5 +1,5 @@
 {
-  "name": "@napi-rs/package-template-android-arm64",
+  "name": "laster-tool-android-arm64",
   "version": "1.0.0",
   "os": [
     "android"
@@ -7,9 +7,9 @@
   "cpu": [
     "arm64"
   ],
-  "main": "package-template.android-arm64.node",
+  "main": "laster-tool.android-arm64.node",
   "files": [
-    "package-template.android-arm64.node"
+    "laster-tool.android-arm64.node"
   ],
   "description": "Template project for writing node package with napi-rs",
   "keywords": [
@@ -29,4 +29,4 @@
     "access": "public"
   },
   "repository": "git@github.com:napi-rs/package-template.git"
-}
+}

+ 2 - 2
npm/darwin-arm64/README.md

@@ -1,3 +1,3 @@
-# `@napi-rs/package-template-darwin-arm64`
+# `laster-tool-darwin-arm64`
 
-This is the **aarch64-apple-darwin** binary for `@napi-rs/package-template`
+This is the **aarch64-apple-darwin** binary for `laster-tool`

+ 4 - 4
npm/darwin-arm64/package.json

@@ -1,5 +1,5 @@
 {
-  "name": "@napi-rs/package-template-darwin-arm64",
+  "name": "laster-tool-darwin-arm64",
   "version": "1.0.0",
   "os": [
     "darwin"
@@ -7,9 +7,9 @@
   "cpu": [
     "arm64"
   ],
-  "main": "package-template.darwin-arm64.node",
+  "main": "laster-tool.darwin-arm64.node",
   "files": [
-    "package-template.darwin-arm64.node"
+    "laster-tool.darwin-arm64.node"
   ],
   "description": "Template project for writing node package with napi-rs",
   "keywords": [
@@ -29,4 +29,4 @@
     "access": "public"
   },
   "repository": "git@github.com:napi-rs/package-template.git"
-}
+}

+ 2 - 2
npm/darwin-x64/README.md

@@ -1,3 +1,3 @@
-# `@napi-rs/package-template-darwin-x64`
+# `laster-tool-darwin-x64`
 
-This is the **x86_64-apple-darwin** binary for `@napi-rs/package-template`
+This is the **x86_64-apple-darwin** binary for `laster-tool`

+ 4 - 4
npm/darwin-x64/package.json

@@ -1,5 +1,5 @@
 {
-  "name": "@napi-rs/package-template-darwin-x64",
+  "name": "laster-tool-darwin-x64",
   "version": "1.0.0",
   "os": [
     "darwin"
@@ -7,9 +7,9 @@
   "cpu": [
     "x64"
   ],
-  "main": "package-template.darwin-x64.node",
+  "main": "laster-tool.darwin-x64.node",
   "files": [
-    "package-template.darwin-x64.node"
+    "laster-tool.darwin-x64.node"
   ],
   "description": "Template project for writing node package with napi-rs",
   "keywords": [
@@ -29,4 +29,4 @@
     "access": "public"
   },
   "repository": "git@github.com:napi-rs/package-template.git"
-}
+}

+ 2 - 2
npm/freebsd-x64/README.md

@@ -1,3 +1,3 @@
-# `@napi-rs/package-template-freebsd-x64`
+# `laster-tool-freebsd-x64`
 
-This is the **x86_64-unknown-freebsd** binary for `@napi-rs/package-template`
+This is the **x86_64-unknown-freebsd** binary for `laster-tool`

+ 4 - 4
npm/freebsd-x64/package.json

@@ -1,5 +1,5 @@
 {
-  "name": "@napi-rs/package-template-freebsd-x64",
+  "name": "laster-tool-freebsd-x64",
   "version": "1.0.0",
   "os": [
     "freebsd"
@@ -7,9 +7,9 @@
   "cpu": [
     "x64"
   ],
-  "main": "package-template.freebsd-x64.node",
+  "main": "laster-tool.freebsd-x64.node",
   "files": [
-    "package-template.freebsd-x64.node"
+    "laster-tool.freebsd-x64.node"
   ],
   "description": "Template project for writing node package with napi-rs",
   "keywords": [
@@ -29,4 +29,4 @@
     "access": "public"
   },
   "repository": "git@github.com:napi-rs/package-template.git"
-}
+}

+ 2 - 2
npm/linux-arm-gnueabihf/README.md

@@ -1,3 +1,3 @@
-# `@napi-rs/package-template-linux-arm-gnueabihf`
+# `laster-tool-linux-arm-gnueabihf`
 
-This is the **armv7-unknown-linux-gnueabihf** binary for `@napi-rs/package-template`
+This is the **armv7-unknown-linux-gnueabihf** binary for `laster-tool`

+ 4 - 4
npm/linux-arm-gnueabihf/package.json

@@ -1,5 +1,5 @@
 {
-  "name": "@napi-rs/package-template-linux-arm-gnueabihf",
+  "name": "laster-tool-linux-arm-gnueabihf",
   "version": "1.0.0",
   "os": [
     "linux"
@@ -7,9 +7,9 @@
   "cpu": [
     "arm"
   ],
-  "main": "package-template.linux-arm-gnueabihf.node",
+  "main": "laster-tool.linux-arm-gnueabihf.node",
   "files": [
-    "package-template.linux-arm-gnueabihf.node"
+    "laster-tool.linux-arm-gnueabihf.node"
   ],
   "description": "Template project for writing node package with napi-rs",
   "keywords": [
@@ -29,4 +29,4 @@
     "access": "public"
   },
   "repository": "git@github.com:napi-rs/package-template.git"
-}
+}

+ 2 - 2
npm/linux-arm64-gnu/README.md

@@ -1,3 +1,3 @@
-# `@napi-rs/package-template-linux-arm64-gnu`
+# `laster-tool-linux-arm64-gnu`
 
-This is the **aarch64-unknown-linux-gnu** binary for `@napi-rs/package-template`
+This is the **aarch64-unknown-linux-gnu** binary for `laster-tool`

+ 8 - 8
npm/linux-arm64-gnu/package.json

@@ -1,5 +1,5 @@
 {
-  "name": "@napi-rs/package-template-linux-arm64-gnu",
+  "name": "laster-tool-linux-arm64-gnu",
   "version": "1.0.0",
   "os": [
     "linux"
@@ -7,12 +7,9 @@
   "cpu": [
     "arm64"
   ],
-  "libc": [
-    "glibc"
-  ],
-  "main": "package-template.linux-arm64-gnu.node",
+  "main": "laster-tool.linux-arm64-gnu.node",
   "files": [
-    "package-template.linux-arm64-gnu.node"
+    "laster-tool.linux-arm64-gnu.node"
   ],
   "description": "Template project for writing node package with napi-rs",
   "keywords": [
@@ -31,5 +28,8 @@
     "registry": "https://registry.npmjs.org/",
     "access": "public"
   },
-  "repository": "git@github.com:napi-rs/package-template.git"
-}
+  "repository": "git@github.com:napi-rs/package-template.git",
+  "libc": [
+    "glibc"
+  ]
+}

+ 2 - 2
npm/linux-arm64-musl/README.md

@@ -1,3 +1,3 @@
-# `@napi-rs/package-template-linux-arm64-musl`
+# `laster-tool-linux-arm64-musl`
 
-This is the **aarch64-unknown-linux-musl** binary for `@napi-rs/package-template`
+This is the **aarch64-unknown-linux-musl** binary for `laster-tool`

+ 8 - 8
npm/linux-arm64-musl/package.json

@@ -1,5 +1,5 @@
 {
-  "name": "@napi-rs/package-template-linux-arm64-musl",
+  "name": "laster-tool-linux-arm64-musl",
   "version": "1.0.0",
   "os": [
     "linux"
@@ -7,12 +7,9 @@
   "cpu": [
     "arm64"
   ],
-  "libc": [
-    "musl"
-  ],
-  "main": "package-template.linux-arm64-musl.node",
+  "main": "laster-tool.linux-arm64-musl.node",
   "files": [
-    "package-template.linux-arm64-musl.node"
+    "laster-tool.linux-arm64-musl.node"
   ],
   "description": "Template project for writing node package with napi-rs",
   "keywords": [
@@ -31,5 +28,8 @@
     "registry": "https://registry.npmjs.org/",
     "access": "public"
   },
-  "repository": "git@github.com:napi-rs/package-template.git"
-}
+  "repository": "git@github.com:napi-rs/package-template.git",
+  "libc": [
+    "musl"
+  ]
+}

+ 2 - 2
npm/linux-x64-gnu/README.md

@@ -1,3 +1,3 @@
-# `@napi-rs/package-template-linux-x64-gnu`
+# `laster-tool-linux-x64-gnu`
 
-This is the **x86_64-unknown-linux-gnu** binary for `@napi-rs/package-template`
+This is the **x86_64-unknown-linux-gnu** binary for `laster-tool`

+ 8 - 8
npm/linux-x64-gnu/package.json

@@ -1,5 +1,5 @@
 {
-  "name": "@napi-rs/package-template-linux-x64-gnu",
+  "name": "laster-tool-linux-x64-gnu",
   "version": "1.0.0",
   "os": [
     "linux"
@@ -7,12 +7,9 @@
   "cpu": [
     "x64"
   ],
-  "libc": [
-    "glibc"
-  ],
-  "main": "package-template.linux-x64-gnu.node",
+  "main": "laster-tool.linux-x64-gnu.node",
   "files": [
-    "package-template.linux-x64-gnu.node"
+    "laster-tool.linux-x64-gnu.node"
   ],
   "description": "Template project for writing node package with napi-rs",
   "keywords": [
@@ -31,5 +28,8 @@
     "registry": "https://registry.npmjs.org/",
     "access": "public"
   },
-  "repository": "git@github.com:napi-rs/package-template.git"
-}
+  "repository": "git@github.com:napi-rs/package-template.git",
+  "libc": [
+    "glibc"
+  ]
+}

+ 2 - 2
npm/linux-x64-musl/README.md

@@ -1,3 +1,3 @@
-# `@napi-rs/package-template-linux-x64-musl`
+# `laster-tool-linux-x64-musl`
 
-This is the **x86_64-unknown-linux-musl** binary for `@napi-rs/package-template`
+This is the **x86_64-unknown-linux-musl** binary for `laster-tool`

+ 8 - 8
npm/linux-x64-musl/package.json

@@ -1,5 +1,5 @@
 {
-  "name": "@napi-rs/package-template-linux-x64-musl",
+  "name": "laster-tool-linux-x64-musl",
   "version": "1.0.0",
   "os": [
     "linux"
@@ -7,12 +7,9 @@
   "cpu": [
     "x64"
   ],
-  "libc": [
-    "musl"
-  ],
-  "main": "package-template.linux-x64-musl.node",
+  "main": "laster-tool.linux-x64-musl.node",
   "files": [
-    "package-template.linux-x64-musl.node"
+    "laster-tool.linux-x64-musl.node"
   ],
   "description": "Template project for writing node package with napi-rs",
   "keywords": [
@@ -31,5 +28,8 @@
     "registry": "https://registry.npmjs.org/",
     "access": "public"
   },
-  "repository": "git@github.com:napi-rs/package-template.git"
-}
+  "repository": "git@github.com:napi-rs/package-template.git",
+  "libc": [
+    "musl"
+  ]
+}

+ 2 - 2
npm/win32-arm64-msvc/README.md

@@ -1,3 +1,3 @@
-# `@napi-rs/package-template-win32-arm64-msvc`
+# `laster-tool-win32-arm64-msvc`
 
-This is the **aarch64-pc-windows-msvc** binary for `@napi-rs/package-template`
+This is the **aarch64-pc-windows-msvc** binary for `laster-tool`

+ 4 - 4
npm/win32-arm64-msvc/package.json

@@ -1,5 +1,5 @@
 {
-  "name": "@napi-rs/package-template-win32-arm64-msvc",
+  "name": "laster-tool-win32-arm64-msvc",
   "version": "1.0.0",
   "os": [
     "win32"
@@ -7,9 +7,9 @@
   "cpu": [
     "arm64"
   ],
-  "main": "package-template.win32-arm64-msvc.node",
+  "main": "laster-tool.win32-arm64-msvc.node",
   "files": [
-    "package-template.win32-arm64-msvc.node"
+    "laster-tool.win32-arm64-msvc.node"
   ],
   "description": "Template project for writing node package with napi-rs",
   "keywords": [
@@ -29,4 +29,4 @@
     "access": "public"
   },
   "repository": "git@github.com:napi-rs/package-template.git"
-}
+}

+ 2 - 2
npm/win32-ia32-msvc/README.md

@@ -1,3 +1,3 @@
-# `@napi-rs/package-template-win32-ia32-msvc`
+# `laster-tool-win32-ia32-msvc`
 
-This is the **i686-pc-windows-msvc** binary for `@napi-rs/package-template`
+This is the **i686-pc-windows-msvc** binary for `laster-tool`

+ 4 - 4
npm/win32-ia32-msvc/package.json

@@ -1,5 +1,5 @@
 {
-  "name": "@napi-rs/package-template-win32-ia32-msvc",
+  "name": "laster-tool-win32-ia32-msvc",
   "version": "1.0.0",
   "os": [
     "win32"
@@ -7,9 +7,9 @@
   "cpu": [
     "ia32"
   ],
-  "main": "package-template.win32-ia32-msvc.node",
+  "main": "laster-tool.win32-ia32-msvc.node",
   "files": [
-    "package-template.win32-ia32-msvc.node"
+    "laster-tool.win32-ia32-msvc.node"
   ],
   "description": "Template project for writing node package with napi-rs",
   "keywords": [
@@ -29,4 +29,4 @@
     "access": "public"
   },
   "repository": "git@github.com:napi-rs/package-template.git"
-}
+}

+ 2 - 2
npm/win32-x64-msvc/README.md

@@ -1,3 +1,3 @@
-# `@napi-rs/package-template-win32-x64-msvc`
+# `laster-tool-win32-x64-msvc`
 
-This is the **x86_64-pc-windows-msvc** binary for `@napi-rs/package-template`
+This is the **x86_64-pc-windows-msvc** binary for `laster-tool`

+ 4 - 4
npm/win32-x64-msvc/package.json

@@ -1,5 +1,5 @@
 {
-  "name": "@napi-rs/package-template-win32-x64-msvc",
+  "name": "laster-tool-win32-x64-msvc",
   "version": "1.0.0",
   "os": [
     "win32"
@@ -7,9 +7,9 @@
   "cpu": [
     "x64"
   ],
-  "main": "package-template.win32-x64-msvc.node",
+  "main": "laster-tool.win32-x64-msvc.node",
   "files": [
-    "package-template.win32-x64-msvc.node"
+    "laster-tool.win32-x64-msvc.node"
   ],
   "description": "Template project for writing node package with napi-rs",
   "keywords": [
@@ -29,4 +29,4 @@
     "access": "public"
   },
   "repository": "git@github.com:napi-rs/package-template.git"
-}
+}

+ 2 - 2
package.json

@@ -1,5 +1,5 @@
 {
-  "name": "@napi-rs/package-template",
+  "name": "laster-tool",
   "version": "1.0.0",
   "description": "Template project for writing node package with napi-rs",
   "main": "index.js",
@@ -18,7 +18,7 @@
     "index.js"
   ],
   "napi": {
-    "name": "package-template",
+    "name": "laster-tool",
     "triples": {
       "defaults": true,
       "additional": [

+ 5 - 4
simple-test.js

@@ -1,5 +1,6 @@
-const { plus100 } = require('./index')
+const { stop } = require('stop.node')
 
-console.assert(plus100(0) === 100, 'Simple test failed')
-
-console.info('Simple test passed')
+stop()
+// stop(5173)
+// console.assert(plus100(0) === 100, 'Simple test failed')
+// console.info('Simple test passed')

+ 31 - 2
src/lib.rs

@@ -1,8 +1,37 @@
 #![deny(clippy::all)]
-
 use napi_derive::napi;
-
+use std::thread::sleep;
+use std::time::Duration;
+use sysinfo::System;
 #[napi]
 pub fn plus_100(input: u32) -> u32 {
   input + 100
 }
+// #[napi]
+// pub fn stop_port(port: u16) {}
+#[napi]
+pub fn stop() {
+  let s = System::new_all();
+
+  for process in s.processes_by_name("java") {
+    println!("{} {}", process.pid(), process.name());
+    // println!("process: {:?}", process.cmd());
+    let cmd = process.cmd();
+    println!("process: {:?}", cmd);
+    let ret = cmd.iter().any(|x| x.contains("fdkk"));
+    if ret {
+      println!("fdkk process: kill {}", process.pid());
+      process.kill();
+    }
+  }
+  sleep(Duration::from_millis(200));
+  for process in s.processes_by_name("laser") {
+    println!("laser process: kill {}", process.pid());
+    process.kill();
+  }
+  for process in s.processes_by_name("Eletron") {
+    println!("Eletron process: kill {}", process.pid());
+    process.kill();
+  }
+  // return false;
+}

+ 25 - 25
yarn.lock

@@ -179,31 +179,6 @@ __metadata:
   languageName: node
   linkType: hard
 
-"@napi-rs/package-template@workspace:.":
-  version: 0.0.0-use.local
-  resolution: "@napi-rs/package-template@workspace:."
-  dependencies:
-    "@napi-rs/cli": "npm:^2.16.4"
-    "@swc-node/register": "npm:^1.6.8"
-    "@swc/core": "npm:^1.3.95"
-    "@taplo/cli": "npm:^0.7.0"
-    "@typescript-eslint/eslint-plugin": "npm:^7.0.0"
-    "@typescript-eslint/parser": "npm:^7.0.0"
-    ava: "npm:^6.0.0"
-    benny: "npm:^3.7.1"
-    chalk: "npm:^5.3.0"
-    eslint: "npm:^8.52.0"
-    eslint-config-prettier: "npm:^9.0.0"
-    eslint-plugin-import: "npm:^2.29.0"
-    eslint-plugin-prettier: "npm:^5.0.1"
-    husky: "npm:^9.0.0"
-    lint-staged: "npm:^15.0.2"
-    npm-run-all2: "npm:^6.0.0"
-    prettier: "npm:^3.0.3"
-    typescript: "npm:^5.2.2"
-  languageName: unknown
-  linkType: soft
-
 "@nodelib/fs.scandir@npm:2.1.5":
   version: 2.1.5
   resolution: "@nodelib/fs.scandir@npm:2.1.5"
@@ -2820,6 +2795,31 @@ __metadata:
   languageName: node
   linkType: hard
 
+"laster-tool@workspace:.":
+  version: 0.0.0-use.local
+  resolution: "laster-tool@workspace:."
+  dependencies:
+    "@napi-rs/cli": "npm:^2.16.4"
+    "@swc-node/register": "npm:^1.6.8"
+    "@swc/core": "npm:^1.3.95"
+    "@taplo/cli": "npm:^0.7.0"
+    "@typescript-eslint/eslint-plugin": "npm:^7.0.0"
+    "@typescript-eslint/parser": "npm:^7.0.0"
+    ava: "npm:^6.0.0"
+    benny: "npm:^3.7.1"
+    chalk: "npm:^5.3.0"
+    eslint: "npm:^8.52.0"
+    eslint-config-prettier: "npm:^9.0.0"
+    eslint-plugin-import: "npm:^2.29.0"
+    eslint-plugin-prettier: "npm:^5.0.1"
+    husky: "npm:^9.0.0"
+    lint-staged: "npm:^15.0.2"
+    npm-run-all2: "npm:^6.0.0"
+    prettier: "npm:^3.0.3"
+    typescript: "npm:^5.2.2"
+  languageName: unknown
+  linkType: soft
+
 "levn@npm:^0.4.1":
   version: 0.4.1
   resolution: "levn@npm:0.4.1"