-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from Froxz/feature/ts
Added TypeScript support
- Loading branch information
Showing
20 changed files
with
6,313 additions
and
2,343 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
dist/ | ||
node_modules/ | ||
*.d.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"extends": "@antfu", | ||
"overrides": [ | ||
{ | ||
"files": [ | ||
"**/*.md/*.*" | ||
], | ||
"rules": { | ||
"@typescript-eslint/no-this-alias": "off", | ||
"n/handle-callback-err": "off", | ||
"no-restricted-syntax": "off", | ||
"no-labels": "off" | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './dist' |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,68 @@ | ||
{ | ||
"name": "@froxz/vite-plugin-s3", | ||
"version": "1.1.2", | ||
"description": "Allows you to upload files to S3", | ||
"type": "module", | ||
"keywords": [ | ||
"vite", | ||
"s3", | ||
"vite-plugin" | ||
], | ||
"files": [ | ||
"dist" | ||
], | ||
"main": "./dist/main.cjs", | ||
"module": "./dist/main.js", | ||
"exports": { | ||
".": { | ||
"import": "./dist/main.js", | ||
"require": "./dist/main.cjs" | ||
} | ||
"name": "@froxz/vite-plugin-s3", | ||
"type": "module", | ||
"version": "1.1.2", | ||
"description": "Allows you to upload files to AWS S3 or any other S3 compatible provider", | ||
"author": "Froxz([email protected])", | ||
"license": "MIT", | ||
"homepage": "https://github.com/Froxz/vite-plugin-s3", | ||
"repository": "https://github.com/Froxz/vite-plugin-s3", | ||
"bugs": { | ||
"url": "https://github.com/Froxz/vite-plugin-s3/issues" | ||
}, | ||
"keywords": [ | ||
"vite", | ||
"s3", | ||
"vite-plugin", | ||
"do-spaces" | ||
], | ||
"exports": { | ||
".": { | ||
"types": "./dist/index.d.ts", | ||
"require": "./dist/index.js", | ||
"import": "./dist/index.mjs" | ||
}, | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "vite build", | ||
"preview": "vite preview" | ||
}, | ||
"repository": "https://github.com/Froxz/vite-plugin-s3", | ||
"author": "Froxz([email protected])", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/Froxz/vite-plugin-s3/issues" | ||
}, | ||
"homepage": "https://github.com/Froxz/vite-plugin-s3", | ||
"dependencies": { | ||
"@aws-sdk/client-s3": "^3.0.0", | ||
"mime-types": "^2.1.35", | ||
"progress": "^2.0.3", | ||
"recursive-readdir": "^2.2.3" | ||
}, | ||
"devDependencies": { | ||
"kolorist": "^1.7.0", | ||
"lodash": "^4.17.21", | ||
"vite": "^4.0.0", | ||
"vite-plugin-target": "^0.1.1" | ||
"./*": "./*" | ||
}, | ||
"main": "dist/index.js", | ||
"module": "dist/index.mjs", | ||
"types": "index.d.ts", | ||
"typesVersions": { | ||
"*": { | ||
"*": [ | ||
"./dist/*", | ||
"./*" | ||
] | ||
} | ||
}, | ||
"files": [ | ||
"dist", | ||
"*.d.ts" | ||
], | ||
"scripts": { | ||
"lint": "eslint .", | ||
"lint-fix": "eslint . --fix", | ||
"dev": "npx tsup src/index.ts --watch --ignore-watch dist", | ||
"build": "npx tsup src/index.ts --dts --format cjs,esm" | ||
}, | ||
"peerDependencies": { | ||
"vite": "^3.1.0 || ^4.0.0" | ||
}, | ||
"dependencies": { | ||
"@aws-sdk/client-s3": "^3.0.0", | ||
"mime-types": "^2.1.35", | ||
"recursive-readdir": "^2.2.3" | ||
}, | ||
"devDependencies": { | ||
"@antfu/eslint-config": "^0.36.0", | ||
"@types/lodash": "^4.14.191", | ||
"@types/mime-types": "^2.1.1", | ||
"@types/node": "^18.15.3", | ||
"@types/recursive-readdir": "^2.2.1", | ||
"eslint": "^8.36.0", | ||
"kolorist": "^1.7.0", | ||
"lodash": "^4.17.21", | ||
"tsup": "^6.6.3", | ||
"typescript": "^4.9.5" | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import type { Options } from './types' | ||
|
||
import { | ||
addTrailingS3Sep, | ||
} from './helpers' | ||
|
||
export function createContext(options: Options): Options { | ||
const basePath = options.basePath ? addTrailingS3Sep(options.basePath) : '' | ||
|
||
return { | ||
...options, | ||
basePath, | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import path from 'node:path' | ||
import readDir from 'recursive-readdir' | ||
|
||
import type { File } from './types' | ||
|
||
export const S3_PATH_SEP = '/' | ||
export const PATH_SEP: string = path.sep | ||
|
||
export const DEFAULT_UPLOAD_OPTIONS: object = { | ||
ACL: 'public-read', | ||
} | ||
|
||
export const UPLOAD_IGNORES: string[] = [ | ||
'.DS_Store', | ||
] | ||
|
||
export function addTrailingS3Sep(fPath: string): string { | ||
return fPath ? fPath.replace(/\/?(\?|#|$)/, '/$1') : fPath | ||
} | ||
|
||
export function addSeperatorToPath(fPath: string): string { | ||
if (!fPath) | ||
return fPath | ||
|
||
return fPath.endsWith(PATH_SEP) ? fPath : fPath + PATH_SEP | ||
} | ||
|
||
export function translatePathFromFiles(dir: string, files: string[]): File[] { | ||
return files.map((file: string): File => ({ | ||
path: file, | ||
name: file | ||
.replace(dir, '') | ||
.split(PATH_SEP) | ||
.join(S3_PATH_SEP), | ||
})) | ||
} | ||
|
||
export const getDirectoryFilesRecursive = (dir: string, ignores: ReadonlyArray<string> = []): Promise<File[]> => { | ||
return new Promise((resolve, reject) => { | ||
readDir(dir, ignores, (error: Error, files: string[]) => { | ||
if (error) | ||
reject(error) | ||
|
||
else | ||
resolve(translatePathFromFiles(dir, files)) | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import type { ConfigEnv, Plugin, ResolvedConfig, UserConfig } from 'vite' | ||
import { createContext } from './context' | ||
import Uploader from './uploader' | ||
|
||
import type { Options } from './types' | ||
|
||
export function S3Plugin(enabled: boolean, userOptions: Options): Plugin { | ||
const options: Options = createContext(userOptions) | ||
let vite: ResolvedConfig | ||
|
||
return { | ||
name: 'vite-plugin-s3', | ||
enforce: 'post', | ||
apply(config: UserConfig, { command }: ConfigEnv) { | ||
return command === 'build' && enabled | ||
}, | ||
configResolved(config: ResolvedConfig) { | ||
vite = config | ||
}, | ||
closeBundle: { | ||
async handler() { | ||
if (!vite.build.ssr && enabled) { | ||
const uploader = new Uploader(options, vite) | ||
|
||
await uploader.apply() | ||
} | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
export type { Options } |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.