@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,139 +1,139 @@
1
- import { logger, util } from '../common';
2
- import spawn from 'cross-spawn';
3
- import { promises as fsPromises } from 'fs';
4
- import path from 'path';
5
- import { incrementVersion, syncVersion } from './version.command';
6
-
7
- function getProjectConfigPaths() {
8
- const configDir = path.join(process.cwd());
9
- const configPath = path.join(configDir, 'package.json');
10
- return { configDir, configPath };
11
- }
12
-
13
- async function getScriptValue(scriptName: string, configPath: string): Promise<any> {
14
- try {
15
- const fileExists = await util.checkIfFileExistsAsync(configPath, false);
16
- if (!fileExists) {
17
- return undefined;
18
- }
19
-
20
- const isGulp = await util.isUsingGulp();
21
- let suffix = ':heft';
22
- if (isGulp) {
23
- suffix = ':gulp';
24
- }
25
-
26
- const data = await fsPromises.readFile(configPath, 'utf-8');
27
- const config = JSON.parse(data);
28
- if (config && typeof config === 'object' && config.scripts) {
29
- const scriptWithSuffix = scriptName + suffix;
30
- const hasBase = scriptName in config.scripts;
31
- const hasSuffix = scriptWithSuffix in config.scripts;
32
- if (hasBase && hasSuffix) {
33
- return config.scripts[scriptWithSuffix];
34
- } else if (hasSuffix) {
35
- return config.scripts[scriptWithSuffix];
36
- } else if (hasBase) {
37
- return config.scripts[scriptName];
38
- }
39
- }
40
- return undefined;
41
- } catch (err) {
42
- // File does not exist or cannot be read
43
- return undefined;
44
- }
45
- }
46
-
47
- export async function getScriptByName(scriptName: string): Promise<string | undefined> {
48
- const globalPath = util.getGlobalConfigPaths();
49
- const localPath = getProjectConfigPaths();
50
- let value = undefined;
51
- value = await getScriptValue(scriptName, globalPath.configPath);
52
-
53
- const localValue = await getScriptValue(scriptName, localPath.configPath);
54
- if (localValue !== undefined) {
55
- value = localValue;
56
- }
57
-
58
- return value;
59
- }
60
-
61
- export const run = async (scriptName: string, options?: any) => {
62
- if (scriptName === 'bundle' && options && typeof options === 'string') {
63
- if (options) {
64
- incrementVersion(options as 'major' | 'minor' | 'patch');
65
- } else {
66
- syncVersion();
67
- }
68
- }
69
-
70
- if (scriptName === 'serve') {
71
- const envFilePath = path.join(process.cwd(), '.env');
72
- const envFileExists = await util.checkIfFileExistsAsync(envFilePath, false);
73
- if (envFileExists) {
74
- const envContent = await fsPromises.readFile(envFilePath, 'utf-8');
75
- const lines = envContent.split(/\r?\n/);
76
- const envVars: { [key: string]: string } = {};
77
- for (const line of lines) {
78
- const [key, value] = line.split('=');
79
- if (key && value) {
80
- envVars[key.trim()] = value.trim();
81
- }
82
- }
83
- if (envVars['tenantDomain']) {
84
- process.env['SPFX_SERVE_TENANT_DOMAIN'] = envVars['tenantDomain'];
85
- }
86
- }
87
- }
88
-
89
- const value = await getScriptByName(scriptName);
90
- if (!value) {
91
- logger.error(`Script name '${scriptName}' not found in either local or global package.json!`);
92
- } else {
93
- try {
94
- spawn.sync(value, { stdio: 'inherit', shell: true, cwd: process.cwd() });
95
- } catch (error) {
96
- logger.error(error);
97
- }
98
- }
99
- };
100
-
101
- export const sync = async (scriptName: string, to: 'global' | 'local') => {
102
- const { configPath: globalConfigPath } = util.getGlobalConfigPaths();
103
- const { configPath: localConfigPath } = getProjectConfigPaths();
104
- let sourcePath = to === 'local' ? globalConfigPath : localConfigPath;
105
-
106
- const scriptValue = await getScriptValue(scriptName, sourcePath);
107
- if (!scriptValue) {
108
- logger.error(`Source script name '${scriptName}' not found in the ${sourcePath}!`);
109
- return;
110
- }
111
-
112
- const targetPath = to === 'local' ? localConfigPath : globalConfigPath;
113
- const targetExists = await util.checkIfFileExistsAsync(targetPath, false);
114
- if (!targetExists) {
115
- logger.error(`Target package.json does not exist at path: ${targetPath}`);
116
- return;
117
- }
118
- const data = await fsPromises.readFile(targetPath, 'utf-8');
119
- const targetConfig = JSON.parse(data);
120
- if (!targetConfig.scripts) {
121
- targetConfig.scripts = {};
122
- }
123
-
124
- const isGulp = await util.isUsingGulp();
125
- let suffix = ':heft';
126
- const orgScriptName = scriptName;
127
- if (isGulp) {
128
- suffix = ':gulp';
129
- }
130
- if (to === 'global') {
131
- scriptName = scriptName + suffix;
132
- }
133
-
134
- targetConfig.scripts[scriptName] = scriptValue;
135
-
136
- await fsPromises.writeFile(targetPath, JSON.stringify(targetConfig, null, 2), 'utf-8');
137
-
138
- logger.log(`Synchronized script '${orgScriptName}' to ${targetPath}`);
139
- };
1
+ import { logger, util } from '../common';
2
+ import spawn from 'cross-spawn';
3
+ import { promises as fsPromises } from 'fs';
4
+ import path from 'path';
5
+ import { incrementVersion, syncVersion } from './version.command';
6
+
7
+ function getProjectConfigPaths() {
8
+ const configDir = path.join(process.cwd());
9
+ const configPath = path.join(configDir, 'package.json');
10
+ return { configDir, configPath };
11
+ }
12
+
13
+ async function getScriptValue(scriptName: string, configPath: string): Promise<any> {
14
+ try {
15
+ const fileExists = await util.checkIfFileExistsAsync(configPath, false);
16
+ if (!fileExists) {
17
+ return undefined;
18
+ }
19
+
20
+ const isGulp = await util.isUsingGulp();
21
+ let suffix = ':heft';
22
+ if (isGulp) {
23
+ suffix = ':gulp';
24
+ }
25
+
26
+ const data = await fsPromises.readFile(configPath, 'utf-8');
27
+ const config = JSON.parse(data);
28
+ if (config && typeof config === 'object' && config.scripts) {
29
+ const scriptWithSuffix = scriptName + suffix;
30
+ const hasBase = scriptName in config.scripts;
31
+ const hasSuffix = scriptWithSuffix in config.scripts;
32
+ if (hasBase && hasSuffix) {
33
+ return config.scripts[scriptWithSuffix];
34
+ } else if (hasSuffix) {
35
+ return config.scripts[scriptWithSuffix];
36
+ } else if (hasBase) {
37
+ return config.scripts[scriptName];
38
+ }
39
+ }
40
+ return undefined;
41
+ } catch (err) {
42
+ // File does not exist or cannot be read
43
+ return undefined;
44
+ }
45
+ }
46
+
47
+ export async function getScriptByName(scriptName: string): Promise<string | undefined> {
48
+ const globalPath = util.getGlobalConfigPaths();
49
+ const localPath = getProjectConfigPaths();
50
+ let value = undefined;
51
+ value = await getScriptValue(scriptName, globalPath.configPath);
52
+
53
+ const localValue = await getScriptValue(scriptName, localPath.configPath);
54
+ if (localValue !== undefined) {
55
+ value = localValue;
56
+ }
57
+
58
+ return value;
59
+ }
60
+
61
+ export const run = async (scriptName: string, options?: any) => {
62
+ if (scriptName === 'bundle' && options && typeof options === 'string') {
63
+ if (options) {
64
+ incrementVersion(options as 'major' | 'minor' | 'patch');
65
+ } else {
66
+ syncVersion();
67
+ }
68
+ }
69
+
70
+ if (scriptName === 'serve') {
71
+ const envFilePath = path.join(process.cwd(), '.env');
72
+ const envFileExists = await util.checkIfFileExistsAsync(envFilePath, false);
73
+ if (envFileExists) {
74
+ const envContent = await fsPromises.readFile(envFilePath, 'utf-8');
75
+ const lines = envContent.split(/\r?\n/);
76
+ const envVars: { [key: string]: string } = {};
77
+ for (const line of lines) {
78
+ const [key, value] = line.split('=');
79
+ if (key && value) {
80
+ envVars[key.trim()] = value.trim();
81
+ }
82
+ }
83
+ if (envVars['tenantDomain']) {
84
+ process.env['SPFX_SERVE_TENANT_DOMAIN'] = envVars['tenantDomain'];
85
+ }
86
+ }
87
+ }
88
+
89
+ const value = await getScriptByName(scriptName);
90
+ if (!value) {
91
+ logger.error(`Script name '${scriptName}' not found in either local or global package.json!`);
92
+ } else {
93
+ try {
94
+ spawn.sync(value, { stdio: 'inherit', shell: true, cwd: process.cwd() });
95
+ } catch (error) {
96
+ logger.error(error);
97
+ }
98
+ }
99
+ };
100
+
101
+ export const sync = async (scriptName: string, to: 'global' | 'local') => {
102
+ const { configPath: globalConfigPath } = util.getGlobalConfigPaths();
103
+ const { configPath: localConfigPath } = getProjectConfigPaths();
104
+ let sourcePath = to === 'local' ? globalConfigPath : localConfigPath;
105
+
106
+ const scriptValue = await getScriptValue(scriptName, sourcePath);
107
+ if (!scriptValue) {
108
+ logger.error(`Source script name '${scriptName}' not found in the ${sourcePath}!`);
109
+ return;
110
+ }
111
+
112
+ const targetPath = to === 'local' ? localConfigPath : globalConfigPath;
113
+ const targetExists = await util.checkIfFileExistsAsync(targetPath, false);
114
+ if (!targetExists) {
115
+ logger.error(`Target package.json does not exist at path: ${targetPath}`);
116
+ return;
117
+ }
118
+ const data = await fsPromises.readFile(targetPath, 'utf-8');
119
+ const targetConfig = JSON.parse(data);
120
+ if (!targetConfig.scripts) {
121
+ targetConfig.scripts = {};
122
+ }
123
+
124
+ const isGulp = await util.isUsingGulp();
125
+ let suffix = ':heft';
126
+ const orgScriptName = scriptName;
127
+ if (isGulp) {
128
+ suffix = ':gulp';
129
+ }
130
+ if (to === 'global') {
131
+ scriptName = scriptName + suffix;
132
+ }
133
+
134
+ targetConfig.scripts[scriptName] = scriptValue;
135
+
136
+ await fsPromises.writeFile(targetPath, JSON.stringify(targetConfig, null, 2), 'utf-8');
137
+
138
+ logger.log(`Synchronized script '${orgScriptName}' to ${targetPath}`);
139
+ };
@@ -1,5 +1,5 @@
1
- import { logger } from './logger';
2
- import * as constants from './constants';
3
- import * as util from './util';
4
- // import * as settings from '../commands/settings';
5
- export { logger, constants, util };
1
+ import { logger } from './logger';
2
+ import * as constants from './constants';
3
+ import * as util from './util';
4
+ // import * as settings from '../commands/settings';
5
+ export { logger, constants, util };
@@ -1,113 +1,114 @@
1
- import { promises as fsPromises } from 'fs';
2
- import fs from 'fs';
3
- import os from 'os';
4
- import path from 'path';
5
- import { logger } from './logger';
6
-
7
- export async function checkIfFileExistsAsync(filename, includeError = true) {
8
- if (!fs.existsSync(filename)) {
9
- if (includeError) {
10
- logger.error(`No ${filename} found!`);
11
- }
12
- return false;
13
- }
14
-
15
- return true;
16
- }
17
-
18
- export function getGlobalConfigPaths() {
19
- const configDir = path.join(os.homedir(), '.spfx-toolkit');
20
- const configPath = path.join(configDir, 'package.json');
21
-
22
- return { configDir, configPath };
23
- }
24
-
25
- export async function isUsingGulp(): Promise<boolean> {
26
- const gulpFile = 'gulpfile.js';
27
- return await checkIfFileExistsAsync(gulpFile, false);
28
- }
29
-
30
- export async function ensureGlobalPackageJsonExists() {
31
- const { configDir, configPath } = getGlobalConfigPaths();
32
- const exists = await checkIfFileExistsAsync(configPath, false);
33
-
34
- if (!exists) {
35
- // Create the directory if it doesn't exist and then create an empty package.json
36
-
37
- await fsPromises.mkdir(configDir, { recursive: true });
38
-
39
- await fsPromises.writeFile(configPath, JSON.stringify({ scripts: {} }, null, 2), 'utf-8');
40
- }
41
- }
42
-
43
- export async function openGlobalPackageJsonInEditor() {
44
- const { configPath } = getGlobalConfigPaths();
45
- await ensureGlobalPackageJsonExists();
46
-
47
- const spawn = require('child_process').spawn;
48
- // Open the global package.json in VS Code
49
- spawn(process.platform === 'win32' ? 'code.cmd' : 'code', [configPath], {
50
- stdio: 'inherit',
51
- shell: true
52
- });
53
- }
54
-
55
- export async function initGlobalPackageJsonWithDefaults(force?: boolean) {
56
- const { configPath } = getGlobalConfigPaths();
57
- ensureGlobalPackageJsonExists();
58
-
59
- const defaultScripts = {
60
- 'build:gulp': 'gulp build',
61
- 'build:heft': 'heft build',
62
- 'bundle:gulp': 'heft test --clean --production && heft package-solution --production',
63
- 'bundle:heft': 'heft build --clean && heft package',
64
- 'serve:heft': 'heft build-watch --serve',
65
- 'serve:gulp': 'gulp serve'
66
- };
67
-
68
- const defaultPackages = {
69
- pnp: {
70
- dependencies: ['@pnp/graph', '@pnp/core', '@pnp/odata', '@pnp/queryable', '@pnp/sp']
71
- },
72
- 'react-query': {
73
- dependencies: [
74
- '@tanstack/react-query@4',
75
- '@tanstack/query-async-storage-persister@4',
76
- '@tanstack/query-persist-client-core@4',
77
- '@tanstack/query-sync-storage-persister@5'
78
- ],
79
- devDependencies: ['@tanstack/react-query-devtools@4']
80
- }
81
- };
82
-
83
- const packageJsonContent = await fsPromises.readFile(configPath, 'utf-8');
84
- const packageJson = JSON.parse(packageJsonContent);
85
-
86
- // Only add/overwrite scripts if force is true, otherwise do not overwrite existing matching scripts
87
- packageJson.scripts = packageJson.scripts || {};
88
- for (const [key, value] of Object.entries(defaultScripts)) {
89
- if (force || !(key in packageJson.scripts)) {
90
- packageJson.scripts[key] = value;
91
- }
92
- }
93
-
94
- // packageJson.packages
95
- packageJson.packages = packageJson.packages || {};
96
- for (const [key, value] of Object.entries(defaultPackages)) {
97
- if (force || !(key in packageJson.packages)) {
98
- packageJson.packages[key] = value;
99
- }
100
- }
101
-
102
- await fsPromises.writeFile(configPath, JSON.stringify(packageJson, null, 2), 'utf-8');
103
- logger.success(`Global package.json initialized at ${configPath}`);
104
- }
105
-
106
- export const openVSCodeInDirectory = (directory: string) => {
107
- const spawn = require('child_process').spawn;
108
- // Open the selected directory in VS Code
109
- spawn(process.platform === 'win32' ? 'code.cmd' : 'code', [directory], {
110
- stdio: 'inherit',
111
- shell: true
112
- });
113
- };
1
+ import { promises as fsPromises } from 'fs';
2
+ import fs from 'fs';
3
+ import os from 'os';
4
+ import path from 'path';
5
+ import { logger } from './logger';
6
+
7
+ export async function checkIfFileExistsAsync(filename: string, includeError = true) {
8
+ if (!fs.existsSync(filename)) {
9
+ if (includeError) {
10
+ logger.error(`No ${filename} found!`);
11
+ }
12
+ return false;
13
+ }
14
+
15
+ return true;
16
+ }
17
+
18
+ export function getGlobalConfigPaths() {
19
+ const configDir = path.join(os.homedir(), '.spfx-toolkit');
20
+ const configPath = path.join(configDir, 'package.json');
21
+
22
+ return { configDir, configPath };
23
+ }
24
+
25
+ export async function isUsingGulp(): Promise<boolean> {
26
+ const gulpFile = 'gulpfile.js';
27
+ return await checkIfFileExistsAsync(gulpFile, false);
28
+ }
29
+
30
+ export async function ensureGlobalPackageJsonExists() {
31
+ const { configDir, configPath } = getGlobalConfigPaths();
32
+ const exists = await checkIfFileExistsAsync(configPath, false);
33
+
34
+ if (!exists) {
35
+ logger.info('Global package.json for spfx-toolkit not found. Creating one...');
36
+ // Create the directory if it doesn't exist and then create an empty package.json
37
+
38
+ await fsPromises.mkdir(configDir, { recursive: true });
39
+
40
+ await fsPromises.writeFile(configPath, JSON.stringify({ scripts: {} }, null, 2), 'utf-8');
41
+ }
42
+ }
43
+
44
+ export async function openGlobalPackageJsonInEditor() {
45
+ const { configPath } = getGlobalConfigPaths();
46
+ await ensureGlobalPackageJsonExists();
47
+
48
+ const spawn = require('child_process').spawn;
49
+ // Open the global package.json in VS Code
50
+ spawn(process.platform === 'win32' ? 'code.cmd' : 'code', [configPath], {
51
+ stdio: 'inherit',
52
+ shell: true
53
+ });
54
+ }
55
+
56
+ export async function initGlobalPackageJsonWithDefaults(force?: boolean) {
57
+ const { configPath } = getGlobalConfigPaths();
58
+ await ensureGlobalPackageJsonExists();
59
+
60
+ const defaultScripts = {
61
+ 'build:gulp': 'gulp build',
62
+ 'build:heft': 'heft build',
63
+ 'bundle:gulp': 'heft test --clean --production && heft package-solution --production',
64
+ 'bundle:heft': 'heft build --clean && heft package',
65
+ 'serve:heft': 'heft build-watch --serve',
66
+ 'serve:gulp': 'gulp serve'
67
+ };
68
+
69
+ const defaultPackages = {
70
+ pnp: {
71
+ dependencies: ['@pnp/graph', '@pnp/core', '@pnp/odata', '@pnp/queryable', '@pnp/sp']
72
+ },
73
+ 'react-query': {
74
+ dependencies: [
75
+ '@tanstack/react-query@4',
76
+ '@tanstack/query-async-storage-persister@4',
77
+ '@tanstack/query-persist-client-core@4',
78
+ '@tanstack/query-sync-storage-persister@5'
79
+ ],
80
+ devDependencies: ['@tanstack/react-query-devtools@4']
81
+ }
82
+ };
83
+
84
+ const packageJsonContent = await fsPromises.readFile(configPath, 'utf-8');
85
+ const packageJson = JSON.parse(packageJsonContent);
86
+
87
+ // Only add/overwrite scripts if force is true, otherwise do not overwrite existing matching scripts
88
+ packageJson.scripts = packageJson.scripts || {};
89
+ for (const [key, value] of Object.entries(defaultScripts)) {
90
+ if (force || !(key in packageJson.scripts)) {
91
+ packageJson.scripts[key] = value;
92
+ }
93
+ }
94
+
95
+ // packageJson.packages
96
+ packageJson.packages = packageJson.packages || {};
97
+ for (const [key, value] of Object.entries(defaultPackages)) {
98
+ if (force || !(key in packageJson.packages)) {
99
+ packageJson.packages[key] = value;
100
+ }
101
+ }
102
+
103
+ await fsPromises.writeFile(configPath, JSON.stringify(packageJson, null, 2), 'utf-8');
104
+ logger.success(`Global package.json initialized at ${configPath}`);
105
+ }
106
+
107
+ export const openVSCodeInDirectory = (directory: string) => {
108
+ const spawn = require('child_process').spawn;
109
+ // Open the selected directory in VS Code
110
+ spawn(process.platform === 'win32' ? 'code.cmd' : 'code', [directory], {
111
+ stdio: 'inherit',
112
+ shell: true
113
+ });
114
+ };