Skip to content

Commit

Permalink
0
Browse files Browse the repository at this point in the history
  • Loading branch information
yArna committed Apr 1, 2023
0 parents commit 2e2977b
Show file tree
Hide file tree
Showing 65 changed files with 14,924 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
dist
.idea
node_modules
__debug__
yarn-error.log
.DS_Store
RefreshAndPredload.log
secret.json
7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"printWidth": 120,
"tabWidth": 4,
"bracketSpacing":true,
"semi":false
}

4 changes: 4 additions & 0 deletions build/publish.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Created on 2023/03/26 - 00:39
import { publish } from "@moonvy/deploy"

publish("web", "./dist", "apps/ops")
65 changes: 65 additions & 0 deletions data/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import csv from "csvtojson"
import fs from "fs"
import { fromNotion } from "./src/notion/fromNotion.js"
import localCommandDesc from "./src/localCommandDesc.js"

const __dirname = new URL(".", import.meta.url).pathname

let localPromptDefineMap = {}

// Add notion database https://www.notion.so/moonvy/5ac19c115d11488f95847c9e2d789dff?v=5ce9b783b4504c23bb7b492aa70c1cfc
let notionPromptDescMap = await fromNotion()
Object.assign(localPromptDefineMap, notionPromptDescMap)

// Add src/dict/*.csv
let pathLang = `${__dirname}src/dict`
for (let file of fs.readdirSync(pathLang, { withFileTypes: true })) {
if (file.isFile() && file.name.toLowerCase().endsWith(".csv")) {
let re = await csv().fromFile(`${pathLang}/${file.name}`)
re.forEach((item) => addToMap(item))
console.log(`Add src/dict/${file.name}`)
}
}
console.log(`Add src/dict/*.csv`)

// src/localCommandDesc.js
localCommandDesc().forEach((item) => addToMap(item))
console.log(`Add src/localCommandDesc.js`)

// ------------------------------------

Object.values(localPromptDefineMap).forEach((item) => {
if (item?.tags?.length == 0) delete item.tags
})

let jsonText = JSON.stringify(localPromptDefineMap, null, 1)
fs.writeFileSync(__dirname + "localPromptDefineMap.json", jsonText)
fs.writeFileSync(__dirname + "../web/public/localPromptDefineMap.json", jsonText)

let finSize = fs.statSync(__dirname + "/localPromptDefineMap.json").size
let itemsLength = Object.keys(localPromptDefineMap).length

console.log(`[generated] localPromptDescMap.json ( ${itemsLength} items | ${(finSize / 1024).toFixed(1)}KB )`)

// --------------------------

function addToMap(item) {
const subTypeMap = {
普通: "normal",
风格: "style",
质量: "quality",
命令: "command",
负面: "eg",
}
// console.log("item", item)
let key = item.text.toLowerCase()
if (item.subType && subTypeMap[item.subType]) {
item.subType = subTypeMap[item.subType]
}

if (localPromptDefineMap[key]) {
Object.assign(localPromptDefineMap[key], item)
} else {
localPromptDefineMap[key] = item
}
}
Loading

0 comments on commit 2e2977b

Please sign in to comment.