Files
code-utils/frontend/src/packCmds.js
2026-08-15 17:18:00 +08:00

36 lines
1.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 打包命令本地存储:启动台应用 / 项目各自多条 name+cmd不进云同步。
const PACK_KEY = 'cc-pack-cmds'
/** @typedef {{ name: string, cmd: string }} PackCmd */
function loadAll() {
try { return JSON.parse(localStorage.getItem(PACK_KEY) || '{}') || {} } catch { return {} }
}
function saveAll(map) {
localStorage.setItem(PACK_KEY, JSON.stringify(map))
}
/** @param {'lp'|'proj'} scope @param {number|string} id */
export function packKey(scope, id) {
return `${scope}:${id}`
}
/** @returns {PackCmd[]} */
export function getPackCmds(scope, id) {
const list = loadAll()[packKey(scope, id)]
return Array.isArray(list) ? list.filter(x => x && String(x.cmd || '').trim()) : []
}
/** @param {PackCmd[]} cmds */
export function setPackCmds(scope, id, cmds) {
const map = loadAll()
const cleaned = (cmds || [])
.map(x => ({ name: String(x.name || '').trim(), cmd: String(x.cmd || '').trim() }))
.filter(x => x.cmd)
const k = packKey(scope, id)
if (!cleaned.length) delete map[k]
else map[k] = cleaned
saveAll(map)
}