slicejs-cli 3.3.0 → 3.4.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.
Files changed (46) hide show
  1. package/AGENTS.md +247 -0
  2. package/LICENSE +21 -21
  3. package/client.js +663 -626
  4. package/commands/Print.js +163 -167
  5. package/commands/Validations.js +92 -103
  6. package/commands/build/build.js +40 -40
  7. package/commands/buildProduction/buildProduction.js +576 -579
  8. package/commands/bundle/bundle.js +234 -235
  9. package/commands/createComponent/VisualComponentTemplate.js +55 -55
  10. package/commands/createComponent/createComponent.js +124 -126
  11. package/commands/deleteComponent/deleteComponent.js +77 -77
  12. package/commands/doctor/doctor.js +366 -369
  13. package/commands/getComponent/getComponent.js +684 -747
  14. package/commands/init/init.js +269 -261
  15. package/commands/listComponents/listComponents.js +172 -175
  16. package/commands/startServer/startServer.js +261 -264
  17. package/commands/startServer/watchServer.js +79 -79
  18. package/commands/types/types.js +69 -27
  19. package/commands/utils/LocalCliDelegation.js +53 -53
  20. package/commands/utils/PathHelper.js +75 -68
  21. package/commands/utils/VersionChecker.js +167 -167
  22. package/commands/utils/bundling/BundleGenerator.js +2292 -2292
  23. package/commands/utils/bundling/DependencyAnalyzer.js +925 -933
  24. package/commands/utils/loadConfig.js +31 -0
  25. package/commands/utils/updateManager.js +452 -453
  26. package/docs/superpowers/specs/2026-05-10-pwa-generate-design.md +105 -105
  27. package/package.json +58 -46
  28. package/post.js +66 -65
  29. package/tests/bundle-generator.test.js +691 -708
  30. package/tests/bundle-v2-register-output.test.js +470 -470
  31. package/tests/client-launcher-contract.test.js +211 -211
  32. package/tests/client-update-flow-contract.test.js +272 -272
  33. package/tests/component-registry-parse.test.js +34 -0
  34. package/tests/dependency-analyzer.test.js +24 -24
  35. package/tests/fixtures/components.js +8 -0
  36. package/tests/fixtures/sliceConfig.json +74 -0
  37. package/tests/getcomponent.test.js +407 -0
  38. package/tests/helpers/setup.js +97 -0
  39. package/tests/init-command-contract.test.js +46 -0
  40. package/tests/local-cli-delegation.test.js +81 -79
  41. package/tests/path-helper.test.js +206 -0
  42. package/tests/types-breakage.test.js +491 -0
  43. package/tests/types-generator-errors.test.js +361 -0
  44. package/tests/types-generator.test.js +172 -184
  45. package/tests/update-manager-notifications.test.js +88 -88
  46. package/.github/workflows/docs-render-cicd.yml +0 -65
@@ -1,126 +1,124 @@
1
-
2
- import componentTemplates from './VisualComponentTemplate.js';
3
- import fs from 'fs-extra';
4
- import path from 'path';
5
- import { fileURLToPath } from 'url';
6
- import Validations from '../Validations.js';
7
- import Print from '../Print.js';
8
- import { getSrcPath } from '../utils/PathHelper.js';
9
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
10
-
11
- function createComponent(componentName, category) {
12
- // Validación: Nombre de componente requerido
13
- if (!componentName) {
14
- Print.error('Component name is required');
15
- Print.commandExample("Create a component", "slice component create");
16
- return false;
17
- }
18
-
19
- // Validación: Nombre de componente válido
20
- if (!Validations.isValidComponentName(componentName)) {
21
- Print.error(`Invalid component name: '${componentName}'`);
22
- Print.info('Component name must start with a letter and contain only alphanumeric characters');
23
- Print.commandExample("Valid names", "Button, UserCard, NavBar");
24
- Print.commandExample("Invalid names", "1Button, user-card, Nav_Bar");
25
- return false;
26
- }
27
-
28
- // Validación: Componente ya existe
29
- if(Validations.componentExists(componentName)){
30
- Print.error(`Component '${componentName}' already exists in your project`);
31
- Print.info('Please use a different name or delete the existing component first');
32
- Print.commandExample("Delete component", "slice component delete");
33
- return false;
34
- }
35
-
36
- // Validación: Categoría válida
37
- let flagCategory = Validations.isValidCategory(category);
38
-
39
- if (!flagCategory.isValid) {
40
- Print.error(`Invalid category: '${category}'`);
41
- const availableCategories = Object.keys(Validations.getCategories()).join(', ');
42
- Print.info(`Available categories: ${availableCategories}`);
43
- return false;
44
- }
45
- category = flagCategory.category;
46
-
47
- // Crear el nombre de la clase y del archivo
48
- const className = componentName.charAt(0).toUpperCase() + componentName.slice(1);
49
- const fileName = `${className}.js`;
50
- let template;
51
-
52
- const type = Validations.getCategoryType(category);
53
-
54
- // Generar template según el tipo
55
- if(type === 'Visual'){
56
- template = componentTemplates.visual(className);
57
- } else if(type === 'Service'){
58
- template = componentTemplates.service(className);
59
- } else {
60
- Print.error(`Unsupported component type: '${type}'`);
61
- Print.info('Only Visual and Service components are currently supported');
62
- return false;
63
- }
64
-
65
- const categoryPath = Validations.getCategoryPath(category);
66
- const categoryPathClean = categoryPath ? categoryPath.replace(/^[/\\]+/, '') : '';
67
- const componentDir = getSrcPath(import.meta.url, categoryPathClean, className);
68
-
69
- try {
70
- // Crear directorio del componente
71
- fs.ensureDirSync(componentDir);
72
- } catch (error) {
73
- Print.error(`Failed to create component directory: '${componentDir}'`);
74
- Print.info(`Error details: ${error.message}`);
75
- return false;
76
- }
77
-
78
- // Determinar la ruta del archivo
79
- let componentPath = path.join(componentDir, fileName);
80
-
81
- // Verificar si el archivo ya existe (doble verificación)
82
- if (fs.existsSync(componentPath)) {
83
- Print.error(`Component file already exists at: '${componentPath}'`);
84
- Print.info('This component may have been created outside the CLI');
85
- return false;
86
- }
87
-
88
- try {
89
- // Escribir el código del componente en el archivo
90
- fs.writeFileSync(componentPath, template);
91
-
92
- // Si es Visual, crear archivos adicionales (CSS y HTML)
93
- if(type === 'Visual'){
94
- const cssPath = `${componentDir}/${className}.css`;
95
- const htmlPath = `${componentDir}/${className}.html`;
96
-
97
- fs.writeFileSync(cssPath, '/* Styles for ' + componentName + ' component */\n');
98
- fs.writeFileSync(htmlPath, `<div class="${componentName.toLowerCase()}">\n ${componentName}\n</div>`);
99
-
100
- Print.info(`Created files: ${fileName}, ${className}.css, ${className}.html`);
101
- } else {
102
- Print.info(`Created file: ${fileName}`);
103
- }
104
-
105
- return true;
106
- } catch (error) {
107
- Print.error(`Failed to create component files`);
108
- Print.info(`Error details: ${error.message}`);
109
-
110
- // Intentar limpiar archivos parcialmente creados
111
- try {
112
- if (fs.existsSync(componentDir)) {
113
- fs.removeSync(componentDir);
114
- Print.info('Cleaned up partial files');
115
- }
116
- } catch (cleanupError) {
117
- Print.warning('Could not clean up partial files. You may need to delete them manually');
118
- }
119
-
120
- return false;
121
- }
122
- }
123
-
124
-
125
- export default createComponent;
126
-
1
+
2
+ import componentTemplates from './VisualComponentTemplate.js';
3
+ import fs from 'fs-extra';
4
+ import path from 'path';
5
+ import Validations from '../Validations.js';
6
+ import Print from '../Print.js';
7
+ import { getSrcPath } from '../utils/PathHelper.js';
8
+
9
+ function createComponent(componentName, category) {
10
+ // Validation: Component name is required
11
+ if (!componentName) {
12
+ Print.error('Component name is required');
13
+ Print.commandExample("Create a component", "slice component create");
14
+ return false;
15
+ }
16
+
17
+ // Validation: Valid component name
18
+ if (!Validations.isValidComponentName(componentName)) {
19
+ Print.error(`Invalid component name: '${componentName}'`);
20
+ Print.info('Component name must start with a letter and contain only alphanumeric characters');
21
+ Print.commandExample("Valid names", "Button, UserCard, NavBar");
22
+ Print.commandExample("Invalid names", "1Button, user-card, Nav_Bar");
23
+ return false;
24
+ }
25
+
26
+ // Validation: Component already exists
27
+ if(Validations.componentExists(componentName)){
28
+ Print.error(`Component '${componentName}' already exists in your project`);
29
+ Print.info('Please use a different name or delete the existing component first');
30
+ Print.commandExample("Delete component", "slice component delete");
31
+ return false;
32
+ }
33
+
34
+ // Validation: Valid category
35
+ let flagCategory = Validations.isValidCategory(category);
36
+
37
+ if (!flagCategory.isValid) {
38
+ Print.error(`Invalid category: '${category}'`);
39
+ const availableCategories = Object.keys(Validations.getCategories()).join(', ');
40
+ Print.info(`Available categories: ${availableCategories}`);
41
+ return false;
42
+ }
43
+ category = flagCategory.category;
44
+
45
+ // Create class name and file name
46
+ const className = componentName.charAt(0).toUpperCase() + componentName.slice(1);
47
+ const fileName = `${className}.js`;
48
+ let template;
49
+
50
+ const type = Validations.getCategoryType(category);
51
+
52
+ // Generate template based on type
53
+ if(type === 'Visual'){
54
+ template = componentTemplates.visual(className);
55
+ } else if(type === 'Service'){
56
+ template = componentTemplates.service(className);
57
+ } else {
58
+ Print.error(`Unsupported component type: '${type}'`);
59
+ Print.info('Only Visual and Service components are currently supported');
60
+ return false;
61
+ }
62
+
63
+ const categoryPath = Validations.getCategoryPath(category);
64
+ const categoryPathClean = categoryPath ? categoryPath.replace(/^[/\\]+/, '') : '';
65
+ const componentDir = getSrcPath(import.meta.url, categoryPathClean, className);
66
+
67
+ try {
68
+ // Create component directory
69
+ fs.ensureDirSync(componentDir);
70
+ } catch (error) {
71
+ Print.error(`Failed to create component directory: '${componentDir}'`);
72
+ Print.info(`Error details: ${error.message}`);
73
+ return false;
74
+ }
75
+
76
+ // Determine the file path
77
+ let componentPath = path.join(componentDir, fileName);
78
+
79
+ // Verify if the file already exists (double check)
80
+ if (fs.existsSync(componentPath)) {
81
+ Print.error(`Component file already exists at: '${componentPath}'`);
82
+ Print.info('This component may have been created outside the CLI');
83
+ return false;
84
+ }
85
+
86
+ try {
87
+ // Write component code to file
88
+ fs.writeFileSync(componentPath, template);
89
+
90
+ // If Visual, create additional files (CSS and HTML)
91
+ if(type === 'Visual'){
92
+ const cssPath = path.join(componentDir, `${className}.css`);
93
+ const htmlPath = path.join(componentDir, `${className}.html`);
94
+
95
+ fs.writeFileSync(cssPath, '/* Styles for ' + componentName + ' component */\n');
96
+ fs.writeFileSync(htmlPath, `<div class="${componentName.toLowerCase()}">\n ${componentName}\n</div>`);
97
+
98
+ Print.info(`Created files: ${fileName}, ${className}.css, ${className}.html`);
99
+ } else {
100
+ Print.info(`Created file: ${fileName}`);
101
+ }
102
+
103
+ return true;
104
+ } catch (error) {
105
+ Print.error(`Failed to create component files`);
106
+ Print.info(`Error details: ${error.message}`);
107
+
108
+ // Try to clean up partially created files
109
+ try {
110
+ if (fs.existsSync(componentDir)) {
111
+ fs.removeSync(componentDir);
112
+ Print.info('Cleaned up partial files');
113
+ }
114
+ } catch (cleanupError) {
115
+ Print.warning('Could not clean up partial files. You may need to delete them manually');
116
+ }
117
+
118
+ return false;
119
+ }
120
+ }
121
+
122
+
123
+ export default createComponent;
124
+
@@ -1,77 +1,77 @@
1
- import fs from 'fs-extra';
2
- import path from 'path';
3
- import Validations from '../Validations.js';
4
- import Print from '../Print.js';
5
- import { fileURLToPath } from 'url';
6
- import { getSrcPath } from '../utils/PathHelper.js';
7
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
8
-
9
- function deleteComponent(componentName, category) {
10
- // Validación: Nombre de componente requerido
11
- if (!componentName) {
12
- Print.error('Component name is required to delete');
13
- Print.commandExample("Delete a component", "slice component delete");
14
- return false;
15
- }
16
-
17
- // Validación: Nombre de componente válido
18
- if (!Validations.isValidComponentName(componentName)) {
19
- Print.error(`Invalid component name: '${componentName}'`);
20
- Print.info('Component name must start with a letter and contain only alphanumeric characters');
21
- return false;
22
- }
23
-
24
- // Validación: Categoría válida
25
- let flagCategory = Validations.isValidCategory(category);
26
-
27
- if (!flagCategory.isValid) {
28
- Print.error(`Invalid category: '${category}'`);
29
- const availableCategories = Object.keys(Validations.getCategories()).join(', ');
30
- Print.info(`Available categories: ${availableCategories}`);
31
- return false;
32
- }
33
- category = flagCategory.category;
34
-
35
- const categoryPath = Validations.getCategoryPath(category);
36
- const categoryPathClean = categoryPath ? categoryPath.replace(/^[/\\]+/, '') : '';
37
- const componentDir = getSrcPath(import.meta.url, categoryPathClean, componentName);
38
-
39
- // Verificar si el directorio del componente existe
40
- if (!fs.existsSync(componentDir)) {
41
- Print.error(`Component '${componentName}' does not exist in category '${category}'`);
42
- Print.info('Make sure you selected the correct category');
43
- Print.commandExample("List components", "slice component list");
44
- return false;
45
- }
46
-
47
- // Verificar si es un directorio
48
- try {
49
- const stats = fs.statSync(componentDir);
50
- if (!stats.isDirectory()) {
51
- Print.error(`'${componentName}' is not a valid component directory`);
52
- Print.info('Components must be stored in directories');
53
- return false;
54
- }
55
- } catch (error) {
56
- Print.error(`Failed to access component directory: '${componentDir}'`);
57
- Print.info(`Error details: ${error.message}`);
58
- return false;
59
- }
60
-
61
- // Intentar eliminar el directorio del componente y su contenido
62
- try {
63
- const files = fs.readdirSync(componentDir);
64
- Print.info(`Deleting ${files.length} file(s) from component directory...`);
65
-
66
- fs.removeSync(componentDir);
67
- return true;
68
- } catch (error) {
69
- Print.error(`Failed to delete component '${componentName}'`);
70
- Print.info(`Error details: ${error.message}`);
71
- Print.warning('You may need to delete the component files manually');
72
- Print.info(`Component location: ${componentDir}`);
73
- return false;
74
- }
75
- }
76
-
77
- export default deleteComponent;
1
+ import fs from 'fs-extra';
2
+ import path from 'path';
3
+ import Validations from '../Validations.js';
4
+ import Print from '../Print.js';
5
+ import { fileURLToPath } from 'url';
6
+ import { getSrcPath } from '../utils/PathHelper.js';
7
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
8
+
9
+ function deleteComponent(componentName, category) {
10
+ // Validation: Component name is required
11
+ if (!componentName) {
12
+ Print.error('Component name is required to delete');
13
+ Print.commandExample("Delete a component", "slice component delete");
14
+ return false;
15
+ }
16
+
17
+ // Validation: Valid component name
18
+ if (!Validations.isValidComponentName(componentName)) {
19
+ Print.error(`Invalid component name: '${componentName}'`);
20
+ Print.info('Component name must start with a letter and contain only alphanumeric characters');
21
+ return false;
22
+ }
23
+
24
+ // Validation: Valid category
25
+ let flagCategory = Validations.isValidCategory(category);
26
+
27
+ if (!flagCategory.isValid) {
28
+ Print.error(`Invalid category: '${category}'`);
29
+ const availableCategories = Object.keys(Validations.getCategories()).join(', ');
30
+ Print.info(`Available categories: ${availableCategories}`);
31
+ return false;
32
+ }
33
+ category = flagCategory.category;
34
+
35
+ const categoryPath = Validations.getCategoryPath(category);
36
+ const categoryPathClean = categoryPath ? categoryPath.replace(/^[/\\]+/, '') : '';
37
+ const componentDir = getSrcPath(import.meta.url, categoryPathClean, componentName);
38
+
39
+ // Check if component directory exists
40
+ if (!fs.existsSync(componentDir)) {
41
+ Print.error(`Component '${componentName}' does not exist in category '${category}'`);
42
+ Print.info('Make sure you selected the correct category');
43
+ Print.commandExample("List components", "slice component list");
44
+ return false;
45
+ }
46
+
47
+ // Verify it's a directory
48
+ try {
49
+ const stats = fs.statSync(componentDir);
50
+ if (!stats.isDirectory()) {
51
+ Print.error(`'${componentName}' is not a valid component directory`);
52
+ Print.info('Components must be stored in directories');
53
+ return false;
54
+ }
55
+ } catch (error) {
56
+ Print.error(`Failed to access component directory: '${componentDir}'`);
57
+ Print.info(`Error details: ${error.message}`);
58
+ return false;
59
+ }
60
+
61
+ // Try to delete the component directory and its contents
62
+ try {
63
+ const files = fs.readdirSync(componentDir);
64
+ Print.info(`Deleting ${files.length} file(s) from component directory...`);
65
+
66
+ fs.removeSync(componentDir);
67
+ return true;
68
+ } catch (error) {
69
+ Print.error(`Failed to delete component '${componentName}'`);
70
+ Print.info(`Error details: ${error.message}`);
71
+ Print.warning('You may need to delete the component files manually');
72
+ Print.info(`Component location: ${componentDir}`);
73
+ return false;
74
+ }
75
+ }
76
+
77
+ export default deleteComponent;