forked from tagspaces/tagspaces
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckWSinstalled.js
108 lines (100 loc) · 2.66 KB
/
checkWSinstalled.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#! /usr/bin/env node
const path = require('path');
const fs = require('fs-extra');
// const shell = require('shelljs');
const childProcess = require('child_process');
const packageJson = require('../release/app/package.json');
function isInstalled(packageName, checkVersion = undefined) {
try {
const packageVersions =
packageName + (checkVersion ? '@' + checkVersion : '');
const versions = childProcess
.execSync(
'npm list --depth=0 --prefix ' + path.join(__dirname, '../release/app'),
)
//.execSync('npm view ' + packageName + ' version')
.toString();
if (versions.indexOf(packageVersions) > 0) {
return true;
}
/*if (checkVersion) {
if (checkVersion === version) {
return true;
}
} else if (version.length > 0) {
return true;
}*/
// require.resolve('../app/node_modules/' + packageName);
return false;
} catch (err) {
return false;
}
}
function dirExist(dir) {
try {
fs.statSync(dir);
return true;
} catch (err) {
if (err.code === 'ENOENT') {
return false;
}
}
return false;
}
/*function checkSharpPlatform(targetPlatform, arch) {
if (!targetPlatform || !arch) {
return true;
}
try {
const sharp = require('../app/node_modules/sharp');
const vendor = sharp.vendor;
console.log('vendor: ' + vendor);
return vendor.current === targetPlatform + '-' + arch;
} catch (e) {
console.log('checkSharpPlatform: ', e);
return false;
}
}*/
let platform = 'node';
let installCmd;
const dir = path.join(__dirname, '../release/app/node_modules');
if (process.env.PD_PLATFORM) {
platform = process.env.PD_PLATFORM;
}
if (platform === 'node') {
if (
//!checkSharpPlatform(process.env.TARGET_PLATFORM, process.env.TARGET_ARCH) ||
!dirExist(dir) ||
!isInstalled(
'@tagspaces/extensions',
packageJson.dependencies['@tagspaces/extensions'],
) ||
!isInstalled(
'@tagspaces/tagspaces-ws',
packageJson.dependencies['@tagspaces/tagspaces-ws'],
) ||
!isInstalled('sharp', packageJson.dependencies['sharp'])
) {
installCmd = 'npm run-script install-ext-node';
}
} else if (platform === 'web') {
if (
!dirExist(dir) ||
!isInstalled(
'@tagspaces/extensions',
packageJson.dependencies['@tagspaces/extensions'],
) ||
isInstalled('@tagspaces/tagspaces-ws')
) {
installCmd = 'npm run-script install-ext-web';
}
}
if (installCmd) {
console.log(childProcess.execSync(installCmd).toString());
/*if (shell.exec(installCmd).code !== 0) {
shell.echo(
'Error: Install ' + process.env.PD_PLATFORM + ' platform failed'
);
shell.exit(1);
}*/
}