@mschauer5/spfx-toolkit 1.0.22 → 1.0.24
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/lib/commands/env.commands.js +69 -0
- package/lib/commands/env.commands.js.map +1 -0
- package/lib/commands/index.js +6 -2
- package/lib/commands/index.js.map +1 -1
- package/lib/commands/installer.command.js +53 -2
- 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/index.js +25 -3
- package/lib/index.js.map +1 -1
- package/mschauer5-spfx-toolkit-1.0.22.tgz +0 -0
- package/package.json +5 -3
- package/src/commands/env.commands.ts +63 -0
- package/src/commands/index.ts +3 -1
- package/src/commands/installer.command.ts +49 -1
- package/src/commands/nvmrc.command.ts +76 -0
- package/src/index.ts +29 -3
- package/mschauer5-spfx-toolkit-1.0.12.tgz +0 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.setEnv = void 0;
|
|
13
|
+
const logger_1 = require("../common/logger");
|
|
14
|
+
var readlineSync = require('readline-sync');
|
|
15
|
+
const setEnv = (tenantDomain) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
+
const lines = [];
|
|
17
|
+
let td = tenantDomain;
|
|
18
|
+
// if tenantDomain is provided, set it in the .env file
|
|
19
|
+
if (!tenantDomain) {
|
|
20
|
+
// check env variable first
|
|
21
|
+
if (process.env['SPFX_SERVE_TENANT_DOMAIN']) {
|
|
22
|
+
// if they want to use this env variable
|
|
23
|
+
// add default of yes
|
|
24
|
+
const inputDomain = readlineSync.question(`Do you want to use global tenant domain of ${process.env['SPFX_SERVE_TENANT_DOMAIN']}? (yes/no) : Default is 'yes' `);
|
|
25
|
+
if (inputDomain.toLowerCase() === 'yes' || inputDomain.toLowerCase() === 'y' || inputDomain === '') {
|
|
26
|
+
td = `${process.env['SPFX_SERVE_TENANT_DOMAIN']}`;
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
td = undefined;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (td) {
|
|
34
|
+
if (td.startsWith('https://')) {
|
|
35
|
+
td = td.replace('https://', '');
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
// otherwise, prompt the user for it
|
|
40
|
+
const inputDomain = readlineSync.question('Enter the tenant domain (e.g., contoso.sharepoint.com): ');
|
|
41
|
+
td = inputDomain;
|
|
42
|
+
}
|
|
43
|
+
td = `tenantDomain=${td}`;
|
|
44
|
+
lines.push(td);
|
|
45
|
+
// if file exists, read existing lines except tenantDomain
|
|
46
|
+
const fsPromises = require('fs').promises;
|
|
47
|
+
const path = require('path');
|
|
48
|
+
const envFilePath = path.join(process.cwd(), '.env');
|
|
49
|
+
const fileExists = require('fs').existsSync(envFilePath);
|
|
50
|
+
if (fileExists) {
|
|
51
|
+
const existingContent = yield fsPromises.readFile(envFilePath, 'utf-8');
|
|
52
|
+
const existingLines = existingContent.split(/\r?\n/);
|
|
53
|
+
for (const line of existingLines) {
|
|
54
|
+
if (!line.startsWith('tenantDomain=')) {
|
|
55
|
+
lines.push(line);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const fs = require('fs');
|
|
59
|
+
fs.writeFileSync('.env', lines.join('\n'), { encoding: 'utf-8' });
|
|
60
|
+
logger_1.logger.success(`.env file updated with: ${lines.join('\n')}`);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
const fs = require('fs');
|
|
64
|
+
fs.writeFileSync('.env', lines.join('\n'), { encoding: 'utf-8' });
|
|
65
|
+
logger_1.logger.success(`.env file created with: ${lines.join('\n')}`);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
exports.setEnv = setEnv;
|
|
69
|
+
//# sourceMappingURL=env.commands.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.commands.js","sourceRoot":"","sources":["../../src/commands/env.commands.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6CAA0C;AAC1C,IAAI,YAAY,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;AAErC,MAAM,MAAM,GAAG,CAAO,YAAqB,EAAE,EAAE;IACpD,MAAM,KAAK,GAAG,EAAE,CAAC;IAEjB,IAAI,EAAE,GAAG,YAAY,CAAC;IAEtB,uDAAuD;IACvD,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,2BAA2B;QAC3B,IAAI,OAAO,CAAC,GAAG,CAAC,0BAA0B,CAAC,EAAE,CAAC;YAC5C,wCAAwC;YAExC,qBAAqB;YACrB,MAAM,WAAW,GAAG,YAAY,CAAC,QAAQ,CACvC,8CAA8C,OAAO,CAAC,GAAG,CAAC,0BAA0B,CAAC,gCAAgC,CACtH,CAAC;YACF,IAAI,WAAW,CAAC,WAAW,EAAE,KAAK,KAAK,IAAI,WAAW,CAAC,WAAW,EAAE,KAAK,GAAG,IAAI,WAAW,KAAK,EAAE,EAAE,CAAC;gBACnG,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,0BAA0B,CAAC,EAAE,CAAC;YACpD,CAAC;iBAAM,CAAC;gBACN,EAAE,GAAG,SAAS,CAAC;Y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AK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;QAClE,eAAM,CAAC,OAAO,CAAC,2BAA2B,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAChE,CAAC;SAAM,CAAC;QACN,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;QACzB,EAAE,CAAC,aAAa,CAAC,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;QAClE,eAAM,CAAC,OAAO,CAAC,2BAA2B,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAChE,CAAC;AACH,CAAC,CAAA,CAAC;AA3DW,QAAA,MAAM,UA2DjB"}
|
package/lib/commands/index.js
CHANGED
|
@@ -33,11 +33,11 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.installer = exports.openSolution = exports.scripts = exports.version = exports.
|
|
36
|
+
exports.envCommands = exports.nvmrc = exports.installer = exports.openSolution = exports.scripts = exports.version = exports.env = exports.alias = void 0;
|
|
37
37
|
const alias = __importStar(require("./alias.command"));
|
|
38
38
|
exports.alias = alias;
|
|
39
39
|
const eslint = __importStar(require("./eslint.command"));
|
|
40
|
-
exports.
|
|
40
|
+
exports.env = eslint;
|
|
41
41
|
const version = __importStar(require("./version.command"));
|
|
42
42
|
exports.version = version;
|
|
43
43
|
const scripts = __importStar(require("./scripts.command"));
|
|
@@ -46,4 +46,8 @@ const open_solution_command_1 = require("./open-solution.command");
|
|
|
46
46
|
Object.defineProperty(exports, "openSolution", { enumerable: true, get: function () { return open_solution_command_1.openSolution; } });
|
|
47
47
|
const installer = __importStar(require("./installer.command"));
|
|
48
48
|
exports.installer = installer;
|
|
49
|
+
const nvmrc = __importStar(require("./nvmrc.command"));
|
|
50
|
+
exports.nvmrc = nvmrc;
|
|
51
|
+
const envCommands = __importStar(require("./env.commands"));
|
|
52
|
+
exports.envCommands = envCommands;
|
|
49
53
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/commands/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uDAAyC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/commands/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uDAAyC;AAQhC,sBAAK;AAPd,yDAA2C;AAOjB,qBAAG;AAN7B,2DAA6C;AAMd,0BAAO;AALtC,2DAA6C;AAKL,0BAAO;AAJ/C,mEAAuD;AAIN,6FAJxC,oCAAY,OAIwC;AAH7D,+DAAiD;AAGc,8BAAS;AAFxE,uDAAyC;AAEiC,sBAAK;AAD/E,4DAA8C;AACmC,kCAAW"}
|
|
@@ -8,11 +8,62 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.uninstall = exports.install = void 0;
|
|
15
|
+
exports.uninstall = exports.install = exports.addNvmrcToStartup = void 0;
|
|
13
16
|
const detect_package_manager_1 = require("detect-package-manager");
|
|
14
17
|
const scripts_command_1 = require("./scripts.command");
|
|
15
18
|
const logger_1 = require("../common/logger");
|
|
19
|
+
const os_1 = __importDefault(require("os"));
|
|
20
|
+
const path_1 = __importDefault(require("path"));
|
|
21
|
+
const fs_1 = __importDefault(require("fs"));
|
|
22
|
+
/**
|
|
23
|
+
* Adds a command to the user's shell profile to run spfx-toolkit nvmrc use on terminal startup.
|
|
24
|
+
* Supports bash, zsh (macOS/Linux) and PowerShell (Windows).
|
|
25
|
+
*/
|
|
26
|
+
const addNvmrcToStartup = () => {
|
|
27
|
+
const homedir = os_1.default.homedir();
|
|
28
|
+
const isWin = process.platform === 'win32';
|
|
29
|
+
let profilePath = '';
|
|
30
|
+
let shellType = '';
|
|
31
|
+
let lineToAdd = '';
|
|
32
|
+
if (isWin) {
|
|
33
|
+
// PowerShell profile
|
|
34
|
+
const profileEnv = process.env.USERPROFILE || homedir;
|
|
35
|
+
// Default PowerShell profile path
|
|
36
|
+
profilePath = path_1.default.join(profileEnv, 'Documents', 'WindowsPowerShell', 'Microsoft.PowerShell_profile.ps1');
|
|
37
|
+
shellType = 'PowerShell';
|
|
38
|
+
lineToAdd = 'spfx-toolkit nvmrc use';
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
// Check for zsh or bash
|
|
42
|
+
if (process.env.SHELL && process.env.SHELL.includes('zsh')) {
|
|
43
|
+
profilePath = path_1.default.join(homedir, '.zshrc');
|
|
44
|
+
shellType = 'zsh';
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
profilePath = path_1.default.join(homedir, '.bashrc');
|
|
48
|
+
shellType = 'bash';
|
|
49
|
+
}
|
|
50
|
+
lineToAdd = 'spfx-toolkit nvmrc use';
|
|
51
|
+
}
|
|
52
|
+
// Check if profile exists, create if not
|
|
53
|
+
if (!fs_1.default.existsSync(profilePath)) {
|
|
54
|
+
fs_1.default.writeFileSync(profilePath, '', { encoding: 'utf-8' });
|
|
55
|
+
}
|
|
56
|
+
// Check if line already exists
|
|
57
|
+
const profileContent = fs_1.default.readFileSync(profilePath, 'utf-8');
|
|
58
|
+
if (!profileContent.includes(lineToAdd)) {
|
|
59
|
+
fs_1.default.appendFileSync(profilePath, `\n# Added by spfx-toolkit\n${lineToAdd}\n`, { encoding: 'utf-8' });
|
|
60
|
+
console.log(`Added '${lineToAdd}' to your ${shellType} profile: ${profilePath}`);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
console.log(`'${lineToAdd}' is already present in your ${shellType} profile: ${profilePath}`);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
exports.addNvmrcToStartup = addNvmrcToStartup;
|
|
16
67
|
const install = (name, fromScripts) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
68
|
const usercommand = yield (0, detect_package_manager_1.detect)();
|
|
18
69
|
const spawn = require('cross-spawn');
|
|
@@ -31,7 +82,7 @@ const install = (name, fromScripts) => __awaiter(void 0, void 0, void 0, functio
|
|
|
31
82
|
return;
|
|
32
83
|
}
|
|
33
84
|
if (name === undefined || name.length === 0) {
|
|
34
|
-
spawn.sync(usercommand, 'install', { stdio: 'inherit' });
|
|
85
|
+
spawn.sync(usercommand, ['install'], { stdio: 'inherit' });
|
|
35
86
|
return;
|
|
36
87
|
}
|
|
37
88
|
const args = name.split(' ');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"installer.command.js","sourceRoot":"","sources":["../../src/commands/installer.command.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"installer.command.js","sourceRoot":"","sources":["../../src/commands/installer.command.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,mEAAgD;AAChD,uDAAoD;AACpD,6CAA0C;AAC1C,4CAAoB;AACpB,gDAAwB;AACxB,4CAAoB;AAEpB;;;GAGG;AACI,MAAM,iBAAiB,GAAG,GAAG,EAAE;IACpC,MAAM,OAAO,GAAG,YAAE,CAAC,OAAO,EAAE,CAAC;IAC7B,MAAM,KAAK,GAAG,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC;IAC3C,IAAI,WAAW,GAAG,EAAE,CAAC;IACrB,IAAI,SAAS,GAAG,EAAE,CAAC;IACnB,IAAI,SAAS,GAAG,EAAE,CAA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{
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.useNvmrc = exports.addNvmrc = void 0;
|
|
13
|
+
const addNvmrc = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
14
|
+
const spawn = require('cross-spawn');
|
|
15
|
+
const result = spawn.sync('nvm', ['current'], { encoding: 'utf-8' });
|
|
16
|
+
if (result.status !== 0) {
|
|
17
|
+
console.error('Error detecting current Node version with nvm. Make sure nvm is installed and accessible from your PATH.');
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const currentVersion = result.stdout.trim();
|
|
21
|
+
const nvmrcContent = currentVersion;
|
|
22
|
+
const fs = require('fs');
|
|
23
|
+
fs.writeFileSync('.nvmrc', nvmrcContent, { encoding: 'utf-8' });
|
|
24
|
+
console.log(`.nvmrc file created with Node version: ${currentVersion}`);
|
|
25
|
+
});
|
|
26
|
+
exports.addNvmrc = addNvmrc;
|
|
27
|
+
const useNvmrc = () => {
|
|
28
|
+
const fs = require('fs');
|
|
29
|
+
const spawn = require('cross-spawn');
|
|
30
|
+
const readlineSync = require('readline-sync');
|
|
31
|
+
let requiredVersion = '';
|
|
32
|
+
let source = '';
|
|
33
|
+
// Check .nvmrc first
|
|
34
|
+
const nvmrcPath = '.nvmrc';
|
|
35
|
+
if (fs.existsSync(nvmrcPath)) {
|
|
36
|
+
requiredVersion = fs.readFileSync(nvmrcPath, 'utf-8').trim();
|
|
37
|
+
source = '.nvmrc';
|
|
38
|
+
}
|
|
39
|
+
else if (fs.existsSync('package.json')) {
|
|
40
|
+
// Fallback to package.json engines.node
|
|
41
|
+
try {
|
|
42
|
+
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf-8'));
|
|
43
|
+
if (pkg.engines && pkg.engines.node) {
|
|
44
|
+
requiredVersion = pkg.engines.node.trim();
|
|
45
|
+
source = 'package.json';
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
catch (e) {
|
|
49
|
+
console.error('Could not parse package.json:', e);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (!requiredVersion) {
|
|
53
|
+
console.log('No .nvmrc or engines.node in package.json found.');
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const result = spawn.sync('nvm', ['current'], { encoding: 'utf-8' });
|
|
57
|
+
if (result.status !== 0) {
|
|
58
|
+
console.error('Error detecting current Node version with nvm. Make sure nvm is installed and accessible from your PATH.');
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const currentVersion = result.stdout.trim();
|
|
62
|
+
// Normalize for semver range (e.g., ">=14.0.0")
|
|
63
|
+
const semver = require('semver');
|
|
64
|
+
let needsSwitch = false;
|
|
65
|
+
if (source === 'package.json') {
|
|
66
|
+
needsSwitch = !semver.satisfies(currentVersion, requiredVersion);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
needsSwitch = currentVersion !== requiredVersion;
|
|
70
|
+
}
|
|
71
|
+
if (needsSwitch) {
|
|
72
|
+
const response = readlineSync.question(`Current Node version is ${currentVersion}. Switch to ${requiredVersion} as per ${source}? (y/n) [y]: `);
|
|
73
|
+
if (response === 'y' || response === '') {
|
|
74
|
+
console.log(`Switching Node version to ${requiredVersion} as per ${source}`);
|
|
75
|
+
const switchResult = spawn.sync('nvm', ['use', requiredVersion], { stdio: 'inherit' });
|
|
76
|
+
if (switchResult.status !== 0) {
|
|
77
|
+
console.error(`Failed to switch Node version to ${requiredVersion}.`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
console.log(`Node version ${currentVersion} matches required version from ${source}.`);
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
exports.useNvmrc = useNvmrc;
|
|
86
|
+
//# sourceMappingURL=nvmrc.command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nvmrc.command.js","sourceRoot":"","sources":["../../src/commands/nvmrc.command.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAO,MAAM,QAAQ,GAAG,GAAS,EAAE;IACjC,MAAM,KAAK,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;IACrC,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,SAAS,CAAC,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;IAErE,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxB,OAAO,CAAC,KAAK,CAAC,0GAA0G,CAAC,CAAC;QAC1H,OAAO;IACT,CAAC;IAED,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;IAC5C,MAAM,YAAY,GAAG,cAAc,CAAC;IAEpC,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACzB,EAAE,CAAC,aAAa,CAAC,QAAQ,EAAE,YAAY,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;IAChE,OAAO,CAAC,GAAG,CAAC,0CAA0C,cAAc,EAAE,CAAC,CAAC;AAC1E,CAAC,CAAA,CAAC;AAfW,QAAA,QAAQ,YAenB;AAEK,MAAM,QAAQ,GAAG,GAAG,EAAE;IAC3B,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACzB,MAAM,KAAK,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;IACrC,MAAM,YAAY,G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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')
|
|
@@ -113,6 +113,18 @@ program
|
|
|
113
113
|
.action((name) => {
|
|
114
114
|
commands.installer.install(name, true);
|
|
115
115
|
});
|
|
116
|
+
program
|
|
117
|
+
.command('add-nvmrc')
|
|
118
|
+
.description('Add .nvmrc file with current specified Node version')
|
|
119
|
+
.action(() => {
|
|
120
|
+
commands.nvmrc.addNvmrc();
|
|
121
|
+
});
|
|
122
|
+
program
|
|
123
|
+
.command('use-nvmrc')
|
|
124
|
+
.description('Use Node version specified in .nvmrc file')
|
|
125
|
+
.action(() => {
|
|
126
|
+
commands.nvmrc.useNvmrc();
|
|
127
|
+
});
|
|
116
128
|
program
|
|
117
129
|
.command('uninstall')
|
|
118
130
|
.alias('un')
|
|
@@ -170,15 +182,25 @@ program
|
|
|
170
182
|
.option('-r, --restore', 'Restore from backup eslint file')
|
|
171
183
|
.action((options) => {
|
|
172
184
|
if (options.backup) {
|
|
173
|
-
commands.
|
|
185
|
+
commands.env.backupEslint();
|
|
174
186
|
}
|
|
175
187
|
else if (options.restore) {
|
|
176
|
-
commands.
|
|
188
|
+
commands.env.restoreEslint();
|
|
177
189
|
}
|
|
178
190
|
else {
|
|
179
191
|
common_1.logger.error('No action specified. Use --backup | -b <OR> --restore | -r');
|
|
180
192
|
}
|
|
181
193
|
});
|
|
194
|
+
program
|
|
195
|
+
.command('set-env')
|
|
196
|
+
.description('Set tenantDomain environment variables')
|
|
197
|
+
.addArgument(new commander.Argument('[tenantDomain]', 'Tenant domain to set'))
|
|
198
|
+
.option('-t, --tenant <tenantDomain>', 'Specify the tenant domain')
|
|
199
|
+
.action((tenantDomain, options) => {
|
|
200
|
+
// Prefer positional argument, fallback to option
|
|
201
|
+
const domain = tenantDomain || options.tenant;
|
|
202
|
+
commands.envCommands.setEnv(domain);
|
|
203
|
+
});
|
|
182
204
|
program
|
|
183
205
|
.command('version')
|
|
184
206
|
.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;I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package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mschauer5/spfx-toolkit",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.24",
|
|
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.22.tgz -g && npm pack . && npm install .\\mschauer5-spfx-toolkit-1.0.22.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,6 @@ 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
|
+
export { alias, eslint as env, version, scripts, openSolution, installer, nvmrc, envCommands };
|
|
@@ -1,6 +1,54 @@
|
|
|
1
1
|
import { detect } from 'detect-package-manager';
|
|
2
2
|
import { getScriptByName } from './scripts.command';
|
|
3
3
|
import { logger } from '../common/logger';
|
|
4
|
+
import os from 'os';
|
|
5
|
+
import path from 'path';
|
|
6
|
+
import fs from 'fs';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Adds a command to the user's shell profile to run spfx-toolkit nvmrc use on terminal startup.
|
|
10
|
+
* Supports bash, zsh (macOS/Linux) and PowerShell (Windows).
|
|
11
|
+
*/
|
|
12
|
+
export const addNvmrcToStartup = () => {
|
|
13
|
+
const homedir = os.homedir();
|
|
14
|
+
const isWin = process.platform === 'win32';
|
|
15
|
+
let profilePath = '';
|
|
16
|
+
let shellType = '';
|
|
17
|
+
let lineToAdd = '';
|
|
18
|
+
|
|
19
|
+
if (isWin) {
|
|
20
|
+
// PowerShell profile
|
|
21
|
+
const profileEnv = process.env.USERPROFILE || homedir;
|
|
22
|
+
// Default PowerShell profile path
|
|
23
|
+
profilePath = path.join(profileEnv, 'Documents', 'WindowsPowerShell', 'Microsoft.PowerShell_profile.ps1');
|
|
24
|
+
shellType = 'PowerShell';
|
|
25
|
+
lineToAdd = 'spfx-toolkit nvmrc use';
|
|
26
|
+
} else {
|
|
27
|
+
// Check for zsh or bash
|
|
28
|
+
if (process.env.SHELL && process.env.SHELL.includes('zsh')) {
|
|
29
|
+
profilePath = path.join(homedir, '.zshrc');
|
|
30
|
+
shellType = 'zsh';
|
|
31
|
+
} else {
|
|
32
|
+
profilePath = path.join(homedir, '.bashrc');
|
|
33
|
+
shellType = 'bash';
|
|
34
|
+
}
|
|
35
|
+
lineToAdd = 'spfx-toolkit nvmrc use';
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Check if profile exists, create if not
|
|
39
|
+
if (!fs.existsSync(profilePath)) {
|
|
40
|
+
fs.writeFileSync(profilePath, '', { encoding: 'utf-8' });
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Check if line already exists
|
|
44
|
+
const profileContent = fs.readFileSync(profilePath, 'utf-8');
|
|
45
|
+
if (!profileContent.includes(lineToAdd)) {
|
|
46
|
+
fs.appendFileSync(profilePath, `\n# Added by spfx-toolkit\n${lineToAdd}\n`, { encoding: 'utf-8' });
|
|
47
|
+
console.log(`Added '${lineToAdd}' to your ${shellType} profile: ${profilePath}`);
|
|
48
|
+
} else {
|
|
49
|
+
console.log(`'${lineToAdd}' is already present in your ${shellType} profile: ${profilePath}`);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
4
52
|
|
|
5
53
|
export const install = async (name: string, fromScripts: boolean) => {
|
|
6
54
|
const usercommand = await detect();
|
|
@@ -21,7 +69,7 @@ export const install = async (name: string, fromScripts: boolean) => {
|
|
|
21
69
|
return;
|
|
22
70
|
}
|
|
23
71
|
if (name === undefined || name.length === 0) {
|
|
24
|
-
spawn.sync(usercommand, 'install', { stdio: 'inherit' });
|
|
72
|
+
spawn.sync(usercommand, ['install'], { stdio: 'inherit' });
|
|
25
73
|
return;
|
|
26
74
|
}
|
|
27
75
|
|
|
@@ -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
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -12,7 +12,7 @@ program
|
|
|
12
12
|
.name('Matt Schauer SPFx Toolkit')
|
|
13
13
|
.description('CLI to help with SPFx development')
|
|
14
14
|
.addHelpText('beforeAll', chalk.blueBright('Developed by Matt Schauer'))
|
|
15
|
-
.version('1.0.
|
|
15
|
+
.version('1.0.24');
|
|
16
16
|
|
|
17
17
|
program
|
|
18
18
|
.command('add-alias')
|
|
@@ -87,6 +87,20 @@ program
|
|
|
87
87
|
commands.installer.install(name, true);
|
|
88
88
|
});
|
|
89
89
|
|
|
90
|
+
program
|
|
91
|
+
.command('add-nvmrc')
|
|
92
|
+
.description('Add .nvmrc file with current specified Node version')
|
|
93
|
+
.action(() => {
|
|
94
|
+
commands.nvmrc.addNvmrc();
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
program
|
|
98
|
+
.command('use-nvmrc')
|
|
99
|
+
.description('Use Node version specified in .nvmrc file')
|
|
100
|
+
.action(() => {
|
|
101
|
+
commands.nvmrc.useNvmrc();
|
|
102
|
+
});
|
|
103
|
+
|
|
90
104
|
program
|
|
91
105
|
.command('uninstall')
|
|
92
106
|
.alias('un')
|
|
@@ -151,14 +165,26 @@ program
|
|
|
151
165
|
.option('-r, --restore', 'Restore from backup eslint file')
|
|
152
166
|
.action((options) => {
|
|
153
167
|
if (options.backup) {
|
|
154
|
-
commands.
|
|
168
|
+
commands.env.backupEslint();
|
|
155
169
|
} else if (options.restore) {
|
|
156
|
-
commands.
|
|
170
|
+
commands.env.restoreEslint();
|
|
157
171
|
} else {
|
|
158
172
|
logger.error('No action specified. Use --backup | -b <OR> --restore | -r');
|
|
159
173
|
}
|
|
160
174
|
});
|
|
161
175
|
|
|
176
|
+
program
|
|
177
|
+
.command('set-env')
|
|
178
|
+
.description('Set tenantDomain environment variables')
|
|
179
|
+
.addArgument(new commander.Argument('[tenantDomain]', 'Tenant domain to set'))
|
|
180
|
+
.option('-t, --tenant <tenantDomain>', 'Specify the tenant domain')
|
|
181
|
+
.action((tenantDomain, options) => {
|
|
182
|
+
// Prefer positional argument, fallback to option
|
|
183
|
+
const domain = tenantDomain || options.tenant;
|
|
184
|
+
|
|
185
|
+
commands.envCommands.setEnv(domain);
|
|
186
|
+
});
|
|
187
|
+
|
|
162
188
|
program
|
|
163
189
|
.command('version')
|
|
164
190
|
.option('-l, --list', 'List SPFx project versions')
|
|
Binary file
|