@pulse-editor/cli 0.1.0-beta.1 → 0.1.0-beta.3

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 CHANGED
@@ -1,6 +1,5 @@
1
- import React from 'react';
2
1
  import { Result } from 'meow';
3
2
  import { Flags } from './lib/cli-flags.js';
4
3
  export default function App({ cli }: {
5
4
  cli: Result<Flags>;
6
- }): React.JSX.Element;
5
+ }): import("react/jsx-runtime").JSX.Element;
package/dist/app.js CHANGED
@@ -1,4 +1,5 @@
1
- import React, { useEffect, useState } from 'react';
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { useEffect, useState } from 'react';
2
3
  import { Text } from 'ink';
3
4
  import Login from './components/commands/login.js';
4
5
  import Publish from './components/commands/publish.js';
@@ -8,16 +9,15 @@ import Logout from './components/commands/logout.js';
8
9
  import Create from './components/commands/create.js';
9
10
  export default function App({ cli }) {
10
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
+ }
11
18
  useEffect(() => {
12
19
  const cmd = cli.input[0] ?? 'help';
13
20
  setCommand(cmd);
14
21
  }, [cli.input]);
15
- return (React.createElement(React.Fragment, null, command === 'help' ? (React.createElement(Help, { cli: cli })) : command === 'chat' ? (React.createElement(Chat, { cli: cli })) : command === 'login' ? (React.createElement(Login, { cli: cli })) : command === 'logout' ? (React.createElement(Logout, { cli: cli })) : command === 'publish' ? (React.createElement(Publish, { cli: cli })) : command === 'create' ? (React.createElement(Create, { cli: cli })) : (command !== undefined && (React.createElement(React.Fragment, null,
16
- React.createElement(Text, { color: 'redBright' },
17
- "Invalid command: ",
18
- command),
19
- React.createElement(Text, null,
20
- "Run ",
21
- React.createElement(Text, { color: 'blueBright' }, "pulse help"),
22
- " to see the list of available commands."))))));
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."] })] })))] }));
23
23
  }
package/dist/cli.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import React from 'react';
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(React.createElement(App, { cli: cli }));
22
+ render(_jsx(App, { cli: cli }));
@@ -1,6 +1,5 @@
1
1
  import { Result } from 'meow';
2
2
  import { Flags } from '../../lib/cli-flags.js';
3
- import React from 'react';
4
3
  export default function Chat({ cli }: {
5
4
  cli: Result<Flags>;
6
- }): React.JSX.Element;
5
+ }): import("react/jsx-runtime").JSX.Element;
@@ -1,9 +1,6 @@
1
- import React from 'react';
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 (React.createElement(React.Fragment, null,
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,6 +1,5 @@
1
1
  import { Result } from 'meow';
2
- import React from 'react';
3
2
  import { Flags } from '../../lib/cli-flags.js';
4
3
  export default function Create({ cli }: {
5
4
  cli: Result<Flags>;
6
- }): React.JSX.Element;
5
+ }): import("react/jsx-runtime").JSX.Element;
@@ -1,5 +1,6 @@
1
- import React, { useEffect, useState } from 'react';
2
- import { Box, Text } from 'ink';
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
5
  import { $, execa } from 'execa';
5
6
  import SelectInput from 'ink-select-input';
@@ -9,8 +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 [isFrameworkSelected, setIsFrameworkSelected] = useState(false);
13
- const [message, setMessage] = useState();
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();
14
19
  const frameworkItems = [
15
20
  {
16
21
  label: 'React',
@@ -29,88 +34,107 @@ export default function Create({ cli }) {
29
34
  value: 'angular',
30
35
  },
31
36
  ];
37
+ const { exit } = useApp();
32
38
  useEffect(() => {
33
39
  const framework = cli.flags.framework;
34
- setFramework(framework);
40
+ if (framework) {
41
+ setFramework(framework);
42
+ }
43
+ else {
44
+ setIsShowFrameworkSelect(true);
45
+ }
35
46
  }, [cli]);
36
47
  useEffect(() => {
37
- async function createFromTemplate(name) {
38
- if (framework === 'react') {
39
- // Clone the template repository
40
- setMessage(React.createElement(Box, null,
41
- React.createElement(Spinner, { type: "dots" }),
42
- React.createElement(Text, null,
43
- ' ',
44
- "Creating a new Pulse Editor app using React template...")));
45
- try {
46
- await $ `git clone --depth 1 https://github.com/ClayPulse/pulse-editor-extension-template.git ${name}`;
47
- }
48
- catch (error) {
49
- setMessage(React.createElement(Text, { color: "redBright" }, "\u274C Failed to clone the template. Please check your internet connection and try again."));
50
- return;
51
- }
52
- // Modify the package.json file to update the name
53
- setMessage(React.createElement(Box, null,
54
- React.createElement(Spinner, { type: "dots" }),
55
- React.createElement(Text, null, " Initializing project...")));
56
- const packageJsonPath = path.join(process.cwd(), name, 'package.json');
57
- const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
58
- packageJson.name = name.replaceAll('-', '_');
59
- // Write the modified package.json back to the file
60
- fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
61
- // Remove the .git directory
62
- const gitDirPath = path.join(process.cwd(), name, '.git');
63
- if (fs.existsSync(gitDirPath)) {
64
- fs.rmSync(gitDirPath, { recursive: true, force: true });
65
- }
66
- // Remove the .github directory
67
- const githubDirPath = path.join(process.cwd(), name, '.github');
68
- if (fs.existsSync(githubDirPath)) {
69
- fs.rmSync(githubDirPath, { recursive: true, force: true });
70
- }
71
- setMessage(React.createElement(Box, null,
72
- React.createElement(Spinner, { type: "dots" }),
73
- React.createElement(Text, null, " Installing dependencies...")));
74
- // Run `npm i`
75
- try {
76
- await execa(`npm install`, {
77
- cwd: path.join(process.cwd(), name),
78
- });
79
- }
80
- catch (error) {
81
- setMessage(React.createElement(Text, { color: "redBright" }, "\u274C Failed to install dependencies. Please check your internet connection and try again."));
82
- return;
83
- }
84
- setMessage(React.createElement(Text, null, "\uD83D\uDE80 Pulse Editor React app project created successfully!"));
85
- }
48
+ if (framework) {
49
+ setIsShowProjectNameInput(true);
86
50
  }
51
+ }, [framework]);
52
+ useEffect(() => {
87
53
  if (projectName) {
88
54
  // Check if the project already exists
89
55
  const projectPath = path.join(process.cwd(), projectName);
90
56
  if (fs.existsSync(projectPath)) {
91
- setMessage(React.createElement(Text, { color: "redBright" }, "\u274C A project with same name already exists in current path."));
57
+ setErrorMessage(_jsx(Text, { color: "redBright", children: "\u274C A project with same name already exists in current path." }));
58
+ setTimeout(() => {
59
+ exit();
60
+ }, 0);
92
61
  return;
93
62
  }
94
- createFromTemplate(projectName);
63
+ setIsShowVisibilitySelect(true);
95
64
  }
96
65
  }, [projectName]);
97
66
  useEffect(() => {
98
- setTimeout(() => {
99
- setIsFrameworkSelected(framework !== undefined);
100
- }, 0);
101
- }, [framework]);
102
- return (React.createElement(React.Fragment, null,
103
- !cli.flags.framework && (React.createElement(React.Fragment, null,
104
- React.createElement(Text, null, "\uD83D\uDEA9Create a new Pulse Editor app using your favorite web framework!"),
105
- React.createElement(SelectInput, { items: frameworkItems, onSelect: item => {
106
- setFramework(item.value);
107
- }, isFocused: framework === undefined }),
108
- React.createElement(Text, null, " "))),
109
- isFrameworkSelected && (React.createElement(React.Fragment, null,
110
- React.createElement(Box, null,
111
- React.createElement(Text, null, "Enter your project name: "),
112
- React.createElement(UncontrolledTextInput, { onSubmit: value => setProjectName(value), focus: projectName === undefined })),
113
- projectName && (React.createElement(React.Fragment, null,
114
- framework === 'react' && React.createElement(React.Fragment, null, message),
115
- framework !== 'react' && (React.createElement(Text, null, "\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."))))))));
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-app-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: " " })] }));
116
140
  }
@@ -1,6 +1,5 @@
1
1
  import { Result } from 'meow';
2
- import React from 'react';
3
2
  import { Flags } from '../../lib/cli-flags.js';
4
3
  export default function Help({ cli }: {
5
4
  cli: Result<Flags>;
6
- }): React.JSX.Element;
5
+ }): import("react/jsx-runtime").JSX.Element;
@@ -1,10 +1,8 @@
1
- import React from 'react';
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 (React.createElement(React.Fragment, null, subCommand ? (React.createElement(Text, null, commandsManual[subCommand])) : (React.createElement(React.Fragment, null,
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,6 +1,5 @@
1
- import React from 'react';
2
1
  import { Flags } from '../../lib/cli-flags.js';
3
2
  import { Result } from 'meow';
4
3
  export default function Login({ cli }: {
5
4
  cli: Result<Flags>;
6
- }): React.JSX.Element;
5
+ }): import("react/jsx-runtime").JSX.Element;
@@ -1,4 +1,5 @@
1
- import React, { useEffect, useState } from 'react';
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 (React.createElement(React.Fragment, null,
62
- isShowLoginMethod && (React.createElement(React.Fragment, null,
63
- React.createElement(Text, null, "Login to the Pulse Editor Platform"),
64
- React.createElement(SelectInput, { items: loginMethodItems, onSelect: item => {
65
- setLoginMethod(item.value);
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
- if (value === 'y') {
92
- saveToken(token);
93
- setIsTokenSaved(true);
94
- setTimeout(() => {
95
- exit();
96
- }, 0);
97
- }
98
- else {
99
- exit();
100
- }
101
- } })))),
102
- isTokenSaved && (React.createElement(Text, null,
103
- "Token saved to ",
104
- path.join(os.homedir(), '.pulse-editor'))))) : (React.createElement(Text, null, "Authentication error: please enter valid credentials."))),
105
- isMethodSelected && loginMethod === 'flow' && (React.createElement(React.Fragment, null,
106
- React.createElement(Text, null, "(WIP) Open the following URL in your browser:"),
107
- React.createElement(Text, null, "https://pulse-editor.com/login")))));
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,6 +1,5 @@
1
1
  import { Result } from 'meow';
2
2
  import { Flags } from '../../lib/cli-flags.js';
3
- import React from 'react';
4
3
  export default function Logout({ cli }: {
5
4
  cli: Result<Flags>;
6
- }): React.JSX.Element;
5
+ }): import("react/jsx-runtime").JSX.Element;
@@ -1,14 +1,13 @@
1
- import React, { useEffect, useState } from 'react';
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 (React.createElement(React.Fragment, null, isLoggedOut ? (React.createElement(Text, null, "\uD83D\uDE80 Successfully logged out!")) : (React.createElement(Box, null,
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,6 +1,5 @@
1
- import React from 'react';
2
1
  import { Result } from 'meow';
3
2
  import { Flags } from '../../lib/cli-flags.js';
4
3
  export default function Publish({ cli }: {
5
4
  cli: Result<Flags>;
6
- }): React.JSX.Element;
5
+ }): import("react/jsx-runtime").JSX.Element;
@@ -1,4 +1,5 @@
1
- import React, { useEffect, useState } from 'react';
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
- // Check if the current dir contains pulse.config.ts
19
- const currentDir = process.cwd();
20
- const pulseConfigPath = `${currentDir}/pulse.config.ts`;
21
- if (fs.existsSync(pulseConfigPath)) {
22
- setIsInProjectDir(true);
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
- ? 'http://localhost:3000/api/extension/publish'
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 (React.createElement(React.Fragment, null, !isInProjectDir ? (React.createElement(Text, { color: 'redBright' }, "\u26D4 The current directory does not contain a Pulse Editor project.")) : isCheckingAuth ? (React.createElement(Box, null,
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
- import React from 'react';
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 (React.createElement(Box, { flexDirection: "column", alignItems: "center" },
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
  }
@@ -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 config = {
9
- accessToken: token,
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(config, null, 2));
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 = process.env['PE_ACCESS_TOKEN'];
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
- if (config.accessToken) {
29
- return config.accessToken;
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 = process.env['PE_ACCESS_TOKEN'];
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
- ? 'http://localhost:3000/api/api-keys/check'
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.1",
3
+ "version": "0.1.0-beta.3",
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.5.2",
23
- "ink": "^5.2.0",
24
- "ink-select-input": "^6.0.0",
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.4.2",
29
- "react": "^18.0.32"
28
+ "openid-client": "^6.6.3",
29
+ "react": "^19.1.1"
30
30
  },
31
31
  "devDependencies": {
32
- "@sindresorhus/tsconfig": "^7.0.0",
33
- "@types/react": "^18.0.32",
32
+ "@sindresorhus/tsconfig": "^8.0.1",
33
+ "@types/react": "^19.1.9",
34
34
  "@vdemedes/prettier-config": "^2.0.1",
35
- "ava": "^6.2.0",
36
- "chalk": "^5.4.1",
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.5.3",
41
+ "prettier": "^3.6.2",
42
42
  "ts-node": "^10.9.2",
43
- "typescript": "^5.8.2",
44
- "xo": "^0.60.0"
43
+ "typescript": "^5.9.2",
44
+ "xo": "^1.2.1"
45
45
  },
46
46
  "ava": {
47
47
  "extensions": {