@2kog/kacha 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +63 -2
- package/bin/init-project.js +63 -0
- package/bin/kacha.js +51 -0
- package/index.html +5 -0
- package/package.json +45 -4
- package/server/asset-directories.js +65 -0
- package/server/asset-watch.js +35 -0
- package/server/character-assets.js +399 -0
- package/server/image-assets.js +652 -0
- package/server/index.js +15 -0
- package/server/project-brand.js +56 -0
- package/server/project-paths.js +4 -0
- package/server/project-settings.js +55 -0
- package/src/App.vue +34 -0
- package/src/assets/css/workbench.css +272 -0
- package/src/assets/img/rabbit-mark.svg +1 -0
- package/src/components/AssetDeleteButton.vue +53 -0
- package/src/components/AssetHistory.vue +40 -0
- package/src/components/AssetStoryEditor.vue +32 -0
- package/src/components/AssetTagInput.vue +26 -0
- package/src/components/ProjectMarkdown.vue +33 -0
- package/src/i18n/en.json +163 -0
- package/src/i18n/index.js +40 -0
- package/src/layouts/WorkbenchLayout.vue +61 -0
- package/src/main.js +7 -0
- package/src/router/index.js +38 -0
- package/src/service/assets.js +13 -0
- package/src/service/project-markdown.js +26 -0
- package/src/views/assets/AudioAssets.vue +325 -0
- package/src/views/assets/CharacterAssets.vue +412 -0
- package/src/views/assets/ImageAssets.vue +456 -0
- package/src/views/settings/ProjectSettings.vue +80 -0
- package/templates/project/AGENTS.md +14 -0
- package/templates/project/README.md +7 -0
- package/templates/project/assets/audio/README.md +5 -0
- package/templates/project/assets/characters/README.md +5 -0
- package/templates/project/assets/other/README.md +3 -0
- package/templates/project/assets/props/README.md +3 -0
- package/templates/project/assets/scenes/README.md +3 -0
- package/vite.config.js +10 -0
package/README.md
CHANGED
|
@@ -1,3 +1,64 @@
|
|
|
1
|
-
#
|
|
1
|
+
# 咔嚓 · kacha
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
咔嚓是面向创作项目的本地制作工作台。当前版本覆盖资产管理,可浏览、创建和更新角色、场景、道具、其他素材与音频,并查看版本归档。工作台支持简体中文和英文,默认显示简体中文。
|
|
4
|
+
|
|
5
|
+
## 开始使用
|
|
6
|
+
|
|
7
|
+
新建一个项目目录并进入其中。npm 包发布后,可按项目安装:
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
mkdir my-project
|
|
11
|
+
cd my-project
|
|
12
|
+
npm install --save-dev @2kog/kacha
|
|
13
|
+
npx kacha init
|
|
14
|
+
npx kacha
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
常用多个项目时,也可以全局安装一次,再到各项目目录执行初始化和启动命令:
|
|
18
|
+
|
|
19
|
+
```sh
|
|
20
|
+
npm install -g @2kog/kacha
|
|
21
|
+
mkdir my-project
|
|
22
|
+
cd my-project
|
|
23
|
+
kacha init
|
|
24
|
+
kacha
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
启动后访问 `http://127.0.0.1:24074`。可以通过 `kacha /path/to/project --port 24075` 指定项目路径和端口。按项目安装时,在命令前加 `npx`。
|
|
28
|
+
|
|
29
|
+
## 项目结构
|
|
30
|
+
|
|
31
|
+
```text
|
|
32
|
+
my-project/
|
|
33
|
+
├── .gitignore
|
|
34
|
+
├── AGENTS.md
|
|
35
|
+
├── README.md
|
|
36
|
+
└── assets/
|
|
37
|
+
├── characters/
|
|
38
|
+
├── scenes/
|
|
39
|
+
├── props/
|
|
40
|
+
├── other/
|
|
41
|
+
└── audio/
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
每个资产库附有目录说明。单项资产用 `index.json` 登记元数据,用 `README.md` 记录制作说明。需要分组时,可在每层分组目录放置 `group.json`。初始化可重复执行,已有文件会保留。
|
|
45
|
+
|
|
46
|
+
工作台从项目的 `package.json` 读取名称和简介,从 `config/logo.*` 读取可选的项目 Logo。
|
|
47
|
+
|
|
48
|
+
## 素材存储
|
|
49
|
+
|
|
50
|
+
创作项目以 OSS 和微云为主要存储。Git 用于记录现行采用的资产和说明。新项目的 `.gitignore` 默认忽略任意层级的 `archive/`、常见视频文件和本地依赖,项目可按需要追加规则。OSS 和微云的配置方式将在后续补充。
|
|
51
|
+
|
|
52
|
+
## 创作模板
|
|
53
|
+
|
|
54
|
+
[creative-templates/](creative-templates/) 用于收录可直接套用的创作模板,例如 3D CG 电影的风格设定和生成提示词框架。创作者可以按题材和项目要求调整模板。模板随源码维护,独立于 npm 发布包。
|
|
55
|
+
|
|
56
|
+
## 本地开发
|
|
57
|
+
|
|
58
|
+
在本仓库运行 `npm install` 安装依赖,用 `npm run dev -- /path/to/project` 启动工作台,用 `npm run build` 执行生产构建。
|
|
59
|
+
|
|
60
|
+
## 发布 npm 包
|
|
61
|
+
|
|
62
|
+
把 `package.json` 和锁文件更新到同一版本并提交,再推送对应的 `v<版本>` 标签。例如 `v0.1.1`。GitHub Actions 会校验标签、安装依赖、构建并检查打包内容,随后发布到 npm。也可在 Actions 中选择对应标签手动运行。
|
|
63
|
+
|
|
64
|
+
首发时,用有 `@2kog` 发布权限的 npm 账号创建允许在该作用域发布新包的短期 Granular Access Token,开启 Bypass 2FA,并将其保存为仓库的 Actions Secret `NPM_TOKEN`。首发成功后,如需改用 Trusted Publishing,在 npm 的 `@2kog/kacha` 包设置中添加 GitHub Actions 发布者,填写组织或用户名 `iRuxu`、仓库 `kacha`、工作流 `publish.yml`,开启 `npm publish` 权限,环境留空。移除 GitHub 的 `NPM_TOKEN` 后,工作流会使用 OIDC 发布。 [npm Trusted Publishing](https://docs.npmjs.com/trusted-publishers/)
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { constants } from 'node:fs'
|
|
2
|
+
import { copyFile, lstat, mkdir, readdir, writeFile } from 'node:fs/promises'
|
|
3
|
+
import { join } from 'node:path'
|
|
4
|
+
import { fileURLToPath } from 'node:url'
|
|
5
|
+
|
|
6
|
+
const templateRoot = fileURLToPath(new URL('../templates/project/', import.meta.url))
|
|
7
|
+
|
|
8
|
+
const gitignore = `node_modules/
|
|
9
|
+
.DS_Store
|
|
10
|
+
|
|
11
|
+
# 资产历史版本
|
|
12
|
+
archive/
|
|
13
|
+
|
|
14
|
+
# 视频素材
|
|
15
|
+
*.[mM][pP]4
|
|
16
|
+
*.[mM][oO][vV]
|
|
17
|
+
*.[mM]4[vV]
|
|
18
|
+
*.[wW][eE][bB][mM]
|
|
19
|
+
*.[mM][kK][vV]
|
|
20
|
+
*.[aA][vV][iI]
|
|
21
|
+
*.[mM][pP][gG]
|
|
22
|
+
*.[mM][pP][eE][gG]
|
|
23
|
+
*.[wW][mM][vV]
|
|
24
|
+
*.[fF][lL][vV]
|
|
25
|
+
*.[mM][xX][fF]
|
|
26
|
+
*.3[gG][pP]
|
|
27
|
+
*.3[gG]2
|
|
28
|
+
*.[oO][gG][vV]
|
|
29
|
+
*.[mM][tT][sS]
|
|
30
|
+
*.[mM]2[tT][sS]
|
|
31
|
+
*.[vV][oO][bB]
|
|
32
|
+
*.[rR][mM]
|
|
33
|
+
*.[rR][mM][vV][bB]
|
|
34
|
+
`
|
|
35
|
+
|
|
36
|
+
async function keepExisting(operation) {
|
|
37
|
+
try {
|
|
38
|
+
await operation()
|
|
39
|
+
} catch (error) {
|
|
40
|
+
if (error.code !== 'EEXIST') throw error
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async function copyTemplates(source, destination) {
|
|
45
|
+
for (const entry of await readdir(source, { withFileTypes: true })) {
|
|
46
|
+
const from = join(source, entry.name)
|
|
47
|
+
const to = join(destination, entry.name)
|
|
48
|
+
if (entry.isDirectory()) {
|
|
49
|
+
await keepExisting(() => mkdir(to))
|
|
50
|
+
if (!(await lstat(to)).isDirectory()) {
|
|
51
|
+
throw new Error(`Expected a directory at ${to}`)
|
|
52
|
+
}
|
|
53
|
+
await copyTemplates(from, to)
|
|
54
|
+
} else {
|
|
55
|
+
await keepExisting(() => copyFile(from, to, constants.COPYFILE_EXCL))
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export async function initProject(projectRoot) {
|
|
61
|
+
await copyTemplates(templateRoot, projectRoot)
|
|
62
|
+
await keepExisting(() => writeFile(join(projectRoot, '.gitignore'), gitignore, { flag: 'wx' }))
|
|
63
|
+
}
|
package/bin/kacha.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { stat } from 'node:fs/promises'
|
|
3
|
+
import { resolve } from 'node:path'
|
|
4
|
+
import { fileURLToPath } from 'node:url'
|
|
5
|
+
import { parseArgs } from 'node:util'
|
|
6
|
+
import { initProject } from './init-project.js'
|
|
7
|
+
|
|
8
|
+
const packageRoot = fileURLToPath(new URL('../', import.meta.url))
|
|
9
|
+
|
|
10
|
+
try {
|
|
11
|
+
const { values, positionals } = parseArgs({
|
|
12
|
+
allowPositionals: true,
|
|
13
|
+
options: {
|
|
14
|
+
help: { type: 'boolean', short: 'h' },
|
|
15
|
+
port: { type: 'string', short: 'p', default: '24074' },
|
|
16
|
+
},
|
|
17
|
+
})
|
|
18
|
+
if (values.help) {
|
|
19
|
+
console.log('Usage: kacha [project-directory] [--port 24074]\n kacha init')
|
|
20
|
+
} else if (positionals[0] === 'init' && positionals.length === 1) {
|
|
21
|
+
await initProject(process.cwd())
|
|
22
|
+
console.log('Kacha project initialized in ' + process.cwd())
|
|
23
|
+
} else {
|
|
24
|
+
if (positionals.length > 1) throw new Error('Pass at most one project directory.')
|
|
25
|
+
const port = Number(values.port)
|
|
26
|
+
if (!/^\d+$/.test(values.port) || !Number.isInteger(port) || port < 1 || port > 65535) {
|
|
27
|
+
throw new Error('Port must be an integer from 1 to 65535.')
|
|
28
|
+
}
|
|
29
|
+
const projectRoot = resolve(positionals[0] ?? '.')
|
|
30
|
+
if (!(await stat(projectRoot)).isDirectory()) throw new Error('The project path must be a directory.')
|
|
31
|
+
|
|
32
|
+
process.env.KACHA_PROJECT_ROOT = projectRoot
|
|
33
|
+
const { createServer } = await import('vite')
|
|
34
|
+
const server = await createServer({
|
|
35
|
+
root: packageRoot,
|
|
36
|
+
configFile: resolve(packageRoot, 'vite.config.js'),
|
|
37
|
+
cacheDir: resolve(projectRoot, 'node_modules/.vite-kacha'),
|
|
38
|
+
server: { port },
|
|
39
|
+
})
|
|
40
|
+
try {
|
|
41
|
+
await server.listen()
|
|
42
|
+
server.printUrls()
|
|
43
|
+
} catch (error) {
|
|
44
|
+
await server.close()
|
|
45
|
+
throw error
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
} catch (error) {
|
|
49
|
+
console.error('kacha: ' + error.message)
|
|
50
|
+
process.exitCode = 1
|
|
51
|
+
}
|
package/index.html
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,47 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@2kog/kacha",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Local production workbench for creative projects",
|
|
5
|
+
"author": "rx6",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/iRuxu/kacha.git"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/iRuxu/kacha#readme",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/iRuxu/kacha/issues"
|
|
13
|
+
},
|
|
14
|
+
"type": "module",
|
|
15
|
+
"bin": {
|
|
16
|
+
"kacha": "./bin/kacha.js"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"bin/",
|
|
20
|
+
"server/",
|
|
21
|
+
"templates/",
|
|
22
|
+
"src/",
|
|
23
|
+
"index.html",
|
|
24
|
+
"vite.config.js"
|
|
25
|
+
],
|
|
26
|
+
"engines": {
|
|
27
|
+
"node": ">=20.19.0"
|
|
28
|
+
},
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public",
|
|
31
|
+
"registry": "https://registry.npmjs.org/"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"dev": "node bin/kacha.js",
|
|
35
|
+
"build": "vite build"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@vitejs/plugin-vue": "^5.2.0",
|
|
39
|
+
"dompurify": "^3.2.0",
|
|
40
|
+
"element-plus": "^2.14.8",
|
|
41
|
+
"lucide-vue-next": "^0.468.0",
|
|
42
|
+
"marked": "^15.0.0",
|
|
43
|
+
"vite": "^6.0.0",
|
|
44
|
+
"vue": "^3.5.0",
|
|
45
|
+
"vue-router": "^4.6.5"
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import * as fs from 'node:fs/promises'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
|
|
4
|
+
const reserved = new Set(['archive', 'images', 'tracks', 'voice', 'portraits', 'skin', 'skins', '特写', '音色参考', '生成记录'])
|
|
5
|
+
|
|
6
|
+
export const assetId = (root, dir) => path.relative(root, dir).split(path.sep).join('/')
|
|
7
|
+
export const isAssetFolderName = name => !name.startsWith('.') && !reserved.has(name)
|
|
8
|
+
|
|
9
|
+
export async function deleteAssetDirectory(root, dir) {
|
|
10
|
+
const library = path.resolve(root)
|
|
11
|
+
const target = path.resolve(dir)
|
|
12
|
+
const [realLibrary, realTarget, stat] = await Promise.all([
|
|
13
|
+
fs.realpath(library),
|
|
14
|
+
fs.realpath(target),
|
|
15
|
+
fs.lstat(target),
|
|
16
|
+
])
|
|
17
|
+
if (!target.startsWith(library + path.sep) || realLibrary !== library || realTarget !== target || !stat.isDirectory()) {
|
|
18
|
+
throw Object.assign(new Error('资产目录不在当前资产库内'), { status: 400 })
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const group = await fs.lstat(path.join(target, 'group.json')).catch(error => {
|
|
22
|
+
if (error.code !== 'ENOENT') throw error
|
|
23
|
+
return null
|
|
24
|
+
})
|
|
25
|
+
if (group) throw Object.assign(new Error('请选择具体资产,不能删除分组目录'), { status: 400 })
|
|
26
|
+
|
|
27
|
+
await fs.rm(target, { recursive: true })
|
|
28
|
+
return { deleted: true }
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async function entries(dir) {
|
|
32
|
+
try {
|
|
33
|
+
return await fs.readdir(dir, { withFileTypes: true })
|
|
34
|
+
} catch (error) {
|
|
35
|
+
if (error.code === 'ENOENT') return []
|
|
36
|
+
throw error
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export async function scanAssets(root, isAssetMarker = () => false) {
|
|
41
|
+
async function walk(dir, groups, allowEmpty) {
|
|
42
|
+
const assets = []
|
|
43
|
+
let hasGroups = false
|
|
44
|
+
for (const item of await entries(dir)) {
|
|
45
|
+
if (!item.isDirectory() || !isAssetFolderName(item.name)) continue
|
|
46
|
+
const child = path.join(dir, item.name)
|
|
47
|
+
const files = (await entries(child)).filter(entry => entry.isFile())
|
|
48
|
+
const has = name => files.some(entry => entry.name === name)
|
|
49
|
+
const indexed = has('index.json') || files.some(file => isAssetMarker(file.name))
|
|
50
|
+
const group = !indexed && (has('group.json') || /^\d+-/.test(item.name))
|
|
51
|
+
const asset = { dir: child, id: assetId(root, child), groups }
|
|
52
|
+
if (!group && (indexed || has('README.md'))) {
|
|
53
|
+
assets.push(asset)
|
|
54
|
+
continue
|
|
55
|
+
}
|
|
56
|
+
const nested = await walk(child, [...groups, item.name.replace(/^\d+-/, '')], group)
|
|
57
|
+
if (nested.assets.length || nested.hasGroups || group) {
|
|
58
|
+
assets.push(...nested.assets)
|
|
59
|
+
hasGroups = true
|
|
60
|
+
} else if (allowEmpty) assets.push(asset)
|
|
61
|
+
}
|
|
62
|
+
return { assets, hasGroups }
|
|
63
|
+
}
|
|
64
|
+
return (await walk(path.resolve(root), [], true)).assets
|
|
65
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
import { assetRoot, projectRoot } from './project-paths.js'
|
|
3
|
+
|
|
4
|
+
const roots = Object.fromEntries(['characters', 'scenes', 'props', 'other', 'audio'].map(kind => [
|
|
5
|
+
kind, assetRoot(kind),
|
|
6
|
+
]))
|
|
7
|
+
|
|
8
|
+
roots.settings = path.join(projectRoot, 'docs')
|
|
9
|
+
|
|
10
|
+
export function assetWatch() {
|
|
11
|
+
return {
|
|
12
|
+
name: 'workbench-asset-watch',
|
|
13
|
+
configureServer(server) {
|
|
14
|
+
const pending = new Map()
|
|
15
|
+
server.watcher.add(Object.values(roots))
|
|
16
|
+
const onChange = (event, file) => {
|
|
17
|
+
if (!['add', 'change', 'unlink', 'addDir', 'unlinkDir'].includes(event)) return
|
|
18
|
+
for (const [kind, root] of Object.entries(roots)) {
|
|
19
|
+
const relative = path.relative(root, file)
|
|
20
|
+
if (relative.split(path.sep).some(part => part.startsWith('.')) || path.isAbsolute(relative)) continue
|
|
21
|
+
clearTimeout(pending.get(kind))
|
|
22
|
+
pending.set(kind, setTimeout(() => {
|
|
23
|
+
pending.delete(kind)
|
|
24
|
+
server.ws.send({ type: 'custom', event: 'workbench:' + kind + ':changed', data: {} })
|
|
25
|
+
}, 150))
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
server.watcher.on('all', onChange)
|
|
29
|
+
server.httpServer?.once('close', () => {
|
|
30
|
+
server.watcher.off('all', onChange)
|
|
31
|
+
for (const timer of pending.values()) clearTimeout(timer)
|
|
32
|
+
})
|
|
33
|
+
},
|
|
34
|
+
}
|
|
35
|
+
}
|