Skip to content

Commit

Permalink
🐛 fix(package.json): update package version to 0.1.6
Browse files Browse the repository at this point in the history
✨ feat(options.type.ts): add prefixDir property to T_Options type
✨ feat(uploader.ts): add prefixDir option to getFilePath method to add a prefix to the uploaded file path.
  • Loading branch information
ferdiunal committed Apr 18, 2023
1 parent 56c62d8 commit ea77085
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vite-cdn-uploader",
"version": "0.1.5",
"version": "0.1.6",
"description": "A Vite plugin to upload built files to various CDN providers",
"main": "dist/index.js",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import path from "node:path"
import * as dotenv from "dotenv"
import { I_Options } from './interfaces';
import { Uploader } from './uploader';
import * as Providers from "./providers"
import * as providers from "./providers"

dotenv.config()

Expand All @@ -27,4 +27,4 @@ export const cdnUploaderPlugin = (options: I_Options): Plugin => {
}


export { cdnUploaderPlugin as default, Providers}
export { cdnUploaderPlugin as default, providers}
1 change: 1 addition & 0 deletions src/types/options.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export type T_Options = {
provider: Provider,
root?: string,
buildDir?: string,
prefixDir?: string,
}

export type T_ProviderOptions = Record<string, string | {
Expand Down
18 changes: 17 additions & 1 deletion src/uploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,22 @@ export class Uploader {
return allFiles;
}

private getFilePath(filePath: string) {
filePath = filePath.replace(
this.options.root + "/",
""
)

if(this.options.prefixDir) {
return path.join(
this.options.prefixDir,
filePath
)
}

return filePath
}


async upload() {
const files = this.files(
Expand All @@ -47,7 +63,7 @@ export class Uploader {

await this.options.provider.upload(
fs.readFileSync(file),
file
this.getFilePath(file)
)

this.bar.update(process + 1)
Expand Down

0 comments on commit ea77085

Please sign in to comment.