@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.
Files changed (52) hide show
  1. package/.vscode/settings.json +22 -22
  2. package/LICENSE +21 -21
  3. package/README.md +72 -72
  4. package/lib/common/util.js +2 -1
  5. package/lib/common/util.js.map +1 -1
  6. package/package.json +3 -2
  7. package/src/commands/env.commands.ts +63 -63
  8. package/src/commands/index.ts +12 -12
  9. package/src/commands/installer.command.ts +134 -134
  10. package/src/commands/nvmrc.command.ts +76 -76
  11. package/src/commands/projects.command.ts +37 -37
  12. package/src/commands/repo.command.ts +206 -206
  13. package/src/commands/scripts.command.ts +139 -139
  14. package/src/common/index.ts +5 -5
  15. package/src/common/util.ts +114 -113
  16. package/src/index.ts +261 -261
  17. package/lib/commands/install.command.js +0 -28
  18. package/lib/commands/install.command.js.map +0 -1
  19. package/lib/commands/open-solution.command.js +0 -30
  20. package/lib/commands/open-solution.command.js.map +0 -1
  21. package/lib/commands/serve.command.js +0 -27
  22. package/lib/commands/serve.command.js.map +0 -1
  23. package/lib/commands/settings.js +0 -68
  24. package/lib/commands/settings.js.map +0 -1
  25. package/lib/package.json +0 -45
  26. package/lib/src/commands/alias.command.js +0 -104
  27. package/lib/src/commands/alias.command.js.map +0 -1
  28. package/lib/src/commands/build.command.js +0 -61
  29. package/lib/src/commands/build.command.js.map +0 -1
  30. package/lib/src/commands/bundle.command.js +0 -70
  31. package/lib/src/commands/bundle.command.js.map +0 -1
  32. package/lib/src/commands/eslint.command.js +0 -34
  33. package/lib/src/commands/eslint.command.js.map +0 -1
  34. package/lib/src/commands/index.js +0 -49
  35. package/lib/src/commands/index.js.map +0 -1
  36. package/lib/src/commands/serve.command.js +0 -27
  37. package/lib/src/commands/serve.command.js.map +0 -1
  38. package/lib/src/commands/version.command.js +0 -98
  39. package/lib/src/commands/version.command.js.map +0 -1
  40. package/lib/src/common/constants.js +0 -10
  41. package/lib/src/common/constants.js.map +0 -1
  42. package/lib/src/common/index.js +0 -43
  43. package/lib/src/common/index.js.map +0 -1
  44. package/lib/src/common/logger.js +0 -42
  45. package/lib/src/common/logger.js.map +0 -1
  46. package/lib/src/common/util.js +0 -80
  47. package/lib/src/common/util.js.map +0 -1
  48. package/lib/src/index.js +0 -146
  49. package/lib/src/index.js.map +0 -1
  50. package/lib/test/index.test.js +0 -17
  51. package/lib/test/index.test.js.map +0 -1
  52. package/mschauer5-spfx-toolkit-1.0.25.tgz +0 -0
@@ -1,206 +1,206 @@
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
- import { openVSCodeInDirectory } from '../common/util';
8
-
9
- const codeEmoji = '</>';
10
- const dirEmpoji = '📁 ';
11
-
12
- const displayOptions = (location: string) => {
13
- const fs = require('fs');
14
- const rootPackageJsonPath = path.join(location, 'package.json');
15
- const hasPackageJson = fs.existsSync(rootPackageJsonPath);
16
- if (hasPackageJson) {
17
- openVSCodeInDirectory(location);
18
- return;
19
- }
20
-
21
- const childDirs = fs.readdirSync(location).filter((file: string) => {
22
- return fs.statSync(path.join(location, file)).isDirectory();
23
- });
24
-
25
- const options = childDirs.map((dir: string, index: number) => {
26
- const newPath = path.join(location, dir);
27
- const packageJsonPath = path.join(newPath, 'package.json');
28
- const hasPackageJson = fs.existsSync(packageJsonPath);
29
- return { path: path.join(location, dir), label: `[${index + 1}] ${dir}`, hasPackageJson: hasPackageJson, emoji: hasPackageJson ? codeEmoji : dirEmpoji };
30
- });
31
-
32
- logger.log(`${dirEmpoji} Directories in current location:`, chalk.cyan);
33
- options.forEach((option) => {
34
- logger.log(`${option.emoji} ${option.label}`);
35
- });
36
-
37
- const rl = readline.createInterface({
38
- input: process.stdin,
39
- output: process.stdout
40
- });
41
-
42
- rl.question('Enter the number of the directory to select or 0 to cancel (append -vs to force open in VS Code): ', (answer) => {
43
- const trimmed = answer.trim();
44
- const vsFlag = trimmed.endsWith('-vs');
45
- const numPart = vsFlag ? trimmed.replace(/-vs$/i, '').trim() : trimmed;
46
- const idx = parseInt(numPart, 10) - 1;
47
-
48
- if (idx >= 0 && idx < childDirs.length) {
49
- const newPath = options[idx].path;
50
- if (options[idx].hasPackageJson || vsFlag) {
51
- // Valid selection or forced VS Code open
52
- openVSCodeInDirectory(newPath);
53
- rl.close();
54
- return;
55
- } else {
56
- rl.close();
57
- // Recursively prompt in the new directory
58
- displayOptions(newPath);
59
- return;
60
- }
61
- } else if (numPart === '0') {
62
- if (vsFlag) {
63
- openVSCodeInDirectory(location);
64
- }
65
- rl.close();
66
- return;
67
- } else {
68
- console.log('Invalid selection.');
69
- rl.close();
70
- return;
71
- }
72
- });
73
- };
74
-
75
- const findDirectory = (location: string, chars: string): Promise<string | undefined> => {
76
- const fs = require('fs');
77
- const readline = require('readline');
78
- const childDirs = fs.readdirSync(location).filter((file: string) => {
79
- return fs.statSync(path.join(location, file)).isDirectory();
80
- });
81
-
82
- // Find all matches (case-insensitive, must start with chars)
83
- const matches = childDirs.filter((dir: string) => dir.toLowerCase().startsWith(chars.toLowerCase()));
84
-
85
- if (matches.length === 0) {
86
- return Promise.resolve(undefined);
87
- } else if (matches.length === 1) {
88
- return new Promise((resolve) => resolve(path.join(location, matches[0])));
89
- } else {
90
- // Multiple matches, prompt user to select with emoji and label
91
- console.log('Multiple directories match your input:');
92
- const options = matches.map((dir: string, idx: number) => {
93
- const newPath = path.join(location, dir);
94
- const packageJsonPath = path.join(newPath, 'package.json');
95
- const hasPackageJson = fs.existsSync(packageJsonPath);
96
- return {
97
- path: newPath,
98
- label: `[${idx + 1}] ${dir}`,
99
- emoji: hasPackageJson ? codeEmoji : dirEmpoji
100
- };
101
- });
102
- options.forEach((option) => {
103
- console.log(`${option.emoji} ${option.label}`);
104
- });
105
- const rl = readline.createInterface({
106
- input: process.stdin,
107
- output: process.stdout
108
- });
109
- return new Promise<string | undefined>((resolve) => {
110
- rl.question('Enter the number to select or 0 to cancel (append -vs to force open in VS Code): ', (answer: string) => {
111
- const trimmed = answer.trim();
112
- const vsFlag = trimmed.endsWith('-vs');
113
- const numPart = vsFlag ? trimmed.replace(/-vs$/i, '').trim() : trimmed;
114
- const idx = parseInt(numPart, 10) - 1;
115
- if (idx >= 0 && idx < options.length) {
116
- if (vsFlag) {
117
- openVSCodeInDirectory(options[idx].path);
118
- rl.close();
119
- resolve('***');
120
- return;
121
- }
122
- rl.close();
123
- resolve(options[idx].path);
124
- return;
125
- } else if (numPart === '0') {
126
- if (vsFlag) {
127
- openVSCodeInDirectory(location);
128
- rl.close();
129
- resolve('***');
130
- return;
131
- }
132
- rl.close();
133
- resolve('***');
134
- return;
135
- } else {
136
- console.log('Invalid selection.');
137
- rl.close();
138
- resolve(undefined);
139
- return;
140
- }
141
- });
142
- });
143
- }
144
- };
145
-
146
- export const getRepo = async (): Promise<string | undefined> => {
147
- const globalPath = util.getGlobalConfigPaths();
148
- const fileExists = await util.checkIfFileExistsAsync(globalPath.configPath, true);
149
- if (!fileExists) {
150
- return;
151
- }
152
- const data = await fsPromises.readFile(globalPath.configPath, 'utf-8');
153
- const config = JSON.parse(data);
154
- const name = 'repositoryDirectory';
155
- if (config && typeof config === 'object' && config[name]) {
156
- const repo = config[name];
157
- return repo;
158
- } else {
159
- return;
160
- }
161
- };
162
-
163
- export const SetRepo = async () => {
164
- const globalPath = util.getGlobalConfigPaths();
165
- const fileExists = await util.checkIfFileExistsAsync(globalPath.configPath, true);
166
- if (!fileExists) {
167
- await util.initGlobalPackageJsonWithDefaults(true);
168
- }
169
-
170
- const local = path.join(process.cwd());
171
- logger.info(`Setting repository to: ${local}`);
172
-
173
- const data = await fsPromises.readFile(globalPath.configPath, 'utf-8');
174
- const packageJson = JSON.parse(data);
175
-
176
- packageJson.repositoryDirectory = local;
177
- await fsPromises.writeFile(globalPath.configPath, JSON.stringify(packageJson, null, 2), 'utf-8');
178
- };
179
-
180
- export const goToRepo = async (args?: string[]) => {
181
- const repo = await getRepo();
182
-
183
- if (repo === undefined) {
184
- logger.error('No repository set. Please run " set-repo" first to set the repository location.');
185
- return;
186
- }
187
-
188
- if (!args || args.length === 0) {
189
- displayOptions(repo);
190
- return;
191
- }
192
-
193
- let targetPath = repo;
194
- for (const arg of args) {
195
- targetPath = await findDirectory(targetPath, arg);
196
- if (targetPath === undefined) {
197
- logger.error(`Could not find directory matching "${arg}". Exiting.`);
198
- return;
199
- } else if (targetPath.endsWith('***')) {
200
- // Check if VS Code was opened (user used -vs)
201
- // If the directory was opened, do not log error, just exit
202
- return;
203
- }
204
- }
205
- displayOptions(targetPath);
206
- };
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
+ import { openVSCodeInDirectory } from '../common/util';
8
+
9
+ const codeEmoji = '</>';
10
+ const dirEmpoji = '📁 ';
11
+
12
+ const displayOptions = (location: string) => {
13
+ const fs = require('fs');
14
+ const rootPackageJsonPath = path.join(location, 'package.json');
15
+ const hasPackageJson = fs.existsSync(rootPackageJsonPath);
16
+ if (hasPackageJson) {
17
+ openVSCodeInDirectory(location);
18
+ return;
19
+ }
20
+
21
+ const childDirs = fs.readdirSync(location).filter((file: string) => {
22
+ return fs.statSync(path.join(location, file)).isDirectory();
23
+ });
24
+
25
+ const options = childDirs.map((dir: string, index: number) => {
26
+ const newPath = path.join(location, dir);
27
+ const packageJsonPath = path.join(newPath, 'package.json');
28
+ const hasPackageJson = fs.existsSync(packageJsonPath);
29
+ return { path: path.join(location, dir), label: `[${index + 1}] ${dir}`, hasPackageJson: hasPackageJson, emoji: hasPackageJson ? codeEmoji : dirEmpoji };
30
+ });
31
+
32
+ logger.log(`${dirEmpoji} Directories in current location:`, chalk.cyan);
33
+ options.forEach((option) => {
34
+ logger.log(`${option.emoji} ${option.label}`);
35
+ });
36
+
37
+ const rl = readline.createInterface({
38
+ input: process.stdin,
39
+ output: process.stdout
40
+ });
41
+
42
+ rl.question('Enter the number of the directory to select or 0 to cancel (append -vs to force open in VS Code): ', (answer) => {
43
+ const trimmed = answer.trim();
44
+ const vsFlag = trimmed.endsWith('-vs');
45
+ const numPart = vsFlag ? trimmed.replace(/-vs$/i, '').trim() : trimmed;
46
+ const idx = parseInt(numPart, 10) - 1;
47
+
48
+ if (idx >= 0 && idx < childDirs.length) {
49
+ const newPath = options[idx].path;
50
+ if (options[idx].hasPackageJson || vsFlag) {
51
+ // Valid selection or forced VS Code open
52
+ openVSCodeInDirectory(newPath);
53
+ rl.close();
54
+ return;
55
+ } else {
56
+ rl.close();
57
+ // Recursively prompt in the new directory
58
+ displayOptions(newPath);
59
+ return;
60
+ }
61
+ } else if (numPart === '0') {
62
+ if (vsFlag) {
63
+ openVSCodeInDirectory(location);
64
+ }
65
+ rl.close();
66
+ return;
67
+ } else {
68
+ console.log('Invalid selection.');
69
+ rl.close();
70
+ return;
71
+ }
72
+ });
73
+ };
74
+
75
+ const findDirectory = (location: string, chars: string): Promise<string | undefined> => {
76
+ const fs = require('fs');
77
+ const readline = require('readline');
78
+ const childDirs = fs.readdirSync(location).filter((file: string) => {
79
+ return fs.statSync(path.join(location, file)).isDirectory();
80
+ });
81
+
82
+ // Find all matches (case-insensitive, must start with chars)
83
+ const matches = childDirs.filter((dir: string) => dir.toLowerCase().startsWith(chars.toLowerCase()));
84
+
85
+ if (matches.length === 0) {
86
+ return Promise.resolve(undefined);
87
+ } else if (matches.length === 1) {
88
+ return new Promise((resolve) => resolve(path.join(location, matches[0])));
89
+ } else {
90
+ // Multiple matches, prompt user to select with emoji and label
91
+ console.log('Multiple directories match your input:');
92
+ const options = matches.map((dir: string, idx: number) => {
93
+ const newPath = path.join(location, dir);
94
+ const packageJsonPath = path.join(newPath, 'package.json');
95
+ const hasPackageJson = fs.existsSync(packageJsonPath);
96
+ return {
97
+ path: newPath,
98
+ label: `[${idx + 1}] ${dir}`,
99
+ emoji: hasPackageJson ? codeEmoji : dirEmpoji
100
+ };
101
+ });
102
+ options.forEach((option) => {
103
+ console.log(`${option.emoji} ${option.label}`);
104
+ });
105
+ const rl = readline.createInterface({
106
+ input: process.stdin,
107
+ output: process.stdout
108
+ });
109
+ return new Promise<string | undefined>((resolve) => {
110
+ rl.question('Enter the number to select or 0 to cancel (append -vs to force open in VS Code): ', (answer: string) => {
111
+ const trimmed = answer.trim();
112
+ const vsFlag = trimmed.endsWith('-vs');
113
+ const numPart = vsFlag ? trimmed.replace(/-vs$/i, '').trim() : trimmed;
114
+ const idx = parseInt(numPart, 10) - 1;
115
+ if (idx >= 0 && idx < options.length) {
116
+ if (vsFlag) {
117
+ openVSCodeInDirectory(options[idx].path);
118
+ rl.close();
119
+ resolve('***');
120
+ return;
121
+ }
122
+ rl.close();
123
+ resolve(options[idx].path);
124
+ return;
125
+ } else if (numPart === '0') {
126
+ if (vsFlag) {
127
+ openVSCodeInDirectory(location);
128
+ rl.close();
129
+ resolve('***');
130
+ return;
131
+ }
132
+ rl.close();
133
+ resolve('***');
134
+ return;
135
+ } else {
136
+ console.log('Invalid selection.');
137
+ rl.close();
138
+ resolve(undefined);
139
+ return;
140
+ }
141
+ });
142
+ });
143
+ }
144
+ };
145
+
146
+ export const getRepo = async (): Promise<string | undefined> => {
147
+ const globalPath = util.getGlobalConfigPaths();
148
+ const fileExists = await util.checkIfFileExistsAsync(globalPath.configPath, true);
149
+ if (!fileExists) {
150
+ return;
151
+ }
152
+ const data = await fsPromises.readFile(globalPath.configPath, 'utf-8');
153
+ const config = JSON.parse(data);
154
+ const name = 'repositoryDirectory';
155
+ if (config && typeof config === 'object' && config[name]) {
156
+ const repo = config[name];
157
+ return repo;
158
+ } else {
159
+ return;
160
+ }
161
+ };
162
+
163
+ export const SetRepo = async () => {
164
+ const globalPath = util.getGlobalConfigPaths();
165
+ const fileExists = await util.checkIfFileExistsAsync(globalPath.configPath, true);
166
+ if (!fileExists) {
167
+ await util.initGlobalPackageJsonWithDefaults(true);
168
+ }
169
+
170
+ const local = path.join(process.cwd());
171
+ logger.info(`Setting repository to: ${local}`);
172
+
173
+ const data = await fsPromises.readFile(globalPath.configPath, 'utf-8');
174
+ const packageJson = JSON.parse(data);
175
+
176
+ packageJson.repositoryDirectory = local;
177
+ await fsPromises.writeFile(globalPath.configPath, JSON.stringify(packageJson, null, 2), 'utf-8');
178
+ };
179
+
180
+ export const goToRepo = async (args?: string[]) => {
181
+ const repo = await getRepo();
182
+
183
+ if (repo === undefined) {
184
+ logger.error('No repository set. Please run " set-repo" first to set the repository location.');
185
+ return;
186
+ }
187
+
188
+ if (!args || args.length === 0) {
189
+ displayOptions(repo);
190
+ return;
191
+ }
192
+
193
+ let targetPath = repo;
194
+ for (const arg of args) {
195
+ targetPath = await findDirectory(targetPath, arg);
196
+ if (targetPath === undefined) {
197
+ logger.error(`Could not find directory matching "${arg}". Exiting.`);
198
+ return;
199
+ } else if (targetPath.endsWith('***')) {
200
+ // Check if VS Code was opened (user used -vs)
201
+ // If the directory was opened, do not log error, just exit
202
+ return;
203
+ }
204
+ }
205
+ displayOptions(targetPath);
206
+ };