@mschauer5/spfx-toolkit 1.0.27 → 1.0.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.vscode/settings.json +22 -22
- package/LICENSE +21 -21
- package/README.md +72 -72
- package/lib/common/util.js +2 -1
- package/lib/common/util.js.map +1 -1
- package/package.json +3 -2
- package/src/commands/env.commands.ts +63 -63
- package/src/commands/index.ts +12 -12
- package/src/commands/installer.command.ts +134 -134
- package/src/commands/nvmrc.command.ts +76 -76
- package/src/commands/projects.command.ts +37 -37
- package/src/commands/repo.command.ts +206 -206
- package/src/commands/scripts.command.ts +139 -139
- package/src/common/index.ts +5 -5
- package/src/common/util.ts +114 -113
- package/src/index.ts +261 -261
- package/lib/commands/install.command.js +0 -28
- package/lib/commands/install.command.js.map +0 -1
- package/lib/commands/open-solution.command.js +0 -30
- package/lib/commands/open-solution.command.js.map +0 -1
- package/lib/commands/serve.command.js +0 -27
- package/lib/commands/serve.command.js.map +0 -1
- package/lib/commands/settings.js +0 -68
- package/lib/commands/settings.js.map +0 -1
- package/lib/package.json +0 -45
- package/lib/src/commands/alias.command.js +0 -104
- package/lib/src/commands/alias.command.js.map +0 -1
- package/lib/src/commands/build.command.js +0 -61
- package/lib/src/commands/build.command.js.map +0 -1
- package/lib/src/commands/bundle.command.js +0 -70
- package/lib/src/commands/bundle.command.js.map +0 -1
- package/lib/src/commands/eslint.command.js +0 -34
- package/lib/src/commands/eslint.command.js.map +0 -1
- package/lib/src/commands/index.js +0 -49
- package/lib/src/commands/index.js.map +0 -1
- package/lib/src/commands/serve.command.js +0 -27
- package/lib/src/commands/serve.command.js.map +0 -1
- package/lib/src/commands/version.command.js +0 -98
- package/lib/src/commands/version.command.js.map +0 -1
- package/lib/src/common/constants.js +0 -10
- package/lib/src/common/constants.js.map +0 -1
- package/lib/src/common/index.js +0 -43
- package/lib/src/common/index.js.map +0 -1
- package/lib/src/common/logger.js +0 -42
- package/lib/src/common/logger.js.map +0 -1
- package/lib/src/common/util.js +0 -80
- package/lib/src/common/util.js.map +0 -1
- package/lib/src/index.js +0 -146
- package/lib/src/index.js.map +0 -1
- package/lib/test/index.test.js +0 -17
- package/lib/test/index.test.js.map +0 -1
- package/mschauer5-spfx-toolkit-1.0.25.tgz +0 -0
|
@@ -1,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
|
+
};
|
package/src/common/index.ts
CHANGED
|
@@ -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 };
|
package/src/common/util.ts
CHANGED
|
@@ -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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
'build:
|
|
62
|
-
'
|
|
63
|
-
'bundle:
|
|
64
|
-
'
|
|
65
|
-
'serve:
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
'@tanstack/query
|
|
76
|
-
'@tanstack/query-
|
|
77
|
-
'@tanstack/query-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
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
|
+
};
|