Format & lint
This commit is contained in:
parent
fefac224b0
commit
7f62273e72
179 changed files with 2210 additions and 1319 deletions
|
|
@ -37,22 +37,19 @@ export function parseArgs(argv: string[]): CliArgs {
|
|||
).env("VAULTLINK_LOCAL_PATH")
|
||||
)
|
||||
.addOption(
|
||||
new Option(
|
||||
"-r, --remote-uri <uri>",
|
||||
"Remote server URI"
|
||||
).env("VAULTLINK_REMOTE_URI")
|
||||
new Option("-r, --remote-uri <uri>", "Remote server URI").env(
|
||||
"VAULTLINK_REMOTE_URI"
|
||||
)
|
||||
)
|
||||
.addOption(
|
||||
new Option(
|
||||
"-t, --token <token>",
|
||||
"Authentication token"
|
||||
).env("VAULTLINK_TOKEN")
|
||||
new Option("-t, --token <token>", "Authentication token").env(
|
||||
"VAULTLINK_TOKEN"
|
||||
)
|
||||
)
|
||||
.addOption(
|
||||
new Option(
|
||||
"-v, --vault-name <name>",
|
||||
"Vault name"
|
||||
).env("VAULTLINK_VAULT_NAME")
|
||||
new Option("-v, --vault-name <name>", "Vault name").env(
|
||||
"VAULTLINK_VAULT_NAME"
|
||||
)
|
||||
)
|
||||
.addOption(
|
||||
new Option(
|
||||
|
|
@ -147,10 +144,7 @@ Environment variables:
|
|||
const lineEndingsStr = (opts.lineEndings as string | undefined) ?? "auto";
|
||||
/* eslint-enable @typescript-eslint/no-unsafe-type-assertion */
|
||||
|
||||
const requireOption = <T>(
|
||||
value: T | undefined,
|
||||
name: string
|
||||
): T => {
|
||||
const requireOption = <T>(value: T | undefined, name: string): T => {
|
||||
if (value === undefined) {
|
||||
const option = program.options.find(
|
||||
(o) => o.attributeName() === name
|
||||
|
|
@ -173,9 +167,7 @@ Environment variables:
|
|||
|
||||
// Validate remote URI protocol
|
||||
if (
|
||||
!VALID_PROTOCOLS.some((prefix) =>
|
||||
requiredRemoteUri.startsWith(prefix)
|
||||
)
|
||||
!VALID_PROTOCOLS.some((prefix) => requiredRemoteUri.startsWith(prefix))
|
||||
) {
|
||||
throw new Error(
|
||||
`Invalid remote URI '${requiredRemoteUri}'. Must start with ${VALID_PROTOCOLS.join(", ")}`
|
||||
|
|
|
|||
|
|
@ -50,9 +50,7 @@ function createLogHandler(minLevel: LogLevel): (logLine: LogLine) => void {
|
|||
const HEALTH_CHECK_INTERVAL_MS = 30 * 1000;
|
||||
const PROGRESS_LOG_INTERVAL_MS = 2000;
|
||||
|
||||
function resolveLineEndings(
|
||||
mode: "auto" | "lf" | "crlf"
|
||||
): string {
|
||||
function resolveLineEndings(mode: "auto" | "lf" | "crlf"): string {
|
||||
switch (mode) {
|
||||
case "lf":
|
||||
return "\n";
|
||||
|
|
@ -94,9 +92,7 @@ async function main(): Promise<void> {
|
|||
logger.info(`Remote URI: ${args.remoteUri}`);
|
||||
logger.info(`Vault name: ${args.vaultName}`);
|
||||
if (args.lineEndings !== "auto") {
|
||||
logger.info(
|
||||
`Line endings: ${args.lineEndings.toUpperCase()}`
|
||||
);
|
||||
logger.info(`Line endings: ${args.lineEndings.toUpperCase()}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -138,9 +134,7 @@ async function main(): Promise<void> {
|
|||
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
||||
database = JSON.parse(content) as Partial<StoredDatabase>;
|
||||
} catch {
|
||||
logger.warn(
|
||||
`Cannot read data file at ${dataFile}`
|
||||
);
|
||||
logger.warn(`Cannot read data file at ${dataFile}`);
|
||||
}
|
||||
|
||||
return {
|
||||
|
|
@ -225,9 +219,7 @@ async function main(): Promise<void> {
|
|||
}
|
||||
isShuttingDown = true;
|
||||
|
||||
client.logger.info(
|
||||
`${signal} received, shutting down gracefully`
|
||||
);
|
||||
client.logger.info(`${signal} received, shutting down gracefully`);
|
||||
|
||||
fileWatcher.stop();
|
||||
await client.waitUntilFinished();
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@ export class FileWatcher {
|
|||
renameDetection: true,
|
||||
renameTimeout: 125,
|
||||
ignoreInitial: true,
|
||||
ignore: (filePath: string): boolean =>
|
||||
this.shouldIgnore(filePath)
|
||||
ignore: (filePath: string): boolean => this.shouldIgnore(filePath)
|
||||
});
|
||||
|
||||
this.watcher.on("add", (filePath: string) => {
|
||||
|
|
@ -91,8 +90,4 @@ export class FileWatcher {
|
|||
private toRelativePath(absolutePath: string): RelativePath {
|
||||
return toUnixPath(path.relative(this.basePath, absolutePath));
|
||||
}
|
||||
|
||||
private formatError(err: unknown): string {
|
||||
return err instanceof Error ? err.message : String(err);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,18 +15,12 @@ export class NodeFileSystemOperations implements FileSystemOperations {
|
|||
directory: RelativePath | undefined
|
||||
): Promise<RelativePath[]> {
|
||||
const files: RelativePath[] = [];
|
||||
await this.walkDirectory(
|
||||
directory ?? "",
|
||||
files
|
||||
);
|
||||
await this.walkDirectory(directory ?? "", files);
|
||||
return files;
|
||||
}
|
||||
|
||||
public async read(relativePath: RelativePath): Promise<Uint8Array> {
|
||||
const fullPath = path.join(
|
||||
this.basePath,
|
||||
relativePath
|
||||
);
|
||||
const fullPath = path.join(this.basePath, relativePath);
|
||||
try {
|
||||
return await fs.readFile(fullPath);
|
||||
} catch (error) {
|
||||
|
|
@ -40,10 +34,7 @@ export class NodeFileSystemOperations implements FileSystemOperations {
|
|||
relativePath: RelativePath,
|
||||
content: Uint8Array
|
||||
): Promise<void> {
|
||||
const fullPath = path.join(
|
||||
this.basePath,
|
||||
relativePath
|
||||
);
|
||||
const fullPath = path.join(this.basePath, relativePath);
|
||||
const dir = path.dirname(fullPath);
|
||||
|
||||
try {
|
||||
|
|
@ -60,10 +51,7 @@ export class NodeFileSystemOperations implements FileSystemOperations {
|
|||
relativePath: RelativePath,
|
||||
updater: (current: TextWithCursors) => TextWithCursors
|
||||
): Promise<string> {
|
||||
const fullPath = path.join(
|
||||
this.basePath,
|
||||
relativePath
|
||||
);
|
||||
const fullPath = path.join(this.basePath, relativePath);
|
||||
|
||||
try {
|
||||
const currentContent = await fs.readFile(fullPath, "utf-8");
|
||||
|
|
@ -78,10 +66,7 @@ export class NodeFileSystemOperations implements FileSystemOperations {
|
|||
}
|
||||
|
||||
public async getFileSize(relativePath: RelativePath): Promise<number> {
|
||||
const fullPath = path.join(
|
||||
this.basePath,
|
||||
relativePath
|
||||
);
|
||||
const fullPath = path.join(this.basePath, relativePath);
|
||||
try {
|
||||
const stats = await fs.stat(fullPath);
|
||||
return stats.size;
|
||||
|
|
@ -93,10 +78,7 @@ export class NodeFileSystemOperations implements FileSystemOperations {
|
|||
}
|
||||
|
||||
public async exists(relativePath: RelativePath): Promise<boolean> {
|
||||
const fullPath = path.join(
|
||||
this.basePath,
|
||||
relativePath
|
||||
);
|
||||
const fullPath = path.join(this.basePath, relativePath);
|
||||
try {
|
||||
await fs.access(fullPath);
|
||||
return true;
|
||||
|
|
@ -106,10 +88,7 @@ export class NodeFileSystemOperations implements FileSystemOperations {
|
|||
}
|
||||
|
||||
public async createDirectory(relativePath: RelativePath): Promise<void> {
|
||||
const fullPath = path.join(
|
||||
this.basePath,
|
||||
relativePath
|
||||
);
|
||||
const fullPath = path.join(this.basePath, relativePath);
|
||||
try {
|
||||
await fs.mkdir(fullPath, { recursive: false });
|
||||
} catch (error) {
|
||||
|
|
@ -120,10 +99,7 @@ export class NodeFileSystemOperations implements FileSystemOperations {
|
|||
}
|
||||
|
||||
public async delete(relativePath: RelativePath): Promise<void> {
|
||||
const fullPath = path.join(
|
||||
this.basePath,
|
||||
relativePath
|
||||
);
|
||||
const fullPath = path.join(this.basePath, relativePath);
|
||||
try {
|
||||
await fs.unlink(fullPath);
|
||||
} catch (error) {
|
||||
|
|
@ -191,5 +167,4 @@ export class NodeFileSystemOperations implements FileSystemOperations {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,10 +8,7 @@ export function toUnixPath(nativePath: string): string {
|
|||
// Match a file path against a glob pattern
|
||||
// Extends path.matchesGlob so that "dir/**" also matches the directory itself
|
||||
export function matchesGlob(filePath: string, pattern: string): boolean {
|
||||
if (
|
||||
pattern.endsWith("/**") &&
|
||||
filePath === pattern.slice(0, -3)
|
||||
) {
|
||||
if (pattern.endsWith("/**") && filePath === pattern.slice(0, -3)) {
|
||||
return true;
|
||||
}
|
||||
return path.matchesGlob(filePath, pattern);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue