@pulse-editor/cli 0.1.0-beta.0 → 0.1.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app.d.ts +1 -2
- package/dist/app.js +10 -8
- package/dist/cli.js +2 -2
- package/dist/components/commands/chat.d.ts +1 -2
- package/dist/components/commands/chat.js +2 -5
- package/dist/components/commands/create.d.ts +1 -2
- package/dist/components/commands/create.js +99 -52
- package/dist/components/commands/help.d.ts +1 -2
- package/dist/components/commands/help.js +2 -4
- package/dist/components/commands/login.d.ts +1 -2
- package/dist/components/commands/login.js +25 -46
- package/dist/components/commands/logout.d.ts +1 -2
- package/dist/components/commands/logout.js +4 -5
- package/dist/components/commands/publish.d.ts +1 -2
- package/dist/components/commands/publish.js +20 -28
- package/dist/components/header.d.ts +1 -2
- package/dist/components/header.js +2 -5
- package/dist/lib/token.d.ts +3 -3
- package/dist/lib/token.js +27 -12
- package/package.json +13 -13
- package/readme.md +10 -1
package/dist/app.d.ts
CHANGED
package/dist/app.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useState } from 'react';
|
|
3
|
+
import { Text } from 'ink';
|
|
2
4
|
import Login from './components/commands/login.js';
|
|
3
5
|
import Publish from './components/commands/publish.js';
|
|
4
6
|
import Help from './components/commands/help.js';
|
|
@@ -7,15 +9,15 @@ import Logout from './components/commands/logout.js';
|
|
|
7
9
|
import Create from './components/commands/create.js';
|
|
8
10
|
export default function App({ cli }) {
|
|
9
11
|
const [command, setCommand] = useState(undefined);
|
|
12
|
+
if (cli.flags.dev) {
|
|
13
|
+
process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0';
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '1';
|
|
17
|
+
}
|
|
10
18
|
useEffect(() => {
|
|
11
19
|
const cmd = cli.input[0] ?? 'help';
|
|
12
20
|
setCommand(cmd);
|
|
13
21
|
}, [cli.input]);
|
|
14
|
-
return (
|
|
15
|
-
command === 'help' && React.createElement(Help, { cli: cli }),
|
|
16
|
-
command === 'chat' && React.createElement(Chat, { cli: cli }),
|
|
17
|
-
command === 'login' && React.createElement(Login, { cli: cli }),
|
|
18
|
-
command === 'logout' && React.createElement(Logout, { cli: cli }),
|
|
19
|
-
command === 'publish' && React.createElement(Publish, { cli: cli }),
|
|
20
|
-
command === 'create' && React.createElement(Create, { cli: cli })));
|
|
22
|
+
return (_jsxs(_Fragment, { children: [cli.flags.dev && (_jsx(Text, { color: 'yellow', children: "\u26A0\uFE0F You are in development mode." })), command === 'help' ? (_jsx(Help, { cli: cli })) : command === 'chat' ? (_jsx(Chat, { cli: cli })) : command === 'login' ? (_jsx(Login, { cli: cli })) : command === 'logout' ? (_jsx(Logout, { cli: cli })) : command === 'publish' ? (_jsx(Publish, { cli: cli })) : command === 'create' ? (_jsx(Create, { cli: cli })) : (command !== undefined && (_jsxs(_Fragment, { children: [_jsxs(Text, { color: 'redBright', children: ["Invalid command: ", command] }), _jsxs(Text, { children: ["Run ", _jsx(Text, { color: 'blueBright', children: "pulse help" }), " to see the list of available commands."] })] })))] }));
|
|
21
23
|
}
|
package/dist/cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import { render } from 'ink';
|
|
4
4
|
import meow from 'meow';
|
|
5
5
|
import App from './app.js';
|
|
@@ -19,4 +19,4 @@ Examples
|
|
|
19
19
|
importMeta: import.meta,
|
|
20
20
|
flags: flags,
|
|
21
21
|
});
|
|
22
|
-
render(
|
|
22
|
+
render(_jsx(App, { cli: cli }));
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { Text } from 'ink';
|
|
3
3
|
export default function Chat({ cli }) {
|
|
4
4
|
const message = cli.input[1];
|
|
5
|
-
return (
|
|
6
|
-
React.createElement(Text, null,
|
|
7
|
-
"Hello, ",
|
|
8
|
-
React.createElement(Text, { color: "green" }, message))));
|
|
5
|
+
return (_jsx(_Fragment, { children: _jsxs(Text, { children: ["Hello, ", _jsx(Text, { color: "green", children: message })] }) }));
|
|
9
6
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useState } from 'react';
|
|
3
|
+
import { Box, Text, useApp } from 'ink';
|
|
3
4
|
import Spinner from 'ink-spinner';
|
|
4
|
-
import {
|
|
5
|
+
import { $, execa } from 'execa';
|
|
5
6
|
import SelectInput from 'ink-select-input';
|
|
6
7
|
import { UncontrolledTextInput } from 'ink-text-input';
|
|
7
8
|
import fs from 'fs';
|
|
@@ -9,10 +10,12 @@ import path from 'path';
|
|
|
9
10
|
export default function Create({ cli }) {
|
|
10
11
|
const [framework, setFramework] = useState(undefined);
|
|
11
12
|
const [projectName, setProjectName] = useState(undefined);
|
|
12
|
-
const [
|
|
13
|
-
const [
|
|
14
|
-
const [
|
|
15
|
-
const [
|
|
13
|
+
const [visibility, setVisibility] = useState(undefined);
|
|
14
|
+
const [isShowFrameworkSelect, setIsShowFrameworkSelect] = useState(true);
|
|
15
|
+
const [isShowProjectNameInput, setIsShowProjectNameInput] = useState(false);
|
|
16
|
+
const [isShowVisibilitySelect, setIsShowVisibilitySelect] = useState(false);
|
|
17
|
+
const [createMessage, setCreateMessage] = useState();
|
|
18
|
+
const [errorMessage, setErrorMessage] = useState();
|
|
16
19
|
const frameworkItems = [
|
|
17
20
|
{
|
|
18
21
|
label: 'React',
|
|
@@ -31,63 +34,107 @@ export default function Create({ cli }) {
|
|
|
31
34
|
value: 'angular',
|
|
32
35
|
},
|
|
33
36
|
];
|
|
37
|
+
const { exit } = useApp();
|
|
34
38
|
useEffect(() => {
|
|
35
39
|
const framework = cli.flags.framework;
|
|
36
|
-
|
|
40
|
+
if (framework) {
|
|
41
|
+
setFramework(framework);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
setIsShowFrameworkSelect(true);
|
|
45
|
+
}
|
|
37
46
|
}, [cli]);
|
|
38
47
|
useEffect(() => {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
// Clone the template repository
|
|
42
|
-
try {
|
|
43
|
-
await $ `git clone https://github.com/ClayPulse/pulse-editor-extension-template.git ${name}`;
|
|
44
|
-
setIsCreated(true);
|
|
45
|
-
}
|
|
46
|
-
catch (error) {
|
|
47
|
-
setIsCloneFailed(true);
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
// Modify the package.json file to update the name
|
|
51
|
-
const packageJsonPath = path.join(process.cwd(), name, 'package.json');
|
|
52
|
-
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
53
|
-
packageJson.name = name;
|
|
54
|
-
// Write the modified package.json back to the file
|
|
55
|
-
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
|
|
56
|
-
}
|
|
48
|
+
if (framework) {
|
|
49
|
+
setIsShowProjectNameInput(true);
|
|
57
50
|
}
|
|
51
|
+
}, [framework]);
|
|
52
|
+
useEffect(() => {
|
|
58
53
|
if (projectName) {
|
|
59
54
|
// Check if the project already exists
|
|
60
55
|
const projectPath = path.join(process.cwd(), projectName);
|
|
61
56
|
if (fs.existsSync(projectPath)) {
|
|
62
|
-
|
|
57
|
+
setErrorMessage(_jsx(Text, { color: "redBright", children: "\u274C A project with same name already exists in current path." }));
|
|
58
|
+
setTimeout(() => {
|
|
59
|
+
exit();
|
|
60
|
+
}, 0);
|
|
63
61
|
return;
|
|
64
62
|
}
|
|
65
|
-
|
|
63
|
+
setIsShowVisibilitySelect(true);
|
|
66
64
|
}
|
|
67
65
|
}, [projectName]);
|
|
68
66
|
useEffect(() => {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
}, [
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
67
|
+
if (visibility && projectName) {
|
|
68
|
+
createFromTemplate(projectName, visibility);
|
|
69
|
+
}
|
|
70
|
+
}, [visibility, projectName]);
|
|
71
|
+
async function createFromTemplate(name, visibility) {
|
|
72
|
+
if (framework === 'react') {
|
|
73
|
+
// Clone the template repository
|
|
74
|
+
setCreateMessage(_jsxs(Box, { children: [_jsx(Spinner, { type: "dots" }), _jsx(Text, { children: " Creating a new Pulse Editor app using React template..." })] }));
|
|
75
|
+
try {
|
|
76
|
+
await $ `git clone --depth 1 https://github.com/ClayPulse/pulse-editor-extension-template.git ${name}`;
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
setCreateMessage(_jsx(Text, { color: "redBright", children: "\u274C Failed to clone the template. Please check your internet connection and try again." }));
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
// Modify the package.json file to update the name
|
|
83
|
+
setCreateMessage(_jsxs(Box, { children: [_jsx(Spinner, { type: "dots" }), _jsx(Text, { children: " Initializing project..." })] }));
|
|
84
|
+
const packageJsonPath = path.join(process.cwd(), name, 'package.json');
|
|
85
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
86
|
+
packageJson.name = name.replaceAll('-', '_');
|
|
87
|
+
// Modify the visibility
|
|
88
|
+
packageJson['pulse-editor-marketplace'] = {
|
|
89
|
+
visibility,
|
|
90
|
+
};
|
|
91
|
+
// Write the modified package.json back to the file
|
|
92
|
+
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
|
|
93
|
+
// Remove the .git directory
|
|
94
|
+
const gitDirPath = path.join(process.cwd(), name, '.git');
|
|
95
|
+
if (fs.existsSync(gitDirPath)) {
|
|
96
|
+
fs.rmSync(gitDirPath, { recursive: true, force: true });
|
|
97
|
+
}
|
|
98
|
+
// Remove the .github directory
|
|
99
|
+
const githubDirPath = path.join(process.cwd(), name, '.github');
|
|
100
|
+
if (fs.existsSync(githubDirPath)) {
|
|
101
|
+
fs.rmSync(githubDirPath, { recursive: true, force: true });
|
|
102
|
+
}
|
|
103
|
+
// Remove LICENSE file
|
|
104
|
+
const licenseFilePath = path.join(process.cwd(), name, 'LICENSE');
|
|
105
|
+
if (fs.existsSync(licenseFilePath)) {
|
|
106
|
+
fs.rmSync(licenseFilePath, { force: true });
|
|
107
|
+
}
|
|
108
|
+
setCreateMessage(_jsxs(Box, { children: [_jsx(Spinner, { type: "dots" }), _jsx(Text, { children: " Installing dependencies..." })] }));
|
|
109
|
+
// Run `npm i`
|
|
110
|
+
try {
|
|
111
|
+
await execa(`npm install`, {
|
|
112
|
+
cwd: path.join(process.cwd(), name),
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
setCreateMessage(_jsx(Text, { color: "redBright", children: "\u274C Failed to install dependencies. Please check your internet connection and try again." }));
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
setCreateMessage(_jsx(Text, { children: "\uD83D\uDE80 Pulse Editor React app project created successfully!" }));
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return (_jsxs(_Fragment, { children: [isShowFrameworkSelect && (_jsx(FrameworkSelect, { cli: cli, frameworkItems: frameworkItems, framework: framework, setFramework: setFramework })), isShowProjectNameInput && (_jsx(ProjectNameInput, { projectName: projectName, setProjectName: setProjectName })), isShowVisibilitySelect && (_jsx(VisibilitySelect, { visibility: visibility, setVisibility: setVisibility })), visibility !== undefined && (_jsxs(_Fragment, { children: [framework === 'react' && _jsx(_Fragment, { children: createMessage }), framework !== 'react' && (_jsx(Text, { children: "\uD83D\uDEA7 Currently not available. We'd like to invite you to work on these frameworks if you are interested in! Check out our tutorial to integrate your favorite web framework with Pulse Editor using Module Federation." }))] })), _jsx(Text, { children: errorMessage })] }));
|
|
123
|
+
}
|
|
124
|
+
function FrameworkSelect({ cli, frameworkItems, framework, setFramework, }) {
|
|
125
|
+
return (_jsx(_Fragment, { children: !cli.flags.framework && (_jsxs(_Fragment, { children: [_jsx(Text, { children: "\uD83D\uDEA9Create a new Pulse Editor app using your favorite web framework!" }), _jsx(SelectInput, { items: frameworkItems, onSelect: item => {
|
|
126
|
+
setFramework(item.value);
|
|
127
|
+
}, isFocused: framework === undefined }), _jsx(Text, { children: " " })] })) }));
|
|
128
|
+
}
|
|
129
|
+
function ProjectNameInput({ projectName, setProjectName, }) {
|
|
130
|
+
return (_jsx(_Fragment, { children: _jsxs(Box, { children: [_jsx(Text, { children: "Enter your project name: " }), _jsx(UncontrolledTextInput, { onSubmit: value => setTimeout(() => setProjectName(value), 0), focus: projectName === undefined })] }) }));
|
|
131
|
+
}
|
|
132
|
+
function VisibilitySelect({ visibility, setVisibility, }) {
|
|
133
|
+
return (_jsxs(_Fragment, { children: [_jsx(Text, { children: "Enter marketplace visibility for your project:" }), _jsx(SelectInput, { items: [
|
|
134
|
+
{ label: 'Public', value: 'public' },
|
|
135
|
+
{ label: 'Unlisted', value: 'unlisted' },
|
|
136
|
+
{ label: 'Private', value: 'private' },
|
|
137
|
+
], onSelect: item => {
|
|
138
|
+
setVisibility(item.value);
|
|
139
|
+
}, isFocused: visibility === undefined }), _jsx(Text, { children: " " })] }));
|
|
93
140
|
}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Text } from 'ink';
|
|
3
3
|
import { commandsManual } from '../../lib/manual.js';
|
|
4
4
|
import Header from '../header.js';
|
|
5
5
|
export default function Help({ cli }) {
|
|
6
6
|
const subCommand = cli.input[1];
|
|
7
|
-
return (
|
|
8
|
-
React.createElement(Header, null),
|
|
9
|
-
React.createElement(Text, null, cli.help)))));
|
|
7
|
+
return (_jsx(_Fragment, { children: subCommand ? (_jsx(Text, { children: commandsManual[subCommand] })) : (_jsxs(_Fragment, { children: [_jsx(Header, {}), _jsx(Text, { children: cli.help })] })) }));
|
|
10
8
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useState } from 'react';
|
|
2
3
|
import { Box, Text, useApp } from 'ink';
|
|
3
4
|
import SelectInput from 'ink-select-input';
|
|
4
5
|
import TextInput from 'ink-text-input';
|
|
@@ -29,7 +30,7 @@ export default function Login({ cli }) {
|
|
|
29
30
|
const { exit } = useApp();
|
|
30
31
|
// Check login method
|
|
31
32
|
useEffect(() => {
|
|
32
|
-
const savedToken = getToken();
|
|
33
|
+
const savedToken = getToken(cli.flags.dev);
|
|
33
34
|
setIsShowLoginMethod(!savedToken && !cli.flags.token && !cli.flags.flow);
|
|
34
35
|
if (savedToken) {
|
|
35
36
|
setLoginMethod('token');
|
|
@@ -58,51 +59,29 @@ export default function Login({ cli }) {
|
|
|
58
59
|
setIsMethodSelected(loginMethod !== undefined);
|
|
59
60
|
}, 0);
|
|
60
61
|
}, [loginMethod]);
|
|
61
|
-
return (
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}, isFocused: loginMethod === undefined }),
|
|
67
|
-
React.createElement(Text, null, " "))),
|
|
68
|
-
isMethodSelected &&
|
|
69
|
-
loginMethod === 'token' &&
|
|
70
|
-
(token.length === 0 ? (React.createElement(React.Fragment, null,
|
|
71
|
-
React.createElement(Text, null, "Enter your Pulse Editor access token:"),
|
|
72
|
-
React.createElement(TextInput, { mask: "*", value: tokenInput, onChange: setTokenInput, onSubmit: value => {
|
|
73
|
-
if (value.length === 0) {
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
setToken(value);
|
|
77
|
-
} }))) : isCheckingAuth ? (React.createElement(Box, null,
|
|
78
|
-
React.createElement(Spinner, { type: "dots" }),
|
|
79
|
-
React.createElement(Text, null, " Checking authentication..."))) : isAuthenticated ? (React.createElement(React.Fragment, null,
|
|
80
|
-
React.createElement(Text, null, "\u2705 You are signed in successfully."),
|
|
81
|
-
!isTokenInEnv() && getToken() !== token && (React.createElement(React.Fragment, null,
|
|
82
|
-
React.createElement(Text, null, "\uD83D\uDFE2 It is recommended to save your access token as an environment variable PE_ACCESS_TOKEN."),
|
|
83
|
-
React.createElement(Box, null,
|
|
84
|
-
React.createElement(Text, null,
|
|
85
|
-
"\u26A0\uFE0F (NOT recommended) Or, do you want to save access token to user home directory? (y/n)",
|
|
86
|
-
' '),
|
|
87
|
-
React.createElement(TextInput, { value: saveTokenInput, onChange: setSaveTokenInput, onSubmit: value => {
|
|
62
|
+
return (_jsxs(_Fragment, { children: [isShowLoginMethod && (_jsxs(_Fragment, { children: [_jsx(Text, { children: "Login to the Pulse Editor Platform" }), _jsx(SelectInput, { items: loginMethodItems, onSelect: item => {
|
|
63
|
+
setLoginMethod(item.value);
|
|
64
|
+
}, isFocused: loginMethod === undefined }), _jsx(Text, { children: " " })] })), isMethodSelected &&
|
|
65
|
+
loginMethod === 'token' &&
|
|
66
|
+
(token.length === 0 ? (_jsxs(_Fragment, { children: [_jsx(Text, { children: "Enter your Pulse Editor access token:" }), _jsx(TextInput, { mask: "*", value: tokenInput, onChange: setTokenInput, onSubmit: value => {
|
|
88
67
|
if (value.length === 0) {
|
|
89
68
|
return;
|
|
90
69
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
70
|
+
setToken(value);
|
|
71
|
+
} })] })) : isCheckingAuth ? (_jsxs(Box, { children: [_jsx(Spinner, { type: "dots" }), _jsx(Text, { children: " Checking authentication..." })] })) : isAuthenticated ? (_jsxs(_Fragment, { children: [_jsx(Text, { children: "\u2705 You are signed in successfully." }), !isTokenInEnv(cli.flags.dev) &&
|
|
72
|
+
getToken(cli.flags.dev) !== token && (_jsxs(_Fragment, { children: [_jsx(Text, { children: "\uD83D\uDFE2 It is recommended to save your access token as an environment variable PE_ACCESS_TOKEN." }), _jsxs(Box, { children: [_jsxs(Text, { children: ["\u26A0\uFE0F (NOT recommended) Or, do you want to save access token to user home directory? (y/n)", ' '] }), _jsx(TextInput, { value: saveTokenInput, onChange: setSaveTokenInput, onSubmit: value => {
|
|
73
|
+
if (value.length === 0) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if (value === 'y') {
|
|
77
|
+
saveToken(token, cli.flags.dev);
|
|
78
|
+
setIsTokenSaved(true);
|
|
79
|
+
setTimeout(() => {
|
|
80
|
+
exit();
|
|
81
|
+
}, 0);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
exit();
|
|
85
|
+
}
|
|
86
|
+
} })] })] })), isTokenSaved && (_jsxs(Text, { children: ["Token saved to ", path.join(os.homedir(), '.pulse-editor')] }))] })) : (_jsx(Text, { children: "Authentication error: please enter valid credentials." }))), isMethodSelected && loginMethod === 'flow' && (_jsxs(_Fragment, { children: [_jsx(Text, { children: "(WIP) Open the following URL in your browser:" }), _jsx(Text, { children: "https://pulse-editor.com/login" })] }))] }));
|
|
108
87
|
}
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useState } from 'react';
|
|
2
3
|
import { Box, Text } from 'ink';
|
|
3
4
|
import { saveToken } from '../../lib/token.js';
|
|
4
5
|
import Spinner from 'ink-spinner';
|
|
5
6
|
export default function Logout({ cli }) {
|
|
6
7
|
const [isLoggedOut, setIsLoggedOut] = useState(false);
|
|
7
8
|
useEffect(() => {
|
|
8
|
-
saveToken(undefined);
|
|
9
|
+
saveToken(undefined, cli.flags.dev);
|
|
9
10
|
setIsLoggedOut(true);
|
|
10
11
|
}, []);
|
|
11
|
-
return (
|
|
12
|
-
React.createElement(Spinner, { type: "dots" }),
|
|
13
|
-
React.createElement(Text, null, " Logging out...")))));
|
|
12
|
+
return (_jsx(_Fragment, { children: isLoggedOut ? (_jsx(Text, { children: "\uD83D\uDE80 Successfully logged out!" })) : (_jsxs(Box, { children: [_jsx(Spinner, { type: "dots" }), _jsx(Text, { children: " Logging out..." })] })) }));
|
|
14
13
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useState } from 'react';
|
|
2
3
|
import { Box, Text } from 'ink';
|
|
3
4
|
import { checkToken, getToken } from '../../lib/token.js';
|
|
4
5
|
import Spinner from 'ink-spinner';
|
|
@@ -15,17 +16,20 @@ export default function Publish({ cli }) {
|
|
|
15
16
|
const [isPublished, setIsPublished] = useState(false);
|
|
16
17
|
const [failureMessage, setFailureMessage] = useState(undefined);
|
|
17
18
|
useEffect(() => {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
async function checkConfig() {
|
|
20
|
+
// Check if the current dir contains pulse.config.ts
|
|
21
|
+
const currentDir = process.cwd();
|
|
22
|
+
const pulseConfigPath = `${currentDir}/pulse.config.ts`;
|
|
23
|
+
if (fs.existsSync(pulseConfigPath)) {
|
|
24
|
+
setIsInProjectDir(true);
|
|
25
|
+
}
|
|
23
26
|
}
|
|
27
|
+
checkConfig();
|
|
24
28
|
}, []);
|
|
25
29
|
// Check if the user is authenticated
|
|
26
30
|
useEffect(() => {
|
|
27
31
|
async function checkAuth() {
|
|
28
|
-
const token = getToken();
|
|
32
|
+
const token = getToken(cli.flags.dev);
|
|
29
33
|
if (token) {
|
|
30
34
|
const isValid = await checkToken(token, cli.flags.dev);
|
|
31
35
|
if (isValid) {
|
|
@@ -58,21 +62,27 @@ export default function Publish({ cli }) {
|
|
|
58
62
|
}
|
|
59
63
|
async function publishExtension() {
|
|
60
64
|
setIsPublishing(true);
|
|
65
|
+
// Read package.json
|
|
66
|
+
const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf-8'));
|
|
67
|
+
const visibility = packageJson['pulse-editor-marketplace']
|
|
68
|
+
.visibility;
|
|
61
69
|
// Upload the zip file to the server
|
|
62
70
|
try {
|
|
63
71
|
const formData = new FormData();
|
|
64
72
|
const buffer = fs.readFileSync('./node_modules/@pulse-editor/dist.zip');
|
|
73
|
+
// @ts-ignore Create a Blob from the buffer
|
|
65
74
|
const blob = new Blob([buffer], {
|
|
66
75
|
type: 'application/zip',
|
|
67
76
|
});
|
|
68
77
|
formData.append('file', blob, 'dist.zip');
|
|
78
|
+
formData.append('visibility', visibility);
|
|
69
79
|
// Send the file to the server
|
|
70
80
|
const res = await fetch(cli.flags.dev
|
|
71
|
-
? '
|
|
81
|
+
? 'https://localhost:8080/api/extension/publish'
|
|
72
82
|
: 'https://pulse-editor.com/api/extension/publish', {
|
|
73
83
|
method: 'POST',
|
|
74
84
|
headers: {
|
|
75
|
-
Authorization: `Bearer ${getToken()}`,
|
|
85
|
+
Authorization: `Bearer ${getToken(cli.flags.dev)}`,
|
|
76
86
|
},
|
|
77
87
|
body: formData,
|
|
78
88
|
});
|
|
@@ -103,23 +113,5 @@ export default function Publish({ cli }) {
|
|
|
103
113
|
buildExtension();
|
|
104
114
|
}
|
|
105
115
|
}, [isAuthenticated]);
|
|
106
|
-
return (
|
|
107
|
-
React.createElement(Spinner, { type: "dots" }),
|
|
108
|
-
React.createElement(Text, null, " Checking authentication..."))) : isAuthenticated ? (React.createElement(React.Fragment, null,
|
|
109
|
-
isBuilding && (React.createElement(Box, null,
|
|
110
|
-
React.createElement(Spinner, { type: "dots" }),
|
|
111
|
-
React.createElement(Text, null, " Building..."))),
|
|
112
|
-
isBuildingError && (React.createElement(Text, { color: 'redBright' }, "\u274C Error building the extension. Please run `npm run build` to see the error.")),
|
|
113
|
-
isPublishing && (React.createElement(Box, null,
|
|
114
|
-
React.createElement(Spinner, { type: "dots" }),
|
|
115
|
-
React.createElement(Text, null, " Publishing..."))),
|
|
116
|
-
isPublishingError && (React.createElement(React.Fragment, null,
|
|
117
|
-
React.createElement(Text, { color: 'redBright' }, "\u274C Failed to publish extension."),
|
|
118
|
-
failureMessage && (React.createElement(Text, { color: 'redBright' },
|
|
119
|
-
"Error: ",
|
|
120
|
-
failureMessage)))),
|
|
121
|
-
isPublished && (React.createElement(Text, { color: 'greenBright' }, "\u2705 Extension published successfully.")))) : (React.createElement(Text, null,
|
|
122
|
-
"You are not authenticated or your access token is invalid. Publishing to Extension Marketplace is in Beta access. Please visit",
|
|
123
|
-
React.createElement(Text, { color: 'blueBright' }, " https://pulse-editor.com/beta "),
|
|
124
|
-
"to apply for Beta access."))));
|
|
116
|
+
return (_jsx(_Fragment, { children: !isInProjectDir ? (_jsx(Text, { color: 'redBright', children: "\u26D4 The current directory does not contain a Pulse Editor project." })) : isCheckingAuth ? (_jsxs(Box, { children: [_jsx(Spinner, { type: "dots" }), _jsx(Text, { children: " Checking authentication..." })] })) : isAuthenticated ? (_jsxs(_Fragment, { children: [isBuilding && (_jsxs(Box, { children: [_jsx(Spinner, { type: "dots" }), _jsx(Text, { children: " Building..." })] })), isBuildingError && (_jsx(Text, { color: 'redBright', children: "\u274C Error building the extension. Please run `npm run build` to see the error." })), isPublishing && (_jsxs(Box, { children: [_jsx(Spinner, { type: "dots" }), _jsx(Text, { children: " Publishing..." })] })), isPublishingError && (_jsxs(_Fragment, { children: [_jsx(Text, { color: 'redBright', children: "\u274C Failed to publish extension." }), failureMessage && (_jsxs(Text, { color: 'redBright', children: ["Error: ", failureMessage] }))] })), isPublished && (_jsx(Text, { color: 'greenBright', children: "\u2705 Extension published successfully." }))] })) : (_jsxs(Text, { children: ["You are not authenticated or your access token is invalid. Publishing to Extension Marketplace is in Beta access. Please visit", _jsx(Text, { color: 'blueBright', children: " https://pulse-editor.com/beta " }), "to apply for Beta access."] })) }));
|
|
125
117
|
}
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export default function Header(): React.JSX.Element;
|
|
1
|
+
export default function Header(): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
1
2
|
import { Box, Text } from 'ink';
|
|
2
|
-
import React from 'react';
|
|
3
3
|
export default function Header() {
|
|
4
|
-
return (
|
|
5
|
-
React.createElement(Text, { color: 'whiteBright' }, "Pulse Editor CLI"),
|
|
6
|
-
React.createElement(Text, null, "Version: 0.0.1"),
|
|
7
|
-
React.createElement(Text, { color: 'blueBright' }, "https://pulse-editor.com")));
|
|
4
|
+
return (_jsxs(Box, { flexDirection: "column", alignItems: "center", children: [_jsx(Text, { color: 'whiteBright', children: "Pulse Editor CLI" }), _jsx(Text, { children: "Version: 0.0.1" }), _jsx(Text, { color: 'blueBright', children: "https://pulse-editor.com" })] }));
|
|
8
5
|
}
|
package/dist/lib/token.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare function saveToken(token: string | undefined): void;
|
|
2
|
-
export declare function getToken(): string | undefined;
|
|
3
|
-
export declare function isTokenInEnv(): boolean;
|
|
1
|
+
export declare function saveToken(token: string | undefined, devMode: boolean): void;
|
|
2
|
+
export declare function getToken(devMode: boolean): string | undefined;
|
|
3
|
+
export declare function isTokenInEnv(devMode: boolean): boolean;
|
|
4
4
|
export declare function checkToken(token: string, devMode: boolean): Promise<boolean>;
|
package/dist/lib/token.js
CHANGED
|
@@ -1,21 +1,33 @@
|
|
|
1
1
|
import os from 'os';
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import fs from 'fs';
|
|
4
|
-
export function saveToken(token) {
|
|
4
|
+
export function saveToken(token, devMode) {
|
|
5
5
|
// Save the token to .pulse-editor/config.json in user home directory
|
|
6
6
|
const configDir = path.join(os.homedir(), '.pulse-editor');
|
|
7
7
|
const configFile = path.join(configDir, 'config.json');
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
const hasConfig = fs.existsSync(configFile);
|
|
9
|
+
const existingConfig = hasConfig
|
|
10
|
+
? JSON.parse(fs.readFileSync(configFile, 'utf8'))
|
|
11
|
+
: {};
|
|
12
|
+
const newConfig = devMode
|
|
13
|
+
? {
|
|
14
|
+
...existingConfig,
|
|
15
|
+
devAccessToken: token,
|
|
16
|
+
}
|
|
17
|
+
: {
|
|
18
|
+
...existingConfig,
|
|
19
|
+
accessToken: token,
|
|
20
|
+
};
|
|
11
21
|
if (!fs.existsSync(configDir)) {
|
|
12
22
|
fs.mkdirSync(configDir, { recursive: true });
|
|
13
23
|
}
|
|
14
|
-
fs.writeFileSync(configFile, JSON.stringify(
|
|
24
|
+
fs.writeFileSync(configFile, JSON.stringify(newConfig, null, 2));
|
|
15
25
|
}
|
|
16
|
-
export function getToken() {
|
|
26
|
+
export function getToken(devMode) {
|
|
17
27
|
// First try to get the token from the environment variable
|
|
18
|
-
const tokenEnv =
|
|
28
|
+
const tokenEnv = devMode
|
|
29
|
+
? process.env['PE_DEV_ACCESS_TOKEN']
|
|
30
|
+
: process.env['PE_ACCESS_TOKEN'];
|
|
19
31
|
if (tokenEnv) {
|
|
20
32
|
return tokenEnv;
|
|
21
33
|
}
|
|
@@ -25,8 +37,9 @@ export function getToken() {
|
|
|
25
37
|
if (fs.existsSync(configFile)) {
|
|
26
38
|
try {
|
|
27
39
|
const config = JSON.parse(fs.readFileSync(configFile, 'utf8'));
|
|
28
|
-
|
|
29
|
-
|
|
40
|
+
const token = devMode ? config.devAccessToken : config.accessToken;
|
|
41
|
+
if (token) {
|
|
42
|
+
return token;
|
|
30
43
|
}
|
|
31
44
|
}
|
|
32
45
|
catch (error) {
|
|
@@ -38,9 +51,11 @@ export function getToken() {
|
|
|
38
51
|
// If not found, return undefined
|
|
39
52
|
return undefined;
|
|
40
53
|
}
|
|
41
|
-
export function isTokenInEnv() {
|
|
54
|
+
export function isTokenInEnv(devMode) {
|
|
42
55
|
// Check if the token is set in the environment variable
|
|
43
|
-
const tokenEnv =
|
|
56
|
+
const tokenEnv = devMode
|
|
57
|
+
? process.env['PE_DEV_ACCESS_TOKEN']
|
|
58
|
+
: process.env['PE_ACCESS_TOKEN'];
|
|
44
59
|
if (tokenEnv) {
|
|
45
60
|
return true;
|
|
46
61
|
}
|
|
@@ -48,7 +63,7 @@ export function isTokenInEnv() {
|
|
|
48
63
|
}
|
|
49
64
|
export async function checkToken(token, devMode) {
|
|
50
65
|
const res = await fetch(devMode
|
|
51
|
-
? '
|
|
66
|
+
? 'https://localhost:8080/api/api-keys/check'
|
|
52
67
|
: 'https://pulse-editor.com/api/api-keys/check', {
|
|
53
68
|
body: JSON.stringify({ token }),
|
|
54
69
|
headers: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pulse-editor/cli",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"bin": {
|
|
6
6
|
"pulse": "./dist/cli.js"
|
|
@@ -19,29 +19,29 @@
|
|
|
19
19
|
"dist"
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"execa": "^9.
|
|
23
|
-
"ink": "^
|
|
24
|
-
"ink-select-input": "^6.
|
|
22
|
+
"execa": "^9.6.0",
|
|
23
|
+
"ink": "^6.1.0",
|
|
24
|
+
"ink-select-input": "^6.2.0",
|
|
25
25
|
"ink-spinner": "^5.0.0",
|
|
26
26
|
"ink-text-input": "^6.0.0",
|
|
27
27
|
"meow": "^13.2.0",
|
|
28
|
-
"openid-client": "^6.
|
|
29
|
-
"react": "^
|
|
28
|
+
"openid-client": "^6.6.3",
|
|
29
|
+
"react": "^19.1.1"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@sindresorhus/tsconfig": "^
|
|
33
|
-
"@types/react": "^
|
|
32
|
+
"@sindresorhus/tsconfig": "^8.0.1",
|
|
33
|
+
"@types/react": "^19.1.9",
|
|
34
34
|
"@vdemedes/prettier-config": "^2.0.1",
|
|
35
|
-
"ava": "^6.
|
|
36
|
-
"chalk": "^5.
|
|
35
|
+
"ava": "^6.4.1",
|
|
36
|
+
"chalk": "^5.5.0",
|
|
37
37
|
"eslint-config-xo-react": "^0.28.0",
|
|
38
38
|
"eslint-plugin-react": "^7.37.5",
|
|
39
39
|
"eslint-plugin-react-hooks": "^5.2.0",
|
|
40
40
|
"ink-testing-library": "^4.0.0",
|
|
41
|
-
"prettier": "^3.
|
|
41
|
+
"prettier": "^3.6.2",
|
|
42
42
|
"ts-node": "^10.9.2",
|
|
43
|
-
"typescript": "^5.
|
|
44
|
-
"xo": "^
|
|
43
|
+
"typescript": "^5.9.2",
|
|
44
|
+
"xo": "^1.2.1"
|
|
45
45
|
},
|
|
46
46
|
"ava": {
|
|
47
47
|
"extensions": {
|
package/readme.md
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
# Pulse CLI
|
|
2
2
|
## Install
|
|
3
|
-
|
|
4
3
|
```bash
|
|
5
4
|
$ npm install --global @pulse-editor/cli
|
|
6
5
|
```
|
|
7
6
|
|
|
7
|
+
## Link local development version
|
|
8
|
+
```bash
|
|
9
|
+
npm run link
|
|
10
|
+
```
|
|
11
|
+
|
|
8
12
|
## CLI Manual
|
|
9
13
|
|
|
10
14
|
```
|
|
@@ -41,3 +45,8 @@ $ npm install --global @pulse-editor/cli
|
|
|
41
45
|
pulse help publish
|
|
42
46
|
|
|
43
47
|
```
|
|
48
|
+
|
|
49
|
+
## Development
|
|
50
|
+
```
|
|
51
|
+
npm run dev
|
|
52
|
+
```
|