@pulse-editor/cli 0.1.1-beta.3 → 0.1.1-beta.30

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.
Files changed (35) hide show
  1. package/dist/app.js +2 -1
  2. package/dist/cli.js +1 -0
  3. package/dist/components/commands/build.js +18 -33
  4. package/dist/components/commands/create.js +38 -12
  5. package/dist/components/commands/dev.js +36 -4
  6. package/dist/components/commands/help.js +2 -1
  7. package/dist/components/commands/preview.js +51 -7
  8. package/dist/components/commands/publish.js +23 -37
  9. package/dist/components/commands/{preview copy.d.ts → upgrade.d.ts} +1 -1
  10. package/dist/components/commands/upgrade.js +53 -0
  11. package/dist/lib/backend/publish-app.d.ts +1 -0
  12. package/dist/lib/backend/publish-app.js +27 -0
  13. package/dist/lib/cli-flags.d.ts +14 -0
  14. package/dist/lib/cli-flags.js +14 -0
  15. package/dist/lib/execa-utils/clean.js +1 -1
  16. package/dist/lib/execa-utils/deps.js +10 -1
  17. package/dist/lib/manual.js +52 -0
  18. package/dist/lib/server/express.js +33 -18
  19. package/dist/lib/server/preview/backend/load-remote.cjs +33 -23
  20. package/dist/lib/server/preview/frontend/index.html +11 -11
  21. package/dist/lib/webpack/compile.d.ts +2 -0
  22. package/dist/lib/webpack/compile.js +28 -0
  23. package/dist/lib/webpack/webpack.config.d.ts +2 -0
  24. package/dist/lib/webpack/webpack.config.js +497 -0
  25. package/package.json +29 -15
  26. package/readme.md +35 -1
  27. package/dist/components/commands/preview copy.js +0 -14
  28. package/dist/components/commands/start copy.d.ts +0 -5
  29. package/dist/components/commands/start copy.js +0 -14
  30. package/dist/lib/deps.d.ts +0 -1
  31. package/dist/lib/deps.js +0 -5
  32. package/dist/lib/node_module_bin.d.ts +0 -1
  33. package/dist/lib/node_module_bin.js +0 -7
  34. package/dist/lib/server/preview/backend/index.d.ts +0 -1
  35. package/dist/lib/server/preview/backend/index.js +0 -23
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
  }
package/dist/cli.js CHANGED
@@ -15,6 +15,7 @@ ${Object.entries(commandsManual)
15
15
  .join('')}
16
16
  Examples
17
17
  pulse help publish
18
+
18
19
  `, {
19
20
  importMeta: import.meta,
20
21
  flags: flags,
@@ -3,6 +3,7 @@ import { useEffect } from 'react';
3
3
  import { execa } from 'execa';
4
4
  import fs from 'fs';
5
5
  import { cleanDist } from '../../lib/execa-utils/clean.js';
6
+ import { webpackCompile } from '../../lib/webpack/compile.js';
6
7
  export default function Build({ cli }) {
7
8
  useEffect(() => {
8
9
  async function buildProd() {
@@ -23,6 +24,19 @@ export default function Build({ cli }) {
23
24
  });
24
25
  }
25
26
  }
27
+ // Create node_modules/.pulse/server directory
28
+ if (!fs.existsSync('node_modules/.pulse/server')) {
29
+ if (process.platform === 'win32') {
30
+ await execa('mkdir node_modules\\.pulse\\server', {
31
+ shell: true,
32
+ });
33
+ }
34
+ else {
35
+ await execa('mkdir -p node_modules/.pulse/server', {
36
+ shell: true,
37
+ });
38
+ }
39
+ }
26
40
  if (process.platform === 'win32') {
27
41
  await execa('xcopy /E /I node_modules\\@pulse-editor\\cli\\dist\\lib\\server node_modules\\.pulse\\server', {
28
42
  shell: true,
@@ -35,40 +49,11 @@ export default function Build({ cli }) {
35
49
  }
36
50
  }
37
51
  await cleanDist();
38
- if (buildTarget === undefined) {
39
- // Start building
40
- await execa('npx webpack --mode production', {
41
- stdio: 'inherit',
42
- shell: true,
43
- env: {
44
- NODE_OPTIONS: '--import=tsx',
45
- },
46
- });
47
- }
48
- else if (buildTarget === 'client') {
49
- // Start building client only
50
- await execa('npx webpack --mode production', {
51
- stdio: 'inherit',
52
- shell: true,
53
- env: {
54
- NODE_OPTIONS: '--import=tsx',
55
- BUILD_TARGET: 'client',
56
- },
57
- });
58
- }
59
- else if (buildTarget === 'server') {
60
- // Start building server only
61
- await execa('npx webpack --mode production', {
62
- stdio: 'inherit',
63
- shell: true,
64
- env: {
65
- NODE_OPTIONS: '--import=tsx',
66
- BUILD_TARGET: 'server',
67
- },
68
- });
52
+ try {
53
+ await webpackCompile('production', buildTarget);
69
54
  }
70
- else {
71
- console.error(`❌ Unknown build target: ${buildTarget}`);
55
+ catch (err) {
56
+ console.error('❌ Webpack build failed', err);
72
57
  }
73
58
  }
74
59
  buildProd();
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
- import { useEffect, useState } from 'react';
2
+ import { useEffect, useMemo, useState } from 'react';
3
3
  import { Box, Text, useApp } from 'ink';
4
4
  import Spinner from 'ink-spinner';
5
5
  import { $, execa } from 'execa';
@@ -10,9 +10,14 @@ import path from 'path';
10
10
  export default function Create({ cli }) {
11
11
  const [framework, setFramework] = useState(undefined);
12
12
  const [projectName, setProjectName] = useState(undefined);
13
+ const [displayName, setDisplayName] = useState(undefined);
13
14
  const [visibility, setVisibility] = useState(undefined);
15
+ const projectPath = useMemo(() => {
16
+ return cli.flags.path ?? projectName;
17
+ }, [projectName, cli]);
14
18
  const [isShowFrameworkSelect, setIsShowFrameworkSelect] = useState(true);
15
19
  const [isShowProjectNameInput, setIsShowProjectNameInput] = useState(false);
20
+ const [isShowDisplayNameInput, setIsShowDisplayNameInput] = useState(false);
16
21
  const [isShowVisibilitySelect, setIsShowVisibilitySelect] = useState(false);
17
22
  const [createMessage, setCreateMessage] = useState();
18
23
  const [errorMessage, setErrorMessage] = useState();
@@ -59,13 +64,26 @@ export default function Create({ cli }) {
59
64
  if (projectName) {
60
65
  // Check if the project already exists
61
66
  const projectPath = path.join(process.cwd(), projectName);
62
- if (fs.existsSync(projectPath)) {
67
+ if (fs.existsSync(projectPath) &&
68
+ fs.lstatSync(projectPath).isDirectory() &&
69
+ fs.readdirSync(projectPath).length > 0) {
63
70
  setErrorMessage(_jsx(Text, { color: "redBright", children: "\u274C A project with same name already exists in current path." }));
64
71
  setTimeout(() => {
65
72
  exit();
66
73
  }, 0);
67
74
  return;
68
75
  }
76
+ const displayName = cli.flags.displayName;
77
+ if (displayName) {
78
+ setDisplayName(displayName);
79
+ }
80
+ else {
81
+ setIsShowDisplayNameInput(true);
82
+ }
83
+ }
84
+ }, [projectName, cli]);
85
+ useEffect(() => {
86
+ if (displayName) {
69
87
  const visibility = cli.flags.visibility;
70
88
  if (visibility) {
71
89
  setVisibility(visibility);
@@ -74,50 +92,55 @@ export default function Create({ cli }) {
74
92
  setIsShowVisibilitySelect(true);
75
93
  }
76
94
  }
77
- }, [projectName, cli]);
95
+ }, [displayName, cli]);
78
96
  useEffect(() => {
79
97
  if (visibility && projectName) {
80
98
  createFromTemplate(projectName, visibility);
81
99
  }
82
100
  }, [visibility, projectName]);
83
101
  async function createFromTemplate(name, visibility) {
102
+ if (!projectPath) {
103
+ setErrorMessage(_jsx(Text, { color: "redBright", children: "\u274C Project path is not defined." }));
104
+ return;
105
+ }
84
106
  if (framework === 'react') {
85
107
  // Clone the template repository
86
108
  setCreateMessage(_jsxs(Box, { children: [_jsx(Spinner, { type: "dots" }), _jsx(Text, { children: " Creating a new Pulse Editor app using React template..." })] }));
87
109
  try {
88
- await $ `git clone --depth 1 https://github.com/ClayPulse/pulse-app-template.git ${name}`;
110
+ await $ `git clone --depth 1 https://github.com/ClayPulse/pulse-app-template.git ${projectPath}`;
89
111
  }
90
112
  catch (error) {
91
- setCreateMessage(_jsx(Text, { color: "redBright", children: "\u274C Failed to clone the template. Please check your internet connection and try again." }));
113
+ setCreateMessage(_jsxs(Text, { color: "redBright", children: ["\u274C Failed to clone the template. ", error.message] }));
92
114
  return;
93
115
  }
94
116
  // Modify the package.json file to update the name
95
117
  setCreateMessage(_jsxs(Box, { children: [_jsx(Spinner, { type: "dots" }), _jsx(Text, { children: " Initializing project..." })] }));
96
118
  /* Setup pulse.config.ts */
97
- const pulseConfigPath = path.join(process.cwd(), name, 'pulse.config.ts');
119
+ const pulseConfigPath = path.join(process.cwd(), projectPath, 'pulse.config.ts');
98
120
  let pulseConfig = fs.readFileSync(pulseConfigPath, 'utf8');
99
121
  // Modify visibility by matching the block that starts with 'visibility:',
100
122
  // and replacing the entire line with the new visibility value.
101
123
  pulseConfig = pulseConfig.replace(/visibility:\s*['"`](public|unlisted|private)['"`],?/, `visibility: '${visibility}',`);
102
124
  fs.writeFileSync(pulseConfigPath, pulseConfig);
103
125
  /* Setup packages.json */
104
- const packageJsonPath = path.join(process.cwd(), name, 'package.json');
126
+ const packageJsonPath = path.join(process.cwd(), projectPath, 'package.json');
105
127
  const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
106
128
  packageJson.name = name.replaceAll('-', '_');
129
+ packageJson.displayName = displayName;
107
130
  // Write the modified package.json back to the file
108
131
  fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
109
132
  // Remove the .git directory
110
- const gitDirPath = path.join(process.cwd(), name, '.git');
133
+ const gitDirPath = path.join(process.cwd(), projectPath, '.git');
111
134
  if (fs.existsSync(gitDirPath)) {
112
135
  fs.rmSync(gitDirPath, { recursive: true, force: true });
113
136
  }
114
137
  // Remove the .github directory
115
- const githubDirPath = path.join(process.cwd(), name, '.github');
138
+ const githubDirPath = path.join(process.cwd(), projectPath, '.github');
116
139
  if (fs.existsSync(githubDirPath)) {
117
140
  fs.rmSync(githubDirPath, { recursive: true, force: true });
118
141
  }
119
142
  // Remove LICENSE file
120
- const licenseFilePath = path.join(process.cwd(), name, 'LICENSE');
143
+ const licenseFilePath = path.join(process.cwd(), projectPath, 'LICENSE');
121
144
  if (fs.existsSync(licenseFilePath)) {
122
145
  fs.rmSync(licenseFilePath, { force: true });
123
146
  }
@@ -125,7 +148,7 @@ export default function Create({ cli }) {
125
148
  // Run `npm i`
126
149
  try {
127
150
  await execa(`npm install`, {
128
- cwd: path.join(process.cwd(), name),
151
+ cwd: path.join(process.cwd(), projectPath),
129
152
  shell: true,
130
153
  });
131
154
  }
@@ -136,7 +159,7 @@ export default function Create({ cli }) {
136
159
  setCreateMessage(_jsx(Text, { children: "\uD83D\uDE80 Pulse Editor React app project created successfully!" }));
137
160
  }
138
161
  }
139
- 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 })] }));
162
+ return (_jsxs(_Fragment, { children: [isShowFrameworkSelect && (_jsx(FrameworkSelect, { cli: cli, frameworkItems: frameworkItems, framework: framework, setFramework: setFramework })), isShowProjectNameInput && (_jsx(ProjectNameInput, { projectName: projectName, setProjectName: setProjectName })), isShowDisplayNameInput && (_jsx(DisplayNameInput, { projectName: projectName ?? '', displayName: displayName, setDisplayName: setDisplayName })), 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 })] }));
140
163
  }
141
164
  function FrameworkSelect({ cli, frameworkItems, framework, setFramework, }) {
142
165
  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 => {
@@ -146,6 +169,9 @@ function FrameworkSelect({ cli, frameworkItems, framework, setFramework, }) {
146
169
  function ProjectNameInput({ projectName, setProjectName, }) {
147
170
  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 })] }) }));
148
171
  }
172
+ function DisplayNameInput({ projectName, displayName, setDisplayName, }) {
173
+ return (_jsx(_Fragment, { children: _jsxs(Box, { children: [_jsxs(Text, { children: ["Enter your project display name: (default: ", projectName, ")"] }), _jsx(UncontrolledTextInput, { onSubmit: value => setTimeout(() => setDisplayName(value.length > 0 ? value : projectName), 0), focus: displayName === undefined })] }) }));
174
+ }
149
175
  function VisibilitySelect({ visibility, setVisibility, }) {
150
176
  return (_jsxs(_Fragment, { children: [_jsx(Text, { children: "Enter marketplace visibility for your project:" }), _jsx(SelectInput, { items: [
151
177
  { label: 'Public', value: 'public' },
@@ -1,10 +1,10 @@
1
- import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
2
- import { Text } from 'ink';
1
+ import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
3
2
  import { useEffect } from 'react';
4
3
  import { execa } from 'execa';
5
4
  import fs from 'fs';
6
5
  import { getDepsBinPath } from '../../lib/execa-utils/deps.js';
7
6
  import { cleanDist } from '../../lib/execa-utils/clean.js';
7
+ import { webpackCompile } from '../../lib/webpack/compile.js';
8
8
  export default function Dev({ cli }) {
9
9
  useEffect(() => {
10
10
  async function startDevServer() {
@@ -22,6 +22,19 @@ export default function Dev({ cli }) {
22
22
  });
23
23
  }
24
24
  }
25
+ // Create node_modules/.pulse/server directory
26
+ if (!fs.existsSync('node_modules/.pulse/server')) {
27
+ if (process.platform === 'win32') {
28
+ await execa('mkdir node_modules\\.pulse\\server', {
29
+ shell: true,
30
+ });
31
+ }
32
+ else {
33
+ await execa('mkdir -p node_modules/.pulse/server', {
34
+ shell: true,
35
+ });
36
+ }
37
+ }
25
38
  if (process.platform === 'win32') {
26
39
  await execa('xcopy /E /I node_modules\\@pulse-editor\\cli\\dist\\lib\\server node_modules\\.pulse\\server', {
27
40
  shell: true,
@@ -34,7 +47,14 @@ export default function Dev({ cli }) {
34
47
  }
35
48
  // Start dev server
36
49
  await cleanDist();
37
- await execa(`${getDepsBinPath('concurrently')} --prefix none "webpack --mode development --watch" "tsx watch --clear-screen=false node_modules/@pulse-editor/cli/dist/lib/server/express.js"`, {
50
+ // Start webpack in dev watch mode and watch for changes
51
+ const compiler = await webpackCompile('development', undefined, true);
52
+ // Start server with tsx
53
+ await execa(getDepsBinPath('tsx'), [
54
+ 'watch',
55
+ '--clear-screen=false',
56
+ 'node_modules/@pulse-editor/cli/dist/lib/server/express.js',
57
+ ], {
38
58
  stdio: 'inherit',
39
59
  shell: true,
40
60
  env: {
@@ -42,8 +62,20 @@ export default function Dev({ cli }) {
42
62
  NODE_ENV: 'development',
43
63
  },
44
64
  });
65
+ // Handle process exit to close webpack compiler
66
+ process.on('SIGINT', () => {
67
+ if (compiler && typeof compiler.close === 'function') {
68
+ compiler.close(() => {
69
+ process.exit();
70
+ });
71
+ }
72
+ else {
73
+ process.exit();
74
+ }
75
+ });
45
76
  }
77
+ console.log('🚀 Starting development server...');
46
78
  startDevServer();
47
79
  }, []);
48
- return (_jsx(_Fragment, { children: _jsx(Text, { children: "Starting dev server..." }) }));
80
+ return _jsx(_Fragment, {});
49
81
  }
@@ -4,5 +4,6 @@ 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 (_jsx(_Fragment, { children: subCommand ? (_jsx(Text, { children: commandsManual[subCommand] })) : (_jsxs(_Fragment, { children: [_jsx(Header, {}), _jsx(Text, { children: cli.help })] })) }));
7
+ return (_jsx(_Fragment, { children: subCommand ? (_jsx(Text, { children: commandsManual[subCommand]?.trimEnd() ??
8
+ `No help found for command: ${subCommand}` })) : (_jsxs(_Fragment, { children: [_jsx(Header, {}), _jsx(Text, { children: cli.help })] })) }));
8
9
  }
@@ -1,10 +1,10 @@
1
- import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
2
- import { Text } from 'ink';
1
+ import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
3
2
  import { useEffect } from 'react';
4
3
  import { execa } from 'execa';
5
4
  import fs from 'fs';
6
5
  import { getDepsBinPath } from '../../lib/execa-utils/deps.js';
7
6
  import { cleanDist } from '../../lib/execa-utils/clean.js';
7
+ import { webpackCompile } from '../../lib/webpack/compile.js';
8
8
  export default function Preview({ cli }) {
9
9
  useEffect(() => {
10
10
  async function startPreviewServer() {
@@ -22,9 +22,19 @@ export default function Preview({ cli }) {
22
22
  });
23
23
  }
24
24
  }
25
- await execa('mkdir "node_modules/.pulse/server"', {
26
- shell: true,
27
- });
25
+ // Create node_modules/.pulse/server directory
26
+ if (!fs.existsSync('node_modules/.pulse/server')) {
27
+ if (process.platform === 'win32') {
28
+ await execa('mkdir node_modules\\.pulse\\server', {
29
+ shell: true,
30
+ });
31
+ }
32
+ else {
33
+ await execa('mkdir -p node_modules/.pulse/server', {
34
+ shell: true,
35
+ });
36
+ }
37
+ }
28
38
  if (process.platform === 'win32') {
29
39
  await execa('xcopy /E /I node_modules\\@pulse-editor\\cli\\dist\\lib\\server node_modules\\.pulse\\server', {
30
40
  shell: true,
@@ -37,7 +47,29 @@ export default function Preview({ cli }) {
37
47
  }
38
48
  // Start preview server
39
49
  await cleanDist();
40
- await execa(`${getDepsBinPath('concurrently')} --prefix none "npx webpack --mode development --watch" "tsx watch --clear-screen=false node_modules/@pulse-editor/cli/dist/lib/server/express.js"`, {
50
+ // await execa(
51
+ // getDepsBinPath('concurrently'),
52
+ // [
53
+ // '--prefix',
54
+ // 'none',
55
+ // '"npx webpack --mode development --watch"',
56
+ // '"tsx watch --clear-screen=false node_modules/@pulse-editor/cli/dist/lib/server/express.js"',
57
+ // ],
58
+ // {
59
+ // stdio: 'inherit',
60
+ // shell: true,
61
+ // env: {
62
+ // NODE_OPTIONS: '--import=tsx',
63
+ // PREVIEW: 'true',
64
+ // },
65
+ // },
66
+ // );
67
+ const compiler = await webpackCompile('preview', undefined, true);
68
+ await execa(getDepsBinPath('tsx'), [
69
+ 'watch',
70
+ '--clear-screen=false',
71
+ 'node_modules/@pulse-editor/cli/dist/lib/server/express.js',
72
+ ], {
41
73
  stdio: 'inherit',
42
74
  shell: true,
43
75
  env: {
@@ -45,8 +77,20 @@ export default function Preview({ cli }) {
45
77
  PREVIEW: 'true',
46
78
  },
47
79
  });
80
+ // Handle process exit to close webpack compiler
81
+ process.on('SIGINT', () => {
82
+ if (compiler && typeof compiler.close === 'function') {
83
+ compiler.close(() => {
84
+ process.exit();
85
+ });
86
+ }
87
+ else {
88
+ process.exit();
89
+ }
90
+ });
48
91
  }
92
+ console.log('🚀 Starting preview server...');
49
93
  startPreviewServer();
50
94
  }, []);
51
- return (_jsx(_Fragment, { children: _jsx(Text, { children: "Starting preview server..." }) }));
95
+ return _jsx(_Fragment, {});
52
96
  }
@@ -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
- await $({ cwd: 'dist' }) `zip -r ../node_modules/@pulse-editor/dist.zip *`;
68
+ await $({ cwd: 'dist' }) `zip -r ../node_modules/@pulse-editor/dist.zip .`;
61
69
  }
62
70
  catch (error) {
63
- setIsBuildingError(true);
64
- setIsBuilding(false);
65
- setFailureMessage('Failed to zip the build output.');
71
+ setIsZippingError(true);
72
+ setFailureMessage('Failed to zip the build output. ' + error.message);
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 && (_jsxs(Text, { color: 'redBright', children: ["\u274C Error zipping the build output. ", failureMessage] })), 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
  }
@@ -1,5 +1,5 @@
1
1
  import { Result } from 'meow';
2
2
  import { Flags } from '../../lib/cli-flags.js';
3
- export default function Preview({ cli }: {
3
+ export default function Upgrade({ cli }: {
4
4
  cli: Result<Flags>;
5
5
  }): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,53 @@
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
+ // Remove webpack.config.ts if exists
44
+ const webpackConfigPath = `${process.cwd()}/webpack.config.ts`;
45
+ if (fs.existsSync(webpackConfigPath)) {
46
+ fs.unlinkSync(webpackConfigPath);
47
+ }
48
+ // Uninstall @module-federation/node html-webpack-plugin copy-webpack-plugin glob mini-css-extract-plugin webpack webpack-cli webpack-dev-server
49
+ await $ `npm uninstall @module-federation/node html-webpack-plugin copy-webpack-plugin glob mini-css-extract-plugin webpack webpack-cli webpack-dev-server --silent --force`;
50
+ setStep('done');
51
+ }
52
+ 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." }) })) }));
53
+ }
@@ -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,19 @@ 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
+ };
35
+ path: {
36
+ type: "string";
37
+ shortFlag: string;
38
+ };
39
+ displayName: {
40
+ type: "string";
41
+ };
28
42
  };
29
43
  export type Flags = typeof flags;