@pulse-editor/cli 0.1.1-beta.23 → 0.1.1-beta.25

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);
@@ -59,7 +62,9 @@ export default function Create({ cli }) {
59
62
  if (projectName) {
60
63
  // Check if the project already exists
61
64
  const projectPath = path.join(process.cwd(), projectName);
62
- if (fs.existsSync(projectPath)) {
65
+ if (fs.existsSync(projectPath) &&
66
+ fs.lstatSync(projectPath).isDirectory() &&
67
+ fs.readdirSync(projectPath).length > 0) {
63
68
  setErrorMessage(_jsx(Text, { color: "redBright", children: "\u274C A project with same name already exists in current path." }));
64
69
  setTimeout(() => {
65
70
  exit();
@@ -81,43 +86,47 @@ export default function Create({ cli }) {
81
86
  }
82
87
  }, [visibility, projectName]);
83
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
+ }
84
93
  if (framework === 'react') {
85
94
  // Clone the template repository
86
95
  setCreateMessage(_jsxs(Box, { children: [_jsx(Spinner, { type: "dots" }), _jsx(Text, { children: " Creating a new Pulse Editor app using React template..." })] }));
87
96
  try {
88
- await $ `git clone --depth 1 https://github.com/ClayPulse/pulse-app-template.git ${name}`;
97
+ await $ `git clone --depth 1 https://github.com/ClayPulse/pulse-app-template.git ${projectPath}`;
89
98
  }
90
99
  catch (error) {
91
- setCreateMessage(_jsx(Text, { color: "redBright", children: "\u274C Failed to clone the template. Please check your internet connection and try again." }));
100
+ setCreateMessage(_jsxs(Text, { color: "redBright", children: ["\u274C Failed to clone the template. ", error.message] }));
92
101
  return;
93
102
  }
94
103
  // Modify the package.json file to update the name
95
104
  setCreateMessage(_jsxs(Box, { children: [_jsx(Spinner, { type: "dots" }), _jsx(Text, { children: " Initializing project..." })] }));
96
105
  /* Setup pulse.config.ts */
97
- const pulseConfigPath = path.join(process.cwd(), name, 'pulse.config.ts');
106
+ const pulseConfigPath = path.join(process.cwd(), projectPath, 'pulse.config.ts');
98
107
  let pulseConfig = fs.readFileSync(pulseConfigPath, 'utf8');
99
108
  // Modify visibility by matching the block that starts with 'visibility:',
100
109
  // and replacing the entire line with the new visibility value.
101
110
  pulseConfig = pulseConfig.replace(/visibility:\s*['"`](public|unlisted|private)['"`],?/, `visibility: '${visibility}',`);
102
111
  fs.writeFileSync(pulseConfigPath, pulseConfig);
103
112
  /* Setup packages.json */
104
- const packageJsonPath = path.join(process.cwd(), name, 'package.json');
113
+ const packageJsonPath = path.join(process.cwd(), projectPath, 'package.json');
105
114
  const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
106
115
  packageJson.name = name.replaceAll('-', '_');
107
116
  // Write the modified package.json back to the file
108
117
  fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
109
118
  // Remove the .git directory
110
- const gitDirPath = path.join(process.cwd(), name, '.git');
119
+ const gitDirPath = path.join(process.cwd(), projectPath, '.git');
111
120
  if (fs.existsSync(gitDirPath)) {
112
121
  fs.rmSync(gitDirPath, { recursive: true, force: true });
113
122
  }
114
123
  // Remove the .github directory
115
- const githubDirPath = path.join(process.cwd(), name, '.github');
124
+ const githubDirPath = path.join(process.cwd(), projectPath, '.github');
116
125
  if (fs.existsSync(githubDirPath)) {
117
126
  fs.rmSync(githubDirPath, { recursive: true, force: true });
118
127
  }
119
128
  // Remove LICENSE file
120
- const licenseFilePath = path.join(process.cwd(), name, 'LICENSE');
129
+ const licenseFilePath = path.join(process.cwd(), projectPath, 'LICENSE');
121
130
  if (fs.existsSync(licenseFilePath)) {
122
131
  fs.rmSync(licenseFilePath, { force: true });
123
132
  }
@@ -125,7 +134,7 @@ export default function Create({ cli }) {
125
134
  // Run `npm i`
126
135
  try {
127
136
  await execa(`npm install`, {
128
- cwd: path.join(process.cwd(), name),
137
+ cwd: path.join(process.cwd(), projectPath),
129
138
  shell: true,
130
139
  });
131
140
  }
@@ -32,5 +32,9 @@ export declare const flags: {
32
32
  type: "boolean";
33
33
  default: true;
34
34
  };
35
+ path: {
36
+ type: "string";
37
+ shortFlag: string;
38
+ };
35
39
  };
36
40
  export type Flags = typeof flags;
@@ -36,4 +36,8 @@ export const flags = defineFlags({
36
36
  type: 'boolean',
37
37
  default: true,
38
38
  },
39
+ path: {
40
+ type: 'string',
41
+ shortFlag: 'p',
42
+ },
39
43
  });
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pulse-editor/cli",
3
- "version": "0.1.1-beta.23",
3
+ "version": "0.1.1-beta.25",
4
4
  "license": "MIT",
5
5
  "bin": {
6
6
  "pulse": "dist/cli.js"
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
+ ```
@@ -1 +0,0 @@
1
- export declare function loadAndCall(func: string, req: Request): Promise<Response>;
@@ -1,23 +0,0 @@
1
- /* This folder contains temporary code to be moved to a different package in the future. */
2
- // @ts-expect-error ignore ts error
3
- import { createInstance } from '@module-federation/runtime';
4
- import { performReload } from '@module-federation/node/utils';
5
- import { readConfigFile } from '../../utils.js';
6
- export async function loadAndCall(func, req) {
7
- const pulseConfig = await readConfigFile();
8
- await performReload(true);
9
- // here we assign the return value of the init() function, which can be used to do some more complex
10
- // things with the module federation runtime
11
- const instance = createInstance({
12
- name: 'preview_host',
13
- remotes: [
14
- {
15
- name: pulseConfig.id + '_server',
16
- entry: `http://localhost:3030/.server-function/remoteEntry.js`,
17
- },
18
- ],
19
- });
20
- const loadedFunc = (await instance.loadRemote(`${pulseConfig.id}_server/${func}`)).default;
21
- const res = await loadedFunc(req);
22
- return res;
23
- }