@talex-touch/utils 1.0.12 → 1.0.14
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/common/env-tool.ts +16 -5
- package/package.json +1 -1
package/common/env-tool.ts
CHANGED
|
@@ -3,11 +3,11 @@ import { exec, ExecException } from 'child_process';
|
|
|
3
3
|
export interface IGlobalPkgResult {
|
|
4
4
|
exist: boolean
|
|
5
5
|
error?: ExecException
|
|
6
|
-
name
|
|
7
|
-
version
|
|
6
|
+
name?: string
|
|
7
|
+
version?: string
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
export function checkGlobalPackageExist(packageName: string) {
|
|
10
|
+
export function checkGlobalPackageExist(packageName: string): Promise<IGlobalPkgResult> {
|
|
11
11
|
return new Promise((resolve, reject) => {
|
|
12
12
|
exec(`npm list -g ${packageName}`, (error, stdout, stderr) => {
|
|
13
13
|
if (error) {
|
|
@@ -26,7 +26,7 @@ export function checkGlobalPackageExist(packageName: string) {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
const lines = stdout.split('\n');
|
|
29
|
-
const lastLine = lines[lines.length -
|
|
29
|
+
const lastLine = lines[lines.length - 3];
|
|
30
30
|
const match = lastLine.match(/(\S+)@(\S+)/);
|
|
31
31
|
if (match) {
|
|
32
32
|
resolve({
|
|
@@ -39,8 +39,19 @@ export function checkGlobalPackageExist(packageName: string) {
|
|
|
39
39
|
|
|
40
40
|
resolve({
|
|
41
41
|
exist: false
|
|
42
|
-
})
|
|
42
|
+
} as IGlobalPkgResult)
|
|
43
43
|
|
|
44
44
|
});
|
|
45
45
|
})
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Check npm version
|
|
49
|
+
export function getNpmVersion(): Promise<string | null> {
|
|
50
|
+
return new Promise((resolve) => {
|
|
51
|
+
exec(`npm --version`, (error, stdout, stderr) => {
|
|
52
|
+
if (error || stderr) resolve(null)
|
|
53
|
+
|
|
54
|
+
resolve(stdout.trim())
|
|
55
|
+
})
|
|
56
|
+
})
|
|
46
57
|
}
|