@pulse-editor/cli 0.1.0-beta.0 → 0.1.0-beta.1
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 +9 -7
- package/dist/components/commands/create.js +39 -16
- package/package.json +1 -1
- package/readme.md +10 -1
package/dist/app.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React, { useEffect, useState } from 'react';
|
|
2
|
+
import { Text } from 'ink';
|
|
2
3
|
import Login from './components/commands/login.js';
|
|
3
4
|
import Publish from './components/commands/publish.js';
|
|
4
5
|
import Help from './components/commands/help.js';
|
|
@@ -11,11 +12,12 @@ export default function App({ cli }) {
|
|
|
11
12
|
const cmd = cli.input[0] ?? 'help';
|
|
12
13
|
setCommand(cmd);
|
|
13
14
|
}, [cli.input]);
|
|
14
|
-
return (React.createElement(React.Fragment, null,
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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."))))));
|
|
21
23
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { useEffect, useState } from 'react';
|
|
2
2
|
import { Box, Text } from 'ink';
|
|
3
3
|
import Spinner from 'ink-spinner';
|
|
4
|
-
import {
|
|
4
|
+
import { $, execa } from 'execa';
|
|
5
5
|
import SelectInput from 'ink-select-input';
|
|
6
6
|
import { UncontrolledTextInput } from 'ink-text-input';
|
|
7
7
|
import fs from 'fs';
|
|
@@ -9,10 +9,8 @@ import path from 'path';
|
|
|
9
9
|
export default function Create({ cli }) {
|
|
10
10
|
const [framework, setFramework] = useState(undefined);
|
|
11
11
|
const [projectName, setProjectName] = useState(undefined);
|
|
12
|
-
const [isCreated, setIsCreated] = useState(false);
|
|
13
12
|
const [isFrameworkSelected, setIsFrameworkSelected] = useState(false);
|
|
14
|
-
const [
|
|
15
|
-
const [isCloneFailed, setIsCloneFailed] = useState(false);
|
|
13
|
+
const [message, setMessage] = useState();
|
|
16
14
|
const frameworkItems = [
|
|
17
15
|
{
|
|
18
16
|
label: 'React',
|
|
@@ -39,27 +37,58 @@ export default function Create({ cli }) {
|
|
|
39
37
|
async function createFromTemplate(name) {
|
|
40
38
|
if (framework === 'react') {
|
|
41
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...")));
|
|
42
45
|
try {
|
|
43
|
-
await $ `git clone https://github.com/ClayPulse/pulse-editor-extension-template.git ${name}`;
|
|
44
|
-
setIsCreated(true);
|
|
46
|
+
await $ `git clone --depth 1 https://github.com/ClayPulse/pulse-editor-extension-template.git ${name}`;
|
|
45
47
|
}
|
|
46
48
|
catch (error) {
|
|
47
|
-
|
|
49
|
+
setMessage(React.createElement(Text, { color: "redBright" }, "\u274C Failed to clone the template. Please check your internet connection and try again."));
|
|
48
50
|
return;
|
|
49
51
|
}
|
|
50
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...")));
|
|
51
56
|
const packageJsonPath = path.join(process.cwd(), name, 'package.json');
|
|
52
57
|
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
53
|
-
packageJson.name = name;
|
|
58
|
+
packageJson.name = name.replaceAll('-', '_');
|
|
54
59
|
// Write the modified package.json back to the file
|
|
55
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!"));
|
|
56
85
|
}
|
|
57
86
|
}
|
|
58
87
|
if (projectName) {
|
|
59
88
|
// Check if the project already exists
|
|
60
89
|
const projectPath = path.join(process.cwd(), projectName);
|
|
61
90
|
if (fs.existsSync(projectPath)) {
|
|
62
|
-
|
|
91
|
+
setMessage(React.createElement(Text, { color: "redBright" }, "\u274C A project with same name already exists in current path."));
|
|
63
92
|
return;
|
|
64
93
|
}
|
|
65
94
|
createFromTemplate(projectName);
|
|
@@ -82,12 +111,6 @@ export default function Create({ cli }) {
|
|
|
82
111
|
React.createElement(Text, null, "Enter your project name: "),
|
|
83
112
|
React.createElement(UncontrolledTextInput, { onSubmit: value => setProjectName(value), focus: projectName === undefined })),
|
|
84
113
|
projectName && (React.createElement(React.Fragment, null,
|
|
85
|
-
framework === 'react' &&
|
|
86
|
-
(!isPathValid ? (React.createElement(Text, { color: "redBright" }, "\u274C A project with same name already exists in current path.")) : isCloneFailed ? (React.createElement(Text, { color: "redBright" }, "\u274C Failed to clone the template. Please check your internet connection and try again.")) : isCreated ? (React.createElement(Text, null, "\uD83D\uDE80 Pulse Editor React app project created successfully!")) : (React.createElement(React.Fragment, null,
|
|
87
|
-
React.createElement(Box, null,
|
|
88
|
-
React.createElement(Spinner, { type: "dots" }),
|
|
89
|
-
React.createElement(Text, null,
|
|
90
|
-
' ',
|
|
91
|
-
"Creating a new Pulse Editor app using React template..."))))),
|
|
114
|
+
framework === 'react' && React.createElement(React.Fragment, null, message),
|
|
92
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."))))))));
|
|
93
116
|
}
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
# Pulse CLI
|
|
2
2
|
## Install
|
|
3
|
-
|
|
4
3
|
```bash
|
|
5
4
|
$ npm install --global @pulse-editor/cli
|
|
6
5
|
```
|
|
7
6
|
|
|
7
|
+
## Link local development version
|
|
8
|
+
```bash
|
|
9
|
+
npm run link
|
|
10
|
+
```
|
|
11
|
+
|
|
8
12
|
## CLI Manual
|
|
9
13
|
|
|
10
14
|
```
|
|
@@ -41,3 +45,8 @@ $ npm install --global @pulse-editor/cli
|
|
|
41
45
|
pulse help publish
|
|
42
46
|
|
|
43
47
|
```
|
|
48
|
+
|
|
49
|
+
## Development
|
|
50
|
+
```
|
|
51
|
+
npm run dev
|
|
52
|
+
```
|