mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-06 03:20:13 +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'
|
- '3000:3000'
|
||||||
volumes:
|
volumes:
|
||||||
- /var/run/docker.sock:/var/run/docker.sock
|
- /var/run/docker.sock:/var/run/docker.sock
|
||||||
- ./server/src:/app/src
|
- ./server/src:/app/server/src
|
||||||
- ./server/swagger.yaml:/app/swagger.yaml
|
- ./server/swagger.yaml:/app/server/swagger.yaml
|
||||||
|
- ./packages:/app/packages
|
||||||
- ./quests:/app/quests
|
- ./quests:/app/quests
|
||||||
environment:
|
environment:
|
||||||
- MONGO_URL=mongodb://db:27017/odyssey-test
|
- MONGO_URL=mongodb://db:27017/odyssey-test
|
||||||
|
|||||||
@@ -54,4 +54,8 @@ export default class FileGraph {
|
|||||||
// Implement other cases if needed
|
// 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",
|
"version": "1.0.0",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
|
"exports": "./index.js",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
+7
-3
@@ -1,13 +1,17 @@
|
|||||||
FROM node
|
FROM node
|
||||||
|
|
||||||
WORKDIR /app
|
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
|
RUN yarn install --frozen-lockfile --production
|
||||||
|
|
||||||
COPY server/src ./src
|
COPY ./server ./server
|
||||||
COPY server/swagger.yaml .
|
COPY packages/file-graph ./packages/file-graph
|
||||||
COPY quests ./quests
|
COPY quests ./quests
|
||||||
|
|
||||||
|
WORKDIR /app/server
|
||||||
|
|
||||||
ENV NODE_ENV=production
|
ENV NODE_ENV=production
|
||||||
ENV HOST=0.0.0.0
|
ENV HOST=0.0.0.0
|
||||||
ENV PORT=3000
|
ENV PORT=3000
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
FROM node
|
FROM node
|
||||||
|
|
||||||
WORKDIR /app
|
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
|
RUN yarn install --frozen-lockfile
|
||||||
|
|
||||||
ENV NODE_ENV=development
|
ENV NODE_ENV=development
|
||||||
@@ -9,4 +11,4 @@ ENV HOST=0.0.0.0
|
|||||||
ENV PORT=3000
|
ENV PORT=3000
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
|
|
||||||
CMD [ "yarn", "dev" ]
|
CMD [ "yarn", "server" ]
|
||||||
@@ -10,6 +10,7 @@
|
|||||||
"clean": "node src/cli/clean.js"
|
"clean": "node src/cli/clean.js"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@linux-odyssey/file-graph": "1.0.0",
|
||||||
"commander": "^11.0.0",
|
"commander": "^11.0.0",
|
||||||
"dockerode": "^3.3.5",
|
"dockerode": "^3.3.5",
|
||||||
"express": "^4.18.2",
|
"express": "^4.18.2",
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
import minimist from 'minimist'
|
import minimist from 'minimist'
|
||||||
|
import { FileGraph } from '@linux-odyssey/file-graph'
|
||||||
import Quest from '../models/quest.js'
|
import Quest from '../models/quest.js'
|
||||||
import { pushToSession } from '../api/socket.js'
|
import { pushToSession } from '../api/socket.js'
|
||||||
|
|
||||||
|
console.log(typeof FileGraph)
|
||||||
|
|
||||||
// 檢查 pattern 是否符合 input
|
// 檢查 pattern 是否符合 input
|
||||||
const checkMatch = (pattern, input) => {
|
const checkMatch = (pattern, input) => {
|
||||||
if (pattern.length === 0) return true
|
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) {
|
async function commandHandler(session, commandInput, additionalData) {
|
||||||
const quest = await Quest.findById(session.quest)
|
const quest = await Quest.findById(session.quest)
|
||||||
const stage = quest.stages.find((s) => s.id === session.progress)
|
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(' '))
|
const argv = minimist(commandInput.command.split(' '))
|
||||||
|
|
||||||
if ('discover' in additionalData) {
|
handleEvent(session, commandInput, additionalData)
|
||||||
pushToSession(session.id, 'graph', {
|
if (argv._[0] === 'cd') {
|
||||||
pwd: commandInput.pwd,
|
|
||||||
discover: additionalData.discover,
|
|
||||||
})
|
|
||||||
} else if (argv._[0] === 'cd') {
|
|
||||||
pushToSession(session.id, 'graph', { pwd: commandInput.pwd })
|
pushToSession(session.id, 'graph', { pwd: commandInput.pwd })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import yaml from 'yaml'
|
|||||||
|
|
||||||
import Quest from '../models/quest.js'
|
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() {
|
export default async function loadAndUpdateQuests() {
|
||||||
const questNames = await fs.readdir(questDirectory)
|
const questNames = await fs.readdir(questDirectory)
|
||||||
|
|||||||
Reference in new issue
Block a user