Skip to content

Commit

Permalink
chore: 🤖 暂存一下
Browse files Browse the repository at this point in the history
  • Loading branch information
meetqy committed Jun 30, 2023
1 parent f233098 commit d586d1e
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 18 deletions.
1 change: 0 additions & 1 deletion packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"@acme/curd": "^0.1.0",
"@acme/db": "^0.1.0",
"@acme/eagle": "^0.1.0",
"@acme/folder": "^0.1.0",
"@trpc/client": "^10.23.0",
"@trpc/server": "^10.23.0",
"superjson": "^1.12.3",
Expand Down
47 changes: 35 additions & 12 deletions packages/support/eagle/index.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,54 @@
import * as fs from "fs";
import { join } from "path";
import * as fg from "fast-glob";
import chokidar from "chokidar";
import * as fs from "fs-extra";

import curd from "@acme/curd";
import { type Library } from "@acme/db";

import { handleFolder } from "./folder";
import { handleImage } from "./image";
import { type LibraryMetadata } from "./types";

export type EagleEmitOption = { type: "folder" | "image"; current: number; count: number; failCount?: number };
export type EagleEmit = (option: EagleEmitOption) => void;
import { type EmitOption, type LibraryMetadata } from "./types";

interface Props {
library: Library;
emit?: EagleEmit;
emit?: (option: EmitOption) => void;
onError?: (err: unknown) => void;
}

/**
* 是否第一次监听,第一次监听无需记录,直接添加
*/
export const isFirst = async (library: Library) => {
const libs = await curd.library.get({ library: library.id });
const lib = libs && libs[0];
if (lib && lib._count.images > 0) {
return false;
}

return true;
};

export const start = async ({ library, emit, onError }: Props) => {
try {
const base = JSON.parse(fs.readFileSync(`${library.dir}/metadata.json`, "utf-8")) as LibraryMetadata;
const images = fg.sync(join(library.dir, "images", "**", "metadata.json").replace(/\\/g, "/"));

// handle folder
const base = fs.readJSONSync(join(library.dir, "metadata.json")) as LibraryMetadata;
await handleFolder(base.folders, library, emit);

await handleImage({ images, library, emit, onError });
const first = await isFirst(library);

chokidar.watch(library.dir).on(join(library.dir, "images", "**", "metadata.json"), (path) => {
if (first) {
}
});
} catch (e) {
onError?.(e);
}

// try {
// const base = JSON.parse(fs.readFileSync(`${library.dir}/metadata.json`, "utf-8")) as LibraryMetadata;
// const images = fg.sync(join(library.dir, "images", "**", "metadata.json").replace(/\\/g, "/"));
// await handleFolder(base.folders, library, emit);
// await handleImage({ images, library, emit, onError });
// } catch (e) {
// onError?.(e);
// }
};
4 changes: 3 additions & 1 deletion packages/support/eagle/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
"@acme/constant": "^0.1.0",
"@acme/curd": "^0.1.0",
"@acme/db": "^0.1.0",
"chokidar": "^3.5.3",
"chroma-js": "^2.4.2",
"fast-glob": "^3.2.12"
"fast-glob": "^3.2.12",
"fs-extra": "^11.1.1"
},
"devDependencies": {
"@acme/eslint-config": "^0.1.0",
Expand Down
18 changes: 18 additions & 0 deletions packages/support/eagle/src/image.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import * as fs from "fs-extra";

import curd from "@acme/curd";
import { type Library } from "@acme/db";

import { type EmitOption, type Metadata } from "../types";

export const createImage = (path: string, library: Library, emit: (option: EmitOption) => void) => {
try {
const metadata = fs.readJSONSync(path) as Metadata;

// curd.image.add({

// })
} catch (e) {
throw e;
}
};
2 changes: 1 addition & 1 deletion packages/support/eagle/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"extends": "../../../tsconfig.json",
"include": ["*.ts", "test", "../../../global.d.ts"]
"include": ["*.ts", "test", "src", "../../../global.d.ts"]
}
2 changes: 2 additions & 0 deletions packages/support/eagle/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { CONSTANT, type Constant } from "@acme/constant";

export const SUPPORT_EXT = CONSTANT.EXT;

export type EmitOption = { type: Constant["app"]; current: number; count: number; failCount?: number };

export interface Metadata {
id: string;
name: string;
Expand Down
9 changes: 6 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d586d1e

Please sign in to comment.