-
-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
580 additions
and
171 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
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 |
---|---|---|
@@ -1,29 +1,36 @@ | ||
//@ts-check | ||
|
||
const { pino } = require("pino"); | ||
const { app } = require("electron"); | ||
const path = require("path"); | ||
const dayjs = require("dayjs"); | ||
const util = require("util"); | ||
const fs = require("fs"); | ||
|
||
module.exports = function logger(name) { | ||
const dest = path.join(app.getPath("logs"), "/", dayjs().format("YYYY-MM-DD"), "/", name + ".log"); | ||
|
||
return pino( | ||
{ | ||
base: null, | ||
formatters: { | ||
level(label, number) { | ||
return { level: label }; | ||
}, | ||
}, | ||
timestamp: () => `,"time":"${new Date(Date.now()).toLocaleString()}"`, | ||
level: "debug", | ||
}, | ||
pino.destination({ | ||
dest, | ||
append: true, | ||
mkdir: true, | ||
sync: false, | ||
}) | ||
); | ||
function log(level, ...msg) { | ||
const data = msg | ||
.map((s) => { | ||
if (typeof s === "object" || typeof s === "function") { | ||
s = util.inspect(s); | ||
} | ||
return s; | ||
}) | ||
.join(""); | ||
const txt = `[${level}] ${new Date().toLocaleString()} \t ` + data; | ||
console.log(txt); | ||
if (!fs.existsSync(path.dirname(dest))) { | ||
fs.mkdirSync(path.dirname(dest), { recursive: true }); | ||
} | ||
fs.appendFileSync(dest, txt + "\n"); | ||
} | ||
|
||
return { | ||
log: (...msg) => log("信息", ...msg), | ||
info: (...msg) => log("信息", ...msg), | ||
error: (...msg) => log("错误", ...msg), | ||
debug: (...msg) => log("调试", ...msg), | ||
warn: (...msg) => log("警告", ...msg), | ||
}; | ||
}; |
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
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 @@ | ||
|
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
File renamed without changes.
File renamed without changes
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 |
---|---|---|
@@ -1,14 +1,14 @@ | ||
<template> | ||
<IconFont :type="icon" class="ocsicon"></IconFont> | ||
<IconFont :type="type" class="ocsicon"></IconFont> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { ref, reactive, toRefs } from "vue"; | ||
interface IconProps { | ||
icon: string; | ||
type: string; | ||
} | ||
const props = withDefaults(defineProps<IconProps>(), {}); | ||
const { icon } = toRefs(props); | ||
const { type } = toRefs(props); | ||
</script> | ||
|
||
<style scope lang="less"></style> |
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,84 @@ | ||
import { Stats } from "fs"; | ||
import { store } from "../../store"; | ||
|
||
const fs = require("fs") as typeof import("fs"); | ||
const path = require("path") as typeof import("path"); | ||
|
||
export { fs, path }; | ||
|
||
export interface File { | ||
title: string; | ||
key: string; | ||
slots: { | ||
icon: string; | ||
}; | ||
|
||
stat?: FileStats; | ||
path?: string; | ||
content?: string; | ||
children?: File[]; | ||
} | ||
|
||
export interface FileStats { | ||
isDirectory: boolean; | ||
createTime: number; | ||
modifyTime: number; | ||
} | ||
|
||
/** | ||
* 获取可用文件名 | ||
* @param name 名字模板, 例如 新建文件夹($count) | ||
*/ | ||
export function validFileName(name: string) { | ||
let count = 0; | ||
let p = ""; | ||
while (true) { | ||
p = path.resolve(store.workspace, name.replace("($count)", count++ === 0 ? "" : `(${count})`)); | ||
if (!fs.existsSync(p)) { | ||
break; | ||
} | ||
} | ||
return p; | ||
} | ||
|
||
/** | ||
* 创建文件(夹)对象 | ||
* | ||
* @param filePath 文件(夹)路径 | ||
* @param title 覆盖文件显示名 | ||
* @returns | ||
*/ | ||
export function createFile(filePath: string, title?: string): File { | ||
const stat = fs.statSync(filePath); | ||
let children; | ||
let content; | ||
let icon; | ||
if (stat.isDirectory()) { | ||
icon = "dir"; | ||
children = fs | ||
.readdirSync(filePath) | ||
.map((childFilePath) => createFile(path.resolve(filePath, childFilePath))) | ||
.filter((f) => !!f); | ||
} else { | ||
icon = "file"; | ||
content = fs.readFileSync(filePath).toString(); | ||
} | ||
|
||
title = title || path.basename(filePath); | ||
let p = path.dirname(filePath); | ||
return { | ||
title, | ||
key: filePath, | ||
slots: { | ||
icon, | ||
}, | ||
stat: { | ||
isDirectory: stat.isDirectory(), | ||
createTime: stat.birthtimeMs, | ||
modifyTime: stat.ctimeMs, | ||
}, | ||
content, | ||
path: p, | ||
children, | ||
}; | ||
} |
Oops, something went wrong.