@@ -5,6 +5,8 @@ import { typedEntries } from "./src/utils/typedEntries";
55import { createBranch , uploadFilesWithProgress } from "./src" ;
66import { pathToFileURL } from "node:url" ;
77import { HUB_URL } from "./src/consts" ;
8+ import { stat } from "node:fs/promises" ;
9+ import { basename , join } from "node:path" ;
810
911// Didn't find the import from "node:util", so duplicated it here
1012type OptionToken =
@@ -39,12 +41,12 @@ const commands = {
3941 positional: true,
4042 default: () => process.cwd(),
4143 },
42- // {
43- // name: "path-in-repo" as const,
44- // description: "The path in the repo to upload the folder to. Defaults to the root of the repo",
45- // positional: true,
46- // default: "/ ",
47- // },
44+ {
45+ name: "path-in-repo" as const,
46+ description: "The path in the repo to upload the folder to. Defaults to the root of the repo",
47+ positional: true,
48+ default: ". ",
49+ },
4850 {
4951 name: "quiet" as const,
5052 short: "q",
@@ -158,6 +160,7 @@ async function run() {
158160 quiet,
159161 commitMessage,
160162 hubUrl,
163+ pathInRepo,
161164 } = parsedArgs ;
162165
163166 if ( revision && revision !== "main" ) {
@@ -172,9 +175,19 @@ async function run() {
172175 } ) ;
173176 }
174177
178+ const isFile = ( await stat ( localFolder ) ) . isFile ( ) ;
179+ const files = isFile
180+ ? [
181+ {
182+ content : pathToFileURL ( localFolder ) ,
183+ path : join ( pathInRepo , `${ basename ( localFolder ) } ` ) . replace ( / ^ [ . ] ? \/ / , "" ) ,
184+ } ,
185+ ]
186+ : [ { content : pathToFileURL ( localFolder ) , path : pathInRepo . replace ( / ^ [ . ] ? \/ / , "" ) } ] ;
187+
175188 for await ( const event of uploadFilesWithProgress ( {
176189 repo : repoType ? { type : repoType as "model" | "dataset" | "space" , name : repoName } : repoName ,
177- files : [ pathToFileURL ( localFolder ) ] ,
190+ files,
178191 branch : revision ,
179192 accessToken : token ,
180193 commitTitle : commitMessage ?. trim ( ) . split ( "\n" ) [ 0 ] ,
0 commit comments