@orxataguy/tyr 1.0.27 → 1.0.29
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 +50 -18
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(`\nCurrent Execution Policy: ${policy || 'Undefined'}`);
|
|
80
|
+
logger.warn('With this policy, PowerShell may block loading your profile (and therefore Tyr functions/aliases).');
|
|
81
|
+
logger.info('To allow it, run in a PowerShell console:');
|
|
82
|
+
logger.info(' Set-ExecutionPolicy RemoteSigned -Scope CurrentUser');
|
|
83
|
+
}
|
|
84
|
+
} catch {
|
|
85
|
+
logger.warn('Could not check PowerShell Execution Policy. Verify it manually if commands do not load.');
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
62
89
|
const PACKAGE_JSON_TEMPLATE = `{
|
|
63
90
|
"name": "tyr-commands",
|
|
64
91
|
"version": "1.0.0",
|
|
@@ -149,23 +176,30 @@ async function configureUnixShell(tyrFs: any, logger: any, homeDir: string, alia
|
|
|
149
176
|
}
|
|
150
177
|
await tyrFs.ensureLine(rcFile, `source "${aliasesPath}"`);
|
|
151
178
|
await tyrFs.ensureLine(rcFile, `source "${pluginsPath}"`);
|
|
152
|
-
logger.success(`Shell
|
|
153
|
-
logger.info(`
|
|
179
|
+
logger.success(`Shell configured: ${rcFile}`);
|
|
180
|
+
logger.info(`Run: source ${rcFile} (or open a new 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 is not defined).');
|
|
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 (or open a new console) to apply the changes.');
|
|
201
|
+
|
|
202
|
+
await checkWindowsExecutionPolicy(shell, logger);
|
|
169
203
|
}
|
|
170
204
|
|
|
171
205
|
export default function config({ logger, fs: tyrFs, frameworkRoot, shell }: TyrContext) {
|
|
@@ -288,21 +322,19 @@ export default function config({ logger, fs: tyrFs, frameworkRoot, shell }: TyrC
|
|
|
288
322
|
}
|
|
289
323
|
}
|
|
290
324
|
|
|
291
|
-
// Garantizar package.json + tsconfig.json + npm install siempre,
|
|
292
|
-
// tanto en init fresh como al clonar un repo existente.
|
|
293
325
|
const packageJsonPath = path.join(userRoot, 'package.json');
|
|
294
326
|
const tsconfigPath = path.join(userRoot, 'tsconfig.json');
|
|
295
327
|
let needsInstall = false;
|
|
296
328
|
|
|
297
329
|
if (!tyrFs.exists(packageJsonPath)) {
|
|
298
330
|
await tyrFs.write(packageJsonPath, PACKAGE_JSON_TEMPLATE);
|
|
299
|
-
logger.success(`
|
|
331
|
+
logger.success(`File created: ${packageJsonPath}`);
|
|
300
332
|
needsInstall = true;
|
|
301
333
|
}
|
|
302
334
|
|
|
303
335
|
if (!tyrFs.exists(tsconfigPath)) {
|
|
304
336
|
await tyrFs.write(tsconfigPath, TSCONFIG_TEMPLATE);
|
|
305
|
-
logger.success(`
|
|
337
|
+
logger.success(`File created: ${tsconfigPath}`);
|
|
306
338
|
needsInstall = true;
|
|
307
339
|
}
|
|
308
340
|
|
|
@@ -321,9 +353,9 @@ export default function config({ logger, fs: tyrFs, frameworkRoot, shell }: TyrC
|
|
|
321
353
|
const pluginsPath = path.join(userRoot, `plugins${ext}`);
|
|
322
354
|
|
|
323
355
|
if (tyrFs.exists(aliasesPath) || tyrFs.exists(pluginsPath)) {
|
|
324
|
-
logger.info('\
|
|
356
|
+
logger.info('\nConfiguring shell...');
|
|
325
357
|
if (isWindows) {
|
|
326
|
-
await configureWindowsShell(tyrFs, logger, aliasesPath, pluginsPath);
|
|
358
|
+
await configureWindowsShell(tyrFs, logger, shell, aliasesPath, pluginsPath);
|
|
327
359
|
} else {
|
|
328
360
|
await configureUnixShell(tyrFs, logger, homeDir, aliasesPath, pluginsPath);
|
|
329
361
|
}
|