Yang Pei
4 years ago
committed by
GitHub
11 changed files with 192 additions and 6 deletions
@ -0,0 +1,13 @@ |
|||||
|
{ |
||||
|
"ignorePatterns": [ |
||||
|
{ |
||||
|
"pattern": "^https?://0.0.0.0:\\d+" |
||||
|
}, |
||||
|
{ |
||||
|
"pattern": "^https?://127.0.0.1:\\d+" |
||||
|
}, |
||||
|
{ |
||||
|
"pattern": "^https?://localhost:\\d+" |
||||
|
} |
||||
|
] |
||||
|
} |
@ -1 +1,27 @@ |
|||||
## iMove-cli |
## iMove-cli |
||||
|
|
||||
|
### Install |
||||
|
|
||||
|
```bash |
||||
|
npm i -g @imove/cli |
||||
|
``` |
||||
|
|
||||
|
### Usage |
||||
|
|
||||
|
- 初始化项目,创建 `imove.config.js` |
||||
|
|
||||
|
```bash |
||||
|
imove -i |
||||
|
# OR |
||||
|
imove --init |
||||
|
``` |
||||
|
|
||||
|
- 启动开发服务及编辑器 |
||||
|
|
||||
|
```bash |
||||
|
imove -de |
||||
|
# OR |
||||
|
imove --dev --editor |
||||
|
``` |
||||
|
|
||||
|
浏览器打开 [http://127.0.0.1:3500/](http://127.0.0.1:3500/) |
||||
|
@ -0,0 +1,35 @@ |
|||||
|
/* 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/dist/app.bundle.js'), |
||||
|
plugins: [ |
||||
|
// fix import('antd/dist/antd.less')
|
||||
|
{ |
||||
|
name: 'resolve-antd-dist-less', |
||||
|
setup: (build) => { |
||||
|
build.onResolve( |
||||
|
{ filter: /antd\/dist\/antd\.less$/, namespace: 'file' }, |
||||
|
() => { |
||||
|
return { |
||||
|
path: '', |
||||
|
watchFiles: undefined, |
||||
|
}; |
||||
|
}, |
||||
|
); |
||||
|
}, |
||||
|
}, |
||||
|
// less
|
||||
|
lessLoader({ |
||||
|
javascriptEnabled: true, |
||||
|
}), |
||||
|
], |
||||
|
}) |
||||
|
.then(() => { |
||||
|
console.log('imove editor builded'); |
||||
|
}) |
||||
|
.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._dbFile || (this.config || '').dbFile; |
||||
|
return dbFile; |
||||
|
} |
||||
|
|
||||
|
set dbFile(val) { |
||||
|
this._dbFile = 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(); |
||||
|
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,13 @@ |
|||||
|
<!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="dist/app.bundle.css" /> |
||||
|
</head> |
||||
|
<body> |
||||
|
<div id="root" style="height:100vh"></div> |
||||
|
<script type="module" src="dist/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