u2a 3.5.1 → 3.5.3
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/.github/workflows/npm-publish.yml +22 -0
- package/package.json +1 -2
- package/src/commands/configure.js +154 -124
- package/src/utils/appGenerator.js +349 -349
- package/src/utils/builder.js +125 -125
- package/src/utils/logger.js +5 -1
- package/src/utils/noroot.js +41 -41
- package/src/utils/osIntegration.js +187 -187
- package/src/utils/postinstall.js +119 -119
- package/src/utils/sanitize.js +20 -20
- package/src/utils/securexec.js +12 -12
- package/src/utils/settings.js +112 -110
- package/src/utils/versionCheck.js +149 -148
package/src/utils/builder.js
CHANGED
|
@@ -1,126 +1,126 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const path = require('path');
|
|
3
|
-
const Logger = require('./logger');
|
|
4
|
-
const { secureExec } = require('./securexec');
|
|
5
|
-
|
|
6
|
-
const logger = new Logger('builder');
|
|
7
|
-
|
|
8
|
-
async function buildExecutable(appDir, appName, platform, iconPath, options) {
|
|
9
|
-
logger.info(`Building executable for ${platform}...`);
|
|
10
|
-
|
|
11
|
-
try {
|
|
12
|
-
const installOptions = {
|
|
13
|
-
cwd: appDir,
|
|
14
|
-
stdio: ['ignore', 'pipe', 'pipe'],
|
|
15
|
-
windowsHide: true
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
secureExec('npm install --save-dev electron-packager electron', installOptions);
|
|
19
|
-
|
|
20
|
-
let platformFlag = '';
|
|
21
|
-
let archFlag = `--arch=${options.arch || 'x64'}`;
|
|
22
|
-
let iconOption = '';
|
|
23
|
-
|
|
24
|
-
switch(platform) {
|
|
25
|
-
case 'windows':
|
|
26
|
-
platformFlag = '--platform=win32';
|
|
27
|
-
iconOption = iconPath ? `--icon="${iconPath}"` : '';
|
|
28
|
-
break;
|
|
29
|
-
case 'darwin':
|
|
30
|
-
platformFlag = '--platform=darwin';
|
|
31
|
-
if (iconPath && !iconPath.endsWith('.icns')) {
|
|
32
|
-
logger.warn('MacOs Icons are not supported at this time.');
|
|
33
|
-
}
|
|
34
|
-
iconOption = iconPath ? `--icon="${iconPath}"` : '';
|
|
35
|
-
break;
|
|
36
|
-
case 'linux':
|
|
37
|
-
platformFlag = '--platform=linux';
|
|
38
|
-
iconOption = iconPath ? `--icon="${iconPath}"` : '';
|
|
39
|
-
break;
|
|
40
|
-
default:
|
|
41
|
-
platformFlag = `--platform=${process.platform}`;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const packageCommand = `npx electron-packager . "${appName}" ${platformFlag} ${archFlag} --out=dist --overwrite --asar ${iconOption}`;
|
|
45
|
-
|
|
46
|
-
logger.debug(`Executing: ${packageCommand}`);
|
|
47
|
-
|
|
48
|
-
secureExec(packageCommand, installOptions);
|
|
49
|
-
|
|
50
|
-
let distPlatform = '';
|
|
51
|
-
switch(platform) {
|
|
52
|
-
case 'windows': distPlatform = 'win32'; break;
|
|
53
|
-
case 'darwin': distPlatform = 'darwin'; break;
|
|
54
|
-
case 'linux': distPlatform = 'linux'; break;
|
|
55
|
-
default: distPlatform = process.platform;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const outputPath = path.join(appDir, 'dist', `${appName}-${distPlatform}-x64`);
|
|
59
|
-
|
|
60
|
-
if (fs.existsSync(outputPath)) {
|
|
61
|
-
logger.debug(`Executable built successfully at: ${outputPath}`);
|
|
62
|
-
return outputPath;
|
|
63
|
-
} else {
|
|
64
|
-
logger.error(`Failed to find the built executable at: ${outputPath}`);
|
|
65
|
-
return null;
|
|
66
|
-
}
|
|
67
|
-
} catch (error) {
|
|
68
|
-
logger.error(`Error while building executable:`, error);
|
|
69
|
-
return null;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
async function buildSetup(appDir, platform, arch) {
|
|
74
|
-
logger.info(`Building setup for ${platform}${arch ? ` (${arch})` : ''}...`);
|
|
75
|
-
|
|
76
|
-
try {
|
|
77
|
-
const installOptions = {
|
|
78
|
-
cwd: appDir,
|
|
79
|
-
stdio: ['ignore', 'pipe', 'pipe'],
|
|
80
|
-
windowsHide: true
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
secureExec('npm install --save-dev electron-builder', installOptions);
|
|
84
|
-
|
|
85
|
-
let builderArgs = '';
|
|
86
|
-
switch(platform) {
|
|
87
|
-
case 'windows':
|
|
88
|
-
builderArgs = '--win';
|
|
89
|
-
break;
|
|
90
|
-
case 'darwin':
|
|
91
|
-
builderArgs = '--mac';
|
|
92
|
-
break;
|
|
93
|
-
case 'linux':
|
|
94
|
-
builderArgs = '--linux';
|
|
95
|
-
break;
|
|
96
|
-
default:
|
|
97
|
-
builderArgs = '';
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (arch) {
|
|
101
|
-
builderArgs += ` --${arch}`;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const builderCommand = `npx electron-builder ${builderArgs}`;
|
|
105
|
-
logger.debug(`Executing: ${builderCommand}`);
|
|
106
|
-
secureExec(builderCommand, installOptions);
|
|
107
|
-
|
|
108
|
-
const installerPath = path.join(appDir, 'installer');
|
|
109
|
-
if (fs.existsSync(installerPath)) {
|
|
110
|
-
logger.debug(`Setup created at: ${installerPath}`);
|
|
111
|
-
return installerPath;
|
|
112
|
-
} else {
|
|
113
|
-
logger.error(`Failed to find the built installer at: ${installerPath}`);
|
|
114
|
-
return null;
|
|
115
|
-
}
|
|
116
|
-
} catch (error) {
|
|
117
|
-
logger.error(`Error while building setup.`, error);
|
|
118
|
-
logger.warn('Try to run u2a with administrator privileges to avoid this error.');
|
|
119
|
-
return null;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
module.exports = {
|
|
124
|
-
buildExecutable,
|
|
125
|
-
buildSetup
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const Logger = require('./logger');
|
|
4
|
+
const { secureExec } = require('./securexec');
|
|
5
|
+
|
|
6
|
+
const logger = new Logger('builder');
|
|
7
|
+
|
|
8
|
+
async function buildExecutable(appDir, appName, platform, iconPath, options) {
|
|
9
|
+
logger.info(`Building executable for ${platform}...`);
|
|
10
|
+
|
|
11
|
+
try {
|
|
12
|
+
const installOptions = {
|
|
13
|
+
cwd: appDir,
|
|
14
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
15
|
+
windowsHide: true
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
secureExec('npm install --save-dev electron-packager electron', installOptions);
|
|
19
|
+
|
|
20
|
+
let platformFlag = '';
|
|
21
|
+
let archFlag = `--arch=${options.arch || 'x64'}`;
|
|
22
|
+
let iconOption = '';
|
|
23
|
+
|
|
24
|
+
switch(platform) {
|
|
25
|
+
case 'windows':
|
|
26
|
+
platformFlag = '--platform=win32';
|
|
27
|
+
iconOption = iconPath ? `--icon="${iconPath}"` : '';
|
|
28
|
+
break;
|
|
29
|
+
case 'darwin':
|
|
30
|
+
platformFlag = '--platform=darwin';
|
|
31
|
+
if (iconPath && !iconPath.endsWith('.icns')) {
|
|
32
|
+
logger.warn('MacOs Icons are not supported at this time.');
|
|
33
|
+
}
|
|
34
|
+
iconOption = iconPath ? `--icon="${iconPath}"` : '';
|
|
35
|
+
break;
|
|
36
|
+
case 'linux':
|
|
37
|
+
platformFlag = '--platform=linux';
|
|
38
|
+
iconOption = iconPath ? `--icon="${iconPath}"` : '';
|
|
39
|
+
break;
|
|
40
|
+
default:
|
|
41
|
+
platformFlag = `--platform=${process.platform}`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const packageCommand = `npx electron-packager . "${appName}" ${platformFlag} ${archFlag} --out=dist --overwrite --asar ${iconOption}`;
|
|
45
|
+
|
|
46
|
+
logger.debug(`Executing: ${packageCommand}`);
|
|
47
|
+
|
|
48
|
+
secureExec(packageCommand, installOptions);
|
|
49
|
+
|
|
50
|
+
let distPlatform = '';
|
|
51
|
+
switch(platform) {
|
|
52
|
+
case 'windows': distPlatform = 'win32'; break;
|
|
53
|
+
case 'darwin': distPlatform = 'darwin'; break;
|
|
54
|
+
case 'linux': distPlatform = 'linux'; break;
|
|
55
|
+
default: distPlatform = process.platform;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const outputPath = path.join(appDir, 'dist', `${appName}-${distPlatform}-x64`);
|
|
59
|
+
|
|
60
|
+
if (fs.existsSync(outputPath)) {
|
|
61
|
+
logger.debug(`Executable built successfully at: ${outputPath}`);
|
|
62
|
+
return outputPath;
|
|
63
|
+
} else {
|
|
64
|
+
logger.error(`Failed to find the built executable at: ${outputPath}`);
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
} catch (error) {
|
|
68
|
+
logger.error(`Error while building executable:`, error);
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async function buildSetup(appDir, platform, arch) {
|
|
74
|
+
logger.info(`Building setup for ${platform}${arch ? ` (${arch})` : ''}...`);
|
|
75
|
+
|
|
76
|
+
try {
|
|
77
|
+
const installOptions = {
|
|
78
|
+
cwd: appDir,
|
|
79
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
80
|
+
windowsHide: true
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
secureExec('npm install --save-dev electron-builder', installOptions);
|
|
84
|
+
|
|
85
|
+
let builderArgs = '';
|
|
86
|
+
switch(platform) {
|
|
87
|
+
case 'windows':
|
|
88
|
+
builderArgs = '--win';
|
|
89
|
+
break;
|
|
90
|
+
case 'darwin':
|
|
91
|
+
builderArgs = '--mac';
|
|
92
|
+
break;
|
|
93
|
+
case 'linux':
|
|
94
|
+
builderArgs = '--linux';
|
|
95
|
+
break;
|
|
96
|
+
default:
|
|
97
|
+
builderArgs = '';
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (arch) {
|
|
101
|
+
builderArgs += ` --${arch}`;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const builderCommand = `npx electron-builder ${builderArgs}`;
|
|
105
|
+
logger.debug(`Executing: ${builderCommand}`);
|
|
106
|
+
secureExec(builderCommand, installOptions);
|
|
107
|
+
|
|
108
|
+
const installerPath = path.join(appDir, 'installer');
|
|
109
|
+
if (fs.existsSync(installerPath)) {
|
|
110
|
+
logger.debug(`Setup created at: ${installerPath}`);
|
|
111
|
+
return installerPath;
|
|
112
|
+
} else {
|
|
113
|
+
logger.error(`Failed to find the built installer at: ${installerPath}`);
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
} catch (error) {
|
|
117
|
+
logger.error(`Error while building setup.`, error);
|
|
118
|
+
logger.warn('Try to run u2a with administrator privileges to avoid this error.');
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
module.exports = {
|
|
124
|
+
buildExecutable,
|
|
125
|
+
buildSetup
|
|
126
126
|
}
|
package/src/utils/logger.js
CHANGED
|
@@ -64,9 +64,13 @@ class Logger {
|
|
|
64
64
|
|
|
65
65
|
debug(message, msg2 = '') {
|
|
66
66
|
// i added msg2 cuz some parts of the code are using it, idk why
|
|
67
|
+
|
|
68
|
+
const { getSetting } = require('./settings');
|
|
69
|
+
const debugSetting = getSetting('always_show_debug');
|
|
70
|
+
|
|
67
71
|
const formattedMessage = this._format('DEBUG', `${message}${msg2 ? ' ' + msg2 : ''}`);
|
|
68
72
|
|
|
69
|
-
if (process.env.DEBUG) {
|
|
73
|
+
if (process.env.DEBUG || debugSetting) {
|
|
70
74
|
console.log(chalk.gray(formattedMessage));
|
|
71
75
|
}
|
|
72
76
|
this._writeToFile(formattedMessage);
|
package/src/utils/noroot.js
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
const os = require('os');
|
|
2
|
-
const isAdmin = require('is-admin');
|
|
3
|
-
const Logger = require('./logger')
|
|
4
|
-
|
|
5
|
-
const logger = new Logger('noroot');
|
|
6
|
-
|
|
7
|
-
async function checkNotRoot(allowRoot = false) {
|
|
8
|
-
if (allowRoot) {
|
|
9
|
-
logger.warn('Running with elevated privileges. This is not recommended.');
|
|
10
|
-
return;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const platform = os.platform();
|
|
14
|
-
|
|
15
|
-
switch (platform) {
|
|
16
|
-
case 'win32':
|
|
17
|
-
if (await isAdmin()) {
|
|
18
|
-
logger.error('This application should not be run as an administrator.');
|
|
19
|
-
logger.warn('Run with --allowroot to avoid this message.');
|
|
20
|
-
logger.warn('Running u2a as administrator can be dangerous.');
|
|
21
|
-
process.exit(1);
|
|
22
|
-
}
|
|
23
|
-
break;
|
|
24
|
-
|
|
25
|
-
case 'darwin':
|
|
26
|
-
case 'linux':
|
|
27
|
-
if (process.getuid() === 0) {
|
|
28
|
-
logger.error('This application should not be run as root.');
|
|
29
|
-
logger.warn('Run with --allowroot to avoid this message.');
|
|
30
|
-
logger.warn('Running u2a as root can be dangerous.');
|
|
31
|
-
process.exit(1);
|
|
32
|
-
}
|
|
33
|
-
break;
|
|
34
|
-
|
|
35
|
-
default:
|
|
36
|
-
logger.error('Unsupported platform:', platform);
|
|
37
|
-
process.exit(1);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
module.exports = { checkNotRoot };
|
|
1
|
+
const os = require('os');
|
|
2
|
+
const isAdmin = require('is-admin');
|
|
3
|
+
const Logger = require('./logger')
|
|
4
|
+
|
|
5
|
+
const logger = new Logger('noroot');
|
|
6
|
+
|
|
7
|
+
async function checkNotRoot(allowRoot = false) {
|
|
8
|
+
if (allowRoot) {
|
|
9
|
+
logger.warn('Running with elevated privileges. This is not recommended.');
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const platform = os.platform();
|
|
14
|
+
|
|
15
|
+
switch (platform) {
|
|
16
|
+
case 'win32':
|
|
17
|
+
if (await isAdmin()) {
|
|
18
|
+
logger.error('This application should not be run as an administrator.');
|
|
19
|
+
logger.warn('Run with --allowroot to avoid this message.');
|
|
20
|
+
logger.warn('Running u2a as administrator can be dangerous.');
|
|
21
|
+
process.exit(1);
|
|
22
|
+
}
|
|
23
|
+
break;
|
|
24
|
+
|
|
25
|
+
case 'darwin':
|
|
26
|
+
case 'linux':
|
|
27
|
+
if (process.getuid() === 0) {
|
|
28
|
+
logger.error('This application should not be run as root.');
|
|
29
|
+
logger.warn('Run with --allowroot to avoid this message.');
|
|
30
|
+
logger.warn('Running u2a as root can be dangerous.');
|
|
31
|
+
process.exit(1);
|
|
32
|
+
}
|
|
33
|
+
break;
|
|
34
|
+
|
|
35
|
+
default:
|
|
36
|
+
logger.error('Unsupported platform:', platform);
|
|
37
|
+
process.exit(1);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
module.exports = { checkNotRoot };
|