-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #130 from chaitin/line-number
添加行号 + docker run 命令转 docker compose 文件
- Loading branch information
Showing
8 changed files
with
402 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import MainContent from '@/components/MainContent'; | ||
import TextFieldWithClean from '@/components/TextFieldWithClean'; | ||
import { ToolsForm } from '@/components/Tools'; | ||
import { saveFile } from '@/utils/download'; | ||
import { Button, Stack, TextField } from '@mui/material'; | ||
import { composerize } from 'composerize-ts'; | ||
import React, { useState } from 'react'; | ||
|
||
const DockerRunToDockerCompose: React.FC = () => { | ||
const [dockerRun, setDockerRun] = useState<string>( | ||
'docker run -p 8080:80 -d --name myapp nginx' | ||
); | ||
const [dockerCompose, setDockerCompose] = useState<string>(''); | ||
const conversionResult = () => { | ||
const res = composerize(dockerRun.trim()).yaml; | ||
setDockerCompose(res); | ||
}; | ||
const handleSaveFile = () => { | ||
saveFile(dockerCompose, 'docker-compose.yml'); | ||
}; | ||
return ( | ||
<MainContent> | ||
<ToolsForm sx={{ width: '100%' }}> | ||
<TextFieldWithClean | ||
multiline | ||
minRows={4} | ||
value={dockerRun} | ||
onChange={(event) => setDockerRun(event.target.value)} | ||
placeholder='请输入docker run命令' | ||
onClean={() => { | ||
setDockerRun(''); | ||
setDockerCompose(''); | ||
}} | ||
variant='outlined' | ||
/> | ||
<Stack direction='row' spacing={2} alignItems='center'> | ||
<Button | ||
size='small' | ||
sx={{ | ||
fontSize: '14px', | ||
width: '90', | ||
borderRadius: '4px', | ||
ml: 'auto', | ||
height: '28px', | ||
}} | ||
color='primary' | ||
variant='contained' | ||
onClick={conversionResult} | ||
> | ||
转换 | ||
</Button> | ||
<Button | ||
size='small' | ||
sx={{ | ||
fontSize: '14px', | ||
width: '90', | ||
borderRadius: '4px', | ||
ml: 'auto', | ||
height: '28px', | ||
}} | ||
color='primary' | ||
variant='contained' | ||
onClick={handleSaveFile} | ||
> | ||
导出 YAML | ||
</Button> | ||
</Stack> | ||
<TextField multiline variant='filled' value={dockerCompose} /> | ||
</ToolsForm> | ||
</MainContent> | ||
); | ||
}; | ||
|
||
export default DockerRunToDockerCompose; |
Oops, something went wrong.