diff --git a/package.json b/package.json index d63982a..125ef66 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kevisual/use-config", - "version": "1.0.4", + "version": "1.0.5", "types": "dist/config.d.ts", "scripts": { "build": "npm run clean && rollup -c", @@ -52,6 +52,10 @@ "./context": { "import": "./dist/context.mjs", "types": "./dist/context.d.ts" + }, + "./file-store": { + "import": "./dist/file-store.mjs", + "types": "./dist/file-store.d.ts" } } } \ No newline at end of file diff --git a/rollup.config.mjs b/rollup.config.mjs index b9ca1c7..2704af7 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -70,4 +70,25 @@ export default [ }, plugins: [dts()], }, + { + input: 'src/file-store.ts', + output: { + file: 'dist/file-store.mjs', + format: 'es', + }, + plugins: [ + resolve(), + commonjs(), + typescript(), + ], + external: [], + }, + { + input: 'src/file-store.ts', + output: { + file: 'dist/file-store.d.ts', + format: 'es', + }, + plugins: [dts()], + } ]; diff --git a/src/file-store.ts b/src/file-store.ts new file mode 100644 index 0000000..4ca3b43 --- /dev/null +++ b/src/file-store.ts @@ -0,0 +1,22 @@ +import path from 'path'; +import fs from 'fs'; +import { fileIsExist } from './config.ts'; + +export type Opts = { + /** 检查是否需要 */ + needExists: boolean; +}; +export const useFileStore = (str: string, opts?: Opts): string => { + const publicPath = process.cwd(); + const filePath = path.join(publicPath, str); + if (opts?.needExists) { + if (!fileIsExist(filePath)) { + fs.mkdirSync(filePath, { recursive: true }); + } + } + return filePath; +}; + +export const usePublicStore = () => { + return useFileStore('public', { needExists: true }); +};