Skip to content

Commit 83b7d34

Browse files
committed
CLI: Install packages after creating new projects
1 parent 780e573 commit 83b7d34

File tree

4 files changed

+69
-41
lines changed

4 files changed

+69
-41
lines changed

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: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,15 @@ export default function App({cli}: {cli: Result<Flags>}) {
3333
) : command === 'create' ? (
3434
<Create cli={cli} />
3535
) : (
36-
<>
37-
<Text color={'redBright'}>Invalid command: {command}</Text>
38-
<Text>
39-
Run <Text color={'blueBright'}>pulse help</Text> to see the list of
40-
available commands.
41-
</Text>
42-
</>
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+
)
4345
)}
4446
</>
4547
);

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

Lines changed: 54 additions & 33 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,15 +46,34 @@ 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 {
5259
await $`git clone https://github.com/ClayPulse/pulse-editor-extension-template.git ${name}`;
53-
setIsCreated(true);
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'),
@@ -65,14 +82,42 @@ export default function Create({cli}: {cli: Result<Flags>}) {
6582

6683
// Write the modified package.json back to the file
6784
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
85+
86+
setMessage(
87+
<Box>
88+
<Spinner type="dots" />
89+
<Text> Installing dependencies...</Text>
90+
</Box>,
91+
);
92+
// Run `npm i`
93+
try {
94+
await execa(`npm install`, {
95+
cwd: path.join(process.cwd(), name),
96+
});
97+
} catch (error) {
98+
setMessage(
99+
<Text color="redBright">
100+
❌ Failed to install dependencies. Please check your internet
101+
connection and try again.
102+
</Text>,
103+
);
104+
return;
105+
}
106+
setMessage(
107+
<Text>🚀 Pulse Editor React app project created successfully!</Text>,
108+
);
68109
}
69110
}
70111

71112
if (projectName) {
72113
// Check if the project already exists
73114
const projectPath = path.join(process.cwd(), projectName);
74115
if (fs.existsSync(projectPath)) {
75-
setIsPathValid(false);
116+
setMessage(
117+
<Text color="redBright">
118+
❌ A project with same name already exists in current path.
119+
</Text>,
120+
);
76121
return;
77122
}
78123
createFromTemplate(projectName);
@@ -116,31 +161,7 @@ export default function Create({cli}: {cli: Result<Flags>}) {
116161

117162
{projectName && (
118163
<>
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-
))}
164+
{framework === 'react' && <>{message}</>}
144165
{framework !== 'react' && (
145166
<Text>
146167
🚧 Currently not available. We'd like to invite you to work on

0 commit comments

Comments
 (0)