add dev input module
This commit is contained in:
parent
956114e891
commit
248e045c63
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@kevisual/use-config",
|
"name": "@kevisual/use-config",
|
||||||
"version": "1.0.15",
|
"version": "1.0.17",
|
||||||
"types": "dist/config.d.ts",
|
"types": "dist/config.d.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "npm run clean && tsup",
|
"build": "npm run clean && tsup",
|
||||||
|
@ -46,7 +46,7 @@ export const fileIsExist = (path: string) => {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
export const getDirname = () => {
|
export const getCwdDirname = () => {
|
||||||
return path.resolve();
|
return path.resolve();
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
@ -55,7 +55,7 @@ export const getDirname = () => {
|
|||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
export const getConfigFile = (fileName = 'app.config.json5') => {
|
export const getConfigFile = (fileName = 'app.config.json5') => {
|
||||||
const dirname = getDirname();
|
const dirname = getCwdDirname();
|
||||||
// 本级
|
// 本级
|
||||||
const benPath = dirname + '/' + fileName;
|
const benPath = dirname + '/' + fileName;
|
||||||
const ben = fileIsExist(benPath);
|
const ben = fileIsExist(benPath);
|
||||||
@ -72,7 +72,7 @@ export const getConfigFile = (fileName = 'app.config.json5') => {
|
|||||||
};
|
};
|
||||||
// 初始化读取配置文件
|
// 初始化读取配置文件
|
||||||
export const init = (initConfigBase?: any): Config => {
|
export const init = (initConfigBase?: any): Config => {
|
||||||
const dirname = getDirname();
|
const dirname = getCwdDirname();
|
||||||
try {
|
try {
|
||||||
// 配置读取路径,3级判断
|
// 配置读取路径,3级判断
|
||||||
const filePath = getConfigFile();
|
const filePath = getConfigFile();
|
||||||
|
45
src/env.ts
45
src/env.ts
@ -41,7 +41,7 @@ export const fileIsExist = (path: string) => {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
export const getDirname = () => {
|
export const getCwdDirname = () => {
|
||||||
return process.cwd();
|
return process.cwd();
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
@ -68,13 +68,13 @@ export type ConfigOpts = {
|
|||||||
*/
|
*/
|
||||||
export const getConfigFile = (opts?: ConfigOpts) => {
|
export const getConfigFile = (opts?: ConfigOpts) => {
|
||||||
if (opts?.envConfigFile) {
|
if (opts?.envConfigFile) {
|
||||||
const filePath = path.join(opts.cwd || getDirname(), opts.envConfigFile);
|
const filePath = path.join(opts.cwd || getCwdDirname(), opts.envConfigFile);
|
||||||
if (fileIsExist(filePath)) {
|
if (fileIsExist(filePath)) {
|
||||||
return filePath;
|
return filePath;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const fileName = opts?.fileName || '.env';
|
const fileName = opts?.fileName || '.env';
|
||||||
const dirname = opts?.cwd || getDirname();
|
const dirname = opts?.cwd || getCwdDirname();
|
||||||
// 本级
|
// 本级
|
||||||
const benPath = dirname + '/' + fileName;
|
const benPath = dirname + '/' + fileName;
|
||||||
const ben = fileIsExist(benPath);
|
const ben = fileIsExist(benPath);
|
||||||
@ -224,6 +224,43 @@ export const resolvePath = (releactivePath: string = '', opts?: ResolvePathOptio
|
|||||||
} else if (opts?.cwd) {
|
} else if (opts?.cwd) {
|
||||||
return path.resolve(opts.cwd, releactivePath);
|
return path.resolve(opts.cwd, releactivePath);
|
||||||
} else {
|
} else {
|
||||||
return path.resolve(getDirname(), releactivePath);
|
return path.resolve(getCwdDirname(), releactivePath);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前文件的路径
|
||||||
|
* @param opts
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
export const getDirname = (opts?: Pick<ResolvePathOptions, 'meta'>) => {
|
||||||
|
if (opts?.meta) {
|
||||||
|
const __filename = fileURLToPath(opts.meta.url);
|
||||||
|
const __dirname = path.dirname(__filename);
|
||||||
|
return {
|
||||||
|
__filename,
|
||||||
|
__dirname,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
__dirname: getCwdDirname(),
|
||||||
|
__filename: path.join(getCwdDirname(), 'index.ts'),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getDevInputs = (files: string[] = []) => {
|
||||||
|
return files.map((item) => {
|
||||||
|
const filename = path.basename(item);
|
||||||
|
return {
|
||||||
|
// 相对路径
|
||||||
|
path: item,
|
||||||
|
// 文件名
|
||||||
|
filename: filename,
|
||||||
|
// 文件后缀
|
||||||
|
extname: path.extname(filename),
|
||||||
|
// 文件名不带后缀
|
||||||
|
naming: filename.replace(path.extname(filename), ''),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user