add file-stsore
This commit is contained in:
parent
ebfdbe6cee
commit
a57579281e
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@kevisual/use-config",
|
"name": "@kevisual/use-config",
|
||||||
"version": "1.0.4",
|
"version": "1.0.5",
|
||||||
"types": "dist/config.d.ts",
|
"types": "dist/config.d.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "npm run clean && rollup -c",
|
"build": "npm run clean && rollup -c",
|
||||||
@ -52,6 +52,10 @@
|
|||||||
"./context": {
|
"./context": {
|
||||||
"import": "./dist/context.mjs",
|
"import": "./dist/context.mjs",
|
||||||
"types": "./dist/context.d.ts"
|
"types": "./dist/context.d.ts"
|
||||||
|
},
|
||||||
|
"./file-store": {
|
||||||
|
"import": "./dist/file-store.mjs",
|
||||||
|
"types": "./dist/file-store.d.ts"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -70,4 +70,25 @@ export default [
|
|||||||
},
|
},
|
||||||
plugins: [dts()],
|
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()],
|
||||||
|
}
|
||||||
];
|
];
|
||||||
|
22
src/file-store.ts
Normal file
22
src/file-store.ts
Normal file
@ -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 });
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user