@pulse-editor/cli 0.1.1-beta.24 → 0.1.1-beta.26
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.
|
@@ -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';
|
|
@@ -11,6 +11,9 @@ export default function Create({ cli }) {
|
|
|
11
11
|
const [framework, setFramework] = useState(undefined);
|
|
12
12
|
const [projectName, setProjectName] = useState(undefined);
|
|
13
13
|
const [visibility, setVisibility] = useState(undefined);
|
|
14
|
+
const projectPath = useMemo(() => {
|
|
15
|
+
return cli.flags.path ?? projectName;
|
|
16
|
+
}, [projectName, cli]);
|
|
14
17
|
const [isShowFrameworkSelect, setIsShowFrameworkSelect] = useState(true);
|
|
15
18
|
const [isShowProjectNameInput, setIsShowProjectNameInput] = useState(false);
|
|
16
19
|
const [isShowVisibilitySelect, setIsShowVisibilitySelect] = useState(false);
|
|
@@ -83,43 +86,47 @@ export default function Create({ cli }) {
|
|
|
83
86
|
}
|
|
84
87
|
}, [visibility, projectName]);
|
|
85
88
|
async function createFromTemplate(name, visibility) {
|
|
89
|
+
if (!projectPath) {
|
|
90
|
+
setErrorMessage(_jsx(Text, { color: "redBright", children: "\u274C Project path is not defined." }));
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
86
93
|
if (framework === 'react') {
|
|
87
94
|
// Clone the template repository
|
|
88
95
|
setCreateMessage(_jsxs(Box, { children: [_jsx(Spinner, { type: "dots" }), _jsx(Text, { children: " Creating a new Pulse Editor app using React template..." })] }));
|
|
89
96
|
try {
|
|
90
|
-
await $ `git clone --depth 1 https://github.com/ClayPulse/pulse-app-template.git ${
|
|
97
|
+
await $ `git clone --depth 1 https://github.com/ClayPulse/pulse-app-template.git ${projectPath}`;
|
|
91
98
|
}
|
|
92
99
|
catch (error) {
|
|
93
|
-
setCreateMessage(
|
|
100
|
+
setCreateMessage(_jsxs(Text, { color: "redBright", children: ["\u274C Failed to clone the template. ", error.message] }));
|
|
94
101
|
return;
|
|
95
102
|
}
|
|
96
103
|
// Modify the package.json file to update the name
|
|
97
104
|
setCreateMessage(_jsxs(Box, { children: [_jsx(Spinner, { type: "dots" }), _jsx(Text, { children: " Initializing project..." })] }));
|
|
98
105
|
/* Setup pulse.config.ts */
|
|
99
|
-
const pulseConfigPath = path.join(process.cwd(),
|
|
106
|
+
const pulseConfigPath = path.join(process.cwd(), projectPath, 'pulse.config.ts');
|
|
100
107
|
let pulseConfig = fs.readFileSync(pulseConfigPath, 'utf8');
|
|
101
108
|
// Modify visibility by matching the block that starts with 'visibility:',
|
|
102
109
|
// and replacing the entire line with the new visibility value.
|
|
103
110
|
pulseConfig = pulseConfig.replace(/visibility:\s*['"`](public|unlisted|private)['"`],?/, `visibility: '${visibility}',`);
|
|
104
111
|
fs.writeFileSync(pulseConfigPath, pulseConfig);
|
|
105
112
|
/* Setup packages.json */
|
|
106
|
-
const packageJsonPath = path.join(process.cwd(),
|
|
113
|
+
const packageJsonPath = path.join(process.cwd(), projectPath, 'package.json');
|
|
107
114
|
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
108
115
|
packageJson.name = name.replaceAll('-', '_');
|
|
109
116
|
// Write the modified package.json back to the file
|
|
110
117
|
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
|
|
111
118
|
// Remove the .git directory
|
|
112
|
-
const gitDirPath = path.join(process.cwd(),
|
|
119
|
+
const gitDirPath = path.join(process.cwd(), projectPath, '.git');
|
|
113
120
|
if (fs.existsSync(gitDirPath)) {
|
|
114
121
|
fs.rmSync(gitDirPath, { recursive: true, force: true });
|
|
115
122
|
}
|
|
116
123
|
// Remove the .github directory
|
|
117
|
-
const githubDirPath = path.join(process.cwd(),
|
|
124
|
+
const githubDirPath = path.join(process.cwd(), projectPath, '.github');
|
|
118
125
|
if (fs.existsSync(githubDirPath)) {
|
|
119
126
|
fs.rmSync(githubDirPath, { recursive: true, force: true });
|
|
120
127
|
}
|
|
121
128
|
// Remove LICENSE file
|
|
122
|
-
const licenseFilePath = path.join(process.cwd(),
|
|
129
|
+
const licenseFilePath = path.join(process.cwd(), projectPath, 'LICENSE');
|
|
123
130
|
if (fs.existsSync(licenseFilePath)) {
|
|
124
131
|
fs.rmSync(licenseFilePath, { force: true });
|
|
125
132
|
}
|
|
@@ -127,7 +134,7 @@ export default function Create({ cli }) {
|
|
|
127
134
|
// Run `npm i`
|
|
128
135
|
try {
|
|
129
136
|
await execa(`npm install`, {
|
|
130
|
-
cwd: path.join(process.cwd(),
|
|
137
|
+
cwd: path.join(process.cwd(), projectPath),
|
|
131
138
|
shell: true,
|
|
132
139
|
});
|
|
133
140
|
}
|
package/dist/lib/cli-flags.d.ts
CHANGED
package/dist/lib/cli-flags.js
CHANGED
package/dist/lib/manual.js
CHANGED
|
@@ -44,6 +44,9 @@ const create = `\
|
|
|
44
44
|
--visibility, -v [visibility]
|
|
45
45
|
The visibility of the new project. Options are private,
|
|
46
46
|
public, and unlisted.
|
|
47
|
+
--path, -p [path]
|
|
48
|
+
The path where to create the new project. Defaults to
|
|
49
|
+
the name of the project in the current working directory.
|
|
47
50
|
|
|
48
51
|
`;
|
|
49
52
|
const preview = `\
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
# Pulse CLI
|
|
2
|
+
|
|
2
3
|
## Install
|
|
4
|
+
|
|
3
5
|
```bash
|
|
4
6
|
$ npm install --global @pulse-editor/cli
|
|
5
7
|
```
|
|
6
8
|
|
|
7
9
|
## Link local development version
|
|
10
|
+
|
|
8
11
|
```bash
|
|
9
12
|
npm run link
|
|
10
13
|
```
|
|
@@ -48,6 +51,8 @@ npm run link
|
|
|
48
51
|
--visibility, -v [visibility]
|
|
49
52
|
The visibility of the new project. Options are private,
|
|
50
53
|
public, and unlisted.
|
|
54
|
+
--path, -p [path]
|
|
55
|
+
The path where to create the new project. Defaults to the name of the project in the current working directory.
|
|
51
56
|
|
|
52
57
|
preview Build the Pulse App in development mode and
|
|
53
58
|
start a preview server accessible via browser
|
|
@@ -75,6 +80,7 @@ npm run link
|
|
|
75
80
|
```
|
|
76
81
|
|
|
77
82
|
## Development
|
|
83
|
+
|
|
78
84
|
```
|
|
79
85
|
npm run dev
|
|
80
|
-
```
|
|
86
|
+
```
|