Skip to content

Commit 5920130

Browse files
authored
Merge pull request #130 from chaitin/line-number
添加行号 + docker run 命令转 docker compose 文件
2 parents d133149 + f658425 commit 5920130

File tree

8 files changed

+402
-2
lines changed

8 files changed

+402
-2
lines changed

package-lock.json

Lines changed: 137 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"big-integer": "^1.6.52",
5050
"change-case": "^5.3.0",
5151
"clean-css": "^5.3.3",
52+
"composerize-ts": "^0.6.2",
5253
"compressorjs": "^1.2.1",
5354
"crypto-js": "^4.2.0",
5455
"css2less": "^0.1.4",

src/components/MainContent/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const MainContent: React.FC<{
4040
dom.style.inset = '0';
4141
dom.style.maxWidth = '100vw';
4242
dom.style.background = '#fff';
43+
dom.style.padding = '84px 14px 14px 14px';
4344
if (riverHeader) riverHeader.style.display = 'none';
4445
}
4546
});
@@ -62,8 +63,8 @@ const MainContent: React.FC<{
6263
dom.style.position = 'unset';
6364
dom.style.inset = '0';
6465
dom.style.maxWidth = 'unset';
66+
dom.style.padding = '0';
6567
if (riverHeader) {
66-
dom.style.paddingTop = '64px';
6768
riverHeader.style.display = 'block';
6869
}
6970
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import MainContent from '@/components/MainContent';
2+
import TextFieldWithClean from '@/components/TextFieldWithClean';
3+
import { ToolsForm } from '@/components/Tools';
4+
import { saveFile } from '@/utils/download';
5+
import { Button, Stack, TextField } from '@mui/material';
6+
import { composerize } from 'composerize-ts';
7+
import React, { useState } from 'react';
8+
9+
const DockerRunToDockerCompose: React.FC = () => {
10+
const [dockerRun, setDockerRun] = useState<string>(
11+
'docker run -p 8080:80 -d --name myapp nginx'
12+
);
13+
const [dockerCompose, setDockerCompose] = useState<string>('');
14+
const conversionResult = () => {
15+
const res = composerize(dockerRun.trim()).yaml;
16+
setDockerCompose(res);
17+
};
18+
const handleSaveFile = () => {
19+
saveFile(dockerCompose, 'docker-compose.yml');
20+
};
21+
return (
22+
<MainContent>
23+
<ToolsForm sx={{ width: '100%' }}>
24+
<TextFieldWithClean
25+
multiline
26+
minRows={4}
27+
value={dockerRun}
28+
onChange={(event) => setDockerRun(event.target.value)}
29+
placeholder='请输入docker run命令'
30+
onClean={() => {
31+
setDockerRun('');
32+
setDockerCompose('');
33+
}}
34+
variant='outlined'
35+
/>
36+
<Stack direction='row' spacing={2} alignItems='center'>
37+
<Button
38+
size='small'
39+
sx={{
40+
fontSize: '14px',
41+
width: '90',
42+
borderRadius: '4px',
43+
ml: 'auto',
44+
height: '28px',
45+
}}
46+
color='primary'
47+
variant='contained'
48+
onClick={conversionResult}
49+
>
50+
转换
51+
</Button>
52+
<Button
53+
size='small'
54+
sx={{
55+
fontSize: '14px',
56+
width: '90',
57+
borderRadius: '4px',
58+
ml: 'auto',
59+
height: '28px',
60+
}}
61+
color='primary'
62+
variant='contained'
63+
onClick={handleSaveFile}
64+
>
65+
导出 YAML
66+
</Button>
67+
</Stack>
68+
<TextField multiline variant='filled' value={dockerCompose} />
69+
</ToolsForm>
70+
</MainContent>
71+
);
72+
};
73+
74+
export default DockerRunToDockerCompose;

0 commit comments

Comments
 (0)