@orxataguy/tyr 1.0.26 → 1.0.28

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orxataguy/tyr",
3
- "version": "1.0.26",
3
+ "version": "1.0.28",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "tyr": "./bin/tyr.js"
@@ -4,7 +4,7 @@ import path from 'path';
4
4
  import { homedir } from 'os';
5
5
 
6
6
  export interface Logger {
7
- line(dashed: boolean): void;
7
+ line(opts: any): void;
8
8
  log(msg: any): void;
9
9
  info(msg: any): void;
10
10
  success(msg: any): void;
@@ -28,9 +28,16 @@ export function createLogger(isDebug: boolean): Logger {
28
28
  };
29
29
 
30
30
  return {
31
- line: (dashed) => {
32
- if (dashed) {
33
- console.log('══════════════════════════════════════════════');
31
+ line: (opts) => {
32
+ if (opts) {
33
+ let {char, title, count} = opts;
34
+ if (!count) count = 45;
35
+ let content = '';
36
+ if (title) content = `${char} ${title} ${char}`;
37
+ else {
38
+ for (let i = 0; i < count; i++) content += char;
39
+ }
40
+ console.log(content);
34
41
  } else {
35
42
  console.log('');
36
43
  }
@@ -59,6 +59,33 @@ function detectShellRcFile(homeDir: string): string | null {
59
59
  return fallbacks.find(p => existsSync(p)) ?? path.join(homeDir, '.bashrc');
60
60
  }
61
61
 
62
+ function getWindowsProfilePaths(): string[] {
63
+ const userProfile = process.env.USERPROFILE;
64
+ if (!userProfile) return [];
65
+ return [
66
+ path.join(userProfile, 'Documents', 'WindowsPowerShell', 'Microsoft.PowerShell_profile.ps1'),
67
+ path.join(userProfile, 'Documents', 'PowerShell', 'Microsoft.PowerShell_profile.ps1'),
68
+ ];
69
+ }
70
+
71
+ async function checkWindowsExecutionPolicy(shell: any, logger: any): Promise<void> {
72
+ try {
73
+ const output: string = await shell.exec(
74
+ 'powershell -NoProfile -Command "Get-ExecutionPolicy -Scope CurrentUser"',
75
+ );
76
+ const policy = String(output).trim();
77
+
78
+ if (policy === 'Restricted' || policy === 'AllSigned' || policy === 'Undefined') {
79
+ logger.warn(`\nExecution Policy actual: ${policy || 'Undefined'}`);
80
+ logger.warn('Con esta política, PowerShell puede bloquear la carga de tu perfil (y por tanto las funciones/alias de Tyr).');
81
+ logger.info('Para permitirlo, ejecuta en una consola de PowerShell:');
82
+ logger.info(' Set-ExecutionPolicy RemoteSigned -Scope CurrentUser');
83
+ }
84
+ } catch {
85
+ logger.warn('No se pudo comprobar la Execution Policy de PowerShell. Verifícala manualmente si los comandos no cargan.');
86
+ }
87
+ }
88
+
62
89
  const PACKAGE_JSON_TEMPLATE = `{
63
90
  "name": "tyr-commands",
64
91
  "version": "1.0.0",
@@ -153,19 +180,26 @@ async function configureUnixShell(tyrFs: any, logger: any, homeDir: string, alia
153
180
  logger.info(`Ejecuta: source ${rcFile} (o abre una nueva terminal)`);
154
181
  }
155
182
 
156
- async function configureWindowsShell(tyrFs: any, logger: any, aliasesPath: string, pluginsPath: string): Promise<void> {
157
- const psProfile = process.env.USERPROFILE
158
- ? path.join(process.env.USERPROFILE, 'Documents', 'PowerShell', 'Microsoft.PowerShell_profile.ps1')
159
- : null;
160
- if (!psProfile) {
161
- logger.warn('Could not detect PowerShell profile.');
183
+ async function configureWindowsShell(tyrFs: any, logger: any, shell: any, aliasesPath: string, pluginsPath: string): Promise<void> {
184
+ const profiles = getWindowsProfilePaths();
185
+
186
+ if (profiles.length === 0) {
187
+ logger.warn('Could not detect PowerShell profile (USERPROFILE no está definido).');
162
188
  logger.info(`Add manually:\n . "${aliasesPath}"\n . "${pluginsPath}"`);
163
189
  return;
164
190
  }
165
- await tyrFs.ensureLine(psProfile, `. "${aliasesPath}"`);
166
- await tyrFs.ensureLine(psProfile, `. "${pluginsPath}"`);
167
- logger.success(`PowerShell profile configured: ${psProfile}`);
168
- logger.info('Restart PowerShell to apply the changes.');
191
+
192
+ for (const psProfile of profiles) {
193
+ await tyrFs.createDir(path.dirname(psProfile));
194
+
195
+ await tyrFs.ensureLine(psProfile, `. "${aliasesPath}"`);
196
+ await tyrFs.ensureLine(psProfile, `. "${pluginsPath}"`);
197
+ logger.success(`PowerShell profile configured: ${psProfile}`);
198
+ }
199
+
200
+ logger.info('Restart PowerShell (o abre una nueva consola) para aplicar los cambios.');
201
+
202
+ await checkWindowsExecutionPolicy(shell, logger);
169
203
  }
170
204
 
171
205
  export default function config({ logger, fs: tyrFs, frameworkRoot, shell }: TyrContext) {
@@ -323,7 +357,7 @@ export default function config({ logger, fs: tyrFs, frameworkRoot, shell }: TyrC
323
357
  if (tyrFs.exists(aliasesPath) || tyrFs.exists(pluginsPath)) {
324
358
  logger.info('\nConfigurando shell...');
325
359
  if (isWindows) {
326
- await configureWindowsShell(tyrFs, logger, aliasesPath, pluginsPath);
360
+ await configureWindowsShell(tyrFs, logger, shell, aliasesPath, pluginsPath);
327
361
  } else {
328
362
  await configureUnixShell(tyrFs, logger, homeDir, aliasesPath, pluginsPath);
329
363
  }