Skip to content

Commit 39d2015

Browse files
authored
Merge pull request #36 from ClayPulse/35-add-video-editor-view
35 add video editor view
2 parents feab595 + ffaa425 commit 39d2015

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1403
-330
lines changed

.changeset/cruel-zoos-play.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@pulse-editor/shared-utils": patch
3+
"@pulse-editor/react-api": patch
4+
---
5+
6+
Add image and video gen hooks

.changeset/lazy-zebras-mate.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@pulse-editor/shared-utils": patch
3+
"@pulse-editor/react-api": patch
4+
---
5+
6+
Add useLoading, image gen, video gen hooks

.changeset/pre.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@
1717
"beige-pandas-rhyme",
1818
"calm-rivers-march",
1919
"chatty-trains-beam",
20+
"cruel-zoos-play",
2021
"curvy-places-wash",
2122
"dirty-swans-rescue",
2223
"early-pumas-listen",
2324
"hot-symbols-fry",
2425
"large-moose-tap",
26+
"lazy-zebras-mate",
2527
"mighty-ghosts-crash",
2628
"real-knives-rest",
2729
"rude-ducks-design",

npm-packages/cli/package.json

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

npm-packages/cli/readme.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
$ npm install --global @pulse-editor/cli
55
```
66

7+
## Link local development version
8+
```bash
9+
npm run link
10+
```
11+
712
## CLI Manual
813

914
```

npm-packages/cli/source/app.tsx

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import React, {useEffect, useState} from 'react';
22
import {Result} from 'meow';
3+
import {Text} from 'ink';
4+
35
import Login from './components/commands/login.js';
46
import {Flags} from './lib/cli-flags.js';
57
import Publish from './components/commands/publish.js';
@@ -18,12 +20,29 @@ export default function App({cli}: {cli: Result<Flags>}) {
1820

1921
return (
2022
<>
21-
{command === 'help' && <Help cli={cli} />}
22-
{command === 'chat' && <Chat cli={cli} />}
23-
{command === 'login' && <Login cli={cli} />}
24-
{command === 'logout' && <Logout cli={cli} />}
25-
{command === 'publish' && <Publish cli={cli} />}
26-
{command === 'create' && <Create cli={cli} />}
23+
{command === 'help' ? (
24+
<Help cli={cli} />
25+
) : command === 'chat' ? (
26+
<Chat cli={cli} />
27+
) : command === 'login' ? (
28+
<Login cli={cli} />
29+
) : command === 'logout' ? (
30+
<Logout cli={cli} />
31+
) : command === 'publish' ? (
32+
<Publish cli={cli} />
33+
) : command === 'create' ? (
34+
<Create cli={cli} />
35+
) : (
36+
command !== undefined && (
37+
<>
38+
<Text color={'redBright'}>Invalid command: {command}</Text>
39+
<Text>
40+
Run <Text color={'blueBright'}>pulse help</Text> to see the list
41+
of available commands.
42+
</Text>
43+
</>
44+
)
45+
)}
2746
</>
2847
);
2948
}

npm-packages/cli/source/components/commands/create.tsx

Lines changed: 68 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import {Result} from 'meow';
2-
import React, {useEffect, useState} from 'react';
2+
import React, {ReactNode, useEffect, useState} from 'react';
33
import {Flags} from '../../lib/cli-flags.js';
44
import {Box, Text} from 'ink';
55
import Spinner from 'ink-spinner';
6-
import {$} from 'execa';
6+
import {$, execa} from 'execa';
77
import SelectInput from 'ink-select-input';
88
import {Item} from '../../lib/types.js';
99
import {UncontrolledTextInput} from 'ink-text-input';
@@ -14,11 +14,9 @@ export default function Create({cli}: {cli: Result<Flags>}) {
1414
const [framework, setFramework] = useState<string | undefined>(undefined);
1515
const [projectName, setProjectName] = useState<string | undefined>(undefined);
1616

17-
const [isCreated, setIsCreated] = useState(false);
1817
const [isFrameworkSelected, setIsFrameworkSelected] = useState(false);
1918

20-
const [isPathValid, setIsPathValid] = useState(true);
21-
const [isCloneFailed, setIsCloneFailed] = useState(false);
19+
const [message, setMessage] = useState<ReactNode>();
2220

2321
const frameworkItems: Item<string>[] = [
2422
{
@@ -48,31 +46,90 @@ export default function Create({cli}: {cli: Result<Flags>}) {
4846
async function createFromTemplate(name: string) {
4947
if (framework === 'react') {
5048
// Clone the template repository
49+
setMessage(
50+
<Box>
51+
<Spinner type="dots" />
52+
<Text>
53+
{' '}
54+
Creating a new Pulse Editor app using React template...
55+
</Text>
56+
</Box>,
57+
);
5158
try {
52-
await $`git clone https://github.com/ClayPulse/pulse-editor-extension-template.git ${name}`;
53-
setIsCreated(true);
59+
await $`git clone --depth 1 https://github.com/ClayPulse/pulse-editor-extension-template.git ${name}`;
5460
} catch (error) {
55-
setIsCloneFailed(true);
61+
setMessage(
62+
<Text color="redBright">
63+
❌ Failed to clone the template. Please check your internet
64+
connection and try again.
65+
</Text>,
66+
);
5667
return;
5768
}
5869

5970
// Modify the package.json file to update the name
71+
setMessage(
72+
<Box>
73+
<Spinner type="dots" />
74+
<Text> Initializing project...</Text>
75+
</Box>,
76+
);
6077
const packageJsonPath = path.join(process.cwd(), name, 'package.json');
6178
const packageJson = JSON.parse(
6279
fs.readFileSync(packageJsonPath, 'utf8'),
6380
);
64-
packageJson.name = name;
81+
packageJson.name = name.replaceAll('-', '_');
6582

6683
// Write the modified package.json back to the file
6784
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
85+
86+
// Remove the .git directory
87+
const gitDirPath = path.join(process.cwd(), name, '.git');
88+
if (fs.existsSync(gitDirPath)) {
89+
fs.rmSync(gitDirPath, {recursive: true, force: true});
90+
}
91+
92+
// Remove the .github directory
93+
const githubDirPath = path.join(process.cwd(), name, '.github');
94+
if (fs.existsSync(githubDirPath)) {
95+
fs.rmSync(githubDirPath, {recursive: true, force: true});
96+
}
97+
98+
setMessage(
99+
<Box>
100+
<Spinner type="dots" />
101+
<Text> Installing dependencies...</Text>
102+
</Box>,
103+
);
104+
// Run `npm i`
105+
try {
106+
await execa(`npm install`, {
107+
cwd: path.join(process.cwd(), name),
108+
});
109+
} catch (error) {
110+
setMessage(
111+
<Text color="redBright">
112+
❌ Failed to install dependencies. Please check your internet
113+
connection and try again.
114+
</Text>,
115+
);
116+
return;
117+
}
118+
setMessage(
119+
<Text>🚀 Pulse Editor React app project created successfully!</Text>,
120+
);
68121
}
69122
}
70123

71124
if (projectName) {
72125
// Check if the project already exists
73126
const projectPath = path.join(process.cwd(), projectName);
74127
if (fs.existsSync(projectPath)) {
75-
setIsPathValid(false);
128+
setMessage(
129+
<Text color="redBright">
130+
❌ A project with same name already exists in current path.
131+
</Text>,
132+
);
76133
return;
77134
}
78135
createFromTemplate(projectName);
@@ -116,31 +173,7 @@ export default function Create({cli}: {cli: Result<Flags>}) {
116173

117174
{projectName && (
118175
<>
119-
{framework === 'react' &&
120-
(!isPathValid ? (
121-
<Text color="redBright">
122-
❌ A project with same name already exists in current path.
123-
</Text>
124-
) : isCloneFailed ? (
125-
<Text color="redBright">
126-
❌ Failed to clone the template. Please check your internet
127-
connection and try again.
128-
</Text>
129-
) : isCreated ? (
130-
<Text>
131-
🚀 Pulse Editor React app project created successfully!
132-
</Text>
133-
) : (
134-
<>
135-
<Box>
136-
<Spinner type="dots" />
137-
<Text>
138-
{' '}
139-
Creating a new Pulse Editor app using React template...
140-
</Text>
141-
</Box>
142-
</>
143-
))}
176+
{framework === 'react' && <>{message}</>}
144177
{framework !== 'react' && (
145178
<Text>
146179
🚧 Currently not available. We'd like to invite you to work on

npm-packages/react-api/CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
# @pulse-editor/react-api
22

3+
## 0.1.1-alpha.18
4+
5+
### Patch Changes
6+
7+
- Add image and video gen hooks
8+
- Updated dependencies
9+
- @pulse-editor/shared-utils@0.1.1-alpha.18
10+
11+
## 0.1.1-alpha.17
12+
13+
### Patch Changes
14+
15+
- Add useLoading, image gen, video gen hooks
16+
- Updated dependencies
17+
- @pulse-editor/shared-utils@0.1.1-alpha.17
18+
319
## 0.1.1-alpha.16
420

521
### Patch Changes

npm-packages/react-api/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pulse-editor/react-api",
3-
"version": "0.1.1-alpha.16",
3+
"version": "0.1.1-alpha.18",
44
"main": "dist/main.js",
55
"files": [
66
"dist"
@@ -38,7 +38,7 @@
3838
"typescript-eslint": "^8.30.1"
3939
},
4040
"peerDependencies": {
41-
"@pulse-editor/shared-utils": "0.1.1-alpha.16",
41+
"@pulse-editor/shared-utils": "0.1.1-alpha.18",
4242
"react": "^19.0.0",
4343
"react-dom": "^19.0.0"
4444
}

npm-packages/react-api/src/hooks/editor/use-file-view.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import useIMC from "../../lib/use-imc";
88

99
export default function useFileView() {
1010
const [viewModel, setViewModel] = useState<ViewModel | undefined>(undefined);
11-
const [isLoaded, setIsLoaded] = useState(false);
1211

1312
const receiverHandlerMap = new Map<
1413
IMCMessageTypeEnum,
@@ -25,12 +24,6 @@ export default function useFileView() {
2524
}
2625
}, [isReady]);
2726

28-
useEffect(() => {
29-
if (isLoaded) {
30-
imc?.sendMessage(IMCMessageTypeEnum.Loaded);
31-
}
32-
}, [isLoaded, imc]);
33-
3427
function updateViewModel(viewModel: ViewModel) {
3528
// sender.sendMessage(ViewBoxMessageTypeEnum.ViewFile, JSON.stringify(file));
3629
imc?.sendMessage(IMCMessageTypeEnum.WriteViewFile, viewModel);
@@ -39,6 +32,5 @@ export default function useFileView() {
3932
return {
4033
viewModel,
4134
updateViewModel,
42-
setIsLoaded,
4335
};
4436
}

0 commit comments

Comments
 (0)