@artilingo/artiframe-cli 1.2.1 → 1.4.0

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.
@@ -0,0 +1,82 @@
1
+ <?php
2
+ namespace ArtiFrame\Cli\Commands;
3
+
4
+ use ArtiFrame\Cli\Services\Translator;
5
+ use ArtiFrame\Cli\Services\Safeguard;
6
+
7
+ class TableCommand
8
+ {
9
+ private Translator $translator;
10
+ private Safeguard $safeguard;
11
+
12
+ public function __construct(Translator $translator)
13
+ {
14
+ $this->translator = $translator;
15
+ $this->safeguard = new Safeguard($translator);
16
+ }
17
+
18
+ public function execute(array $args): void
19
+ {
20
+ $tableName = $args[0] ?? null;
21
+ $action = $args[1] ?? null;
22
+
23
+ if (!$tableName) {
24
+ echo "❌ " . $this->translator->get('ERROR_TABLE_NAME_REQUIRED') . PHP_EOL;
25
+ return;
26
+ }
27
+
28
+ $stubPath = \ARTIFRAME_CLI_ROOT . '/stubs/sql.stub';
29
+
30
+ if (!file_exists($stubPath)) {
31
+ echo "❌ " . $this->translator->get('ERROR_STUB_NOT_FOUND') . PHP_EOL;
32
+ return;
33
+ }
34
+
35
+ $stubContent = file_get_contents($stubPath);
36
+
37
+ // table list
38
+ if ($tableName === 'list') {
39
+ echo "\033[1;36m" . $this->translator->get('TABLE_LIST_HEADER') . "\033[0m" . PHP_EOL;
40
+ preg_match_all('/-- \[TABLE:(.*?)\]/s', $stubContent, $matches);
41
+
42
+ if (!empty($matches[1])) {
43
+ foreach ($matches[1] as $table) {
44
+ $descKey = 'TABLE_DESC_' . strtoupper($table);
45
+ $desc = $this->translator->get($descKey);
46
+ if ($desc === $descKey) {
47
+ $desc = '-';
48
+ }
49
+ echo " \033[0;32m" . str_pad($table, 20) . "\033[0m : " . $desc . PHP_EOL;
50
+ }
51
+ }
52
+ return;
53
+ }
54
+
55
+ $pattern = "/-- \[TABLE:{$tableName}\](.*?)-- \[\/TABLE:{$tableName}\]/s";
56
+
57
+ if (!preg_match($pattern, $stubContent, $matches)) {
58
+ echo "❌ " . sprintf($this->translator->get('ERROR_TABLE_NOT_IN_STUB'), $tableName) . PHP_EOL;
59
+ return;
60
+ }
61
+
62
+ $tableContent = trim($matches[1]);
63
+
64
+ // table:name check
65
+ if ($action === 'check') {
66
+ echo "\033[1;33m--- SQL FOR `{$tableName}` ---\033[0m" . PHP_EOL;
67
+ echo $tableContent . PHP_EOL;
68
+ echo "\033[1;33m---------------------------\033[0m" . PHP_EOL;
69
+ return;
70
+ }
71
+
72
+ $schemaPath = getcwd() . '/schema.sql';
73
+
74
+ if (!file_exists($schemaPath)) {
75
+ file_put_contents($schemaPath, "-- ArtiFrame DB Schema\n-- Created: " . date('Y-m-d') . "\n");
76
+ }
77
+
78
+ file_put_contents($schemaPath, "\n" . $tableContent . "\n", FILE_APPEND);
79
+
80
+ echo "✅ " . sprintf($this->translator->get('SUCCESS_TABLE_ADDED'), $tableName) . PHP_EOL;
81
+ }
82
+ }
package/src/Lang/de.php CHANGED
@@ -75,6 +75,8 @@ return [
75
75
  'HELP_MAJOR_DOWN' => 'Letzte Major-Version zurücksetzen.',
76
76
  'HELP_HELP_DESC' => 'Diese Hilfemeldung anzeigen.',
77
77
  'HELP_EXIT_DESC' => 'Die interaktive Shell beenden.',
78
+ 'HELP_AUTH_DESC' => 'Authentifizieren Sie sich bei GitHub, um Vorschläge einzureichen.',
79
+ 'HELP_SUGGEST_DESC' => 'Reichen Sie einen Funktionswunsch, Fehlerbericht oder Vorschlag direkt bei GitHub ein.',
78
80
 
79
81
  // LangCommand
80
82
  'LANG_CURRENT' => 'Aktuelle Sprache:',
@@ -166,4 +168,16 @@ return [
166
168
  'MODE_INVALID' => 'Ungültiger Modus. Verwenden Sie 1 für Debug, 0 für Prod.',
167
169
  'MODE_NOT_PROJECT' => 'ArtiFrame-Projekt nicht gefunden (config/app-version.php fehlt).',
168
170
  'HELP_MODE_DESC' => 'Ändert den Anwendungsmodus (0=Prod, 1=Debug)',
171
+
172
+ // Table
173
+ 'ERROR_TABLE_NAME_REQUIRED' => 'Tabellenname ist erforderlich.',
174
+ 'ERROR_STUB_NOT_FOUND' => 'sql.stub Datei konnte nicht gefunden werden.',
175
+ 'ERROR_TABLE_NOT_IN_STUB' => 'Tabellendefinition \'%s\' nicht in der Stub-Datei gefunden.',
176
+ 'SUCCESS_TABLE_ADDED' => 'Tabelle \'%s\' erfolgreich an schema.sql angehängt.',
177
+ 'HELP_TABLE_DESC' => 'Hängt ein Standard-Tabellenschema aus sql.stub an schema.sql an.',
178
+ 'TABLE_LIST_HEADER' => 'Unterstützte Tabellen:',
179
+ 'TABLE_DESC_USERS' => 'Basis-Benutzer- und Autorisierungstabelle (UUID).',
180
+ 'TABLE_DESC_USER_SESSIONS' => 'Benutzersitzungen (IP, Gerät, Token) verfolgen.',
181
+ 'TABLE_DESC_USER_PREFERENCES' => 'Benutzereinstellungen (Sprache, Thema, Benachrichtigungen).',
182
+
169
183
  ];
package/src/Lang/en.php CHANGED
@@ -75,6 +75,8 @@ return [
75
75
  'HELP_MAJOR_DOWN' => 'Roll back last major release.',
76
76
  'HELP_HELP_DESC' => 'Show this help message.',
77
77
  'HELP_EXIT_DESC' => 'Exit the interactive shell.',
78
+ 'HELP_AUTH_DESC' => 'Authenticate with GitHub to enable issue suggestions.',
79
+ 'HELP_SUGGEST_DESC' => 'Submit a feature request, bug report, or helper suggestion directly to GitHub.',
78
80
 
79
81
  // LangCommand
80
82
  'LANG_CURRENT' => 'Current language:',
@@ -166,4 +168,16 @@ return [
166
168
  'MODE_INVALID' => 'Invalid mode. Use 1 for Debug, 0 for Prod.',
167
169
  'MODE_NOT_PROJECT' => 'ArtiFrame project not found (config/app-version.php missing).',
168
170
  'HELP_MODE_DESC' => 'Changes the application mode (0=Prod, 1=Debug)',
171
+
172
+ // Table
173
+ 'ERROR_TABLE_NAME_REQUIRED' => 'Table name is required.',
174
+ 'ERROR_STUB_NOT_FOUND' => 'sql.stub file could not be found.',
175
+ 'ERROR_TABLE_NOT_IN_STUB' => 'Table definition \'%s\' not found in stub file.',
176
+ 'SUCCESS_TABLE_ADDED' => 'Table \'%s\' successfully appended to schema.sql',
177
+ 'HELP_TABLE_DESC' => 'Appends a standard table schema from sql.stub to schema.sql',
178
+ 'TABLE_LIST_HEADER' => 'Supported Tables:',
179
+ 'TABLE_DESC_USERS' => 'Basic user and authorization table (UUID).',
180
+ 'TABLE_DESC_USER_SESSIONS' => 'User sessions (IP, device, token) tracking.',
181
+ 'TABLE_DESC_USER_PREFERENCES' => 'User preferences (language, theme, notifications).',
182
+
169
183
  ];
package/src/Lang/es.php CHANGED
@@ -75,6 +75,8 @@ return [
75
75
  'HELP_MAJOR_DOWN' => 'Revertir la última versión mayor.',
76
76
  'HELP_HELP_DESC' => 'Mostrar este mensaje de ayuda.',
77
77
  'HELP_EXIT_DESC' => 'Salir del shell interactivo.',
78
+ 'HELP_AUTH_DESC' => 'Autentifícate con GitHub para habilitar las sugerencias de issues.',
79
+ 'HELP_SUGGEST_DESC' => 'Envía una solicitud de función, un informe de error o una sugerencia de ayuda directamente a GitHub.',
78
80
 
79
81
  // LangCommand
80
82
  'LANG_CURRENT' => 'Idioma actual:',
@@ -166,4 +168,16 @@ return [
166
168
  'MODE_INVALID' => 'Modo no válido. Use 1 para Depuración, 0 para Producción.',
167
169
  'MODE_NOT_PROJECT' => 'Proyecto ArtiFrame no encontrado (falta config/app-version.php).',
168
170
  'HELP_MODE_DESC' => 'Cambia el modo de la aplicación (0=Prod, 1=Debug)',
171
+
172
+ // Table
173
+ 'ERROR_TABLE_NAME_REQUIRED' => 'El nombre de la tabla es obligatorio.',
174
+ 'ERROR_STUB_NOT_FOUND' => 'No se pudo encontrar el archivo sql.stub.',
175
+ 'ERROR_TABLE_NOT_IN_STUB' => 'Definición de tabla \'%s\' no encontrada en el archivo stub.',
176
+ 'SUCCESS_TABLE_ADDED' => 'Tabla \'%s\' añadida con éxito a schema.sql',
177
+ 'HELP_TABLE_DESC' => 'Añade un esquema de tabla estándar de sql.stub a schema.sql',
178
+ 'TABLE_LIST_HEADER' => 'Tablas compatibles:',
179
+ 'TABLE_DESC_USERS' => 'Tabla básica de usuarios y autorización (UUID).',
180
+ 'TABLE_DESC_USER_SESSIONS' => 'Seguimiento de sesiones de usuario (IP, dispositivo, token).',
181
+ 'TABLE_DESC_USER_PREFERENCES' => 'Preferencias de usuario (idioma, tema, notificaciones).',
182
+
169
183
  ];
package/src/Lang/fr.php CHANGED
@@ -75,6 +75,8 @@ return [
75
75
  'HELP_MAJOR_DOWN' => 'Annuler la dernière version majeure.',
76
76
  'HELP_HELP_DESC' => 'Afficher ce message d\'aide.',
77
77
  'HELP_EXIT_DESC' => 'Quitter le shell interactif.',
78
+ 'HELP_AUTH_DESC' => 'Authentifiez-vous avec GitHub pour permettre les suggestions.',
79
+ 'HELP_SUGGEST_DESC' => 'Soumettez une demande de fonctionnalité, un rapport de bogue ou une suggestion d\'aide directement sur GitHub.',
78
80
 
79
81
  // LangCommand
80
82
  'LANG_CURRENT' => 'Langue actuelle :',
@@ -166,4 +168,16 @@ return [
166
168
  'MODE_INVALID' => 'Mode invalide. Utilisez 1 pour Débogage, 0 pour Production.',
167
169
  'MODE_NOT_PROJECT' => 'Projet ArtiFrame introuvable (config/app-version.php manquant).',
168
170
  'HELP_MODE_DESC' => 'Modifie le mode de l\'application (0=Prod, 1=Debug)',
171
+
172
+ // Table
173
+ 'ERROR_TABLE_NAME_REQUIRED' => 'Le nom de la table est requis.',
174
+ 'ERROR_STUB_NOT_FOUND' => 'Le fichier sql.stub est introuvable.',
175
+ 'ERROR_TABLE_NOT_IN_STUB' => 'La définition de la table \'%s\' est introuvable dans le fichier stub.',
176
+ 'SUCCESS_TABLE_ADDED' => 'Table \'%s\' ajoutée avec succès à schema.sql',
177
+ 'HELP_TABLE_DESC' => 'Ajoute un schéma de table standard de sql.stub à schema.sql',
178
+ 'TABLE_LIST_HEADER' => 'Tables prises en charge :',
179
+ 'TABLE_DESC_USERS' => 'Table de base pour les utilisateurs et l\'autorisation (UUID).',
180
+ 'TABLE_DESC_USER_SESSIONS' => 'Suivi des sessions utilisateur (IP, appareil, token).',
181
+ 'TABLE_DESC_USER_PREFERENCES' => 'Préférences de l\'utilisateur (langue, thème, notifications).',
182
+
169
183
  ];
package/src/Lang/tr.php CHANGED
@@ -74,7 +74,9 @@ return [
74
74
  'HELP_MINOR_DOWN' => 'Son minör sürümün geri alınması.',
75
75
  'HELP_MAJOR_DOWN' => 'Son majör sürümün geri alınması.',
76
76
  'HELP_HELP_DESC' => 'Bu yardım mesajını gösterir.',
77
- 'HELP_EXIT_DESC' => 'İnteraktif kabuğu kapatır.',
77
+ 'HELP_EXIT_DESC' => 'Etkileşimli kabuktan çık.',
78
+ 'HELP_AUTH_DESC' => 'Issue önerileri için GitHub ile kimlik doğrulaması yapın.',
79
+ 'HELP_SUGGEST_DESC' => 'GitHub\'a doğrudan özellik isteği, hata bildirimi veya öneri gönderin.',
78
80
 
79
81
  // LangCommand
80
82
  'LANG_CURRENT' => 'Mevcut dil:',
@@ -166,4 +168,16 @@ return [
166
168
  'MODE_INVALID' => 'Hatalı mod. Debug için 1, Prod için 0 kullanın.',
167
169
  'MODE_NOT_PROJECT' => 'ArtiFrame projesi bulunamadı (config/app-version.php eksik).',
168
170
  'HELP_MODE_DESC' => 'Uygulama çalışma modunu değiştirir (0=Prod, 1=Debug)',
171
+
172
+ // Table
173
+ 'ERROR_TABLE_NAME_REQUIRED' => 'Tablo adı gerekli.',
174
+ 'ERROR_STUB_NOT_FOUND' => 'sql.stub dosyası bulunamadı.',
175
+ 'ERROR_TABLE_NOT_IN_STUB' => '\'%s\' tablo şablonu stub dosyasında bulunamadı.',
176
+ 'SUCCESS_TABLE_ADDED' => '\'%s\' tablosu başarıyla schema.sql dosyasına eklendi.',
177
+ 'HELP_TABLE_DESC' => 'sql.stub dosyasındaki standart tablo yapılarını schema.sql\'e ekler.',
178
+ 'TABLE_LIST_HEADER' => 'Desteklenen Tablolar:',
179
+ 'TABLE_DESC_USERS' => 'Temel kullanıcı ve yetkilendirme tablosu (UUID).',
180
+ 'TABLE_DESC_USER_SESSIONS' => 'Kullanıcı oturumları (IP, cihaz, token) takibi.',
181
+ 'TABLE_DESC_USER_PREFERENCES' => 'Kullanıcı tercihleri (dil, tema, bildirimler).',
182
+
169
183
  ];
package/stubs/sql.stub ADDED
@@ -0,0 +1,46 @@
1
+ -- [TABLE:users]
2
+ CREATE TABLE `users` (
3
+ `id` binary(16) NOT NULL,
4
+ `email` varchar(255) NOT NULL,
5
+ `password` varchar(255) NOT NULL,
6
+ `name` varchar(255) DEFAULT NULL,
7
+ `role` enum('user','admin','moderator') NOT NULL DEFAULT 'user',
8
+ `status` tinyint(1) NOT NULL DEFAULT '1',
9
+ `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
10
+ `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
11
+ PRIMARY KEY (`id`),
12
+ UNIQUE KEY `email` (`email`)
13
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
14
+ -- [/TABLE:users]
15
+
16
+ -- [TABLE:user_sessions]
17
+ CREATE TABLE `user_sessions` (
18
+ `id` binary(16) NOT NULL,
19
+ `user_id` binary(16) NOT NULL,
20
+ `token` varchar(255) NOT NULL,
21
+ `ip_address` varchar(45) DEFAULT NULL,
22
+ `user_agent` varchar(255) DEFAULT NULL,
23
+ `expires_at` timestamp NULL DEFAULT NULL,
24
+ `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
25
+ PRIMARY KEY (`id`),
26
+ UNIQUE KEY `token` (`token`),
27
+ KEY `user_id` (`user_id`),
28
+ CONSTRAINT `fk_user_sessions_user_id` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
29
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
30
+ -- [/TABLE:user_sessions]
31
+
32
+ -- [TABLE:user_preferences]
33
+ CREATE TABLE `user_preferences` (
34
+ `id` binary(16) NOT NULL,
35
+ `user_id` binary(16) NOT NULL,
36
+ `language` varchar(10) NOT NULL DEFAULT 'tr',
37
+ `theme` varchar(20) NOT NULL DEFAULT 'light',
38
+ `push_notifications` tinyint(1) NOT NULL DEFAULT '1',
39
+ `email_notifications` tinyint(1) NOT NULL DEFAULT '1',
40
+ `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
41
+ `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
42
+ PRIMARY KEY (`id`),
43
+ UNIQUE KEY `user_id` (`user_id`),
44
+ CONSTRAINT `fk_user_prefs_user_id` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
45
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
46
+ -- [/TABLE:user_preferences]