@devstroupe/devkit-cli 1.1.11 → 1.1.13

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 (2) hide show
  1. package/dist/index.js +81 -0
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -557,12 +557,38 @@ function initUi(frontendRoot, config) {
557
557
  fs.writeFileSync(path.join(profileDir, 'profile.component.ts'), prf.ts, 'utf-8');
558
558
  fs.writeFileSync(path.join(profileDir, 'profile.component.html'), prf.html, 'utf-8');
559
559
  fs.writeFileSync(path.join(profileDir, 'profile.component.css'), prf.css, 'utf-8');
560
+ // 20. Escrever devkit.css contendo o tema de cores dinâmico
561
+ const themeCss = (0, ui_templates_1.devkitThemeCssTemplate)({
562
+ preset: config.designSystem?.spartanStyle,
563
+ theme: config.designSystem?.spartanTheme === 'custom' ? 'custom' : config.designSystem?.spartanTheme,
564
+ primaryColor: config.designSystem?.primaryColor,
565
+ secondaryColor: config.designSystem?.secondaryColor,
566
+ fontFamily: config.designSystem?.fontFamily
567
+ });
568
+ fs.writeFileSync(path.join(targetDir, 'devkit.css'), themeCss, 'utf-8');
569
+ console.log(`[UI] Tema de cores gerado com sucesso em: ${path.join(targetDir, 'devkit.css')}`);
570
+ // 21. Garantir import do devkit.css no styles.css/styles.scss
571
+ ensureDevkitCssImport(frontendRoot);
560
572
  console.log(`[UI] Componentes DevKit, layout, Playground, ThemeService, ProfileService e ProfileComponent gerados com Spartan style="${spartanStyle}".`);
561
573
  // Configurar tsconfig.json
562
574
  ensureTsconfigPaths(frontendRoot);
563
575
  // Atualizar roteamento para suportar MainLayoutComponent
564
576
  updateAppRoutes(frontendRoot, config);
565
577
  }
578
+ function ensureDevkitCssImport(frontendRoot) {
579
+ const stylesPath = [
580
+ path.join(frontendRoot, 'src', 'styles.css'),
581
+ path.join(frontendRoot, 'src', 'styles.scss')
582
+ ].find((candidate) => fs.existsSync(candidate));
583
+ if (!stylesPath)
584
+ return;
585
+ let content = fs.readFileSync(stylesPath, 'utf-8');
586
+ if (!content.includes('devkit.css')) {
587
+ content += '\n@import "./app/shared/components/devkit/devkit.css";\n';
588
+ fs.writeFileSync(stylesPath, content, 'utf-8');
589
+ console.log('[UI] @import do devkit.css adicionado ao arquivo de estilos principal.');
590
+ }
591
+ }
566
592
  function getEntityRoutePath(entityName, config) {
567
593
  const navigation = config.layout?.navigation;
568
594
  if (!Array.isArray(navigation)) {
@@ -672,6 +698,10 @@ export const routes: Routes = [
672
698
  }
673
699
  console.log('[Roteamento] app.entity-routes.ts sincronizado com as entidades ativas.');
674
700
  updateMainLayoutNavigation(frontendRoot, activeEntities, config.layout?.navigation);
701
+ // Atualizar permissões no backend (seed) e frontend (componente de gerenciamento de perfis)
702
+ const backendRoot = path.resolve(process.cwd(), config.backendPath || './backend');
703
+ updateDatabaseSeedPermissions(backendRoot, config);
704
+ updateRolePermissionsComponent(frontendRoot, config);
675
705
  }
676
706
  function updateMainLayoutNavigation(frontendRoot, entities = [], configuredNavigation) {
677
707
  const layoutPath = path.join(frontendRoot, 'src', 'app', 'shared', 'layouts', 'main-layout', 'main-layout.component.ts');
@@ -730,6 +760,57 @@ function updateMainLayoutNavigation(frontendRoot, entities = [], configuredNavig
730
760
  fs.writeFileSync(layoutPath, updated, 'utf-8');
731
761
  console.log('[Navegação] Menu principal sincronizado com as entidades ativas.');
732
762
  }
763
+ function updateDatabaseSeedPermissions(backendRoot, config) {
764
+ const seedPath = path.join(backendRoot, 'src', 'modules', 'user', 'database-seed.service.ts');
765
+ if (!fs.existsSync(seedPath))
766
+ return;
767
+ const entities = config.entities || [];
768
+ try {
769
+ let content = fs.readFileSync(seedPath, 'utf-8');
770
+ // Substituir allPermissions
771
+ const allPermissionsRegex = /const allPermissions = \[[^\]]*\];/s;
772
+ const newAllPermissions = `const allPermissions = [
773
+ '*',
774
+ 'read:role', 'create:role', 'update:role', 'delete:role', 'manage:permissions',
775
+ ${entities.map((e) => {
776
+ const name = e.name.toLowerCase();
777
+ return `'read:${name}', 'create:${name}', 'update:${name}', 'delete:${name}'`;
778
+ }).join(',\n ')}
779
+ ];`;
780
+ content = content.replace(allPermissionsRegex, newAllPermissions);
781
+ // Substituir permissões do Usuário Comum
782
+ const userPermissionsRegex = /name: 'Usuário Comum',\s+permissions: \[[^\]]*\],/s;
783
+ const newUserPermissions = `name: 'Usuário Comum',\n permissions: [${entities.map((e) => `'read:${e.name.toLowerCase()}'`).join(', ')}],`;
784
+ content = content.replace(userPermissionsRegex, newUserPermissions);
785
+ fs.writeFileSync(seedPath, content, 'utf-8');
786
+ console.log('[Permissões] database-seed.service.ts atualizado com as permissões das novas entidades.');
787
+ }
788
+ catch (err) {
789
+ console.error('[Erro] Falha ao atualizar permissões no database-seed.service.ts:', err);
790
+ }
791
+ }
792
+ function updateRolePermissionsComponent(frontendRoot, config) {
793
+ const compPath = path.join(frontendRoot, 'src', 'app', 'modules', 'role', 'role-permissions.component.ts');
794
+ if (!fs.existsSync(compPath))
795
+ return;
796
+ const entities = config.entities || [];
797
+ try {
798
+ let content = fs.readFileSync(compPath, 'utf-8');
799
+ const resourcesRegex = /resources: ResourceItem\[\] = \[[^\]]*\];/s;
800
+ const newResources = `resources: ResourceItem[] = [
801
+ { name: 'role', label: 'Perfis de Acesso' },
802
+ ${entities.map((e) => {
803
+ return `{ name: '${e.name.toLowerCase()}', label: '${e.label || kebabToPascal(e.name)}' }`;
804
+ }).join(',\n ')}
805
+ ];`;
806
+ content = content.replace(resourcesRegex, newResources);
807
+ fs.writeFileSync(compPath, content, 'utf-8');
808
+ console.log('[Permissões] role-permissions.component.ts atualizado com os recursos das novas entidades.');
809
+ }
810
+ catch (err) {
811
+ console.error('[Erro] Falha ao atualizar recursos no role-permissions.component.ts:', err);
812
+ }
813
+ }
733
814
  function writeAppNavigation(frontendRoot, navigation) {
734
815
  const navigationPath = path.join(frontendRoot, 'src', 'app', 'app.navigation.ts');
735
816
  const items = JSON.stringify(navigation, null, 2)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devstroupe/devkit-cli",
3
- "version": "1.1.11",
3
+ "version": "1.1.13",
4
4
  "description": "DevsTroupe Development Kit CLI — scaffold NestJS+Angular projects, inject Spartan UI, generate CRUDs and audit architectural governance",
5
5
  "license": "MIT",
6
6
  "keywords": [
@@ -36,7 +36,7 @@
36
36
  "dependencies": {
37
37
  "commander": "^12.0.0",
38
38
  "fs-extra": "^11.2.0",
39
- "@devstroupe/devkit-core": "1.1.11"
39
+ "@devstroupe/devkit-core": "1.1.13"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@types/fs-extra": "^11.0.4",