@orxataguy/tyr 1.0.27 → 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 +1 -1
- package/src/core/sys/config.ts +45 -11
package/package.json
CHANGED
package/src/core/sys/config.ts
CHANGED
|
@@ -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
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
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
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
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
|
}
|