Skip to content

Commit

Permalink
feat: use koffi instead of ffi-napi to support nodejs >= 18
Browse files Browse the repository at this point in the history
ref: node-ffi-napi/node-ffi-napi#269

Notable changes summary:
1. Use [koffi] as node-ffi to support nodejs >= 18
2. Remove dependencies ffi-napi, ref-napi, ref-struct-di, ref-union-di
3. Easy structures initialization `<struct name>_Factory()`
4. Very easy structure/union definition
5. Auto create necessary struct/union when loading library from method def
6. Multiple Choice Parameters

details: https://github.com/waitingsong/node-win32-api/CHANGES.v22.md
  • Loading branch information
waitingsong committed Jun 28, 2024
1 parent 21b8d17 commit 3e8f7b5
Show file tree
Hide file tree
Showing 418 changed files with 10,970 additions and 8,737 deletions.
17 changes: 0 additions & 17 deletions .eslintrc.yml

This file was deleted.

27 changes: 27 additions & 0 deletions .githooks/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/sh
#
# 根据 commitmsg 以及 branch name 判断是否需要 commitlint
#
# Author: waiting
# Date: 2023.07.21
#

if [[ -z $NVM_DIR ]]; then
if [[ -f $HOME/.nvm/nvm.sh ]]; then
. $HOME/.nvm/nvm.sh
fi
fi

branch=$( git branch | grep \* | cut -d ' ' -f2 )
# ./.githooks/init-repo/is-skip-commitlint.ts $1 "$branch"

# code=$?
code=0
#echo -e 'node exitCode:' $code

if [[ -f ./node_modules/.bin/commitlint ]]; then
if [[ $code = 0 ]] && [[ -d node_modules ]] ; then
./node_modules/.bin/commitlint -e ./.git/COMMIT_EDITMSG
fi
fi

79 changes: 79 additions & 0 deletions .githooks/gen-file-from-example.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

102 changes: 102 additions & 0 deletions .githooks/gen-file-from-example.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#!/usr/bin/env tsx
/**
* 搜索指定目录以 file.example 文件为基础生成不带后缀的文件为不带 .example 后缀的文件
*/
import { dirname, join, sep } from 'node:path'
import { cp, mkdir, readdir } from 'node:fs/promises'
import { fileURLToPath } from 'node:url'

// import { folderArr, globalConfigFileArr } from './init.config.js'
import { genFileFromExample } from './init-example-file.js'


const folderArr: string[] = [
'./',
'.vscode',
'.settings',
'resource',
'configs',
'config', // egg
'src/config', // midway
]

const globalConfigFileArr: string[] = [
'.vscode/tasks.json.example',
'.vscode/launch.json.example',
'.vscode/settings.json.example',
'.vscode/ci.code-snippets.example',
'.vscode/midway.code-snippets.example',
'.vscode/promise.code-snippets.example',
'./tsconfig.base.json',
'./tsconfig.eslint.json',
// './rollup.config.js',
'./bin-hashbang.js',
]

const currentURL = import.meta.url
const currentPath = fileURLToPath(currentURL)
const currentDir = dirname(currentPath)
const currentFileName = currentPath.split(sep).pop()
const rootDir = join(currentDir, '..')
console.log({ rootDir, currentFileName })

const pkgEntryName = 'packages'
const pkgBase = join(rootDir, pkgEntryName)

const files = await cpGlobalConfigsToPkgs(rootDir, globalConfigFileArr, pkgBase)
console.log('Sync config:', files)

const files2 = await genFileFromExample(rootDir, folderArr)
console.info(`生成基础文件:${rootDir}`, files2)

const dirs = await readdir(pkgBase)
const arr: string[] = []

for (const name of dirs) {
const pkgPath = join(pkgBase, name)
const files3 = await genFileFromExample(pkgPath, folderArr)
files3.forEach(file => arr.push(`${pkgEntryName}/${name}/${file}`))
console.info(`生成包文件:`, arr)
}


// ---------------------------------------------

async function cpGlobalConfigsToPkgs(
baseDir: string,
configPaths: string[],
pkgBase: string,
): Promise<string[]> {

const pkgs = await readdir(pkgBase)
const ret: string[] = []

for (const pkg of pkgs) {
for (const path of configPaths) {
try {
const dst = `${pkg}/${path}`
const dstDir = dirname(join(pkgBase, dst))
await mkdir(dstDir, { recursive: true })
await cp(
join(baseDir, path),
join(pkgBase, dst),
)
ret.push(dst)
}
catch (ex: any) {
console.log(ex.message)
}
}
}

return ret
}

/**
* Generate random integer
*
* @see https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Math/random
*/
export function genRandomInt(max: number): number {
return Math.floor(Math.random() * Math.floor(max))
}
102 changes: 102 additions & 0 deletions .githooks/gen-file-from-example.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#!/usr/bin/env tsx
/**
* 搜索指定目录以 file.example 文件为基础生成不带后缀的文件为不带 .example 后缀的文件
*/
import { dirname, join, sep } from 'node:path'
import { cp, mkdir, readdir } from 'node:fs/promises'
import { fileURLToPath } from 'node:url'

// import { folderArr, globalConfigFileArr } from './init.config.js'
import { genFileFromExample } from './init-example-file.js'


const folderArr: string[] = [
'./',
'.vscode',
'.settings',
'resource',
'configs',
'config', // egg
'src/config', // midway
]

const globalConfigFileArr: string[] = [
'.vscode/tasks.json.example',
'.vscode/launch.json.example',
'.vscode/settings.json.example',
'.vscode/ci.code-snippets.example',
'.vscode/midway.code-snippets.example',
'.vscode/promise.code-snippets.example',
'./tsconfig.base.json',
'./tsconfig.eslint.json',
// './rollup.config.js',
'./bin-hashbang.js',
]

const currentURL = import.meta.url
const currentPath = fileURLToPath(currentURL)
const currentDir = dirname(currentPath)
const currentFileName = currentPath.split(sep).pop()
const rootDir = join(currentDir, '..')
console.log({ rootDir, currentFileName })

const pkgEntryName = 'packages'
const pkgBase = join(rootDir, pkgEntryName)

const files = await cpGlobalConfigsToPkgs(rootDir, globalConfigFileArr, pkgBase)
console.log('Sync config:', files)

const files2 = await genFileFromExample(rootDir, folderArr)
console.info(`生成基础文件:${rootDir}`, files2)

const dirs = await readdir(pkgBase)
const arr: string[] = []

for (const name of dirs) {
const pkgPath = join(pkgBase, name)
const files3 = await genFileFromExample(pkgPath, folderArr)
files3.forEach(file => arr.push(`${pkgEntryName}/${name}/${file}`))
console.info(`生成包文件:`, arr)
}


// ---------------------------------------------

async function cpGlobalConfigsToPkgs(
baseDir: string,
configPaths: string[],
pkgBase: string,
): Promise<string[]> {

const pkgs = await readdir(pkgBase)
const ret: string[] = []

for (const pkg of pkgs) {
for (const path of configPaths) {
try {
const dst = `${pkg}/${path}`
const dstDir = dirname(join(pkgBase, dst))
await mkdir(dstDir, { recursive: true })
await cp(
join(baseDir, path),
join(pkgBase, dst),
)
ret.push(dst)
}
catch (ex: any) {
console.log(ex.message)
}
}
}

return ret
}

/**
* Generate random integer
*
* @see https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Math/random
*/
export function genRandomInt(max: number): number {
return Math.floor(Math.random() * Math.floor(max))
}
34 changes: 23 additions & 11 deletions .githooks/init-repo/init-example-file.ts → .githooks/init-example-file.ts
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,31 +1,43 @@
/**
* 搜索指定目录以 file.example 文件为基础生成不带后缀的文件为不带 .example 后缀的文件
* 搜索指定目录以 file.example 文件为基础生成 去除结尾 .example
*/
import { copyFileAsync, isPathAccessible, join, readDirAsync } from './init-utils'
import { join } from 'node:path'
import { cp, readdir, stat } from 'node:fs/promises'


// const rootDir = join(__dirname, '..')
export async function genFileFromExample(rootDir: string, list: string[]): Promise<string[]> {
const copied: string[] = []

for (const dir of list) {
const path = join(rootDir, dir.replace(/\.{2,}/, '/'))
const srcPath = join(rootDir, dir.replace(/\.{2,}/, '/'))

if (! await isPathAccessible(path)) {
try {
const pathStat = await stat(srcPath)
if (! pathStat.isDirectory) { continue }
}
catch {
continue
}
const files = await readDirAsync(path)

const files = await readdir(srcPath)

for (const file of files) {
if (!hasExampleSuffix(file)) {
if (! hasExampleSuffix(file)) {
continue
}
const source = join(path, file)
const source = join(srcPath, file)
const stripped = stripExampleSuffix(file)
const target = join(path, stripped)
const target = join(srcPath, stripped)

if (! await isPathAccessible(target)) {
await copyFileAsync(source, target)
let targetStat
try {
targetStat = await stat(target)
}
catch {
void 0
}
if (! targetStat) {
await cp(source, target, { force: false })
copied.push(`${dir}/${stripped}`)
}
}
Expand Down
Loading

0 comments on commit 3e8f7b5

Please sign in to comment.