@mschauer5/spfx-toolkit 1.0.23 → 1.0.25
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/.nvmrc +1 -0
- package/lib/commands/env.commands.js +69 -0
- package/lib/commands/env.commands.js.map +1 -0
- package/lib/commands/index.js +8 -2
- package/lib/commands/index.js.map +1 -1
- package/lib/commands/installer.command.js +78 -11
- package/lib/commands/installer.command.js.map +1 -1
- package/lib/commands/nvmrc.command.js +86 -0
- package/lib/commands/nvmrc.command.js.map +1 -0
- package/lib/commands/repo.command.js +225 -0
- package/lib/commands/repo.command.js.map +1 -0
- package/lib/commands/scripts.command.js.map +1 -1
- package/lib/common/logger.js +7 -2
- package/lib/common/logger.js.map +1 -1
- package/lib/common/util.js +1 -2
- package/lib/common/util.js.map +1 -1
- package/lib/index.js +47 -7
- package/lib/index.js.map +1 -1
- package/mschauer5-spfx-toolkit-1.0.25.tgz +0 -0
- package/package.json +5 -3
- package/src/commands/env.commands.ts +63 -0
- package/src/commands/index.ts +4 -1
- package/src/commands/installer.command.ts +85 -10
- package/src/commands/nvmrc.command.ts +76 -0
- package/src/commands/repo.command.ts +218 -0
- package/src/commands/scripts.command.ts +0 -1
- package/src/common/logger.ts +6 -2
- package/src/common/util.ts +1 -2
- package/src/index.ts +53 -8
- package/mschauer5-spfx-toolkit-1.0.22.tgz +0 -0
package/lib/common/util.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/common/util.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAKA,wDAUC;AAED,oDAIC;AAED,kCAGC;AAWD,sEAUC;AAED,
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/common/util.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAKA,wDAUC;AAED,oDAIC;AAED,kCAGC;AAWD,sEAUC;AAED,8EAyBC;AA1ED,2BAA4C;AAC5C,4CAAo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;QACH,CAAC;QAED,MAAM,aAAU,CAAC,SAAS,CAAC,UAAU,EAAE,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;IACxF,CAAC;CAAA"}
|
package/lib/index.js
CHANGED
|
@@ -48,7 +48,7 @@ program
|
|
|
48
48
|
.name('Matt Schauer SPFx Toolkit')
|
|
49
49
|
.description('CLI to help with SPFx development')
|
|
50
50
|
.addHelpText('beforeAll', chalk_1.default.blueBright('Developed by Matt Schauer'))
|
|
51
|
-
.version('1.0.
|
|
51
|
+
.version('1.0.24');
|
|
52
52
|
program
|
|
53
53
|
.command('add-alias')
|
|
54
54
|
.description('add alias')
|
|
@@ -62,6 +62,24 @@ program
|
|
|
62
62
|
.action(() => {
|
|
63
63
|
commands.alias.clearAlias(defaultToolkitName);
|
|
64
64
|
});
|
|
65
|
+
program
|
|
66
|
+
.command('set-repo')
|
|
67
|
+
.description('Set current folder as the default repo location')
|
|
68
|
+
.action(() => {
|
|
69
|
+
commands.repo.SetRepo();
|
|
70
|
+
});
|
|
71
|
+
program
|
|
72
|
+
.command('repo [args...]')
|
|
73
|
+
.description('Go to repository location')
|
|
74
|
+
.option('-p, --project', 'If set will look in global package.json for matching shortcut to repository')
|
|
75
|
+
.action((args, options) => {
|
|
76
|
+
console.log('options:', options);
|
|
77
|
+
if (options.project) {
|
|
78
|
+
commands.repo.goToRepoFromProject(Array.isArray(args) ? args : []);
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
commands.repo.goToRepo(Array.isArray(args) ? args : []);
|
|
82
|
+
});
|
|
65
83
|
program
|
|
66
84
|
.command('serve')
|
|
67
85
|
.alias('s')
|
|
@@ -106,13 +124,25 @@ program
|
|
|
106
124
|
commands.installer.install(packages, false);
|
|
107
125
|
});
|
|
108
126
|
program
|
|
109
|
-
.command('install-
|
|
110
|
-
.alias('
|
|
111
|
-
.description('Run an
|
|
112
|
-
.addArgument(new commander.Argument('<name>', '
|
|
127
|
+
.command('install-packages')
|
|
128
|
+
.alias('ips')
|
|
129
|
+
.description('Run an installer package from global package.json by name')
|
|
130
|
+
.addArgument(new commander.Argument('<name>', 'package name in global config to install'))
|
|
113
131
|
.action((name) => {
|
|
114
132
|
commands.installer.install(name, true);
|
|
115
133
|
});
|
|
134
|
+
program
|
|
135
|
+
.command('add-nvmrc')
|
|
136
|
+
.description('Add .nvmrc file with current specified Node version')
|
|
137
|
+
.action(() => {
|
|
138
|
+
commands.nvmrc.addNvmrc();
|
|
139
|
+
});
|
|
140
|
+
program
|
|
141
|
+
.command('use-nvmrc')
|
|
142
|
+
.description('Use Node version specified in .nvmrc file')
|
|
143
|
+
.action(() => {
|
|
144
|
+
commands.nvmrc.useNvmrc();
|
|
145
|
+
});
|
|
116
146
|
program
|
|
117
147
|
.command('uninstall')
|
|
118
148
|
.alias('un')
|
|
@@ -170,15 +200,25 @@ program
|
|
|
170
200
|
.option('-r, --restore', 'Restore from backup eslint file')
|
|
171
201
|
.action((options) => {
|
|
172
202
|
if (options.backup) {
|
|
173
|
-
commands.
|
|
203
|
+
commands.env.backupEslint();
|
|
174
204
|
}
|
|
175
205
|
else if (options.restore) {
|
|
176
|
-
commands.
|
|
206
|
+
commands.env.restoreEslint();
|
|
177
207
|
}
|
|
178
208
|
else {
|
|
179
209
|
common_1.logger.error('No action specified. Use --backup | -b <OR> --restore | -r');
|
|
180
210
|
}
|
|
181
211
|
});
|
|
212
|
+
program
|
|
213
|
+
.command('set-env')
|
|
214
|
+
.description('Set tenantDomain environment variables')
|
|
215
|
+
.addArgument(new commander.Argument('[tenantDomain]', 'Tenant domain to set'))
|
|
216
|
+
.option('-t, --tenant <tenantDomain>', 'Specify the tenant domain')
|
|
217
|
+
.action((tenantDomain, options) => {
|
|
218
|
+
// Prefer positional argument, fallback to option
|
|
219
|
+
const domain = tenantDomain || options.tenant;
|
|
220
|
+
commands.envCommands.setEnv(domain);
|
|
221
|
+
});
|
|
182
222
|
program
|
|
183
223
|
.command('version')
|
|
184
224
|
.option('-l, --list', 'List SPFx project versions')
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,kDAA0B;AAC1B,qDAAuC;AACvC,yCAAoC;AACpC,qDAAuC;AACvC,qCAAwC;AACxC,MAAM,OAAO,GAAG,IAAI,mBAAO,EAAE,CAAC;AAE9B,MAAM,kBAAkB,GAAG,cAAc,CAAC;AAE1C,OAAO;KACJ,IAAI,CAAC,2BAA2B,CAAC;KACjC,WAAW,CAAC,mCAAmC,CAAC;KAChD,WAAW,CAAC,WAAW,EAAE,eAAK,CAAC,UAAU,CAAC,2BAA2B,CAAC,CAAC;KACvE,OAAO,CAAC,QAAQ,CAAC,CAAC;AAErB,OAAO;KACJ,OAAO,CAAC,WAAW,CAAC;KACpB,WAAW,CAAC,WAAW,CAAC;KACxB,WAAW,CAAC,IAAI,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,oCAAoC,CAAC,CAAC;KACnF,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE;IACf,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,EAAE,kBAAkB,CAAC,CAAC;AACpD,CAAC,CAAC,CAAC;AAEL,OAAO;KACJ,OAAO,CAAC,aAAa,CAAC;KACtB,WAAW,CAAC,mCAAmC,CAAC;KAChD,MAAM,CAAC,GAAG,EAAE;IACX,QAAQ,CAAC,KAAK,CAAC,UAAU,CAAC,kBAAkB,CAAC,CAAC;AAChD,CAAC,CAAC,CAAC;AAEL,OAAO;KACJ,OAAO,CAAC,OAAO,CAAC;KAChB,KAAK,CAAC,GAAG,CAAC;KACV,WAAW,CAAC,gCAAgC,CAAC;KAC7C,MAAM,CAAC,GAAG,EAAE;IACX,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,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AAE,OAAO,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QACjD,MAAM,IAAI,KAAK,CAAC,2BAA2B,KAAK,2CAA2C,CAAC,CAAC;IAC/F,CAAC;IACD,OAAO,KAAK,CAAC,CAAC,6BAA6B;AAC7C,CAAC,CAAC;KACD,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE;IAClB,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC;IAC/B,IAAI,IAAI,EAAE,CAAC;QACT,QAAQ,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC;IAClC,CAAC;SAAM,IAAI,IAAI,EAAE,CAAC;QAChB,QAAQ,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC;IACjC,CAAC;SAAM,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;QAC7B,QAAQ,CAAC,OAAO,CAAC,gBAAgB,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IACvD,CAAC;SAAM,CAAC;QACN,eAAM,CAAC,KAAK,CAAC,yEAAyE,CAAC,CAAC;IAC1F,CAAC;AACH,CAAC,CAAC,CAAC;AAEL,OAAO,CAAC,KAAK,EAAE,CAAC"}
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mschauer5/spfx-toolkit",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.25",
|
|
4
4
|
"description": "Toolkit for SPFx projects",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -14,7 +14,8 @@
|
|
|
14
14
|
"test:serve": "npm run build && node lib/index.js serve",
|
|
15
15
|
"test:build": "npm run build && node lib/index.js build",
|
|
16
16
|
"push": "npm run build && npm publish --access public",
|
|
17
|
-
"
|
|
17
|
+
"test:env": "npm run build && node lib/index.js set-env",
|
|
18
|
+
"prepublish": "npm run build && npm uninstall .\\mschauer5-spfx-toolkit-1.0.25.tgz -g && npm pack . && npm install .\\mschauer5-spfx-toolkit-1.0.25.tgz -g"
|
|
18
19
|
},
|
|
19
20
|
"repository": {
|
|
20
21
|
"type": "git",
|
|
@@ -34,7 +35,8 @@
|
|
|
34
35
|
"commander": "^12.1.0",
|
|
35
36
|
"cross-spawn": "^7.0.6",
|
|
36
37
|
"detect-package-manager": "^3.0.2",
|
|
37
|
-
"log-symbols": "^4.1.0"
|
|
38
|
+
"log-symbols": "^4.1.0",
|
|
39
|
+
"readline-sync": "^1.4.10"
|
|
38
40
|
},
|
|
39
41
|
"devDependencies": {
|
|
40
42
|
"@types/cross-spawn": "^6.0.6",
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { logger } from '../common/logger';
|
|
2
|
+
var readlineSync = require('readline-sync');
|
|
3
|
+
|
|
4
|
+
export const setEnv = async (tenantDomain?: string) => {
|
|
5
|
+
const lines = [];
|
|
6
|
+
|
|
7
|
+
let td = tenantDomain;
|
|
8
|
+
|
|
9
|
+
// if tenantDomain is provided, set it in the .env file
|
|
10
|
+
if (!tenantDomain) {
|
|
11
|
+
// check env variable first
|
|
12
|
+
if (process.env['SPFX_SERVE_TENANT_DOMAIN']) {
|
|
13
|
+
// if they want to use this env variable
|
|
14
|
+
|
|
15
|
+
// add default of yes
|
|
16
|
+
const inputDomain = readlineSync.question(
|
|
17
|
+
`Do you want to use global tenant domain of ${process.env['SPFX_SERVE_TENANT_DOMAIN']}? (yes/no) : Default is 'yes' `
|
|
18
|
+
);
|
|
19
|
+
if (inputDomain.toLowerCase() === 'yes' || inputDomain.toLowerCase() === 'y' || inputDomain === '') {
|
|
20
|
+
td = `${process.env['SPFX_SERVE_TENANT_DOMAIN']}`;
|
|
21
|
+
} else {
|
|
22
|
+
td = undefined;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (td) {
|
|
28
|
+
if (td.startsWith('https://')) {
|
|
29
|
+
td = td.replace('https://', '');
|
|
30
|
+
}
|
|
31
|
+
} else {
|
|
32
|
+
// otherwise, prompt the user for it
|
|
33
|
+
|
|
34
|
+
const inputDomain = readlineSync.question('Enter the tenant domain (e.g., contoso.sharepoint.com): ');
|
|
35
|
+
td = inputDomain;
|
|
36
|
+
}
|
|
37
|
+
td = `tenantDomain=${td}`;
|
|
38
|
+
|
|
39
|
+
lines.push(td);
|
|
40
|
+
|
|
41
|
+
// if file exists, read existing lines except tenantDomain
|
|
42
|
+
const fsPromises = require('fs').promises;
|
|
43
|
+
const path = require('path');
|
|
44
|
+
const envFilePath = path.join(process.cwd(), '.env');
|
|
45
|
+
const fileExists = require('fs').existsSync(envFilePath);
|
|
46
|
+
if (fileExists) {
|
|
47
|
+
const existingContent = await fsPromises.readFile(envFilePath, 'utf-8');
|
|
48
|
+
const existingLines = existingContent.split(/\r?\n/);
|
|
49
|
+
for (const line of existingLines) {
|
|
50
|
+
if (!line.startsWith('tenantDomain=')) {
|
|
51
|
+
lines.push(line);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const fs = require('fs');
|
|
56
|
+
fs.writeFileSync('.env', lines.join('\n'), { encoding: 'utf-8' });
|
|
57
|
+
logger.success(`.env file updated with: ${lines.join('\n')}`);
|
|
58
|
+
} else {
|
|
59
|
+
const fs = require('fs');
|
|
60
|
+
fs.writeFileSync('.env', lines.join('\n'), { encoding: 'utf-8' });
|
|
61
|
+
logger.success(`.env file created with: ${lines.join('\n')}`);
|
|
62
|
+
}
|
|
63
|
+
};
|
package/src/commands/index.ts
CHANGED
|
@@ -4,4 +4,7 @@ import * as version from './version.command';
|
|
|
4
4
|
import * as scripts from './scripts.command';
|
|
5
5
|
import { openSolution } from './open-solution.command';
|
|
6
6
|
import * as installer from './installer.command';
|
|
7
|
-
|
|
7
|
+
import * as nvmrc from './nvmrc.command';
|
|
8
|
+
import * as envCommands from './env.commands';
|
|
9
|
+
import * as repo from './repo.command';
|
|
10
|
+
export { alias, eslint as env, version, scripts, openSolution, installer, nvmrc, envCommands, repo };
|
|
@@ -1,25 +1,100 @@
|
|
|
1
1
|
import { detect } from 'detect-package-manager';
|
|
2
2
|
import { getScriptByName } from './scripts.command';
|
|
3
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
|
+
};
|
|
4
73
|
|
|
5
74
|
export const install = async (name: string, fromScripts: boolean) => {
|
|
6
75
|
const usercommand = await detect();
|
|
7
76
|
const spawn = require('cross-spawn');
|
|
8
77
|
|
|
9
78
|
if (fromScripts) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
+
});
|
|
15
94
|
|
|
16
|
-
spawn.sync(usercommand, args, { stdio: 'inherit' });
|
|
17
|
-
return;
|
|
18
|
-
} else {
|
|
19
|
-
logger.error(`No install script found with name ${name} in global or local package.json`);
|
|
20
|
-
}
|
|
21
95
|
return;
|
|
22
96
|
}
|
|
97
|
+
|
|
23
98
|
if (name === undefined || name.length === 0) {
|
|
24
99
|
spawn.sync(usercommand, ['install'], { stdio: 'inherit' });
|
|
25
100
|
return;
|
|
@@ -0,0 +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
|
+
};
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import { logger } from '../common/logger';
|
|
2
|
+
import { util } from '../common';
|
|
3
|
+
import { promises as fsPromises } from 'fs';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import readline from 'readline';
|
|
6
|
+
import chalk from 'chalk';
|
|
7
|
+
|
|
8
|
+
const codeEmoji = '</>';
|
|
9
|
+
const dirEmpoji = '📁 ';
|
|
10
|
+
|
|
11
|
+
const openVSCodeInDirectory = (directory: string) => {
|
|
12
|
+
const spawn = require('child_process').spawn;
|
|
13
|
+
// Open the selected directory in VS Code
|
|
14
|
+
spawn(process.platform === 'win32' ? 'code.cmd' : 'code', [directory], {
|
|
15
|
+
stdio: 'inherit',
|
|
16
|
+
shell: true
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const displayOptions = (location: string) => {
|
|
21
|
+
const fs = require('fs');
|
|
22
|
+
const rootPackageJsonPath = path.join(location, 'package.json');
|
|
23
|
+
const hasPackageJson = fs.existsSync(rootPackageJsonPath);
|
|
24
|
+
if (hasPackageJson) {
|
|
25
|
+
openVSCodeInDirectory(location);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const childDirs = fs.readdirSync(location).filter((file: string) => {
|
|
30
|
+
return fs.statSync(path.join(location, file)).isDirectory();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const options = childDirs.map((dir: string, index: number) => {
|
|
34
|
+
const newPath = path.join(location, dir);
|
|
35
|
+
const packageJsonPath = path.join(newPath, 'package.json');
|
|
36
|
+
const hasPackageJson = fs.existsSync(packageJsonPath);
|
|
37
|
+
return { path: path.join(location, dir), label: `[${index + 1}] ${dir}`, hasPackageJson: hasPackageJson, emoji: hasPackageJson ? codeEmoji : dirEmpoji };
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
logger.log(`${dirEmpoji} Directories in current location:`, chalk.cyan);
|
|
41
|
+
options.forEach((option) => {
|
|
42
|
+
logger.log(`${option.emoji} ${option.label}`);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const rl = readline.createInterface({
|
|
46
|
+
input: process.stdin,
|
|
47
|
+
output: process.stdout
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
rl.question('Enter the number of the directory to select or 0 to cancel (append -vs to force open in VS Code): ', (answer) => {
|
|
51
|
+
const trimmed = answer.trim();
|
|
52
|
+
const vsFlag = trimmed.endsWith('-vs');
|
|
53
|
+
const numPart = vsFlag ? trimmed.replace(/-vs$/i, '').trim() : trimmed;
|
|
54
|
+
const idx = parseInt(numPart, 10) - 1;
|
|
55
|
+
|
|
56
|
+
if (idx >= 0 && idx < childDirs.length) {
|
|
57
|
+
const newPath = options[idx].path;
|
|
58
|
+
if (options[idx].hasPackageJson || vsFlag) {
|
|
59
|
+
// Valid selection or forced VS Code open
|
|
60
|
+
openVSCodeInDirectory(newPath);
|
|
61
|
+
rl.close();
|
|
62
|
+
return;
|
|
63
|
+
} else {
|
|
64
|
+
rl.close();
|
|
65
|
+
// Recursively prompt in the new directory
|
|
66
|
+
displayOptions(newPath);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
} else if (numPart === '0') {
|
|
70
|
+
if (vsFlag) {
|
|
71
|
+
openVSCodeInDirectory(location);
|
|
72
|
+
}
|
|
73
|
+
rl.close();
|
|
74
|
+
return;
|
|
75
|
+
} else {
|
|
76
|
+
console.log('Invalid selection.');
|
|
77
|
+
rl.close();
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const findDirectory = (location: string, chars: string): Promise<string | undefined> => {
|
|
84
|
+
const fs = require('fs');
|
|
85
|
+
const readline = require('readline');
|
|
86
|
+
const childDirs = fs.readdirSync(location).filter((file: string) => {
|
|
87
|
+
return fs.statSync(path.join(location, file)).isDirectory();
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
// Find all matches (case-insensitive, must start with chars)
|
|
91
|
+
const matches = childDirs.filter((dir: string) => dir.toLowerCase().startsWith(chars.toLowerCase()));
|
|
92
|
+
|
|
93
|
+
if (matches.length === 0) {
|
|
94
|
+
return Promise.resolve(undefined);
|
|
95
|
+
} else if (matches.length === 1) {
|
|
96
|
+
return new Promise((resolve) => resolve(path.join(location, matches[0])));
|
|
97
|
+
} else {
|
|
98
|
+
// Multiple matches, prompt user to select with emoji and label
|
|
99
|
+
console.log('Multiple directories match your input:');
|
|
100
|
+
const options = matches.map((dir: string, idx: number) => {
|
|
101
|
+
const newPath = path.join(location, dir);
|
|
102
|
+
const packageJsonPath = path.join(newPath, 'package.json');
|
|
103
|
+
const hasPackageJson = fs.existsSync(packageJsonPath);
|
|
104
|
+
return {
|
|
105
|
+
path: newPath,
|
|
106
|
+
label: `[${idx + 1}] ${dir}`,
|
|
107
|
+
emoji: hasPackageJson ? codeEmoji : dirEmpoji
|
|
108
|
+
};
|
|
109
|
+
});
|
|
110
|
+
options.forEach((option) => {
|
|
111
|
+
console.log(`${option.emoji} ${option.label}`);
|
|
112
|
+
});
|
|
113
|
+
const rl = readline.createInterface({
|
|
114
|
+
input: process.stdin,
|
|
115
|
+
output: process.stdout
|
|
116
|
+
});
|
|
117
|
+
return new Promise<string | undefined>((resolve) => {
|
|
118
|
+
rl.question('Enter the number to select or 0 to cancel (append -vs to force open in VS Code): ', (answer: string) => {
|
|
119
|
+
const trimmed = answer.trim();
|
|
120
|
+
const vsFlag = trimmed.endsWith('-vs');
|
|
121
|
+
const numPart = vsFlag ? trimmed.replace(/-vs$/i, '').trim() : trimmed;
|
|
122
|
+
const idx = parseInt(numPart, 10) - 1;
|
|
123
|
+
if (idx >= 0 && idx < options.length) {
|
|
124
|
+
if (vsFlag) {
|
|
125
|
+
openVSCodeInDirectory(options[idx].path);
|
|
126
|
+
rl.close();
|
|
127
|
+
resolve('***');
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
rl.close();
|
|
131
|
+
resolve(options[idx].path);
|
|
132
|
+
return;
|
|
133
|
+
} else if (numPart === '0') {
|
|
134
|
+
if (vsFlag) {
|
|
135
|
+
openVSCodeInDirectory(location);
|
|
136
|
+
rl.close();
|
|
137
|
+
resolve('***');
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
rl.close();
|
|
141
|
+
resolve('***');
|
|
142
|
+
return;
|
|
143
|
+
} else {
|
|
144
|
+
console.log('Invalid selection.');
|
|
145
|
+
rl.close();
|
|
146
|
+
resolve(undefined);
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
export const getRepo = async (): Promise<string | undefined> => {
|
|
155
|
+
const globalPath = util.getGlobalConfigPaths();
|
|
156
|
+
const fileExists = await util.checkIfFileExistsAsync(globalPath.configPath, true);
|
|
157
|
+
if (!fileExists) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
const data = await fsPromises.readFile(globalPath.configPath, 'utf-8');
|
|
161
|
+
const config = JSON.parse(data);
|
|
162
|
+
const name = 'repositoryDirectory';
|
|
163
|
+
if (config && typeof config === 'object' && config[name]) {
|
|
164
|
+
const repo = config[name];
|
|
165
|
+
return repo;
|
|
166
|
+
} else {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
export const SetRepo = async () => {
|
|
172
|
+
const globalPath = util.getGlobalConfigPaths();
|
|
173
|
+
const fileExists = await util.checkIfFileExistsAsync(globalPath.configPath, true);
|
|
174
|
+
if (!fileExists) {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const local = path.join(process.cwd());
|
|
179
|
+
logger.info(`Setting repository to: ${local}`);
|
|
180
|
+
|
|
181
|
+
const data = await fsPromises.readFile(globalPath.configPath, 'utf-8');
|
|
182
|
+
const packageJson = JSON.parse(data);
|
|
183
|
+
|
|
184
|
+
packageJson.repositoryDirectory = local;
|
|
185
|
+
await fsPromises.writeFile(globalPath.configPath, JSON.stringify(packageJson, null, 2), 'utf-8');
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
export const goToRepoFromProject = async (args?: string[]) => {
|
|
189
|
+
logger.info('Looking for repository from global package.json based on project shortcut...');
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
export const goToRepo = async (args?: string[]) => {
|
|
193
|
+
const repo = await getRepo();
|
|
194
|
+
|
|
195
|
+
if (repo === undefined) {
|
|
196
|
+
logger.error('No repository set. Please run " set-repo" first to set the repository location.');
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (!args || args.length === 0) {
|
|
201
|
+
displayOptions(repo);
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
let targetPath = repo;
|
|
206
|
+
for (const arg of args) {
|
|
207
|
+
targetPath = await findDirectory(targetPath, arg);
|
|
208
|
+
if (targetPath === undefined) {
|
|
209
|
+
logger.error(`Could not find directory matching "${arg}". Exiting.`);
|
|
210
|
+
return;
|
|
211
|
+
} else if (targetPath.endsWith('***')) {
|
|
212
|
+
// Check if VS Code was opened (user used -vs)
|
|
213
|
+
// If the directory was opened, do not log error, just exit
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
displayOptions(targetPath);
|
|
218
|
+
};
|
package/src/common/logger.ts
CHANGED
|
@@ -21,8 +21,12 @@ class Logger {
|
|
|
21
21
|
this.newLine();
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
public log(message: string) {
|
|
25
|
-
|
|
24
|
+
public log(message: string, color?: chalk.Chalk) {
|
|
25
|
+
if (color) {
|
|
26
|
+
this.logger(color(message));
|
|
27
|
+
} else {
|
|
28
|
+
this.logger(message);
|
|
29
|
+
}
|
|
26
30
|
}
|
|
27
31
|
|
|
28
32
|
public warning(message: string) {
|