fix issue

pull/369/head
vapao 2021-08-13 00:43:33 +08:00
parent eb46568470
commit 3140c9ca43
4 changed files with 24 additions and 14 deletions

View File

@ -142,12 +142,12 @@ class Helper:
if env: if env:
env = dict(env.items()) env = dict(env.items())
env.update(os.environ) env.update(os.environ)
command = 'set -e\n' + command
task = subprocess.Popen(command, env=env, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) task = subprocess.Popen(command, env=env, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
while True: while True:
message = task.stdout.readline() message = task.stdout.readline()
if not message: if not message:
break break
self.send_info('local', message.decode()) message = message.decode().rstrip('\r\n')
self.send_info('local', message + '\r\n')
if task.wait() != 0: if task.wait() != 0:
self.send_error('local', f'exit code: {task.returncode}') self.send_error('local', f'exit code: {task.returncode}')

View File

@ -3,21 +3,25 @@
* Copyright (c) <spug.dev@gmail.com> * Copyright (c) <spug.dev@gmail.com>
* Released under the AGPL-3.0 License. * Released under the AGPL-3.0 License.
*/ */
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect, useRef } from 'react';
import { observer } from 'mobx-react'; import { observer } from 'mobx-react';
import { FullscreenOutlined, FullscreenExitOutlined, LoadingOutlined } from '@ant-design/icons'; import { FullscreenOutlined, FullscreenExitOutlined, LoadingOutlined } from '@ant-design/icons';
import { FitAddon } from 'xterm-addon-fit';
import { Terminal } from 'xterm';
import { Modal, Steps } from 'antd'; import { Modal, Steps } from 'antd';
import { X_TOKEN, human_time } from 'libs'; import { X_TOKEN, human_time } from 'libs';
import styles from './index.module.less'; import styles from './index.module.less';
import store from './store'; import store from './store';
export default observer(function Console() { export default observer(function Console() {
const el = useRef()
const [fullscreen, setFullscreen] = useState(false); const [fullscreen, setFullscreen] = useState(false);
const [step, setStep] = useState(0); const [step, setStep] = useState(0);
const [status, setStatus] = useState('process') const [status, setStatus] = useState('process')
useEffect(() => { useEffect(() => {
store.outputs = [`${human_time()} 建立连接... `] const term = initialTerm()
term.write(`${human_time()} 建立连接... `)
let index = 0; let index = 0;
const token = store.record.spug_version; const token = store.record.spug_version;
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:'; const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
@ -29,17 +33,24 @@ export default observer(function Console() {
} else { } else {
index += 1; index += 1;
const {data, step, status} = JSON.parse(e.data); const {data, step, status} = JSON.parse(e.data);
if (data !== undefined) store.outputs.push(data); if (data !== undefined) term.write(data);
if (step !== undefined) setStep(step); if (step !== undefined) setStep(step);
if (status !== undefined) setStatus(status); if (status !== undefined) setStatus(status);
} }
} }
return () => { return () => socket.close();
socket.close();
store.outputs = []
}
}, []) }, [])
function initialTerm() {
const fitPlugin = new FitAddon()
const term = new Terminal({disableStdin: true})
term.loadAddon(fitPlugin)
term.setOption('theme', {background: '#fafafa', foreground: '#000', selection: '#999'})
term.open(el.current)
fitPlugin.fit()
return term
}
function handleClose() { function handleClose() {
store.fetchRecords(); store.fetchRecords();
store.logVisible = false store.logVisible = false
@ -74,7 +85,9 @@ export default observer(function Console() {
<StepItem title="检出后任务" step={3}/> <StepItem title="检出后任务" step={3}/>
<StepItem title="执行打包" step={4}/> <StepItem title="执行打包" step={4}/>
</Steps> </Steps>
<pre className={styles.out}>{store.outputs}</pre> <div className={styles.out}>
<div ref={el}/>
</div>
</Modal> </Modal>
) )
}) })

View File

@ -19,9 +19,7 @@
.out { .out {
margin-top: 24px; margin-top: 24px;
min-height: 40px; padding: 8px 0 0 15px;
max-height: 300px;
padding: 10px 15px;
border: 1px solid #d9d9d9; border: 1px solid #d9d9d9;
border-radius: 4px; border-radius: 4px;
background-color: #fafafa; background-color: #fafafa;

View File

@ -10,7 +10,6 @@ class Store {
@observable records = []; @observable records = [];
@observable record = {}; @observable record = {};
@observable deploy = {}; @observable deploy = {};
@observable outputs = [];
@observable isFetching = false; @observable isFetching = false;
@observable formVisible = false; @observable formVisible = false;
@observable addVisible = false; @observable addVisible = false;