mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-05 19:20:12 +08:00
feat: import file-graph package
* Update Dockerfile structure, copy quests, packages to sub folder
This commit is contained in:
1 parent
6c70a6eaea
commit
c3683ddaea
9 files changed
+64
-15
No files matched your search
+3
-2
@@ -21,8 +21,9 @@ services:
|
||||
- '3000:3000'
|
||||
volumes:
|
||||
- /var/run/docker.sock:/var/run/docker.sock
|
||||
- ./server/src:/app/src
|
||||
- ./server/swagger.yaml:/app/swagger.yaml
|
||||
- ./server/src:/app/server/src
|
||||
- ./server/swagger.yaml:/app/server/swagger.yaml
|
||||
- ./packages:/app/packages
|
||||
- ./quests:/app/quests
|
||||
environment:
|
||||
- MONGO_URL=mongodb://db:27017/odyssey-test
|
||||
|
||||
@@ -54,4 +54,8 @@ export default class FileGraph {
|
||||
// Implement other cases if needed
|
||||
}
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
return this.root.toJSON()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export { default as File } from './file.js'
|
||||
export { default as FileNode } from './fileNode.js'
|
||||
export { default as FileGraph } from './fileGraph.js'
|
||||
@@ -1,7 +1,8 @@
|
||||
{
|
||||
"name": "file-graph",
|
||||
"name": "@linux-odyssey/file-graph",
|
||||
"version": "1.0.0",
|
||||
"main": "index.js",
|
||||
"exports": "./index.js",
|
||||
"license": "MIT",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
|
||||
+7
-3
@@ -1,13 +1,17 @@
|
||||
FROM node
|
||||
|
||||
WORKDIR /app
|
||||
COPY server/package.json yarn.lock ./
|
||||
COPY ./package.json yarn.lock ./
|
||||
COPY server/package.json ./server/package.json
|
||||
COPY packages/file-graph/package.json ./packages/file-graph/package.json
|
||||
RUN yarn install --frozen-lockfile --production
|
||||
|
||||
COPY server/src ./src
|
||||
COPY server/swagger.yaml .
|
||||
COPY ./server ./server
|
||||
COPY packages/file-graph ./packages/file-graph
|
||||
COPY quests ./quests
|
||||
|
||||
WORKDIR /app/server
|
||||
|
||||
ENV NODE_ENV=production
|
||||
ENV HOST=0.0.0.0
|
||||
ENV PORT=3000
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
FROM node
|
||||
|
||||
WORKDIR /app
|
||||
COPY server/package.json yarn.lock ./
|
||||
COPY package.json yarn.lock ./
|
||||
COPY server/package.json ./server/package.json
|
||||
COPY packages/file-graph/package.json ./packages/file-graph/package.json
|
||||
RUN yarn install --frozen-lockfile
|
||||
|
||||
ENV NODE_ENV=development
|
||||
@@ -9,4 +11,4 @@ ENV HOST=0.0.0.0
|
||||
ENV PORT=3000
|
||||
EXPOSE 3000
|
||||
|
||||
CMD [ "yarn", "dev" ]
|
||||
CMD [ "yarn", "server" ]
|
||||
@@ -10,6 +10,7 @@
|
||||
"clean": "node src/cli/clean.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@linux-odyssey/file-graph": "1.0.0",
|
||||
"commander": "^11.0.0",
|
||||
"dockerode": "^3.3.5",
|
||||
"express": "^4.18.2",
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import minimist from 'minimist'
|
||||
import { FileGraph } from '@linux-odyssey/file-graph'
|
||||
import Quest from '../models/quest.js'
|
||||
import { pushToSession } from '../api/socket.js'
|
||||
|
||||
console.log(typeof FileGraph)
|
||||
|
||||
// 檢查 pattern 是否符合 input
|
||||
const checkMatch = (pattern, input) => {
|
||||
if (pattern.length === 0) return true
|
||||
@@ -11,6 +14,40 @@ const checkMatch = (pattern, input) => {
|
||||
})
|
||||
}
|
||||
|
||||
async function discoverHandler(session, commandInput, additionalData) {
|
||||
const graph = new FileGraph(session.graph)
|
||||
graph.discover(additionalData.discover)
|
||||
console.log('graph:', graph.toString())
|
||||
session.graph = graph.toJSON()
|
||||
await session.save()
|
||||
}
|
||||
|
||||
const pushGraph = (session, commandInput, additionalData) => {
|
||||
pushToSession(session.id, 'graph', {
|
||||
pwd: commandInput.pwd,
|
||||
discover: additionalData.discover,
|
||||
})
|
||||
}
|
||||
|
||||
const eventListenr = {
|
||||
add: [],
|
||||
remove: [],
|
||||
discover: [discoverHandler, pushGraph],
|
||||
pwd: [],
|
||||
}
|
||||
|
||||
function handleEvent(session, commandInput, additionalData) {
|
||||
const events = Object.keys(additionalData)
|
||||
events.forEach((event) => {
|
||||
const handlers = eventListenr[event]
|
||||
if (handlers) {
|
||||
handlers.forEach((handler) =>
|
||||
handler(session, commandInput, additionalData)
|
||||
)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
async function commandHandler(session, commandInput, additionalData) {
|
||||
const quest = await Quest.findById(session.quest)
|
||||
const stage = quest.stages.find((s) => s.id === session.progress)
|
||||
@@ -21,12 +58,8 @@ async function commandHandler(session, commandInput, additionalData) {
|
||||
|
||||
const argv = minimist(commandInput.command.split(' '))
|
||||
|
||||
if ('discover' in additionalData) {
|
||||
pushToSession(session.id, 'graph', {
|
||||
pwd: commandInput.pwd,
|
||||
discover: additionalData.discover,
|
||||
})
|
||||
} else if (argv._[0] === 'cd') {
|
||||
handleEvent(session, commandInput, additionalData)
|
||||
if (argv._[0] === 'cd') {
|
||||
pushToSession(session.id, 'graph', { pwd: commandInput.pwd })
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import yaml from 'yaml'
|
||||
|
||||
import Quest from '../models/quest.js'
|
||||
|
||||
const questDirectory = path.join(process.cwd(), 'quests')
|
||||
const questDirectory = path.join(process.cwd(), '..', 'quests')
|
||||
|
||||
export default async function loadAndUpdateQuests() {
|
||||
const questNames = await fs.readdir(questDirectory)
|
||||
|
||||
Reference in new issue
Block a user