@pulse-editor/cli 0.1.1-beta.16 → 0.1.1-beta.17

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.js CHANGED
@@ -12,6 +12,7 @@ import Build from './components/commands/build.js';
12
12
  import Preview from './components/commands/preview.js';
13
13
  import Start from './components/commands/start.js';
14
14
  import Clean from './components/commands/clean.js';
15
+ import Upgrade from './components/commands/upgrade.js';
15
16
  export default function App({ cli }) {
16
17
  const [command, setCommand] = useState(undefined);
17
18
  if (cli.flags.stage) {
@@ -24,5 +25,5 @@ export default function App({ cli }) {
24
25
  const cmd = cli.input[0] ?? 'help';
25
26
  setCommand(cmd);
26
27
  }, [cli.input]);
27
- return (_jsxs(_Fragment, { children: [cli.flags.stage && (_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 === 'dev' ? (_jsx(Dev, { cli: cli })) : command === 'build' ? (_jsx(Build, { cli: cli })) : command === 'preview' ? (_jsx(Preview, { cli: cli })) : command === 'start' ? (_jsx(Start, { cli: cli })) : command === 'clean' ? (_jsx(Clean, { 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."] })] })))] }));
28
+ return (_jsxs(_Fragment, { children: [cli.flags.stage && (_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 === 'dev' ? (_jsx(Dev, { cli: cli })) : command === 'build' ? (_jsx(Build, { cli: cli })) : command === 'preview' ? (_jsx(Preview, { cli: cli })) : command === 'start' ? (_jsx(Start, { cli: cli })) : command === 'clean' ? (_jsx(Clean, { cli: cli })) : command === 'upgrade' ? (_jsx(Upgrade, { 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."] })] })))] }));
28
29
  }
@@ -5,12 +5,15 @@ import { checkToken, getToken } from '../../lib/token.js';
5
5
  import Spinner from 'ink-spinner';
6
6
  import fs from 'fs';
7
7
  import { $ } from 'execa';
8
+ import { publishApp } from '../../lib/backend/publish-app.js';
8
9
  export default function Publish({ cli }) {
9
10
  const [isInProjectDir, setIsInProjectDir] = useState(false);
10
11
  const [isCheckingAuth, setIsCheckingAuth] = useState(true);
11
12
  const [isAuthenticated, setIsAuthenticated] = useState(false);
12
13
  const [isBuilding, setIsBuilding] = useState(false);
13
14
  const [isBuildingError, setIsBuildingError] = useState(false);
15
+ const [isZipping, setIsZipping] = useState(false);
16
+ const [isZippingError, setIsZippingError] = useState(false);
14
17
  const [isPublishing, setIsPublishing] = useState(false);
15
18
  const [isPublishingError, setIsPublishingError] = useState(false);
16
19
  const [isPublished, setIsPublished] = useState(false);
@@ -45,56 +48,39 @@ export default function Publish({ cli }) {
45
48
  // Build the extension
46
49
  useEffect(() => {
47
50
  async function buildExtension() {
48
- setIsBuilding(true);
49
- try {
50
- await $ `npm run build`;
51
- }
52
- catch (error) {
53
- setIsBuildingError(true);
54
- setIsBuilding(false);
55
- setFailureMessage('Build failed. Please run `npm run build` to see the error.');
56
- return;
51
+ if (cli.flags.build) {
52
+ setIsBuilding(true);
53
+ try {
54
+ await $ `npm run build`;
55
+ }
56
+ catch (error) {
57
+ setIsBuildingError(true);
58
+ setFailureMessage('Build failed. Please run `npm run build` to see the error.');
59
+ return;
60
+ }
61
+ finally {
62
+ setIsBuilding(false);
63
+ }
57
64
  }
65
+ setIsZipping(true);
58
66
  // Zip the dist folder
59
67
  try {
60
68
  await $({ cwd: 'dist' }) `zip -r ../node_modules/@pulse-editor/dist.zip *`;
61
69
  }
62
70
  catch (error) {
63
- setIsBuildingError(true);
64
- setIsBuilding(false);
71
+ setIsZippingError(true);
65
72
  setFailureMessage('Failed to zip the build output.');
66
73
  return;
67
74
  }
68
75
  finally {
69
- setIsBuilding(false);
76
+ setIsZipping(false);
70
77
  }
71
78
  await publishExtension();
72
79
  }
73
80
  async function publishExtension() {
74
81
  setIsPublishing(true);
75
- // Read pulse.config.json for visibility
76
- const config = JSON.parse(fs.readFileSync('./dist/client/pulse.config.json', 'utf-8'));
77
- const visibility = config.visibility;
78
- // Upload the zip file to the server
79
82
  try {
80
- const formData = new FormData();
81
- const buffer = fs.readFileSync('./node_modules/@pulse-editor/dist.zip');
82
- // @ts-ignore Create a Blob from the buffer
83
- const blob = new Blob([buffer], {
84
- type: 'application/zip',
85
- });
86
- formData.append('file', blob, 'dist.zip');
87
- formData.append('visibility', visibility);
88
- // Send the file to the server
89
- const res = await fetch(cli.flags.stage
90
- ? 'https://localhost:8080/api/app/publish'
91
- : 'https://pulse-editor.com/api/app/publish', {
92
- method: 'POST',
93
- headers: {
94
- Authorization: `Bearer ${getToken(cli.flags.stage)}`,
95
- },
96
- body: formData,
97
- });
83
+ const res = await publishApp(cli.flags.stage);
98
84
  if (res.status === 200) {
99
85
  setIsPublished(true);
100
86
  }
@@ -122,5 +108,5 @@ export default function Publish({ cli }) {
122
108
  buildExtension();
123
109
  }
124
110
  }, [isAuthenticated]);
125
- 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."] })) }));
111
+ 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(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."] })) : (_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." })), isZipping && (_jsxs(Box, { children: [_jsx(Spinner, { type: "dots" }), _jsx(Text, { children: " Compressing build..." })] })), isZippingError && (_jsx(Text, { color: 'redBright', children: "\u274C Error zipping the build output." })), 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." }))] })) }));
126
112
  }
@@ -0,0 +1,5 @@
1
+ import { Result } from 'meow';
2
+ import { Flags } from '../../lib/cli-flags.js';
3
+ export default function Upgrade({ cli }: {
4
+ cli: Result<Flags>;
5
+ }): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,46 @@
1
+ import { jsxs as _jsxs, jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { $ } from 'execa';
3
+ import React, { useEffect, useState } from 'react';
4
+ import { Box, Text } from 'ink';
5
+ import Spinner from 'ink-spinner';
6
+ import fs from 'fs';
7
+ export default function Upgrade({ cli }) {
8
+ const [isInProjectDir, setIsInProjectDir] = useState(false);
9
+ const [step, setStep] = useState('check-config');
10
+ const [isError, setIsError] = useState(false);
11
+ const [errorMessage, setErrorMessage] = useState(null);
12
+ useEffect(() => {
13
+ async function checkConfig() {
14
+ // Check if the current dir contains pulse.config.ts
15
+ const currentDir = process.cwd();
16
+ const pulseConfigPath = `${currentDir}/pulse.config.ts`;
17
+ if (fs.existsSync(pulseConfigPath)) {
18
+ setIsInProjectDir(true);
19
+ }
20
+ setStep('upgrade');
21
+ }
22
+ checkConfig();
23
+ }, []);
24
+ useEffect(() => {
25
+ async function start() {
26
+ try {
27
+ await upgradePackages();
28
+ }
29
+ catch (error) {
30
+ setIsError(true);
31
+ setErrorMessage(error.message);
32
+ }
33
+ }
34
+ if (isInProjectDir) {
35
+ start();
36
+ }
37
+ }, [isInProjectDir]);
38
+ async function upgradePackages() {
39
+ const tag = cli.flags.beta ? 'beta' : 'latest';
40
+ await $ `npm install react@${React.version} react-dom@${React.version} --save-exact --silent --force`;
41
+ await $ `npm install -D @pulse-editor/cli@${tag} --silent --force`;
42
+ await $ `npm install @pulse-editor/shared-utils@${tag} @pulse-editor/react-api@${tag} --silent --force`;
43
+ setStep('done');
44
+ }
45
+ return (_jsx(_Fragment, { children: isError ? (_jsxs(Text, { color: 'redBright', children: ["\u274C An error occurred: ", errorMessage || 'Unknown error'] })) : !isInProjectDir ? (_jsx(Text, { color: 'redBright', children: "\u26D4 The current directory does not contain a Pulse Editor project." })) : step === 'check-config' ? (_jsxs(Box, { children: [_jsx(Spinner, { type: "dots" }), _jsx(Text, { children: " Checking configuration..." })] })) : step === 'upgrade' ? (_jsx(_Fragment, { children: _jsxs(Box, { children: [_jsx(Spinner, { type: "dots" }), _jsx(Text, { children: " Upgrading packages..." })] }) })) : (_jsx(Box, { children: _jsx(Text, { color: 'greenBright', children: "\u2705 Upgrade completed successfully." }) })) }));
46
+ }
@@ -0,0 +1 @@
1
+ export declare function publishApp(isStage: boolean): Promise<Response>;
@@ -0,0 +1,27 @@
1
+ import { getToken } from '../token.js';
2
+ import fs from 'fs';
3
+ export async function publishApp(isStage) {
4
+ // Upload the zip file to the server
5
+ // Read pulse.config.json for visibility
6
+ const config = JSON.parse(fs.readFileSync('./dist/client/pulse.config.json', 'utf-8'));
7
+ const visibility = config.visibility;
8
+ const formData = new FormData();
9
+ const buffer = fs.readFileSync('./node_modules/@pulse-editor/dist.zip');
10
+ // @ts-ignore Create a Blob from the buffer
11
+ const blob = new Blob([buffer], {
12
+ type: 'application/zip',
13
+ });
14
+ formData.append('file', blob, 'dist.zip');
15
+ formData.append('visibility', visibility);
16
+ // Send the file to the server
17
+ const res = await fetch(isStage
18
+ ? 'https://localhost:8080/api/app/publish'
19
+ : 'https://pulse-editor.com/api/app/publish', {
20
+ method: 'POST',
21
+ headers: {
22
+ Authorization: `Bearer ${getToken(isStage)}`,
23
+ },
24
+ body: formData,
25
+ });
26
+ return res;
27
+ }
@@ -25,5 +25,12 @@ export declare const flags: {
25
25
  type: "string";
26
26
  shortFlag: string;
27
27
  };
28
+ beta: {
29
+ type: "boolean";
30
+ };
31
+ build: {
32
+ type: "boolean";
33
+ default: true;
34
+ };
28
35
  };
29
36
  export type Flags = typeof flags;
@@ -29,4 +29,11 @@ export const flags = defineFlags({
29
29
  type: 'string',
30
30
  shortFlag: 't',
31
31
  },
32
+ beta: {
33
+ type: 'boolean',
34
+ },
35
+ build: {
36
+ type: 'boolean',
37
+ default: true,
38
+ },
32
39
  });
@@ -27,6 +27,9 @@ const logout = `\
27
27
  `;
28
28
  const publish = `\
29
29
  publish Publish Pulse Editor Extension in current directory to the Pulse Editor Platform.
30
+ Flags:
31
+ --noBuild
32
+ Skip the build step before publishing.
30
33
 
31
34
  `;
32
35
  const create = `\
@@ -71,6 +74,13 @@ const start = `\
71
74
  const clean = `\
72
75
  clean Clean the dist/ directory.
73
76
 
77
+ `;
78
+ const upgrade = `\
79
+ upgrade Upgrade Pulse Editor CLI and related packages to the latest version.
80
+ Flags:
81
+ --beta
82
+ Upgrade to the latest beta version.
83
+
74
84
  `;
75
85
  export const commandsManual = {
76
86
  help,
@@ -84,4 +94,5 @@ export const commandsManual = {
84
94
  build,
85
95
  start,
86
96
  clean,
97
+ upgrade,
87
98
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pulse-editor/cli",
3
- "version": "0.1.1-beta.16",
3
+ "version": "0.1.1-beta.17",
4
4
  "license": "MIT",
5
5
  "bin": {
6
6
  "pulse": "dist/cli.js"
@@ -55,15 +55,15 @@
55
55
  "eslint-plugin-react-hooks": "^7.0.1",
56
56
  "ink-testing-library": "^4.0.0",
57
57
  "prettier": "^3.7.4",
58
- "react": "19.2.2",
59
- "react-dom": "19.2.2",
58
+ "react": "19.2.3",
59
+ "react-dom": "19.2.3",
60
60
  "ts-node": "^10.9.2",
61
61
  "typescript": "^5.9.3",
62
62
  "xo": "^1.2.3"
63
63
  },
64
64
  "peerDependencies": {
65
- "react": "19.2.2",
66
- "react-dom": "19.2.2"
65
+ "react": "19.2.3",
66
+ "react-dom": "19.2.3"
67
67
  },
68
68
  "ava": {
69
69
  "extensions": {