@mschauer5/spfx-toolkit 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/.vscode/settings.json +22 -22
- package/LICENSE +21 -21
- package/README.md +72 -72
- package/lib/common/util.js +2 -1
- package/lib/common/util.js.map +1 -1
- package/package.json +3 -2
- package/src/commands/env.commands.ts +63 -63
- package/src/commands/index.ts +12 -12
- package/src/commands/installer.command.ts +134 -134
- package/src/commands/nvmrc.command.ts +76 -76
- package/src/commands/projects.command.ts +37 -37
- package/src/commands/repo.command.ts +206 -206
- package/src/commands/scripts.command.ts +139 -139
- package/src/common/index.ts +5 -5
- package/src/common/util.ts +114 -113
- package/src/index.ts +261 -261
- package/lib/commands/install.command.js +0 -28
- package/lib/commands/install.command.js.map +0 -1
- package/lib/commands/open-solution.command.js +0 -30
- package/lib/commands/open-solution.command.js.map +0 -1
- package/lib/commands/serve.command.js +0 -27
- package/lib/commands/serve.command.js.map +0 -1
- package/lib/commands/settings.js +0 -68
- package/lib/commands/settings.js.map +0 -1
- package/lib/package.json +0 -45
- package/lib/src/commands/alias.command.js +0 -104
- package/lib/src/commands/alias.command.js.map +0 -1
- package/lib/src/commands/build.command.js +0 -61
- package/lib/src/commands/build.command.js.map +0 -1
- package/lib/src/commands/bundle.command.js +0 -70
- package/lib/src/commands/bundle.command.js.map +0 -1
- package/lib/src/commands/eslint.command.js +0 -34
- package/lib/src/commands/eslint.command.js.map +0 -1
- package/lib/src/commands/index.js +0 -49
- package/lib/src/commands/index.js.map +0 -1
- package/lib/src/commands/serve.command.js +0 -27
- package/lib/src/commands/serve.command.js.map +0 -1
- package/lib/src/commands/version.command.js +0 -98
- package/lib/src/commands/version.command.js.map +0 -1
- package/lib/src/common/constants.js +0 -10
- package/lib/src/common/constants.js.map +0 -1
- package/lib/src/common/index.js +0 -43
- package/lib/src/common/index.js.map +0 -1
- package/lib/src/common/logger.js +0 -42
- package/lib/src/common/logger.js.map +0 -1
- package/lib/src/common/util.js +0 -80
- package/lib/src/common/util.js.map +0 -1
- package/lib/src/index.js +0 -146
- package/lib/src/index.js.map +0 -1
- package/lib/test/index.test.js +0 -17
- package/lib/test/index.test.js.map +0 -1
- package/mschauer5-spfx-toolkit-1.0.25.tgz +0 -0
|
@@ -1,134 +1,134 @@
|
|
|
1
|
-
import { detect } from 'detect-package-manager';
|
|
2
|
-
import { getScriptByName } from './scripts.command';
|
|
3
|
-
import { logger } from '../common/logger';
|
|
4
|
-
import { util } from '../common';
|
|
5
|
-
import { promises as fsPromises } from 'fs';
|
|
6
|
-
// /**
|
|
7
|
-
// * Adds a command to the user's shell profile to run spfx-toolkit nvmrc use on terminal startup.
|
|
8
|
-
// * Supports bash, zsh (macOS/Linux) and PowerShell (Windows).
|
|
9
|
-
// */
|
|
10
|
-
// export const addNvmrcToStartup = () => {
|
|
11
|
-
// const homedir = os.homedir();
|
|
12
|
-
// const isWin = process.platform === 'win32';
|
|
13
|
-
// let profilePath = '';
|
|
14
|
-
// let shellType = '';
|
|
15
|
-
// let lineToAdd = '';
|
|
16
|
-
|
|
17
|
-
// if (isWin) {
|
|
18
|
-
// // PowerShell profile
|
|
19
|
-
// const profileEnv = process.env.USERPROFILE || homedir;
|
|
20
|
-
// // Default PowerShell profile path
|
|
21
|
-
// profilePath = path.join(profileEnv, 'Documents', 'WindowsPowerShell', 'Microsoft.PowerShell_profile.ps1');
|
|
22
|
-
// shellType = 'PowerShell';
|
|
23
|
-
// lineToAdd = 'spfx-toolkit nvmrc use';
|
|
24
|
-
// } else {
|
|
25
|
-
// // Check for zsh or bash
|
|
26
|
-
// if (process.env.SHELL && process.env.SHELL.includes('zsh')) {
|
|
27
|
-
// profilePath = path.join(homedir, '.zshrc');
|
|
28
|
-
// shellType = 'zsh';
|
|
29
|
-
// } else {
|
|
30
|
-
// profilePath = path.join(homedir, '.bashrc');
|
|
31
|
-
// shellType = 'bash';
|
|
32
|
-
// }
|
|
33
|
-
// lineToAdd = 'spfx-toolkit nvmrc use';
|
|
34
|
-
// }
|
|
35
|
-
|
|
36
|
-
// // Check if profile exists, create if not
|
|
37
|
-
// if (!fs.existsSync(profilePath)) {
|
|
38
|
-
// fs.writeFileSync(profilePath, '', { encoding: 'utf-8' });
|
|
39
|
-
// }
|
|
40
|
-
|
|
41
|
-
// // Check if line already exists
|
|
42
|
-
// const profileContent = fs.readFileSync(profilePath, 'utf-8');
|
|
43
|
-
// if (!profileContent.includes(lineToAdd)) {
|
|
44
|
-
// fs.appendFileSync(profilePath, `\n# Added by spfx-toolkit\n${lineToAdd}\n`, { encoding: 'utf-8' });
|
|
45
|
-
// console.log(`Added '${lineToAdd}' to your ${shellType} profile: ${profilePath}`);
|
|
46
|
-
// } else {
|
|
47
|
-
// console.log(`'${lineToAdd}' is already present in your ${shellType} profile: ${profilePath}`);
|
|
48
|
-
// }
|
|
49
|
-
// };
|
|
50
|
-
|
|
51
|
-
const packageInstaller = async (name: string): Promise<{ dependencies: string[]; devDependencies: string[] }> => {
|
|
52
|
-
const globalPath = util.getGlobalConfigPaths();
|
|
53
|
-
const fileExists = await util.checkIfFileExistsAsync(globalPath.configPath, true);
|
|
54
|
-
if (!fileExists) {
|
|
55
|
-
return { dependencies: [], devDependencies: [] };
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const data = await fsPromises.readFile(globalPath.configPath, 'utf-8');
|
|
59
|
-
const config = JSON.parse(data);
|
|
60
|
-
if (config && typeof config === 'object' && config.packages) {
|
|
61
|
-
const result = name in config.packages;
|
|
62
|
-
if (result) {
|
|
63
|
-
const packageValue = config.packages[name];
|
|
64
|
-
const dependencies = packageValue.dependencies ?? [];
|
|
65
|
-
const devDependencies = packageValue.devDependencies ?? [];
|
|
66
|
-
|
|
67
|
-
return { dependencies, devDependencies };
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return { dependencies: [], devDependencies: [] };
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
export const install = async (name: string, fromScripts: boolean) => {
|
|
75
|
-
const usercommand = await detect();
|
|
76
|
-
const spawn = require('cross-spawn');
|
|
77
|
-
|
|
78
|
-
if (fromScripts) {
|
|
79
|
-
packageInstaller(name).then((results) => {
|
|
80
|
-
if (results.dependencies.length === 0 && results.devDependencies.length === 0) {
|
|
81
|
-
logger.error(`No package found with name ${name} in global package.json so can't install`);
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
if (results.dependencies.length > 0) {
|
|
85
|
-
results.dependencies.unshift('install');
|
|
86
|
-
spawn.sync(usercommand, results.dependencies, { stdio: 'inherit' });
|
|
87
|
-
}
|
|
88
|
-
if (results.devDependencies.length > 0) {
|
|
89
|
-
results.devDependencies.unshift('--save-dev');
|
|
90
|
-
results.devDependencies.unshift('install');
|
|
91
|
-
spawn.sync(usercommand, results.devDependencies, { stdio: 'inherit' });
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
if (name === undefined || name.length === 0) {
|
|
99
|
-
spawn.sync(usercommand, ['install'], { stdio: 'inherit' });
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
const args = name.split(' ');
|
|
104
|
-
args.unshift('install');
|
|
105
|
-
|
|
106
|
-
spawn.sync(usercommand, args, { stdio: 'inherit' });
|
|
107
|
-
return;
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
export const uninstall = async (name: string, fromScripts: boolean) => {
|
|
111
|
-
const usercommand = await detect();
|
|
112
|
-
const spawn = require('cross-spawn');
|
|
113
|
-
|
|
114
|
-
if (!fromScripts) {
|
|
115
|
-
const getScriptByNameValue = await getScriptByName(`install:${name}`);
|
|
116
|
-
if (getScriptByNameValue !== undefined) {
|
|
117
|
-
const args = getScriptByNameValue.split(' ');
|
|
118
|
-
|
|
119
|
-
args.unshift('uninstall');
|
|
120
|
-
|
|
121
|
-
spawn.sync(usercommand, args, { stdio: 'inherit' });
|
|
122
|
-
return;
|
|
123
|
-
} else {
|
|
124
|
-
logger.error(`No install script found with name ${name} in global or local package.json so can't uninstall`);
|
|
125
|
-
}
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
const args = name.split(' ');
|
|
130
|
-
args.unshift('uninstall');
|
|
131
|
-
|
|
132
|
-
spawn.sync(usercommand, args, { stdio: 'inherit' });
|
|
133
|
-
return;
|
|
134
|
-
};
|
|
1
|
+
import { detect } from 'detect-package-manager';
|
|
2
|
+
import { getScriptByName } from './scripts.command';
|
|
3
|
+
import { logger } from '../common/logger';
|
|
4
|
+
import { util } from '../common';
|
|
5
|
+
import { promises as fsPromises } from 'fs';
|
|
6
|
+
// /**
|
|
7
|
+
// * Adds a command to the user's shell profile to run spfx-toolkit nvmrc use on terminal startup.
|
|
8
|
+
// * Supports bash, zsh (macOS/Linux) and PowerShell (Windows).
|
|
9
|
+
// */
|
|
10
|
+
// export const addNvmrcToStartup = () => {
|
|
11
|
+
// const homedir = os.homedir();
|
|
12
|
+
// const isWin = process.platform === 'win32';
|
|
13
|
+
// let profilePath = '';
|
|
14
|
+
// let shellType = '';
|
|
15
|
+
// let lineToAdd = '';
|
|
16
|
+
|
|
17
|
+
// if (isWin) {
|
|
18
|
+
// // PowerShell profile
|
|
19
|
+
// const profileEnv = process.env.USERPROFILE || homedir;
|
|
20
|
+
// // Default PowerShell profile path
|
|
21
|
+
// profilePath = path.join(profileEnv, 'Documents', 'WindowsPowerShell', 'Microsoft.PowerShell_profile.ps1');
|
|
22
|
+
// shellType = 'PowerShell';
|
|
23
|
+
// lineToAdd = 'spfx-toolkit nvmrc use';
|
|
24
|
+
// } else {
|
|
25
|
+
// // Check for zsh or bash
|
|
26
|
+
// if (process.env.SHELL && process.env.SHELL.includes('zsh')) {
|
|
27
|
+
// profilePath = path.join(homedir, '.zshrc');
|
|
28
|
+
// shellType = 'zsh';
|
|
29
|
+
// } else {
|
|
30
|
+
// profilePath = path.join(homedir, '.bashrc');
|
|
31
|
+
// shellType = 'bash';
|
|
32
|
+
// }
|
|
33
|
+
// lineToAdd = 'spfx-toolkit nvmrc use';
|
|
34
|
+
// }
|
|
35
|
+
|
|
36
|
+
// // Check if profile exists, create if not
|
|
37
|
+
// if (!fs.existsSync(profilePath)) {
|
|
38
|
+
// fs.writeFileSync(profilePath, '', { encoding: 'utf-8' });
|
|
39
|
+
// }
|
|
40
|
+
|
|
41
|
+
// // Check if line already exists
|
|
42
|
+
// const profileContent = fs.readFileSync(profilePath, 'utf-8');
|
|
43
|
+
// if (!profileContent.includes(lineToAdd)) {
|
|
44
|
+
// fs.appendFileSync(profilePath, `\n# Added by spfx-toolkit\n${lineToAdd}\n`, { encoding: 'utf-8' });
|
|
45
|
+
// console.log(`Added '${lineToAdd}' to your ${shellType} profile: ${profilePath}`);
|
|
46
|
+
// } else {
|
|
47
|
+
// console.log(`'${lineToAdd}' is already present in your ${shellType} profile: ${profilePath}`);
|
|
48
|
+
// }
|
|
49
|
+
// };
|
|
50
|
+
|
|
51
|
+
const packageInstaller = async (name: string): Promise<{ dependencies: string[]; devDependencies: string[] }> => {
|
|
52
|
+
const globalPath = util.getGlobalConfigPaths();
|
|
53
|
+
const fileExists = await util.checkIfFileExistsAsync(globalPath.configPath, true);
|
|
54
|
+
if (!fileExists) {
|
|
55
|
+
return { dependencies: [], devDependencies: [] };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const data = await fsPromises.readFile(globalPath.configPath, 'utf-8');
|
|
59
|
+
const config = JSON.parse(data);
|
|
60
|
+
if (config && typeof config === 'object' && config.packages) {
|
|
61
|
+
const result = name in config.packages;
|
|
62
|
+
if (result) {
|
|
63
|
+
const packageValue = config.packages[name];
|
|
64
|
+
const dependencies = packageValue.dependencies ?? [];
|
|
65
|
+
const devDependencies = packageValue.devDependencies ?? [];
|
|
66
|
+
|
|
67
|
+
return { dependencies, devDependencies };
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return { dependencies: [], devDependencies: [] };
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export const install = async (name: string, fromScripts: boolean) => {
|
|
75
|
+
const usercommand = await detect();
|
|
76
|
+
const spawn = require('cross-spawn');
|
|
77
|
+
|
|
78
|
+
if (fromScripts) {
|
|
79
|
+
packageInstaller(name).then((results) => {
|
|
80
|
+
if (results.dependencies.length === 0 && results.devDependencies.length === 0) {
|
|
81
|
+
logger.error(`No package found with name ${name} in global package.json so can't install`);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if (results.dependencies.length > 0) {
|
|
85
|
+
results.dependencies.unshift('install');
|
|
86
|
+
spawn.sync(usercommand, results.dependencies, { stdio: 'inherit' });
|
|
87
|
+
}
|
|
88
|
+
if (results.devDependencies.length > 0) {
|
|
89
|
+
results.devDependencies.unshift('--save-dev');
|
|
90
|
+
results.devDependencies.unshift('install');
|
|
91
|
+
spawn.sync(usercommand, results.devDependencies, { stdio: 'inherit' });
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (name === undefined || name.length === 0) {
|
|
99
|
+
spawn.sync(usercommand, ['install'], { stdio: 'inherit' });
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const args = name.split(' ');
|
|
104
|
+
args.unshift('install');
|
|
105
|
+
|
|
106
|
+
spawn.sync(usercommand, args, { stdio: 'inherit' });
|
|
107
|
+
return;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
export const uninstall = async (name: string, fromScripts: boolean) => {
|
|
111
|
+
const usercommand = await detect();
|
|
112
|
+
const spawn = require('cross-spawn');
|
|
113
|
+
|
|
114
|
+
if (!fromScripts) {
|
|
115
|
+
const getScriptByNameValue = await getScriptByName(`install:${name}`);
|
|
116
|
+
if (getScriptByNameValue !== undefined) {
|
|
117
|
+
const args = getScriptByNameValue.split(' ');
|
|
118
|
+
|
|
119
|
+
args.unshift('uninstall');
|
|
120
|
+
|
|
121
|
+
spawn.sync(usercommand, args, { stdio: 'inherit' });
|
|
122
|
+
return;
|
|
123
|
+
} else {
|
|
124
|
+
logger.error(`No install script found with name ${name} in global or local package.json so can't uninstall`);
|
|
125
|
+
}
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const args = name.split(' ');
|
|
130
|
+
args.unshift('uninstall');
|
|
131
|
+
|
|
132
|
+
spawn.sync(usercommand, args, { stdio: 'inherit' });
|
|
133
|
+
return;
|
|
134
|
+
};
|
|
@@ -1,76 +1,76 @@
|
|
|
1
|
-
export const addNvmrc = async () => {
|
|
2
|
-
const spawn = require('cross-spawn');
|
|
3
|
-
const result = spawn.sync('nvm', ['current'], { encoding: 'utf-8' });
|
|
4
|
-
|
|
5
|
-
if (result.status !== 0) {
|
|
6
|
-
console.error('Error detecting current Node version with nvm. Make sure nvm is installed and accessible from your PATH.');
|
|
7
|
-
return;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const currentVersion = result.stdout.trim();
|
|
11
|
-
const nvmrcContent = currentVersion;
|
|
12
|
-
|
|
13
|
-
const fs = require('fs');
|
|
14
|
-
fs.writeFileSync('.nvmrc', nvmrcContent, { encoding: 'utf-8' });
|
|
15
|
-
console.log(`.nvmrc file created with Node version: ${currentVersion}`);
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export const useNvmrc = () => {
|
|
19
|
-
const fs = require('fs');
|
|
20
|
-
const spawn = require('cross-spawn');
|
|
21
|
-
const readlineSync = require('readline-sync');
|
|
22
|
-
let requiredVersion = '';
|
|
23
|
-
let source = '';
|
|
24
|
-
|
|
25
|
-
// Check .nvmrc first
|
|
26
|
-
const nvmrcPath = '.nvmrc';
|
|
27
|
-
if (fs.existsSync(nvmrcPath)) {
|
|
28
|
-
requiredVersion = fs.readFileSync(nvmrcPath, 'utf-8').trim();
|
|
29
|
-
source = '.nvmrc';
|
|
30
|
-
} else if (fs.existsSync('package.json')) {
|
|
31
|
-
// Fallback to package.json engines.node
|
|
32
|
-
try {
|
|
33
|
-
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf-8'));
|
|
34
|
-
if (pkg.engines && pkg.engines.node) {
|
|
35
|
-
requiredVersion = pkg.engines.node.trim();
|
|
36
|
-
source = 'package.json';
|
|
37
|
-
}
|
|
38
|
-
} catch (e) {
|
|
39
|
-
console.error('Could not parse package.json:', e);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (!requiredVersion) {
|
|
44
|
-
console.log('No .nvmrc or engines.node in package.json found.');
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const result = spawn.sync('nvm', ['current'], { encoding: 'utf-8' });
|
|
49
|
-
if (result.status !== 0) {
|
|
50
|
-
console.error('Error detecting current Node version with nvm. Make sure nvm is installed and accessible from your PATH.');
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
const currentVersion = result.stdout.trim();
|
|
54
|
-
|
|
55
|
-
// Normalize for semver range (e.g., ">=14.0.0")
|
|
56
|
-
const semver = require('semver');
|
|
57
|
-
let needsSwitch = false;
|
|
58
|
-
if (source === 'package.json') {
|
|
59
|
-
needsSwitch = !semver.satisfies(currentVersion, requiredVersion);
|
|
60
|
-
} else {
|
|
61
|
-
needsSwitch = currentVersion !== requiredVersion;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (needsSwitch) {
|
|
65
|
-
const response = readlineSync.question(`Current Node version is ${currentVersion}. Switch to ${requiredVersion} as per ${source}? (y/n) [y]: `);
|
|
66
|
-
if (response === 'y' || response === '') {
|
|
67
|
-
console.log(`Switching Node version to ${requiredVersion} as per ${source}`);
|
|
68
|
-
const switchResult = spawn.sync('nvm', ['use', requiredVersion], { stdio: 'inherit' });
|
|
69
|
-
if (switchResult.status !== 0) {
|
|
70
|
-
console.error(`Failed to switch Node version to ${requiredVersion}.`);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
} else {
|
|
74
|
-
console.log(`Node version ${currentVersion} matches required version from ${source}.`);
|
|
75
|
-
}
|
|
76
|
-
};
|
|
1
|
+
export const addNvmrc = async () => {
|
|
2
|
+
const spawn = require('cross-spawn');
|
|
3
|
+
const result = spawn.sync('nvm', ['current'], { encoding: 'utf-8' });
|
|
4
|
+
|
|
5
|
+
if (result.status !== 0) {
|
|
6
|
+
console.error('Error detecting current Node version with nvm. Make sure nvm is installed and accessible from your PATH.');
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const currentVersion = result.stdout.trim();
|
|
11
|
+
const nvmrcContent = currentVersion;
|
|
12
|
+
|
|
13
|
+
const fs = require('fs');
|
|
14
|
+
fs.writeFileSync('.nvmrc', nvmrcContent, { encoding: 'utf-8' });
|
|
15
|
+
console.log(`.nvmrc file created with Node version: ${currentVersion}`);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const useNvmrc = () => {
|
|
19
|
+
const fs = require('fs');
|
|
20
|
+
const spawn = require('cross-spawn');
|
|
21
|
+
const readlineSync = require('readline-sync');
|
|
22
|
+
let requiredVersion = '';
|
|
23
|
+
let source = '';
|
|
24
|
+
|
|
25
|
+
// Check .nvmrc first
|
|
26
|
+
const nvmrcPath = '.nvmrc';
|
|
27
|
+
if (fs.existsSync(nvmrcPath)) {
|
|
28
|
+
requiredVersion = fs.readFileSync(nvmrcPath, 'utf-8').trim();
|
|
29
|
+
source = '.nvmrc';
|
|
30
|
+
} else if (fs.existsSync('package.json')) {
|
|
31
|
+
// Fallback to package.json engines.node
|
|
32
|
+
try {
|
|
33
|
+
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf-8'));
|
|
34
|
+
if (pkg.engines && pkg.engines.node) {
|
|
35
|
+
requiredVersion = pkg.engines.node.trim();
|
|
36
|
+
source = 'package.json';
|
|
37
|
+
}
|
|
38
|
+
} catch (e) {
|
|
39
|
+
console.error('Could not parse package.json:', e);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (!requiredVersion) {
|
|
44
|
+
console.log('No .nvmrc or engines.node in package.json found.');
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const result = spawn.sync('nvm', ['current'], { encoding: 'utf-8' });
|
|
49
|
+
if (result.status !== 0) {
|
|
50
|
+
console.error('Error detecting current Node version with nvm. Make sure nvm is installed and accessible from your PATH.');
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const currentVersion = result.stdout.trim();
|
|
54
|
+
|
|
55
|
+
// Normalize for semver range (e.g., ">=14.0.0")
|
|
56
|
+
const semver = require('semver');
|
|
57
|
+
let needsSwitch = false;
|
|
58
|
+
if (source === 'package.json') {
|
|
59
|
+
needsSwitch = !semver.satisfies(currentVersion, requiredVersion);
|
|
60
|
+
} else {
|
|
61
|
+
needsSwitch = currentVersion !== requiredVersion;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (needsSwitch) {
|
|
65
|
+
const response = readlineSync.question(`Current Node version is ${currentVersion}. Switch to ${requiredVersion} as per ${source}? (y/n) [y]: `);
|
|
66
|
+
if (response === 'y' || response === '') {
|
|
67
|
+
console.log(`Switching Node version to ${requiredVersion} as per ${source}`);
|
|
68
|
+
const switchResult = spawn.sync('nvm', ['use', requiredVersion], { stdio: 'inherit' });
|
|
69
|
+
if (switchResult.status !== 0) {
|
|
70
|
+
console.error(`Failed to switch Node version to ${requiredVersion}.`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
} else {
|
|
74
|
+
console.log(`Node version ${currentVersion} matches required version from ${source}.`);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
import { logger } from '../common/logger';
|
|
2
|
-
import { promises as fsPromises } from 'fs';
|
|
3
|
-
import { ensureGlobalPackageJsonExists, getGlobalConfigPaths } from '../common/util';
|
|
4
|
-
import { openVSCodeInDirectory } from '../common/util';
|
|
5
|
-
|
|
6
|
-
export const addProject = async (name: string) => {
|
|
7
|
-
const path = process.cwd();
|
|
8
|
-
if (!name) {
|
|
9
|
-
name = path.split('\\').pop();
|
|
10
|
-
}
|
|
11
|
-
await ensureGlobalPackageJsonExists();
|
|
12
|
-
|
|
13
|
-
const { configPath } = getGlobalConfigPaths();
|
|
14
|
-
const packageJsonContent = await fsPromises.readFile(configPath, 'utf-8');
|
|
15
|
-
const packageJson = JSON.parse(packageJsonContent);
|
|
16
|
-
if (!packageJson.projects) {
|
|
17
|
-
packageJson.projects = {};
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
packageJson.projects[name] = path;
|
|
21
|
-
|
|
22
|
-
await fsPromises.writeFile(configPath, JSON.stringify(packageJson, null, 2), 'utf-8');
|
|
23
|
-
|
|
24
|
-
logger.success(`Project '${name}' added for path: ${path}`);
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export const openProject = async (name: string) => {
|
|
28
|
-
const { configPath } = getGlobalConfigPaths();
|
|
29
|
-
const packageJsonContent = await fsPromises.readFile(configPath, 'utf-8');
|
|
30
|
-
const packageJson = JSON.parse(packageJsonContent);
|
|
31
|
-
if (!packageJson.projects || !packageJson.projects[name]) {
|
|
32
|
-
logger.error(`Project name '${name}' not found in global package.json!`);
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
const projectPath = packageJson.projects[name];
|
|
36
|
-
openVSCodeInDirectory(projectPath);
|
|
37
|
-
};
|
|
1
|
+
import { logger } from '../common/logger';
|
|
2
|
+
import { promises as fsPromises } from 'fs';
|
|
3
|
+
import { ensureGlobalPackageJsonExists, getGlobalConfigPaths } from '../common/util';
|
|
4
|
+
import { openVSCodeInDirectory } from '../common/util';
|
|
5
|
+
|
|
6
|
+
export const addProject = async (name: string) => {
|
|
7
|
+
const path = process.cwd();
|
|
8
|
+
if (!name) {
|
|
9
|
+
name = path.split('\\').pop();
|
|
10
|
+
}
|
|
11
|
+
await ensureGlobalPackageJsonExists();
|
|
12
|
+
|
|
13
|
+
const { configPath } = getGlobalConfigPaths();
|
|
14
|
+
const packageJsonContent = await fsPromises.readFile(configPath, 'utf-8');
|
|
15
|
+
const packageJson = JSON.parse(packageJsonContent);
|
|
16
|
+
if (!packageJson.projects) {
|
|
17
|
+
packageJson.projects = {};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
packageJson.projects[name] = path;
|
|
21
|
+
|
|
22
|
+
await fsPromises.writeFile(configPath, JSON.stringify(packageJson, null, 2), 'utf-8');
|
|
23
|
+
|
|
24
|
+
logger.success(`Project '${name}' added for path: ${path}`);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const openProject = async (name: string) => {
|
|
28
|
+
const { configPath } = getGlobalConfigPaths();
|
|
29
|
+
const packageJsonContent = await fsPromises.readFile(configPath, 'utf-8');
|
|
30
|
+
const packageJson = JSON.parse(packageJsonContent);
|
|
31
|
+
if (!packageJson.projects || !packageJson.projects[name]) {
|
|
32
|
+
logger.error(`Project name '${name}' not found in global package.json!`);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const projectPath = packageJson.projects[name];
|
|
36
|
+
openVSCodeInDirectory(projectPath);
|
|
37
|
+
};
|