Hans Chan
4 years ago
10 changed files with 143 additions and 5 deletions
@ -0,0 +1 @@ |
|||||
|
src/cmd/editor/template/*.bundle.* |
@ -1 +1,2 @@ |
|||||
node_modules |
node_modules |
||||
|
src/cmd/editor/template/*.bundle.* |
||||
|
@ -0,0 +1,30 @@ |
|||||
|
/* eslint-disable @typescript-eslint/no-var-requires */ |
||||
|
const path = require('path'); |
||||
|
const { lessLoader } = require('esbuild-plugin-less'); |
||||
|
|
||||
|
require('esbuild') |
||||
|
.build({ |
||||
|
bundle: true, |
||||
|
entryPoints: [path.join(__dirname, 'template/app.jsx')], |
||||
|
outfile: path.join(__dirname, 'template/app.bundle.js'), |
||||
|
plugins: [ |
||||
|
{ |
||||
|
name: 'resolve-antd-dist-less', |
||||
|
setup: (build) => { |
||||
|
build.onResolve( |
||||
|
{ filter: /antd\/dist\/antd\.less$/, namespace: 'file' }, |
||||
|
() => { |
||||
|
return { |
||||
|
path: '', |
||||
|
watchFiles: undefined, |
||||
|
}; |
||||
|
}, |
||||
|
); |
||||
|
}, |
||||
|
}, |
||||
|
lessLoader({ |
||||
|
javascriptEnabled: true, |
||||
|
}), |
||||
|
], |
||||
|
}) |
||||
|
.catch(() => process.exit(1)); |
@ -0,0 +1,79 @@ |
|||||
|
/* eslint-disable @typescript-eslint/no-var-requires */ |
||||
|
const fs = require('fs-extra'); |
||||
|
const path = require('path'); |
||||
|
const low = require('lowdb'); |
||||
|
const FileSync = require('lowdb/adapters/FileSync'); |
||||
|
const express = require('express'); |
||||
|
const Base = require('../base'); |
||||
|
const { createServer } = require('../../utils/server'); |
||||
|
|
||||
|
class Editor extends Base { |
||||
|
constructor(...args) { |
||||
|
super(...args); |
||||
|
if (!this.dbFile) { |
||||
|
fs.ensureDirSync(this.outputPath); |
||||
|
this.dbFile = path.join(this.outputPath, 'db.json'); |
||||
|
} |
||||
|
// make sure dbFile existed
|
||||
|
fs.createFileSync(this.dbFile); |
||||
|
|
||||
|
const adapter = new FileSync(this.dbFile); |
||||
|
this.db = low(adapter); |
||||
|
} |
||||
|
|
||||
|
get projectName() { |
||||
|
const { projectName = 'default' } = this.config || ''; |
||||
|
return projectName; |
||||
|
} |
||||
|
|
||||
|
get outputPath() { |
||||
|
const { outputPath } = this.config || ''; |
||||
|
return outputPath; |
||||
|
} |
||||
|
|
||||
|
get dbFile() { |
||||
|
const { dbFile } = this._dfFile || this.config || ''; |
||||
|
return dbFile; |
||||
|
} |
||||
|
|
||||
|
set dbFile(val) { |
||||
|
this._dfFile = val; |
||||
|
} |
||||
|
|
||||
|
queryGraph(req, res) { |
||||
|
const data = this.db.get(this.projectName).value() || []; |
||||
|
res.send({ status: 200, code: 0, success: true, data: { cells: data } }); |
||||
|
} |
||||
|
|
||||
|
modifyGraph(req, res) { |
||||
|
const { actions = [] } = req.body; |
||||
|
const projectData = this.db.get(this.projectName).value() || []; |
||||
|
actions.forEach((action) => { |
||||
|
const { data, actionType } = action; |
||||
|
if (actionType === 'create') { |
||||
|
projectData.push(data); |
||||
|
} else if (actionType === 'update') { |
||||
|
const foundIdx = projectData.findIndex((item) => item.id === data.id); |
||||
|
if (foundIdx > -1) { |
||||
|
projectData[foundIdx] = data; |
||||
|
} |
||||
|
} else if (actionType === 'remove') { |
||||
|
const foundIdx = projectData.findIndex((item) => item.id === data.id); |
||||
|
if (foundIdx > -1) { |
||||
|
projectData.splice(foundIdx, 1); |
||||
|
} |
||||
|
} |
||||
|
}); |
||||
|
this.db.set(this.projectName, projectData).write(); |
||||
|
res.send({ status: 200, code: 0, success: true, data: [] }); |
||||
|
} |
||||
|
|
||||
|
run() { |
||||
|
const server = createServer(8000); |
||||
|
server.use(express.static(path.join(__dirname, './template'))); |
||||
|
server.post('/api/queryGraph', this.queryGraph.bind(this)); |
||||
|
server.post('/api/modifyGraph', this.modifyGraph.bind(this)); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
module.exports = Editor; |
@ -0,0 +1,5 @@ |
|||||
|
import React from 'react'; |
||||
|
import ReactDOM from 'react-dom'; |
||||
|
import IMove from '@imove/core'; |
||||
|
|
||||
|
ReactDOM.render(<IMove />, document.getElementById('root')); |
@ -0,0 +1,14 @@ |
|||||
|
<!DOCTYPE html> |
||||
|
<html lang="en"> |
||||
|
<head> |
||||
|
<meta charset="UTF-8" /> |
||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> |
||||
|
<title>iMove Editor</title> |
||||
|
<!-- <link rel="stylesheet" href="https://unpkg.com/antd/dist/antd.css" /> --> |
||||
|
<link rel="stylesheet" href="/app.bundle.css" /> |
||||
|
</head> |
||||
|
<body> |
||||
|
<div id="root" style="height:100vh"></div> |
||||
|
<script type="module" src="/app.bundle.js"></script> |
||||
|
</body> |
||||
|
</html> |
@ -1,7 +1,9 @@ |
|||||
const Dev = require('./dev'); |
const Dev = require('./dev'); |
||||
const Init = require('./init'); |
const Init = require('./init'); |
||||
|
const Editor = require('./editor'); |
||||
|
|
||||
module.exports = { |
module.exports = { |
||||
dev: Dev, |
dev: Dev, |
||||
init: Init, |
init: Init, |
||||
|
editor: Editor, |
||||
}; |
}; |
||||
|
Loading…
Reference in new issue