From de3f471812ae506a4b448664f33e528babe4bac4 Mon Sep 17 00:00:00 2001 From: kanno <812137533@qq.com> Date: Sun, 28 Jul 2024 23:01:17 +0800 Subject: [PATCH] feat: add path binding --- internal/Archive.res | 5 ++ internal/bindings/Path.res | 134 +++++++++++++++++++++++++++++++++++++ scripts/gen-entry.ts | 1 - 3 files changed, 139 insertions(+), 1 deletion(-) create mode 100644 internal/Archive.res create mode 100644 internal/bindings/Path.res diff --git a/internal/Archive.res b/internal/Archive.res new file mode 100644 index 0000000..861ea53 --- /dev/null +++ b/internal/Archive.res @@ -0,0 +1,5 @@ +// Archive contains pack and extract functions. + +module Pack = {} + +module Extract = {} diff --git a/internal/bindings/Path.res b/internal/bindings/Path.res new file mode 100644 index 0000000..f4da77b --- /dev/null +++ b/internal/bindings/Path.res @@ -0,0 +1,134 @@ +type t = { + dir: string, + root: string, + base: string, + name: string, + ext: string, +} + +@module("node:path") external basename: string => string = "basename" + +@module("node:path") +external basenameExt: (string, string) => string = "basename" + +@module("node:path") external delimiter: string = "delimiter" + +@module("node:path") external dirname: string => string = "dirname" + +@module("node:path") external extname: string => string = "extname" + +@module("node:path") external format: t => string = "format" + +@module("node:path") external isAbsolute: string => bool = "isAbsolute" + +@module("node:path") @variadic +external join: array => string = "join" + +@module("node:path") external join2: (string, string) => string = "join" + +@module("node:path") external normalize: string => string = "normalize" + +@module("node:path") external parse: string => t = "parse" + +@module("node:path") +external relative: (~from: string, ~to_: string) => string = "relative" + +@module("node:path") @variadic +external resolve: array => string = "resolve" + +@module("node:path") external sep: string = "sep" + +@module("node:path") +external toNamespacedPath: string => string = "toNamespacedPath" + +module Posix = { + @module("node:path") @scope("posix") + external basename: string => string = "basename" + + @module("node:path") @scope("posix") + external basenameExt: (string, string) => string = "basename" + + @module("node:path") @scope("posix") + external delimiter: string = "delimiter" + + @module("node:path") @scope("posix") + external dirname: string => string = "dirname" + + @module("node:path") @scope("posix") + external extname: string => string = "extname" + + @module("node:path") @scope("posix") + external format: t => string = "format" + + @module("node:path") @scope("posix") + external isAbsolute: string => bool = "isAbsolute" + + @module("node:path") @scope("posix") @variadic + external join: array => string = "join" + + @module("node:path") @scope("posix") + external join2: (string, string) => string = "join" + + @module("node:path") @scope("posix") + external normalize: string => string = "normalize" + + @module("node:path") @scope("posix") + external parse: string => t = "parse" + + @module("node:path") @scope("posix") + external relative: (~from: string, ~to_: string) => string = "relative" + + @module("node:path") @scope("posix") @variadic + external resolve: array => string = "resolve" + + @module("node:path") @scope("posix") external sep: string = "sep" + + @module("node:path") @scope("posix") + external toNamespacedPath: string => string = "toNamespacedPath" +} + +module Win32 = { + @module("node:path") @scope("win32") + external basename: string => string = "basename" + + @module("node:path") @scope("win32") + external basenameExt: (string, string) => string = "basename" + + @module("node:path") @scope("win32") + external delimiter: string = "delimiter" + + @module("node:path") @scope("win32") + external dirname: string => string = "dirname" + + @module("node:path") @scope("win32") + external extname: string => string = "extname" + + @module("node:path") @scope("win32") + external format: t => string = "format" + + @module("node:path") @scope("win32") + external isAbsolute: string => bool = "isAbsolute" + + @module("node:path") @scope("win32") @variadic + external join: array => string = "join" + + @module("node:path") @scope("win32") + external join2: (string, string) => string = "join" + + @module("node:path") @scope("win32") + external normalize: string => string = "normalize" + + @module("node:path") @scope("win32") + external parse: string => t = "parse" + + @module("node:path") @scope("win32") + external relative: (~from: string, ~to_: string) => string = "relative" + + @module("node:path") @scope("win32") @variadic + external resolve: array => string = "resolve" + + @module("node:path") @scope("win32") external sep: string = "sep" + + @module("node:path") @scope("win32") + external toNamespacedPath: string => string = "toNamespacedPath" +} diff --git a/scripts/gen-entry.ts b/scripts/gen-entry.ts index 642a3d4..78d3e50 100644 --- a/scripts/gen-entry.ts +++ b/scripts/gen-entry.ts @@ -48,7 +48,6 @@ async function main() { return `export * from './${relativePath}'` }) .join('\n') - console.log(content) await fsp.writeFile(entryPath, content, 'utf-8') }