Skip to content

Commit 2a4a1cb

Browse files
committed
Organize ink components
1 parent 983ffa6 commit 2a4a1cb

File tree

11 files changed

+90
-39
lines changed

11 files changed

+90
-39
lines changed

npm-packages/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pulse-editor/cli",
3-
"version": "0.0.0",
3+
"version": "0.0.1",
44
"license": "MIT",
55
"bin": {
66
"pulse": "./dist/cli.js"

npm-packages/cli/source/app.tsx

Lines changed: 15 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import React, {useEffect, useState} from 'react';
2-
import {Text} from 'ink';
32
import {Result} from 'meow';
4-
import {commandsManual} from './manual.js';
5-
import Login from './components/login.js';
6-
import {Flags} from './flags.js';
3+
import Login from './components/commands/login.js';
4+
import {Flags} from './lib/cli-flags.js';
5+
import Publish from './components/commands/publish.js';
6+
import Help from './components/commands/help.js';
7+
import Chat from './components/commands/chat.js';
8+
import Logout from './components/commands/logout.js';
79

810
export default function App({cli}: {cli: Result<Flags>}) {
911
const [command, setCommand] = useState<string | undefined>(undefined);
@@ -13,35 +15,13 @@ export default function App({cli}: {cli: Result<Flags>}) {
1315
setCommand(cmd);
1416
}, [cli.input]);
1517

16-
if (!command) return null;
17-
else if (command === 'help') {
18-
const subCommand = cli.input[1];
19-
if (!subCommand) {
20-
return <Text>{cli.help}</Text>;
21-
} else {
22-
return <Text>{commandsManual[subCommand]}</Text>;
23-
}
24-
} else if (command === 'chat') {
25-
const message = cli.input[1];
26-
return (
27-
<>
28-
<Text>
29-
Hello, <Text color="green">{message}</Text>
30-
</Text>
31-
</>
32-
);
33-
} else if (command === 'login') {
34-
return <Login cli={cli} />;
35-
} else if (command === 'logout') {
36-
return <Text>Logout from the Pulse Editor Platform</Text>;
37-
} else if (command === 'publish') {
38-
return (
39-
<Text>
40-
Publish Pulse Editor Extension in current directory to the Pulse Editor
41-
Platform
42-
</Text>
43-
);
44-
}
45-
46-
return <Text>{cli.help}</Text>;
18+
return (
19+
<>
20+
{command === 'help' && <Help cli={cli} />}
21+
{command === 'chat' && <Chat cli={cli} />}
22+
{command === 'login' && <Login cli={cli} />}
23+
{command === 'logout' && <Logout cli={cli} />}
24+
{command === 'publish' && <Publish cli={cli} />}
25+
</>
26+
);
4727
}

npm-packages/cli/source/cli.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import React from 'react';
33
import {render} from 'ink';
44
import meow from 'meow';
55
import App from './app.js';
6-
import {commandsManual} from './manual.js';
7-
import {flags} from './flags.js';
6+
import {commandsManual} from './lib/manual.js';
7+
import { flags } from './lib/cli-flags.js';
88

99
const cli = meow(
1010
`\
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import {Result} from 'meow';
2+
import {Flags} from '../../lib/cli-flags.js';
3+
import React from 'react';
4+
import {Text} from 'ink';
5+
6+
export default function Chat({cli}: {cli: Result<Flags>}) {
7+
const message = cli.input[1];
8+
return (
9+
<>
10+
<Text>
11+
Hello, <Text color="green">{message}</Text>
12+
</Text>
13+
</>
14+
);
15+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import {Result} from 'meow';
2+
import React from 'react';
3+
import {Flags} from '../../lib/cli-flags.js';
4+
import {Text} from 'ink';
5+
import {commandsManual} from '../../lib/manual.js';
6+
import Header from '../header.js';
7+
8+
export default function Help({cli}: {cli: Result<Flags>}) {
9+
const subCommand = cli.input[1];
10+
11+
return (
12+
<>
13+
{subCommand ? (
14+
<Text>{commandsManual[subCommand]}</Text>
15+
) : (
16+
<>
17+
<Header />
18+
<Text>{cli.help}</Text>
19+
</>
20+
)}
21+
</>
22+
);
23+
}

npm-packages/cli/source/components/login.tsx renamed to npm-packages/cli/source/components/commands/login.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, {useEffect, useState} from 'react';
22
import {Box, Newline, Text, useApp} from 'ink';
33
import SelectInput from 'ink-select-input';
4-
import {Flags} from '../flags.js';
4+
import {Flags} from '../../lib/cli-flags.js';
55
import {Result} from 'meow';
66
import TextInput, {UncontrolledTextInput} from 'ink-text-input';
77
import Spinner from 'ink-spinner';
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import {Result} from 'meow';
2+
import {Flags} from '../../lib/cli-flags.js';
3+
import React from 'react';
4+
import {Text} from 'ink';
5+
6+
export default function Logout({cli}: {cli: Result<Flags>}) {
7+
return <Text>Logout from the Pulse Editor Platform</Text>;
8+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import React from 'react';
2+
import {Text} from 'ink';
3+
import {Result} from 'meow';
4+
import {Flags} from '../../lib/cli-flags.js';
5+
6+
export default function Publish({cli}: {cli: Result<Flags>}) {
7+
return (
8+
<Text>
9+
Publish Pulse Editor Extension in current directory to the Pulse Editor
10+
Platform
11+
</Text>
12+
);
13+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import {Box, Text} from 'ink';
2+
import React from 'react';
3+
4+
export default function Header() {
5+
return (
6+
<Box flexDirection="column" alignItems="center">
7+
<Text color={'whiteBright'}>Pulse Editor CLI</Text>
8+
<Text>Version: 0.0.1</Text>
9+
<Text color={'blueBright'}>https://pulse-editor.com</Text>
10+
</Box>
11+
);
12+
}
File renamed without changes.

0 commit comments

Comments
 (0)