slicejs-cli 2.7.1 → 2.7.4

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/README.md CHANGED
@@ -1,16 +1,29 @@
1
+ <div align="center">
2
+
1
3
  # Slice.js CLI
4
+ <img src="./assets/Slice.js-logo.png" alt="Slice.js logo" width="200" />
5
+ <br/>
6
+
7
+ <div style="display: flex; justify-content: center; align-items: center; gap: 10px; align-content: center;">
8
+ <a href="https://www.npmjs.com/package/slicejs-cli"><img src="https://img.shields.io/npm/v/slicejs-cli.svg?label=CLI" alt="npm version" /></a>
9
+ <img src="https://img.shields.io/badge/Node-%E2%89%A5%2020.0.0-339933?logo=node.js" alt="node requirement" />
10
+ <a href="#license"><img src="https://img.shields.io/badge/License-ISC-blue.svg" alt="license" /></a>
11
+ </div>
12
+
2
13
 
3
- Command-line interface for developing web applications with the Slice.js framework.
14
+ <p>CLI for building web applications with the Slice.js framework</p>
15
+
16
+ </div>
4
17
 
5
18
  ## Installation
6
19
 
7
- ### Local Installation (Recommended)
20
+ - Local (recommended):
8
21
 
9
22
  ```bash
10
23
  npm install slicejs-cli --save-dev
11
24
  ```
12
25
 
13
- ### Global Installation
26
+ - Global:
14
27
 
15
28
  ```bash
16
29
  npm install -g slicejs-cli
@@ -24,108 +37,104 @@ After installation, you can use the `slice` command directly:
24
37
  slice [command] [options]
25
38
  ```
26
39
 
27
- Or with npx (no installation required):
40
+ Or with npx (without global install):
28
41
 
29
42
  ```bash
30
43
  npx slicejs-cli [command]
31
44
  ```
32
45
 
33
- ## Commands
46
+ ## Essential Commands
34
47
 
35
- ### Project Initialization
48
+ ### Initialize a project
36
49
 
37
50
  ```bash
38
51
  slice init
39
52
  ```
40
53
 
41
- Initializes a new Slice.js project with the complete framework structure.
54
+ Initializes a Slice.js project with the full structure (`src/` and `api/`), installs initial Visual components, and configures npm scripts.
42
55
 
43
- ### Development Server
56
+ ### Development server
44
57
 
45
58
  ```bash
46
- # Start development server on default port (3000)
59
+ # Default port (3000)
47
60
  slice dev
48
61
 
49
- # Start on custom port
62
+ # Custom port
50
63
  slice dev -p 8080
51
64
 
52
- # Alternative command (same as dev)
65
+ # Alias
53
66
  slice start
54
67
  slice start -p 8080
55
68
  ```
56
69
 
57
- ### Component Management (Local)
70
+ ### Component management (local)
58
71
 
59
72
  ```bash
60
- # Create a new component (interactive)
73
+ # Create a component (interactive)
61
74
  slice component create
62
75
 
63
- # List all local components
76
+ # List local components
64
77
  slice component list
65
78
 
66
79
  # Delete a component (interactive)
67
80
  slice component delete
68
81
  ```
69
82
 
70
- **Shortcuts:**
83
+ Shortcuts:
71
84
  ```bash
72
- slice component create → slice comp create
73
- slice component list → slice comp ls
74
- slice component delete → slice comp remove
85
+ slice comp create
86
+ slice comp ls
87
+ slice comp remove
75
88
  ```
76
89
 
77
- ### Component Registry (Official Repository)
90
+ ### Official component registry
78
91
 
79
92
  ```bash
80
- # Install components from official repository
93
+ # Install Visual components
81
94
  slice get Button Card Input
82
95
 
83
- # Install service component
96
+ # Install a Service component
84
97
  slice get FetchManager --service
85
98
 
86
- # Force overwrite existing components
99
+ # Force overwrite
87
100
  slice get Button --force
88
101
 
89
102
  # Browse available components
90
103
  slice browse
91
104
 
92
- # Update all local components to latest versions
105
+ # Update all local components
93
106
  slice sync
94
-
95
- # Force update without confirmation
96
107
  slice sync --force
97
108
  ```
98
109
 
99
- **Shortcuts:**
110
+ Shortcuts:
100
111
  ```bash
101
- slice registry get Button → slice get Button
102
- slice registry list → slice browse
103
- slice registry sync → slice sync
112
+ slice get Button
113
+ slice browse
114
+ slice sync
104
115
  ```
105
116
 
106
117
  ### Utilities
107
118
 
108
119
  ```bash
109
- # Show version information
120
+ # Version info
110
121
  slice version
111
122
  slice -v
112
123
 
113
- # Update CLI and Framework
114
- slice update # Check and prompt for updates
115
- slice update --yes # Update all automatically
116
- slice update --cli # Update only CLI
117
- slice update --framework # Update only Framework
124
+ # Updates (CLI and Framework)
125
+ slice update # Check and prompt to update
126
+ slice update --yes # Update everything automatically
127
+ slice update --cli # CLI only
128
+ slice update --framework # Framework only
118
129
 
119
- # Show help
130
+ # Help
120
131
  slice --help
121
132
  slice [command] --help
122
133
  ```
123
134
 
124
- ## NPM Scripts
125
-
126
- When you install `slicejs-cli`, the following scripts are automatically added to your project's `package.json`:
135
+ ## npm Scripts
127
136
 
128
- ### Recommended (New)
137
+ `slice init` automatically configures the recommended scripts in your `package.json`:
129
138
 
130
139
  ```json
131
140
  {
@@ -149,18 +158,6 @@ npm run get
149
158
  npm run browse
150
159
  ```
151
160
 
152
- ### Legacy (Still Supported)
153
-
154
- ```json
155
- {
156
- "scripts": {
157
- "slice:dev": "slice dev",
158
- "slice:start": "slice start",
159
- "slice:get": "slice get"
160
- }
161
- }
162
- ```
163
-
164
161
  ## Quick Start
165
162
 
166
163
  ```bash
@@ -215,11 +212,11 @@ slice sync
215
212
 
216
213
  ## Development Mode
217
214
 
218
- The development server (`slice dev` or `slice start`) provides:
215
+ The development server (`slice dev` / `slice start`) provides:
219
216
 
220
- - ✅ Hot reload for instant changes
221
- - ✅ Serves files directly from `/src`
222
- - ✅ No build step required
217
+ - ✅ Hot reload
218
+ - ✅ Serves directly from `/src`
219
+ - ✅ No build step
223
220
  - ✅ Port validation
224
221
  - ✅ Clear error messages
225
222
 
@@ -230,35 +227,46 @@ The development server (`slice dev` or `slice start`) provides:
230
227
 
231
228
  ## Configuration
232
229
 
233
- Project configuration is stored in `src/sliceConfig.json`, created automatically during `slice init`.
230
+ Project configuration is stored in `src/sliceConfig.json` and is created automatically by `slice init`.
234
231
 
235
232
  ## Features
236
233
 
237
- - 🚀 Fast development server with hot reload
238
- - 📦 Component registry for sharing components
234
+ - 🚀 Development server with hot reload
235
+ - 📦 Official component registry
239
236
  - 🎨 Visual and Service component types
240
237
  - ✨ Interactive component creation
241
238
  - 🔄 Automatic component synchronization
242
239
  - 🛠️ Built-in validation and error handling
243
- - 📝 Clear, actionable error messages
240
+
241
+ ### Smart Updates
242
+
243
+ - Detects whether the CLI in use is global or local
244
+ - Shows an update plan (GLOBAL/PROJECT) before execution
245
+ - Offers to include global CLI update interactively
246
+ - Applies `uninstall` + `install @latest` to ensure latest versions
247
+
248
+ ### Cross-platform Paths
249
+
250
+ - Centralized path helper avoids `../../..`
251
+ - Windows/Linux/Mac compatibility using `import.meta.url` and `fileURLToPath`
244
252
 
245
253
  ## Troubleshooting
246
254
 
247
- ### Port Already in Use
255
+ ### Port already in use
248
256
 
249
257
  ```bash
250
258
  # Use a different port
251
259
  slice dev -p 8080
252
260
  ```
253
261
 
254
- ### Project Not Initialized
262
+ ### Project not initialized
255
263
 
256
264
  ```bash
257
265
  # Make sure to run init first
258
266
  slice init
259
267
  ```
260
268
 
261
- ### Command Not Found
269
+ ### Command not found
262
270
 
263
271
  ```bash
264
272
  # Use npx if not installed globally
Binary file
package/client.js CHANGED
@@ -13,7 +13,9 @@ import updateManager from "./commands/utils/updateManager.js";
13
13
  import fs from "fs";
14
14
  import path from "path";
15
15
  import { fileURLToPath } from "url";
16
- import { getConfigPath } from "./commands/utils/PathHelper.js";
16
+ import { getConfigPath, getProjectRoot } from "./commands/utils/PathHelper.js";
17
+ import { exec } from "child_process";
18
+ import { promisify } from "util";
17
19
  import validations from "./commands/Validations.js";
18
20
  import Print from "./commands/Print.js";
19
21
 
@@ -24,8 +26,7 @@ const loadConfig = () => {
24
26
  const configPath = getConfigPath(import.meta.url);
25
27
  const rawData = fs.readFileSync(configPath, "utf-8");
26
28
  return JSON.parse(rawData);
27
- } catch (error) {
28
- Print.error(`Loading configuration: ${error.message}`);
29
+ } catch {
29
30
  return null;
30
31
  }
31
32
  };
@@ -38,6 +39,49 @@ const getCategories = () => {
38
39
  // Function to run version check for all commands
39
40
  async function runWithVersionCheck(commandFunction, ...args) {
40
41
  try {
42
+ const execAsync = promisify(exec);
43
+ await (async () => {
44
+ try {
45
+ const info = await updateManager.detectCliInstall();
46
+ if (info && info.type === 'global') {
47
+ const projectRoot = getProjectRoot(import.meta.url);
48
+ const pkgPath = path.join(projectRoot, 'package.json');
49
+ let hasPkg = fs.existsSync(pkgPath);
50
+ if (!hasPkg) {
51
+ const { confirmInit } = await inquirer.prompt([
52
+ {
53
+ type: 'confirm',
54
+ name: 'confirmInit',
55
+ message: 'No package.json found. Initialize npm in this project now?',
56
+ default: true
57
+ }
58
+ ]);
59
+ if (confirmInit) {
60
+ await execAsync('npm init -y', { cwd: projectRoot });
61
+ hasPkg = true;
62
+ }
63
+ }
64
+ if (hasPkg) {
65
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
66
+ const hasFramework = pkg.dependencies?.['slicejs-web-framework'];
67
+ if (!hasFramework) {
68
+ const { confirm } = await inquirer.prompt([
69
+ {
70
+ type: 'confirm',
71
+ name: 'confirm',
72
+ message: 'slicejs-web-framework is not installed in this project. Install it now?',
73
+ default: true
74
+ }
75
+ ]);
76
+ if (confirm) {
77
+ await updateManager.updatePackage('slicejs-web-framework');
78
+ }
79
+ }
80
+ }
81
+ }
82
+ } catch {}
83
+ })();
84
+
41
85
  const updateInfo = await updateManager.checkForUpdates();
42
86
  if (updateInfo && updateInfo.hasUpdates) {
43
87
  await updateManager.checkAndPromptUpdates({});
@@ -58,7 +102,14 @@ async function runWithVersionCheck(commandFunction, ...args) {
58
102
 
59
103
  const sliceClient = program;
60
104
 
61
- sliceClient.version("2.6.1").description("CLI for managing Slice.js framework components");
105
+ try {
106
+ const pkgPath = path.join(__dirname, "./package.json");
107
+ const pkgRaw = fs.readFileSync(pkgPath, "utf-8");
108
+ const pkg = JSON.parse(pkgRaw);
109
+ sliceClient.version(pkg.version).description("CLI for managing Slice.js framework components");
110
+ } catch {
111
+ sliceClient.version("0.0.0").description("CLI for managing Slice.js framework components");
112
+ }
62
113
 
63
114
  // INIT COMMAND
64
115
  sliceClient
@@ -5,6 +5,9 @@ import { createServer } from 'net';
5
5
  import chalk from 'chalk';
6
6
  import Table from 'cli-table3';
7
7
  import Print from '../Print.js';
8
+ import inquirer from 'inquirer';
9
+ import { exec } from 'child_process';
10
+ import { promisify } from 'util';
8
11
  import { getProjectRoot, getSrcPath, getApiPath, getConfigPath, getPath } from '../utils/PathHelper.js';
9
12
 
10
13
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
@@ -173,7 +176,10 @@ async function checkDependencies() {
173
176
  return {
174
177
  warn: true,
175
178
  message: `Missing dependencies: ${missing.join(', ')}`,
176
- suggestion: 'Run "npm install"'
179
+ suggestion: missing.includes('slicejs-web-framework')
180
+ ? 'Run "npm install slicejs-web-framework@latest" in your project'
181
+ : 'Run "npm install -D slicejs-cli@latest" in your project',
182
+ missing
177
183
  };
178
184
  }
179
185
  } catch (error) {
@@ -313,6 +319,34 @@ export default async function runDiagnostics() {
313
319
  Print.newLine();
314
320
  Print.separator();
315
321
 
322
+ const depsResult = results.find(r => r.name === 'Dependencies');
323
+ if (depsResult && depsResult.warn && Array.isArray(depsResult.missing) && depsResult.missing.length > 0) {
324
+ const projectRoot = getProjectRoot(import.meta.url);
325
+ const execAsync = promisify(exec);
326
+ const { confirmInstall } = await inquirer.prompt([
327
+ {
328
+ type: 'confirm',
329
+ name: 'confirmInstall',
330
+ message: `Install missing dependencies in this project now? (${depsResult.missing.join(', ')})`,
331
+ default: true
332
+ }
333
+ ]);
334
+ if (confirmInstall) {
335
+ for (const pkg of depsResult.missing) {
336
+ try {
337
+ const cmd = pkg === 'slicejs-cli'
338
+ ? 'npm install -D slicejs-cli@latest'
339
+ : 'npm install slicejs-web-framework@latest';
340
+ Print.info(`Installing ${pkg}...`);
341
+ await execAsync(cmd, { cwd: projectRoot });
342
+ Print.success(`${pkg} installed`);
343
+ } catch (e) {
344
+ Print.error(`Installing ${pkg}: ${e.message}`);
345
+ }
346
+ }
347
+ }
348
+ }
349
+
316
350
  if (issues === 0 && warnings === 0) {
317
351
  Print.success('All checks passed! 🎉');
318
352
  Print.info('Your Slice.js project is correctly configured');
@@ -184,13 +184,15 @@ class UpdateManager {
184
184
  */
185
185
  async updatePackage(packageName) {
186
186
  try {
187
- let command = `npm install ${packageName}@latest`;
187
+ let installCmd = `npm install ${packageName}@latest`;
188
+ let uninstallCmd = `npm uninstall ${packageName}`;
188
189
  let options = {};
189
190
 
190
191
  if (packageName === 'slicejs-cli') {
191
192
  const info = await this.detectCliInstall();
192
193
  if (info.type === 'global') {
193
- command = `npm install -g slicejs-cli@latest`;
194
+ installCmd = `npm install -g slicejs-cli@latest`;
195
+ uninstallCmd = `npm uninstall -g slicejs-cli`;
194
196
  } else {
195
197
  options.cwd = info.projectRoot || getProjectRoot(import.meta.url);
196
198
  }
@@ -198,7 +200,12 @@ class UpdateManager {
198
200
  options.cwd = getProjectRoot(import.meta.url);
199
201
  }
200
202
 
201
- const { stdout, stderr } = await execAsync(command, options);
203
+ // Try uninstall first (ignore failure)
204
+ try {
205
+ await execAsync(uninstallCmd, options);
206
+ } catch {}
207
+
208
+ const { stdout, stderr } = await execAsync(installCmd, options);
202
209
 
203
210
  return {
204
211
  success: true,
package/package.json CHANGED
@@ -1,11 +1,15 @@
1
1
  {
2
2
  "name": "slicejs-cli",
3
- "version": "2.7.1",
3
+ "version": "2.7.4",
4
4
  "description": "Command client for developing web applications with Slice.js framework",
5
5
  "main": "client.js",
6
6
  "bin": {
7
7
  "slice": "./client.js"
8
8
  },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/vkneider/slicejs-cli.git"
12
+ },
9
13
  "scripts": {
10
14
  "test": "echo \"Error: no test specified\" && exit 1",
11
15
  "postinstall": "node post.js"
package/post.js CHANGED
@@ -12,14 +12,14 @@ const targetRoot = initCwd || path.resolve(__dirname, '../../');
12
12
  const projectPackageJsonPath = path.join(targetRoot, 'package.json');
13
13
 
14
14
  if (isGlobal) {
15
- console.log('ℹ️ Instalación global detectada de slicejs-cli.');
16
- console.log(' Omite configuración de scripts. Usa el binario directamente:');
15
+ console.log('ℹ️ Global installation of slicejs-cli detected.');
16
+ console.log(' Skipping scripts setup. Use the binary directly:');
17
17
  console.log(' slice dev');
18
18
  console.log(' slice get Button');
19
19
  process.exit(0);
20
20
  }
21
21
 
22
- console.log('ℹ️ Instalación local detectada de slicejs-cli.');
23
- console.log(' Se omite configuración automática de scripts en postinstall.');
24
- console.log(' Usa "slice init" para configurar los scripts del proyecto.');
22
+ console.log('ℹ️ Local installation of slicejs-cli detected.');
23
+ console.log(' Skipping automatic scripts setup in postinstall.');
24
+ console.log(' Use "slice init" to configure project scripts.');
25
25
  process.exit(0);