ingeniuscliq-core 0.4.15 → 0.4.16
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/node_modules/@radix-ui/react-accordion/dist/index.js +3 -3
- package/dist/node_modules/@radix-ui/{react-select/node_modules/@radix-ui/react-popper/node_modules/@radix-ui/react-arrow → react-arrow}/dist/index.js +1 -1
- package/dist/node_modules/@radix-ui/react-avatar/dist/index.js +1 -1
- package/dist/node_modules/@radix-ui/react-checkbox/dist/index.js +2 -2
- package/dist/node_modules/@radix-ui/{react-accordion/node_modules/@radix-ui/react-collapsible → react-collapsible}/dist/index.js +7 -7
- package/dist/node_modules/@radix-ui/{react-select/node_modules/@radix-ui/react-collection → react-collection}/dist/index.js +3 -3
- package/dist/node_modules/@radix-ui/react-dialog/dist/index.js +5 -5
- package/dist/node_modules/@radix-ui/{react-select/node_modules/@radix-ui/react-dismissable-layer → react-dismissable-layer}/dist/index.js +4 -4
- package/dist/node_modules/@radix-ui/react-dropdown-menu/dist/index.js +2 -2
- package/dist/node_modules/@radix-ui/{react-dialog/node_modules/@radix-ui/react-focus-scope → react-focus-scope}/dist/index.js +2 -2
- package/dist/node_modules/@radix-ui/react-label/dist/index.js +1 -1
- package/dist/node_modules/@radix-ui/{react-dropdown-menu/node_modules/@radix-ui/react-menu → react-menu}/dist/index.js +17 -17
- package/dist/node_modules/@radix-ui/react-popover/dist/index.js +6 -6
- package/dist/node_modules/@radix-ui/{react-popover/node_modules/@radix-ui/react-popper → react-popper}/dist/index.js +8 -8
- package/dist/node_modules/@radix-ui/{react-popover/node_modules/@radix-ui/react-portal → react-portal}/dist/index.js +1 -1
- package/dist/node_modules/@radix-ui/{react-popover/node_modules/@radix-ui/react-presence → react-presence}/dist/index.js +2 -2
- package/dist/node_modules/@radix-ui/{react-dropdown-menu/node_modules/@radix-ui/react-primitive → react-primitive}/dist/index.js +1 -1
- package/dist/node_modules/@radix-ui/react-radio-group/dist/index.js +3 -3
- package/dist/node_modules/@radix-ui/{react-radio-group/node_modules/@radix-ui/react-roving-focus → react-roving-focus}/dist/index.js +8 -8
- package/dist/node_modules/@radix-ui/react-select/dist/index.js +7 -7
- package/dist/node_modules/@radix-ui/react-separator/dist/index.js +1 -1
- package/dist/node_modules/@radix-ui/react-slider/dist/index.js +2 -2
- package/dist/node_modules/@radix-ui/react-switch/dist/index.js +1 -1
- package/dist/node_modules/@radix-ui/react-tabs/dist/index.js +3 -3
- package/dist/node_modules/@radix-ui/react-tooltip/dist/index.js +5 -5
- package/dist/node_modules/react-i18next/dist/es/defaults.js +2 -1
- package/package.json +9 -9
- package/src/core/commands/create-core-module.js +288 -0
- package/src/core/commands/create-module.js +288 -0
- package/src/core/commands/create-template.js +169 -0
- package/src/core/commands/rollback-core-module.js +195 -0
- package/src/core/commands/rollback-module.js +208 -0
- package/dist/node_modules/@radix-ui/react-accordion/node_modules/@radix-ui/react-collapsible/node_modules/@radix-ui/react-presence/dist/index.js +0 -130
- package/dist/node_modules/@radix-ui/react-accordion/node_modules/@radix-ui/react-collection/dist/index.js +0 -70
- package/dist/node_modules/@radix-ui/react-accordion/node_modules/@radix-ui/react-primitive/dist/index.js +0 -40
- package/dist/node_modules/@radix-ui/react-avatar/node_modules/@radix-ui/react-primitive/dist/index.js +0 -40
- package/dist/node_modules/@radix-ui/react-checkbox/node_modules/@radix-ui/react-presence/dist/index.js +0 -130
- package/dist/node_modules/@radix-ui/react-checkbox/node_modules/@radix-ui/react-primitive/dist/index.js +0 -40
- package/dist/node_modules/@radix-ui/react-dialog/node_modules/@radix-ui/react-dismissable-layer/dist/index.js +0 -211
- package/dist/node_modules/@radix-ui/react-dialog/node_modules/@radix-ui/react-portal/dist/index.js +0 -17
- package/dist/node_modules/@radix-ui/react-dialog/node_modules/@radix-ui/react-presence/dist/index.js +0 -130
- package/dist/node_modules/@radix-ui/react-dialog/node_modules/@radix-ui/react-primitive/dist/index.js +0 -43
- package/dist/node_modules/@radix-ui/react-dropdown-menu/node_modules/@radix-ui/react-menu/node_modules/@radix-ui/react-collection/dist/index.js +0 -70
- package/dist/node_modules/@radix-ui/react-dropdown-menu/node_modules/@radix-ui/react-menu/node_modules/@radix-ui/react-dismissable-layer/dist/index.js +0 -211
- package/dist/node_modules/@radix-ui/react-dropdown-menu/node_modules/@radix-ui/react-menu/node_modules/@radix-ui/react-focus-scope/dist/index.js +0 -207
- package/dist/node_modules/@radix-ui/react-dropdown-menu/node_modules/@radix-ui/react-menu/node_modules/@radix-ui/react-popper/dist/index.js +0 -283
- package/dist/node_modules/@radix-ui/react-dropdown-menu/node_modules/@radix-ui/react-menu/node_modules/@radix-ui/react-popper/node_modules/@radix-ui/react-arrow/dist/index.js +0 -25
- package/dist/node_modules/@radix-ui/react-dropdown-menu/node_modules/@radix-ui/react-menu/node_modules/@radix-ui/react-portal/dist/index.js +0 -17
- package/dist/node_modules/@radix-ui/react-dropdown-menu/node_modules/@radix-ui/react-menu/node_modules/@radix-ui/react-presence/dist/index.js +0 -130
- package/dist/node_modules/@radix-ui/react-dropdown-menu/node_modules/@radix-ui/react-menu/node_modules/@radix-ui/react-roving-focus/dist/index.js +0 -223
- package/dist/node_modules/@radix-ui/react-label/node_modules/@radix-ui/react-primitive/dist/index.js +0 -40
- package/dist/node_modules/@radix-ui/react-popover/node_modules/@radix-ui/react-dismissable-layer/dist/index.js +0 -211
- package/dist/node_modules/@radix-ui/react-popover/node_modules/@radix-ui/react-focus-scope/dist/index.js +0 -207
- package/dist/node_modules/@radix-ui/react-popover/node_modules/@radix-ui/react-popper/node_modules/@radix-ui/react-arrow/dist/index.js +0 -25
- package/dist/node_modules/@radix-ui/react-popover/node_modules/@radix-ui/react-primitive/dist/index.js +0 -43
- package/dist/node_modules/@radix-ui/react-radio-group/node_modules/@radix-ui/react-presence/dist/index.js +0 -130
- package/dist/node_modules/@radix-ui/react-radio-group/node_modules/@radix-ui/react-primitive/dist/index.js +0 -40
- package/dist/node_modules/@radix-ui/react-radio-group/node_modules/@radix-ui/react-roving-focus/node_modules/@radix-ui/react-collection/dist/index.js +0 -70
- package/dist/node_modules/@radix-ui/react-select/node_modules/@radix-ui/react-focus-scope/dist/index.js +0 -207
- package/dist/node_modules/@radix-ui/react-select/node_modules/@radix-ui/react-popper/dist/index.js +0 -283
- package/dist/node_modules/@radix-ui/react-select/node_modules/@radix-ui/react-portal/dist/index.js +0 -17
- package/dist/node_modules/@radix-ui/react-select/node_modules/@radix-ui/react-primitive/dist/index.js +0 -43
- package/dist/node_modules/@radix-ui/react-select/node_modules/@radix-ui/react-visually-hidden/dist/index.js +0 -34
- package/dist/node_modules/@radix-ui/react-separator/node_modules/@radix-ui/react-primitive/dist/index.js +0 -40
- package/dist/node_modules/@radix-ui/react-slider/node_modules/@radix-ui/react-collection/dist/index.js +0 -70
- package/dist/node_modules/@radix-ui/react-slider/node_modules/@radix-ui/react-primitive/dist/index.js +0 -40
- package/dist/node_modules/@radix-ui/react-switch/node_modules/@radix-ui/react-primitive/dist/index.js +0 -40
- package/dist/node_modules/@radix-ui/react-tabs/node_modules/@radix-ui/react-presence/dist/index.js +0 -130
- package/dist/node_modules/@radix-ui/react-tabs/node_modules/@radix-ui/react-primitive/dist/index.js +0 -40
- package/dist/node_modules/@radix-ui/react-tabs/node_modules/@radix-ui/react-roving-focus/dist/index.js +0 -223
- package/dist/node_modules/@radix-ui/react-tabs/node_modules/@radix-ui/react-roving-focus/node_modules/@radix-ui/react-collection/dist/index.js +0 -70
- package/dist/node_modules/@radix-ui/react-tooltip/node_modules/@radix-ui/react-dismissable-layer/dist/index.js +0 -211
- package/dist/node_modules/@radix-ui/react-tooltip/node_modules/@radix-ui/react-popper/dist/index.js +0 -283
- package/dist/node_modules/@radix-ui/react-tooltip/node_modules/@radix-ui/react-popper/node_modules/@radix-ui/react-arrow/dist/index.js +0 -25
- package/dist/node_modules/@radix-ui/react-tooltip/node_modules/@radix-ui/react-presence/dist/index.js +0 -130
- package/dist/node_modules/@radix-ui/react-tooltip/node_modules/@radix-ui/react-primitive/dist/index.js +0 -43
- /package/dist/node_modules/@radix-ui/{react-tooltip/node_modules/@radix-ui/react-visually-hidden → react-visually-hidden}/dist/index.js +0 -0
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { createBaseDir, joinPaths } from './helpers/index.js';
|
|
4
|
+
import chalk from 'chalk';
|
|
5
|
+
import enquirer from 'enquirer';
|
|
6
|
+
import fs from 'fs';
|
|
7
|
+
|
|
8
|
+
const { prompt } = enquirer;
|
|
9
|
+
|
|
10
|
+
function sanitizeTemplateName(input) {
|
|
11
|
+
return input
|
|
12
|
+
.trim()
|
|
13
|
+
.toLowerCase()
|
|
14
|
+
.replace(/\s+/g, '-') // espacios -> guiones
|
|
15
|
+
.replace(/[^a-z0-9-]/g, '') // solo [a-z0-9-]
|
|
16
|
+
.replace(/-+/g, '-'); // colapsar guiones
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function toPascalCase(str) {
|
|
20
|
+
return str
|
|
21
|
+
.split('-')
|
|
22
|
+
.map(word => word.charAt(0).toUpperCase() + word.slice(1))
|
|
23
|
+
.join('');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function ensureDir(dirPath) {
|
|
27
|
+
fs.mkdirSync(dirPath, { recursive: true });
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function createTemplate(templateNameRaw) {
|
|
31
|
+
const templateName = sanitizeTemplateName(templateNameRaw);
|
|
32
|
+
|
|
33
|
+
if (!templateName) {
|
|
34
|
+
console.error(chalk.red.bold('❌ Error: El nombre de la plantilla es requerido.'));
|
|
35
|
+
process.exit(1);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Base: <cwd>/components/templates/<templateName>
|
|
39
|
+
const baseDir = createBaseDir(templateName, ['src', 'components', 'templates']);
|
|
40
|
+
|
|
41
|
+
if (fs.existsSync(baseDir)) {
|
|
42
|
+
console.error(chalk.red.bold(`❌ Error: La plantilla '${templateName}' ya existe en components/templates.`));
|
|
43
|
+
process.exit(1);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
try {
|
|
47
|
+
// Asegurar carpetas padre
|
|
48
|
+
ensureDir(createBaseDir('', ['src', 'components'])); // <cwd>/components
|
|
49
|
+
ensureDir(createBaseDir('', ['src', 'components', 'templates'])); // <cwd>/components/templates
|
|
50
|
+
|
|
51
|
+
// Crear carpeta de la plantilla
|
|
52
|
+
ensureDir(baseDir);
|
|
53
|
+
console.log(chalk.green(`✓ Creado directorio: ${chalk.bold(`src/components/templates/${templateName}`)}`));
|
|
54
|
+
|
|
55
|
+
// Subcarpetas requeridas
|
|
56
|
+
const subdirs = ['components', 'pages', 'styles', 'assets', 'helpers', 'hooks', 'types', 'locale'];
|
|
57
|
+
subdirs.forEach((dir) => {
|
|
58
|
+
ensureDir(joinPaths(baseDir, dir));
|
|
59
|
+
console.log(chalk.green(`✓ Creado directorio: ${chalk.bold(`src/components/templates/${templateName}/${dir}`)}`));
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// Subcarpetas dentro de components
|
|
63
|
+
const componentsSubdirs = ['common', 'skeletons', 'layout'];
|
|
64
|
+
componentsSubdirs.forEach((dir) => {
|
|
65
|
+
ensureDir(joinPaths(baseDir, 'components', dir));
|
|
66
|
+
console.log(chalk.green(`✓ Creado directorio: ${chalk.bold(`src/components/templates/${templateName}/components/${dir}`)}`));
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
// Subcarpetas dentro de pages con archivos index.tsx
|
|
70
|
+
const pagesSubdirs = ['store', 'preview'];
|
|
71
|
+
const pageTemplates = {
|
|
72
|
+
store: `const StorePage = () => {\n return (\n <></>\n )\n}\n\nexport default StorePage\n`,
|
|
73
|
+
preview: `const PreviewPage = () => {\n return (\n <></>\n )\n}\n\nexport default PreviewPage\n`
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
pagesSubdirs.forEach((dir) => {
|
|
77
|
+
const pageDirPath = joinPaths(baseDir, 'pages', dir);
|
|
78
|
+
ensureDir(pageDirPath);
|
|
79
|
+
console.log(chalk.green(`✓ Creado directorio: ${chalk.bold(`src/components/templates/${templateName}/pages/${dir}`)}`));
|
|
80
|
+
|
|
81
|
+
// Crear archivo index.tsx
|
|
82
|
+
const indexPath = joinPaths(pageDirPath, 'index.tsx');
|
|
83
|
+
fs.writeFileSync(indexPath, pageTemplates[dir]);
|
|
84
|
+
console.log(chalk.green(`✓ Creado archivo: ${chalk.bold(`src/components/templates/${templateName}/pages/${dir}/index.tsx`)}`));
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
// Archivos dentro de components/layout
|
|
88
|
+
const pascalCaseName = toPascalCase(templateName);
|
|
89
|
+
const layoutDir = joinPaths(baseDir, 'components', 'layout');
|
|
90
|
+
|
|
91
|
+
// index.tsx en layout
|
|
92
|
+
const layoutIndexContent = `const ${pascalCaseName}Layout = ({ children }: { children: React.ReactNode }) => {\n return (\n <></>\n )\n}\n\nexport default ${pascalCaseName}Layout\n`;
|
|
93
|
+
const layoutIndexPath = joinPaths(layoutDir, 'index.tsx');
|
|
94
|
+
fs.writeFileSync(layoutIndexPath, layoutIndexContent);
|
|
95
|
+
console.log(chalk.green(`✓ Creado archivo: ${chalk.bold(`src/components/templates/${templateName}/components/layout/index.tsx`)}`));
|
|
96
|
+
|
|
97
|
+
// preview.tsx en layout
|
|
98
|
+
const layoutPreviewContent = `interface ${pascalCaseName}PreviewLayoutProps extends React.PropsWithChildren {\n template?: string | null\n}\n\nconst ${pascalCaseName}PreviewLayout = ({ template = null, children }: ${pascalCaseName}PreviewLayoutProps) => {\n return (\n <></>\n )\n}\n\nexport default ${pascalCaseName}PreviewLayout\n`;
|
|
99
|
+
const layoutPreviewPath = joinPaths(layoutDir, 'preview.tsx');
|
|
100
|
+
fs.writeFileSync(layoutPreviewPath, layoutPreviewContent);
|
|
101
|
+
console.log(chalk.green(`✓ Creado archivo: ${chalk.bold(`src/components/templates/${templateName}/components/layout/preview.tsx`)}`));
|
|
102
|
+
|
|
103
|
+
// Estructura de locale
|
|
104
|
+
const localeDir = joinPaths(baseDir, 'locale');
|
|
105
|
+
const localeSubdirs = ['fields', 'messages'];
|
|
106
|
+
const localeFiles = ['en.json', 'es.json'];
|
|
107
|
+
const emptyJsonContent = '{}\n';
|
|
108
|
+
|
|
109
|
+
// Archivos en locale raíz
|
|
110
|
+
localeFiles.forEach((file) => {
|
|
111
|
+
const filePath = joinPaths(localeDir, file);
|
|
112
|
+
fs.writeFileSync(filePath, emptyJsonContent);
|
|
113
|
+
console.log(chalk.green(`✓ Creado archivo: ${chalk.bold(`src/components/templates/${templateName}/locale/${file}`)}`));
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
// Subcarpetas y archivos en locale
|
|
117
|
+
localeSubdirs.forEach((subdir) => {
|
|
118
|
+
const subdirPath = joinPaths(localeDir, subdir);
|
|
119
|
+
ensureDir(subdirPath);
|
|
120
|
+
console.log(chalk.green(`✓ Creado directorio: ${chalk.bold(`src/components/templates/${templateName}/locale/${subdir}`)}`));
|
|
121
|
+
|
|
122
|
+
localeFiles.forEach((file) => {
|
|
123
|
+
const filePath = joinPaths(subdirPath, file);
|
|
124
|
+
fs.writeFileSync(filePath, emptyJsonContent);
|
|
125
|
+
console.log(chalk.green(`✓ Creado archivo: ${chalk.bold(`src/components/templates/${templateName}/locale/${subdir}/${file}`)}`));
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
console.log(chalk.green.bold(`\n✨ Plantilla '${templateName}' creada correctamente.`));
|
|
130
|
+
} catch (error) {
|
|
131
|
+
console.error(chalk.red.bold(`❌ Error creando la plantilla: ${error.message}`));
|
|
132
|
+
process.exit(1);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
async function promptTemplateName() {
|
|
137
|
+
console.log(chalk.cyan.bold('\n==================================='));
|
|
138
|
+
console.log(chalk.cyan.bold(' Create Template'));
|
|
139
|
+
console.log(chalk.cyan.bold('===================================\n'));
|
|
140
|
+
|
|
141
|
+
const { templateName } = await prompt({
|
|
142
|
+
type: 'input',
|
|
143
|
+
name: 'templateName',
|
|
144
|
+
message: 'Ingresa el nombre de la plantilla:',
|
|
145
|
+
validate: (input) => {
|
|
146
|
+
const val = sanitizeTemplateName(input);
|
|
147
|
+
if (!val) return 'El nombre es requerido.';
|
|
148
|
+
const target = createBaseDir(val, ['src', 'components', 'templates']);
|
|
149
|
+
if (fs.existsSync(target)) return `La plantilla '${val}' ya existe.`;
|
|
150
|
+
return true;
|
|
151
|
+
},
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
return templateName;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// CLI
|
|
158
|
+
const templateNameArg = process.argv[2];
|
|
159
|
+
|
|
160
|
+
(async function main() {
|
|
161
|
+
let name = templateNameArg;
|
|
162
|
+
if (!name) {
|
|
163
|
+
name = await promptTemplateName();
|
|
164
|
+
}
|
|
165
|
+
createTemplate(name);
|
|
166
|
+
})().catch((err) => {
|
|
167
|
+
console.error(chalk.red.bold(`❌ Error inesperado: ${err.message}`));
|
|
168
|
+
process.exit(1);
|
|
169
|
+
});
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { createBaseDir, joinPaths } from './helpers/index.js';
|
|
4
|
+
import chalk from 'chalk';
|
|
5
|
+
import enquirer from 'enquirer';
|
|
6
|
+
import fs from 'fs';
|
|
7
|
+
import path from 'path';
|
|
8
|
+
|
|
9
|
+
const { prompt } = enquirer;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Removes the module import from the modules/index.ts file
|
|
13
|
+
* @param {string} moduleName The name of the module to remove
|
|
14
|
+
*/
|
|
15
|
+
function removeModuleImport(moduleName) {
|
|
16
|
+
const modulesDir = createBaseDir('modules', ['core']);
|
|
17
|
+
const indexPath = joinPaths(modulesDir, 'index.ts');
|
|
18
|
+
|
|
19
|
+
try {
|
|
20
|
+
if (fs.existsSync(indexPath)) {
|
|
21
|
+
let content = fs.readFileSync(indexPath, 'utf8');
|
|
22
|
+
const importStatement = `import './${moduleName}'`;
|
|
23
|
+
|
|
24
|
+
// Remove the import line if it exists
|
|
25
|
+
const lines = content.split('\n').filter(line => !line.includes(importStatement));
|
|
26
|
+
|
|
27
|
+
// Clean up empty lines between imports
|
|
28
|
+
let cleanedLines = [];
|
|
29
|
+
let lastLineWasEmpty = false;
|
|
30
|
+
|
|
31
|
+
for (const line of lines) {
|
|
32
|
+
if (line.trim() === '') {
|
|
33
|
+
if (!lastLineWasEmpty) {
|
|
34
|
+
cleanedLines.push(line);
|
|
35
|
+
lastLineWasEmpty = true;
|
|
36
|
+
}
|
|
37
|
+
} else {
|
|
38
|
+
cleanedLines.push(line);
|
|
39
|
+
lastLineWasEmpty = false;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
content = cleanedLines.join('\n');
|
|
44
|
+
|
|
45
|
+
fs.writeFileSync(indexPath, content);
|
|
46
|
+
console.log(chalk.green(`✓ Removed module import from ${chalk.bold('modules/index.ts')}`));
|
|
47
|
+
}
|
|
48
|
+
} catch (error) {
|
|
49
|
+
console.error(chalk.yellow(`⚠️ Warning: Could not update modules index: ${error.message}`));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Recursively removes a directory and its contents
|
|
55
|
+
* @param {string} dirPath The path to the directory to remove
|
|
56
|
+
*/
|
|
57
|
+
function removeDirectory(dirPath) {
|
|
58
|
+
if (fs.existsSync(dirPath)) {
|
|
59
|
+
fs.readdirSync(dirPath).forEach((file) => {
|
|
60
|
+
const curPath = path.join(dirPath, file);
|
|
61
|
+
if (fs.lstatSync(curPath).isDirectory()) {
|
|
62
|
+
removeDirectory(curPath);
|
|
63
|
+
} else {
|
|
64
|
+
fs.unlinkSync(curPath);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
fs.rmdirSync(dirPath);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Rolls back a core module creation
|
|
73
|
+
* @param {string} moduleName The name of the module to roll back
|
|
74
|
+
*/
|
|
75
|
+
async function rollbackModule(moduleName) {
|
|
76
|
+
if (!moduleName) {
|
|
77
|
+
console.error(chalk.red.bold('❌ Error: Core module name is required'));
|
|
78
|
+
console.log(chalk.yellow('⚠️ Usage: npm run rollback:core-module <module-name>'));
|
|
79
|
+
process.exit(1);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const baseDir = createBaseDir(moduleName, ['core', 'modules']);
|
|
83
|
+
|
|
84
|
+
// Check if module exists
|
|
85
|
+
if (!fs.existsSync(baseDir)) {
|
|
86
|
+
console.error(chalk.red.bold(`❌ Error: Core module '${moduleName}' does not exist`));
|
|
87
|
+
process.exit(1);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
try {
|
|
91
|
+
// Ask for confirmation
|
|
92
|
+
const response = await prompt({
|
|
93
|
+
type: 'confirm',
|
|
94
|
+
name: 'confirm',
|
|
95
|
+
message: chalk.yellow(`⚠️ Are you sure you want to delete the module '${moduleName}'? This action cannot be undone.`),
|
|
96
|
+
initial: false
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
if (!response.confirm) {
|
|
100
|
+
console.log(chalk.yellow('Operation cancelled.'));
|
|
101
|
+
process.exit(0);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Remove the module directory
|
|
105
|
+
removeDirectory(baseDir);
|
|
106
|
+
console.log(chalk.green(`✓ Removed module directory: ${chalk.bold(moduleName)}`));
|
|
107
|
+
|
|
108
|
+
// Remove the module import from index.ts
|
|
109
|
+
removeModuleImport(moduleName);
|
|
110
|
+
|
|
111
|
+
console.log(chalk.green.bold(`\n✨ Module '${moduleName}' successfully removed`));
|
|
112
|
+
} catch (error) {
|
|
113
|
+
if (error.message !== 'USER_CANCELLED') {
|
|
114
|
+
console.error(chalk.red.bold(`❌ Error rolling back module: ${error.message}`));
|
|
115
|
+
}
|
|
116
|
+
process.exit(1);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Lists all available core modules
|
|
122
|
+
* @returns {string[]} Array of module names
|
|
123
|
+
*/
|
|
124
|
+
function listAvailableModules() {
|
|
125
|
+
const modulesDir = createBaseDir('modules', ['core']);
|
|
126
|
+
|
|
127
|
+
try {
|
|
128
|
+
if (fs.existsSync(modulesDir)) {
|
|
129
|
+
return fs.readdirSync(modulesDir, { withFileTypes: true })
|
|
130
|
+
.filter(dirent => dirent.isDirectory())
|
|
131
|
+
.map(dirent => dirent.name);
|
|
132
|
+
}
|
|
133
|
+
} catch (error) {
|
|
134
|
+
console.error(chalk.yellow(`⚠️ Warning: Could not read modules directory: ${error.message}`));
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return [];
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Prompts the user to select a module to roll back
|
|
142
|
+
*/
|
|
143
|
+
async function promptModuleSelection() {
|
|
144
|
+
const modules = listAvailableModules();
|
|
145
|
+
|
|
146
|
+
if (modules.length === 0) {
|
|
147
|
+
console.error(chalk.red.bold('❌ Error: No core modules found'));
|
|
148
|
+
process.exit(1);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
try {
|
|
152
|
+
const response = await prompt({
|
|
153
|
+
type: 'select',
|
|
154
|
+
name: 'moduleName',
|
|
155
|
+
message: 'Select the module to roll back:',
|
|
156
|
+
choices: modules.map(module => ({
|
|
157
|
+
name: module,
|
|
158
|
+
value: module,
|
|
159
|
+
message: module
|
|
160
|
+
})),
|
|
161
|
+
styles: {
|
|
162
|
+
primary: chalk.cyan,
|
|
163
|
+
highlight: chalk.cyan.bold,
|
|
164
|
+
selected: chalk.red.bold
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
return response.moduleName;
|
|
169
|
+
} catch (error) {
|
|
170
|
+
console.log(chalk.yellow('⚠️ Operation cancelled.'));
|
|
171
|
+
process.exit(0);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// Get module name from command line arguments or prompt
|
|
176
|
+
const moduleNameArg = process.argv[2];
|
|
177
|
+
|
|
178
|
+
async function main() {
|
|
179
|
+
console.log(chalk.red.bold('\n==================================='));
|
|
180
|
+
console.log(chalk.red.bold(' Rollback Core Module'));
|
|
181
|
+
console.log(chalk.red.bold('===================================\n'));
|
|
182
|
+
|
|
183
|
+
let moduleName = moduleNameArg;
|
|
184
|
+
|
|
185
|
+
if (!moduleName) {
|
|
186
|
+
moduleName = await promptModuleSelection();
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
await rollbackModule(moduleName);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
main().catch(error => {
|
|
193
|
+
console.error(chalk.red.bold(`❌ Unexpected error: ${error.message}`));
|
|
194
|
+
process.exit(1);
|
|
195
|
+
});
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { createBaseDir, joinPaths } from './helpers/index.js';
|
|
4
|
+
import chalk from 'chalk';
|
|
5
|
+
import enquirer from 'enquirer';
|
|
6
|
+
import fs from 'fs';
|
|
7
|
+
import path from 'path';
|
|
8
|
+
|
|
9
|
+
const { prompt } = enquirer;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Removes the module import from the modules/index.ts file if it exists
|
|
13
|
+
* @param {string} moduleName The name of the module to remove
|
|
14
|
+
*/
|
|
15
|
+
function removeModuleImport(moduleName) {
|
|
16
|
+
const modulesDir = createBaseDir('modules', ['src']);
|
|
17
|
+
const indexPath = joinPaths(modulesDir, 'index.ts');
|
|
18
|
+
|
|
19
|
+
try {
|
|
20
|
+
if (fs.existsSync(indexPath)) {
|
|
21
|
+
let content = fs.readFileSync(indexPath, 'utf8');
|
|
22
|
+
const importStatement = `import './${moduleName}'`;
|
|
23
|
+
|
|
24
|
+
// Remove the import line if it exists
|
|
25
|
+
const lines = content.split('\n').filter(line => !line.includes(importStatement));
|
|
26
|
+
|
|
27
|
+
// Clean up empty lines between imports
|
|
28
|
+
let cleanedLines = [];
|
|
29
|
+
let lastLineWasEmpty = false;
|
|
30
|
+
|
|
31
|
+
for (const line of lines) {
|
|
32
|
+
if (line.trim() === '') {
|
|
33
|
+
if (!lastLineWasEmpty) {
|
|
34
|
+
cleanedLines.push(line);
|
|
35
|
+
lastLineWasEmpty = true;
|
|
36
|
+
}
|
|
37
|
+
} else {
|
|
38
|
+
cleanedLines.push(line);
|
|
39
|
+
lastLineWasEmpty = false;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
content = cleanedLines.join('\n');
|
|
44
|
+
|
|
45
|
+
fs.writeFileSync(indexPath, content);
|
|
46
|
+
console.log(chalk.green(`✓ Removed module import from ${chalk.bold('modules/index.ts')}`));
|
|
47
|
+
}
|
|
48
|
+
} catch (error) {
|
|
49
|
+
console.error(chalk.yellow(`⚠️ Warning: Could not update modules index: ${error.message}`));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Recursively removes a directory and its contents
|
|
55
|
+
* @param {string} dirPath The path to the directory to remove
|
|
56
|
+
*/
|
|
57
|
+
function removeDirectory(dirPath) {
|
|
58
|
+
if (fs.existsSync(dirPath)) {
|
|
59
|
+
fs.readdirSync(dirPath).forEach((file) => {
|
|
60
|
+
const curPath = path.join(dirPath, file);
|
|
61
|
+
if (fs.lstatSync(curPath).isDirectory()) {
|
|
62
|
+
removeDirectory(curPath);
|
|
63
|
+
} else {
|
|
64
|
+
fs.unlinkSync(curPath);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
fs.rmdirSync(dirPath);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Rolls back a module creation
|
|
73
|
+
* @param {string} moduleName The name of the module to roll back
|
|
74
|
+
*/
|
|
75
|
+
async function rollbackModule(moduleName) {
|
|
76
|
+
if (!moduleName) {
|
|
77
|
+
console.error(chalk.red.bold('❌ Error: Module name is required'));
|
|
78
|
+
console.log(chalk.yellow('⚠️ Usage: npm run rollback:module <module-name>'));
|
|
79
|
+
process.exit(1);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const baseDir = createBaseDir(moduleName, ['src', 'modules']);
|
|
83
|
+
|
|
84
|
+
// Check if module exists
|
|
85
|
+
if (!fs.existsSync(baseDir)) {
|
|
86
|
+
console.error(chalk.red.bold(`❌ Error: Module '${moduleName}' does not exist`));
|
|
87
|
+
process.exit(1);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
try {
|
|
91
|
+
// Ask for confirmation with module details
|
|
92
|
+
console.log(chalk.yellow('\nModule details:'));
|
|
93
|
+
console.log(chalk.yellow('─────────────────'));
|
|
94
|
+
console.log(chalk.yellow(`Location: ${baseDir}`));
|
|
95
|
+
|
|
96
|
+
// Show module contents
|
|
97
|
+
const contents = fs.readdirSync(baseDir, { withFileTypes: true });
|
|
98
|
+
console.log(chalk.yellow('Contents:'));
|
|
99
|
+
contents.forEach(item => {
|
|
100
|
+
const prefix = item.isDirectory() ? '📁' : '📄';
|
|
101
|
+
console.log(chalk.yellow(` ${prefix} ${item.name}`));
|
|
102
|
+
});
|
|
103
|
+
console.log(chalk.yellow('─────────────────\n'));
|
|
104
|
+
|
|
105
|
+
const response = await prompt({
|
|
106
|
+
type: 'confirm',
|
|
107
|
+
name: 'confirm',
|
|
108
|
+
message: chalk.yellow(`⚠️ Are you sure you want to delete this module? This action cannot be undone.`),
|
|
109
|
+
initial: false
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
if (!response.confirm) {
|
|
113
|
+
console.log(chalk.yellow('Operation cancelled.'));
|
|
114
|
+
process.exit(0);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Remove the module directory
|
|
118
|
+
removeDirectory(baseDir);
|
|
119
|
+
console.log(chalk.green(`✓ Removed module directory: ${chalk.bold(moduleName)}`));
|
|
120
|
+
|
|
121
|
+
// Remove the module import from index.ts
|
|
122
|
+
removeModuleImport(moduleName);
|
|
123
|
+
|
|
124
|
+
console.log(chalk.green.bold(`\n✨ Module '${moduleName}' successfully removed`));
|
|
125
|
+
} catch (error) {
|
|
126
|
+
if (error.message !== 'USER_CANCELLED') {
|
|
127
|
+
console.error(chalk.red.bold(`❌ Error rolling back module: ${error.message}`));
|
|
128
|
+
}
|
|
129
|
+
process.exit(1);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Lists all available modules
|
|
135
|
+
* @returns {string[]} Array of module names
|
|
136
|
+
*/
|
|
137
|
+
function listAvailableModules() {
|
|
138
|
+
const modulesDir = createBaseDir('modules', ['src']);
|
|
139
|
+
|
|
140
|
+
try {
|
|
141
|
+
if (fs.existsSync(modulesDir)) {
|
|
142
|
+
return fs.readdirSync(modulesDir, { withFileTypes: true })
|
|
143
|
+
.filter(dirent => dirent.isDirectory())
|
|
144
|
+
.map(dirent => dirent.name);
|
|
145
|
+
}
|
|
146
|
+
} catch (error) {
|
|
147
|
+
console.error(chalk.yellow(`⚠️ Warning: Could not read modules directory: ${error.message}`));
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return [];
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Prompts the user to select a module to roll back
|
|
155
|
+
*/
|
|
156
|
+
async function promptModuleSelection() {
|
|
157
|
+
const modules = listAvailableModules();
|
|
158
|
+
|
|
159
|
+
if (modules.length === 0) {
|
|
160
|
+
console.error(chalk.red.bold('❌ Error: No modules found'));
|
|
161
|
+
process.exit(1);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
try {
|
|
165
|
+
const response = await prompt({
|
|
166
|
+
type: 'select',
|
|
167
|
+
name: 'moduleName',
|
|
168
|
+
message: 'Select the module to roll back:',
|
|
169
|
+
choices: modules.map(module => ({
|
|
170
|
+
name: module,
|
|
171
|
+
value: module,
|
|
172
|
+
message: module
|
|
173
|
+
})),
|
|
174
|
+
styles: {
|
|
175
|
+
primary: chalk.cyan,
|
|
176
|
+
highlight: chalk.cyan.bold,
|
|
177
|
+
selected: chalk.red.bold
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
return response.moduleName;
|
|
182
|
+
} catch (error) {
|
|
183
|
+
console.log(chalk.yellow('⚠️ Operation cancelled.'));
|
|
184
|
+
process.exit(0);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// Get module name from command line arguments or prompt
|
|
189
|
+
const moduleNameArg = process.argv[2];
|
|
190
|
+
|
|
191
|
+
async function main() {
|
|
192
|
+
console.log(chalk.red.bold('\n==================================='));
|
|
193
|
+
console.log(chalk.red.bold(' Rollback Module'));
|
|
194
|
+
console.log(chalk.red.bold('===================================\n'));
|
|
195
|
+
|
|
196
|
+
let moduleName = moduleNameArg;
|
|
197
|
+
|
|
198
|
+
if (!moduleName) {
|
|
199
|
+
moduleName = await promptModuleSelection();
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
await rollbackModule(moduleName);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
main().catch(error => {
|
|
206
|
+
console.error(chalk.red.bold(`❌ Unexpected error: ${error.message}`));
|
|
207
|
+
process.exit(1);
|
|
208
|
+
});
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { useComposedRefs } from '../../../../../../../../react-compose-refs/dist/index.js';
|
|
3
|
-
import { useLayoutEffect as useLayoutEffect2 } from '../../../../../../../../react-use-layout-effect/dist/index.js';
|
|
4
|
-
|
|
5
|
-
function useStateMachine(initialState, machine) {
|
|
6
|
-
return React.useReducer((state, event) => {
|
|
7
|
-
const nextState = machine[state][event];
|
|
8
|
-
return nextState ?? state;
|
|
9
|
-
}, initialState);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
// src/presence.tsx
|
|
13
|
-
var Presence = (props) => {
|
|
14
|
-
const { present, children } = props;
|
|
15
|
-
const presence = usePresence(present);
|
|
16
|
-
const child = typeof children === "function" ? children({ present: presence.isPresent }) : React.Children.only(children);
|
|
17
|
-
const ref = useComposedRefs(presence.ref, getElementRef(child));
|
|
18
|
-
const forceMount = typeof children === "function";
|
|
19
|
-
return forceMount || presence.isPresent ? React.cloneElement(child, { ref }) : null;
|
|
20
|
-
};
|
|
21
|
-
Presence.displayName = "Presence";
|
|
22
|
-
function usePresence(present) {
|
|
23
|
-
const [node, setNode] = React.useState();
|
|
24
|
-
const stylesRef = React.useRef(null);
|
|
25
|
-
const prevPresentRef = React.useRef(present);
|
|
26
|
-
const prevAnimationNameRef = React.useRef("none");
|
|
27
|
-
const initialState = present ? "mounted" : "unmounted";
|
|
28
|
-
const [state, send] = useStateMachine(initialState, {
|
|
29
|
-
mounted: {
|
|
30
|
-
UNMOUNT: "unmounted",
|
|
31
|
-
ANIMATION_OUT: "unmountSuspended"
|
|
32
|
-
},
|
|
33
|
-
unmountSuspended: {
|
|
34
|
-
MOUNT: "mounted",
|
|
35
|
-
ANIMATION_END: "unmounted"
|
|
36
|
-
},
|
|
37
|
-
unmounted: {
|
|
38
|
-
MOUNT: "mounted"
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
React.useEffect(() => {
|
|
42
|
-
const currentAnimationName = getAnimationName(stylesRef.current);
|
|
43
|
-
prevAnimationNameRef.current = state === "mounted" ? currentAnimationName : "none";
|
|
44
|
-
}, [state]);
|
|
45
|
-
useLayoutEffect2(() => {
|
|
46
|
-
const styles = stylesRef.current;
|
|
47
|
-
const wasPresent = prevPresentRef.current;
|
|
48
|
-
const hasPresentChanged = wasPresent !== present;
|
|
49
|
-
if (hasPresentChanged) {
|
|
50
|
-
const prevAnimationName = prevAnimationNameRef.current;
|
|
51
|
-
const currentAnimationName = getAnimationName(styles);
|
|
52
|
-
if (present) {
|
|
53
|
-
send("MOUNT");
|
|
54
|
-
} else if (currentAnimationName === "none" || styles?.display === "none") {
|
|
55
|
-
send("UNMOUNT");
|
|
56
|
-
} else {
|
|
57
|
-
const isAnimating = prevAnimationName !== currentAnimationName;
|
|
58
|
-
if (wasPresent && isAnimating) {
|
|
59
|
-
send("ANIMATION_OUT");
|
|
60
|
-
} else {
|
|
61
|
-
send("UNMOUNT");
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
prevPresentRef.current = present;
|
|
65
|
-
}
|
|
66
|
-
}, [present, send]);
|
|
67
|
-
useLayoutEffect2(() => {
|
|
68
|
-
if (node) {
|
|
69
|
-
let timeoutId;
|
|
70
|
-
const ownerWindow = node.ownerDocument.defaultView ?? window;
|
|
71
|
-
const handleAnimationEnd = (event) => {
|
|
72
|
-
const currentAnimationName = getAnimationName(stylesRef.current);
|
|
73
|
-
const isCurrentAnimation = currentAnimationName.includes(CSS.escape(event.animationName));
|
|
74
|
-
if (event.target === node && isCurrentAnimation) {
|
|
75
|
-
send("ANIMATION_END");
|
|
76
|
-
if (!prevPresentRef.current) {
|
|
77
|
-
const currentFillMode = node.style.animationFillMode;
|
|
78
|
-
node.style.animationFillMode = "forwards";
|
|
79
|
-
timeoutId = ownerWindow.setTimeout(() => {
|
|
80
|
-
if (node.style.animationFillMode === "forwards") {
|
|
81
|
-
node.style.animationFillMode = currentFillMode;
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
const handleAnimationStart = (event) => {
|
|
88
|
-
if (event.target === node) {
|
|
89
|
-
prevAnimationNameRef.current = getAnimationName(stylesRef.current);
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
node.addEventListener("animationstart", handleAnimationStart);
|
|
93
|
-
node.addEventListener("animationcancel", handleAnimationEnd);
|
|
94
|
-
node.addEventListener("animationend", handleAnimationEnd);
|
|
95
|
-
return () => {
|
|
96
|
-
ownerWindow.clearTimeout(timeoutId);
|
|
97
|
-
node.removeEventListener("animationstart", handleAnimationStart);
|
|
98
|
-
node.removeEventListener("animationcancel", handleAnimationEnd);
|
|
99
|
-
node.removeEventListener("animationend", handleAnimationEnd);
|
|
100
|
-
};
|
|
101
|
-
} else {
|
|
102
|
-
send("ANIMATION_END");
|
|
103
|
-
}
|
|
104
|
-
}, [node, send]);
|
|
105
|
-
return {
|
|
106
|
-
isPresent: ["mounted", "unmountSuspended"].includes(state),
|
|
107
|
-
ref: React.useCallback((node2) => {
|
|
108
|
-
stylesRef.current = node2 ? getComputedStyle(node2) : null;
|
|
109
|
-
setNode(node2);
|
|
110
|
-
}, [])
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
function getAnimationName(styles) {
|
|
114
|
-
return styles?.animationName || "none";
|
|
115
|
-
}
|
|
116
|
-
function getElementRef(element) {
|
|
117
|
-
let getter = Object.getOwnPropertyDescriptor(element.props, "ref")?.get;
|
|
118
|
-
let mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
|
|
119
|
-
if (mayWarn) {
|
|
120
|
-
return element.ref;
|
|
121
|
-
}
|
|
122
|
-
getter = Object.getOwnPropertyDescriptor(element, "ref")?.get;
|
|
123
|
-
mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
|
|
124
|
-
if (mayWarn) {
|
|
125
|
-
return element.props.ref;
|
|
126
|
-
}
|
|
127
|
-
return element.props.ref || element.ref;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export { Presence };
|