appium 2.0.0-beta.33 → 2.0.0-beta.37
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/build/lib/appium.d.ts +41 -52
- package/build/lib/appium.d.ts.map +1 -1
- package/build/lib/appium.js +32 -15
- package/build/lib/cli/args.d.ts +1 -1
- package/build/lib/cli/args.d.ts.map +1 -1
- package/build/lib/cli/args.js +1 -1
- package/build/lib/cli/driver-command.d.ts +5 -5
- package/build/lib/cli/driver-command.d.ts.map +1 -1
- package/build/lib/cli/driver-command.js +8 -8
- package/build/lib/cli/extension-command.d.ts +78 -51
- package/build/lib/cli/extension-command.d.ts.map +1 -1
- package/build/lib/cli/extension-command.js +135 -80
- package/build/lib/cli/extension.d.ts +9 -5
- package/build/lib/cli/extension.d.ts.map +1 -1
- package/build/lib/cli/extension.js +5 -7
- package/build/lib/cli/parser.d.ts +3 -3
- package/build/lib/cli/parser.d.ts.map +1 -1
- package/build/lib/cli/parser.js +1 -1
- package/build/lib/cli/plugin-command.d.ts +9 -15
- package/build/lib/cli/plugin-command.d.ts.map +1 -1
- package/build/lib/cli/plugin-command.js +8 -8
- package/build/lib/cli/utils.js +1 -1
- package/build/lib/config-file.d.ts.map +1 -1
- package/build/lib/config-file.js +1 -1
- package/build/lib/config.d.ts +4 -4
- package/build/lib/config.d.ts.map +1 -1
- package/build/lib/config.js +1 -1
- package/build/lib/constants.d.ts.map +1 -1
- package/build/lib/constants.js +1 -1
- package/build/lib/extension/driver-config.d.ts +29 -32
- package/build/lib/extension/driver-config.d.ts.map +1 -1
- package/build/lib/extension/driver-config.js +7 -20
- package/build/lib/extension/extension-config.d.ts +108 -36
- package/build/lib/extension/extension-config.d.ts.map +1 -1
- package/build/lib/extension/extension-config.js +199 -60
- package/build/lib/extension/index.d.ts +16 -7
- package/build/lib/extension/index.d.ts.map +1 -1
- package/build/lib/extension/index.js +15 -18
- package/build/lib/extension/manifest.d.ts +12 -12
- package/build/lib/extension/manifest.d.ts.map +1 -1
- package/build/lib/extension/manifest.js +13 -3
- package/build/lib/extension/package-changed.d.ts.map +1 -1
- package/build/lib/extension/package-changed.js +1 -1
- package/build/lib/extension/plugin-config.d.ts +19 -24
- package/build/lib/extension/plugin-config.d.ts.map +1 -1
- package/build/lib/extension/plugin-config.js +9 -18
- package/build/lib/grid-register.d.ts.map +1 -1
- package/build/lib/grid-register.js +1 -1
- package/build/lib/logger.d.ts +1 -1
- package/build/lib/logger.d.ts.map +1 -1
- package/build/lib/logger.js +1 -1
- package/build/lib/logsink.d.ts.map +1 -1
- package/build/lib/logsink.js +3 -2
- package/build/lib/main.d.ts +13 -12
- package/build/lib/main.d.ts.map +1 -1
- package/build/lib/main.js +4 -4
- package/build/lib/schema/arg-spec.d.ts +4 -4
- package/build/lib/schema/arg-spec.d.ts.map +1 -1
- package/build/lib/schema/arg-spec.js +1 -1
- package/build/lib/schema/cli-args.d.ts.map +1 -1
- package/build/lib/schema/cli-args.js +1 -1
- package/build/lib/schema/cli-transformers.d.ts.map +1 -1
- package/build/lib/schema/cli-transformers.js +1 -1
- package/build/lib/schema/index.js +1 -1
- package/build/lib/schema/keywords.d.ts.map +1 -1
- package/build/lib/schema/keywords.js +1 -1
- package/build/lib/schema/schema.d.ts +2 -2
- package/build/lib/schema/schema.d.ts.map +1 -1
- package/build/lib/schema/schema.js +1 -1
- package/build/lib/utils.d.ts.map +1 -1
- package/build/lib/utils.js +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/build/types/appium-manifest.d.ts +23 -4
- package/build/types/appium-manifest.d.ts.map +1 -1
- package/build/types/cli.d.ts.map +1 -1
- package/build/types/{external-manifest.d.ts → extension-manifest.d.ts} +15 -7
- package/build/types/extension-manifest.d.ts.map +1 -0
- package/build/types/index.d.ts +6 -5
- package/build/types/index.d.ts.map +1 -1
- package/driver.d.ts +1 -0
- package/driver.js +14 -0
- package/lib/appium.js +208 -124
- package/lib/cli/args.js +143 -93
- package/lib/cli/driver-command.js +46 -26
- package/lib/cli/extension-command.js +314 -157
- package/lib/cli/extension.js +15 -19
- package/lib/cli/parser.js +19 -31
- package/lib/cli/plugin-command.js +39 -24
- package/lib/cli/utils.js +8 -14
- package/lib/config-file.js +21 -25
- package/lib/config.js +82 -64
- package/lib/constants.js +4 -13
- package/lib/extension/driver-config.js +171 -171
- package/lib/extension/extension-config.js +347 -126
- package/lib/extension/index.js +72 -58
- package/lib/extension/manifest.js +48 -57
- package/lib/extension/package-changed.js +9 -8
- package/lib/extension/plugin-config.js +62 -62
- package/lib/grid-register.js +29 -18
- package/lib/logger.js +1 -2
- package/lib/logsink.js +29 -31
- package/lib/main.js +111 -73
- package/lib/schema/arg-spec.js +10 -13
- package/lib/schema/cli-args.js +14 -37
- package/lib/schema/cli-transformers.js +7 -14
- package/lib/schema/keywords.js +15 -13
- package/lib/schema/schema.js +58 -75
- package/lib/utils.js +50 -25
- package/package.json +27 -20
- package/plugin.d.ts +1 -0
- package/plugin.js +13 -0
- package/scripts/autoinstall-extensions.js +177 -0
- package/support.d.ts +1 -0
- package/support.js +13 -0
- package/types/appium-manifest.ts +27 -15
- package/types/cli.ts +2 -9
- package/types/{external-manifest.ts → extension-manifest.ts} +21 -15
- package/types/index.ts +12 -5
- package/build/types/extension.d.ts +0 -43
- package/build/types/extension.d.ts.map +0 -1
- package/build/types/external-manifest.d.ts.map +0 -1
- package/lib/appium-config.schema.json +0 -278
- package/scripts/postinstall.js +0 -71
- package/types/extension.ts +0 -56
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
import _ from 'lodash';
|
|
3
2
|
import {ExtensionConfig} from './extension-config';
|
|
4
3
|
import log from '../logger';
|
|
@@ -8,7 +7,6 @@ import {PLUGIN_TYPE} from '../constants';
|
|
|
8
7
|
* @extends {ExtensionConfig<PluginType>}
|
|
9
8
|
*/
|
|
10
9
|
export class PluginConfig extends ExtensionConfig {
|
|
11
|
-
|
|
12
10
|
/**
|
|
13
11
|
* A mapping of {@link Manifest} instances to {@link PluginConfig} instances.
|
|
14
12
|
*
|
|
@@ -19,95 +17,97 @@ export class PluginConfig extends ExtensionConfig {
|
|
|
19
17
|
* @type {WeakMap<Manifest,PluginConfig>}
|
|
20
18
|
* @private
|
|
21
19
|
*/
|
|
22
|
-
|
|
20
|
+
static _instances = new WeakMap();
|
|
23
21
|
|
|
24
|
-
|
|
22
|
+
/**
|
|
25
23
|
* Call {@link PluginConfig.create} instead.
|
|
26
24
|
*
|
|
27
25
|
* Just calls the superclass' constructor with the correct extension type
|
|
28
26
|
* @private
|
|
29
27
|
* @param {Manifest} manifest - IO object
|
|
30
|
-
* @param {PluginConfigOptions} [opts]
|
|
31
28
|
*/
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
constructor(manifest) {
|
|
30
|
+
super(PLUGIN_TYPE, manifest);
|
|
31
|
+
}
|
|
34
32
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
33
|
+
async validate() {
|
|
34
|
+
return await super._validate(this.manifest.getExtensionData(PLUGIN_TYPE));
|
|
35
|
+
}
|
|
39
36
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
37
|
+
/**
|
|
38
|
+
* Creates a new {@link PluginConfig} instance for a {@link Manifest} instance.
|
|
39
|
+
*
|
|
40
|
+
* @param {Manifest} manifest
|
|
41
|
+
* @throws If `manifest` already associated with a `PluginConfig`
|
|
42
|
+
* @returns {PluginConfig}
|
|
43
|
+
*/
|
|
44
|
+
static create(manifest) {
|
|
45
|
+
const instance = new PluginConfig(manifest);
|
|
46
|
+
if (PluginConfig.getInstance(manifest)) {
|
|
47
|
+
throw new Error(
|
|
48
|
+
`Manifest with APPIUM_HOME ${manifest.appiumHome} already has a PluginConfig; use PluginConfig.getInstance() to retrieve it.`
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
PluginConfig._instances.set(manifest, instance);
|
|
52
|
+
return instance;
|
|
53
|
+
}
|
|
56
54
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
55
|
+
/**
|
|
56
|
+
* Returns a PluginConfig associated with a Manifest
|
|
57
|
+
* @param {Manifest} manifest
|
|
58
|
+
* @returns {PluginConfig|undefined}
|
|
59
|
+
*/
|
|
60
|
+
static getInstance(manifest) {
|
|
61
|
+
return PluginConfig._instances.get(manifest);
|
|
62
|
+
}
|
|
65
63
|
|
|
66
|
-
|
|
64
|
+
/**
|
|
67
65
|
* @param {string} pluginName
|
|
68
|
-
* @param {import('
|
|
66
|
+
* @param {import('appium/types').ExtManifest<PluginType>} pluginData
|
|
69
67
|
* @returns {string}
|
|
70
68
|
*/
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
69
|
+
extensionDesc(pluginName, {version}) {
|
|
70
|
+
return `${pluginName}@${version}`;
|
|
71
|
+
}
|
|
74
72
|
|
|
75
|
-
|
|
73
|
+
/**
|
|
76
74
|
*
|
|
77
75
|
* @param {(keyof PluginRecord)[]} activeNames
|
|
78
76
|
* @returns {void}
|
|
79
77
|
*/
|
|
80
|
-
|
|
81
|
-
|
|
78
|
+
print(activeNames) {
|
|
79
|
+
const pluginNames = Object.keys(this.installedExtensions);
|
|
82
80
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
81
|
+
if (_.isEmpty(pluginNames)) {
|
|
82
|
+
log.info(
|
|
83
|
+
`No plugins have been installed. Use the "appium plugin" ` +
|
|
84
|
+
'command to install the one(s) you want to use.'
|
|
85
|
+
);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
88
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
89
|
+
log.info(`Available plugins:`);
|
|
90
|
+
for (const [pluginName, pluginData] of _.toPairs(this.installedExtensions)) {
|
|
91
|
+
const activeTxt = _.includes(activeNames, pluginName) ? ' (ACTIVE)' : '';
|
|
92
|
+
log.info(` - ${this.extensionDesc(pluginName, pluginData)}${activeTxt}`);
|
|
93
|
+
}
|
|
94
94
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
95
|
+
if (_.isEmpty(activeNames)) {
|
|
96
|
+
log.info(
|
|
97
|
+
'No plugins activated. Use the --use-plugins flag with names of plugins to activate'
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
99
101
|
}
|
|
100
102
|
|
|
101
103
|
/**
|
|
102
104
|
* @typedef PluginConfigOptions
|
|
103
105
|
* @property {import('./extension-config').ExtensionLogFn} [logFn] - Optional logging function
|
|
104
|
-
* @property {import('../../types/appium-manifest').PluginRecord} [extData] - Extension data
|
|
105
106
|
*/
|
|
106
107
|
|
|
107
|
-
|
|
108
108
|
/**
|
|
109
|
-
* @typedef {import('
|
|
110
|
-
* @typedef {import('
|
|
111
|
-
* @typedef {import('
|
|
109
|
+
* @typedef {import('appium/types').PluginRecord} PluginRecord
|
|
110
|
+
* @typedef {import('@appium/types').PluginType} PluginType
|
|
111
|
+
* @typedef {import('appium/types').ExtMetadata<PluginType>} PluginMetadata
|
|
112
112
|
* @typedef {import('./manifest').Manifest} Manifest
|
|
113
113
|
*/
|
package/lib/grid-register.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
|
-
import {
|
|
2
|
+
import {fs} from '@appium/support';
|
|
3
3
|
import logger from './logger';
|
|
4
4
|
import _ from 'lodash';
|
|
5
5
|
|
|
6
|
-
|
|
7
6
|
const hubUri = (config) => {
|
|
8
7
|
const protocol = config.hubProtocol || 'http';
|
|
9
8
|
return `${protocol}://${config.hubHost}:${config.hubPort}`;
|
|
@@ -16,20 +15,24 @@ const hubUri = (config) => {
|
|
|
16
15
|
* @param {number} [port] - Bind to this port
|
|
17
16
|
* @param {string} [basePath] - Base path for the grid
|
|
18
17
|
*/
|
|
19
|
-
async function registerNode
|
|
18
|
+
async function registerNode(data, addr, port, basePath) {
|
|
20
19
|
let configFilePath;
|
|
21
20
|
if (_.isString(data)) {
|
|
22
21
|
configFilePath = data;
|
|
23
22
|
try {
|
|
24
23
|
data = await fs.readFile(data, 'utf-8');
|
|
25
24
|
} catch (err) {
|
|
26
|
-
logger.error(
|
|
25
|
+
logger.error(
|
|
26
|
+
`Unable to load node configuration file ${configFilePath} to register with grid: ${err.message}`
|
|
27
|
+
);
|
|
27
28
|
return;
|
|
28
29
|
}
|
|
29
30
|
try {
|
|
30
31
|
data = JSON.parse(data);
|
|
31
32
|
} catch (err) {
|
|
32
|
-
logger.errorAndThrow(
|
|
33
|
+
logger.errorAndThrow(
|
|
34
|
+
`Syntax error in node configuration file ${configFilePath}: ${err.message}`
|
|
35
|
+
);
|
|
33
36
|
return;
|
|
34
37
|
}
|
|
35
38
|
}
|
|
@@ -37,20 +40,21 @@ async function registerNode (data, addr, port, basePath) {
|
|
|
37
40
|
postRequest(data, addr, port, basePath);
|
|
38
41
|
}
|
|
39
42
|
|
|
40
|
-
async function registerToGrid
|
|
43
|
+
async function registerToGrid(postOptions, configHolder) {
|
|
41
44
|
try {
|
|
42
45
|
const {status} = await axios(postOptions);
|
|
43
46
|
if (status !== 200) {
|
|
44
47
|
throw new Error(`Request failed with code ${status}`);
|
|
45
48
|
}
|
|
46
|
-
logger.debug(
|
|
47
|
-
hubUri(configHolder.configuration)
|
|
49
|
+
logger.debug(
|
|
50
|
+
`Appium successfully registered with the the grid on ` + hubUri(configHolder.configuration)
|
|
51
|
+
);
|
|
48
52
|
} catch (err) {
|
|
49
53
|
logger.error(`An attempt to register with the grid was unsuccessful: ${err.message}`);
|
|
50
54
|
}
|
|
51
55
|
}
|
|
52
56
|
|
|
53
|
-
function postRequest
|
|
57
|
+
function postRequest(configHolder, addr, port, basePath) {
|
|
54
58
|
// Move Selenium 3 configuration properties to configuration object
|
|
55
59
|
if (!_.has(configHolder, 'configuration')) {
|
|
56
60
|
let configuration = {};
|
|
@@ -68,7 +72,11 @@ function postRequest (configHolder, addr, port, basePath) {
|
|
|
68
72
|
// otherwise, we will take whatever the user setup
|
|
69
73
|
// because we will always set localhost/127.0.0.1. this won't work if your
|
|
70
74
|
// node and grid aren't in the same place
|
|
71
|
-
if (
|
|
75
|
+
if (
|
|
76
|
+
!configHolder.configuration.url ||
|
|
77
|
+
!configHolder.configuration.host ||
|
|
78
|
+
!configHolder.configuration.port
|
|
79
|
+
) {
|
|
72
80
|
configHolder.configuration.url = `http://${addr}:${port}${basePath}`;
|
|
73
81
|
configHolder.configuration.host = addr;
|
|
74
82
|
configHolder.configuration.port = port;
|
|
@@ -92,26 +100,30 @@ function postRequest (configHolder, addr, port, basePath) {
|
|
|
92
100
|
|
|
93
101
|
const registerCycleInterval = configHolder.configuration.registerCycle;
|
|
94
102
|
if (isNaN(registerCycleInterval) || registerCycleInterval <= 0) {
|
|
95
|
-
logger.warn(
|
|
96
|
-
`
|
|
103
|
+
logger.warn(
|
|
104
|
+
`'registerCycle' is not a valid positive number. ` +
|
|
105
|
+
`No registration request will be sent to the grid.`
|
|
106
|
+
);
|
|
97
107
|
return;
|
|
98
108
|
}
|
|
99
109
|
// initiate a new Thread
|
|
100
110
|
let first = true;
|
|
101
|
-
logger.debug(
|
|
102
|
-
`
|
|
103
|
-
|
|
111
|
+
logger.debug(
|
|
112
|
+
`Starting auto register thread for the grid. ` +
|
|
113
|
+
`Will try to register every ${registerCycleInterval} ms.`
|
|
114
|
+
);
|
|
115
|
+
setInterval(async function registerRetry() {
|
|
104
116
|
if (first) {
|
|
105
117
|
first = false;
|
|
106
118
|
await registerToGrid(regRequest, configHolder);
|
|
107
|
-
} else if (!await isAlreadyRegistered(configHolder)) {
|
|
119
|
+
} else if (!(await isAlreadyRegistered(configHolder))) {
|
|
108
120
|
// make the http POST to the grid for registration
|
|
109
121
|
await registerToGrid(regRequest, configHolder);
|
|
110
122
|
}
|
|
111
123
|
}, registerCycleInterval);
|
|
112
124
|
}
|
|
113
125
|
|
|
114
|
-
async function isAlreadyRegistered
|
|
126
|
+
async function isAlreadyRegistered(configHolder) {
|
|
115
127
|
//check if node is already registered
|
|
116
128
|
const id = configHolder.configuration.id;
|
|
117
129
|
try {
|
|
@@ -132,5 +144,4 @@ async function isAlreadyRegistered (configHolder) {
|
|
|
132
144
|
}
|
|
133
145
|
}
|
|
134
146
|
|
|
135
|
-
|
|
136
147
|
export default registerNode;
|
package/lib/logger.js
CHANGED
package/lib/logsink.js
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import npmlog from 'npmlog';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import {createLogger, format, transports} from 'winston';
|
|
3
|
+
import {fs, logger} from '@appium/support';
|
|
4
4
|
import _ from 'lodash';
|
|
5
5
|
|
|
6
|
-
|
|
7
6
|
// set up distributed logging before everything else
|
|
8
7
|
logger.patchLogger(npmlog);
|
|
9
8
|
global._global_npmlog = npmlog;
|
|
10
9
|
|
|
11
10
|
// npmlog is used only for emitting, we use winston for output
|
|
12
|
-
npmlog.level = '
|
|
11
|
+
npmlog.level = 'info';
|
|
13
12
|
const levels = {
|
|
14
13
|
debug: 4,
|
|
15
14
|
info: 3,
|
|
@@ -39,16 +38,13 @@ let useLocalTimeZone = false;
|
|
|
39
38
|
|
|
40
39
|
// add the timestamp in the correct format to the log info object
|
|
41
40
|
const timestampFormat = format.timestamp({
|
|
42
|
-
format
|
|
41
|
+
format() {
|
|
43
42
|
let date = new Date();
|
|
44
43
|
if (useLocalTimeZone) {
|
|
45
44
|
date = new Date(date.valueOf() - date.getTimezoneOffset() * 60000);
|
|
46
45
|
}
|
|
47
46
|
// '2012-11-04T14:51:06.157Z' -> '2012-11-04 14:51:06:157'
|
|
48
|
-
return date.toISOString()
|
|
49
|
-
.replace(/[TZ]/g, ' ')
|
|
50
|
-
.replace(/\./g, ':')
|
|
51
|
-
.trim();
|
|
47
|
+
return date.toISOString().replace(/[TZ]/g, ' ').replace(/\./g, ':').trim();
|
|
52
48
|
},
|
|
53
49
|
});
|
|
54
50
|
|
|
@@ -58,14 +54,14 @@ const colorizeFormat = format.colorize({
|
|
|
58
54
|
});
|
|
59
55
|
|
|
60
56
|
// Strip the color marking within messages
|
|
61
|
-
const stripColorFormat = format(function stripColor
|
|
57
|
+
const stripColorFormat = format(function stripColor(info) {
|
|
62
58
|
const code = /\u001b\[(\d+(;\d+)*)?m/g; // eslint-disable-line no-control-regex
|
|
63
59
|
info.message = info.message.replace(code, '');
|
|
64
60
|
return info;
|
|
65
61
|
})();
|
|
66
62
|
|
|
67
|
-
function createConsoleTransport
|
|
68
|
-
return new
|
|
63
|
+
function createConsoleTransport(args, logLvl) {
|
|
64
|
+
return new transports.Console({
|
|
69
65
|
// `name` is unsupported per winston's type declarations
|
|
70
66
|
// @ts-expect-error
|
|
71
67
|
name: 'console',
|
|
@@ -75,7 +71,7 @@ function createConsoleTransport (args, logLvl) {
|
|
|
75
71
|
level: logLvl,
|
|
76
72
|
stderrLevels: ['error'],
|
|
77
73
|
format: format.combine(
|
|
78
|
-
format(function adjustDebug
|
|
74
|
+
format(function adjustDebug(info) {
|
|
79
75
|
// prepend debug marker, and shift to `info` log level
|
|
80
76
|
if (info.level === 'debug') {
|
|
81
77
|
info.level = 'info';
|
|
@@ -85,15 +81,15 @@ function createConsoleTransport (args, logLvl) {
|
|
|
85
81
|
})(),
|
|
86
82
|
timestampFormat,
|
|
87
83
|
args.logNoColors ? stripColorFormat : colorizeFormat,
|
|
88
|
-
format.printf(function printInfo
|
|
84
|
+
format.printf(function printInfo(info) {
|
|
89
85
|
return `${args.logTimestamp ? `${info.timestamp} - ` : ''}${info.message}`;
|
|
90
86
|
})
|
|
91
87
|
),
|
|
92
88
|
});
|
|
93
89
|
}
|
|
94
90
|
|
|
95
|
-
function createFileTransport
|
|
96
|
-
return new
|
|
91
|
+
function createFileTransport(args, logLvl) {
|
|
92
|
+
return new transports.File({
|
|
97
93
|
// @ts-expect-error
|
|
98
94
|
name: 'file',
|
|
99
95
|
filename: args.logFile,
|
|
@@ -105,14 +101,14 @@ function createFileTransport (args, logLvl) {
|
|
|
105
101
|
format: format.combine(
|
|
106
102
|
stripColorFormat,
|
|
107
103
|
timestampFormat,
|
|
108
|
-
format.printf(function printInfo
|
|
104
|
+
format.printf(function printInfo(info) {
|
|
109
105
|
return `${info.timestamp} ${info.message}`;
|
|
110
106
|
})
|
|
111
|
-
)
|
|
107
|
+
),
|
|
112
108
|
});
|
|
113
109
|
}
|
|
114
110
|
|
|
115
|
-
function createHttpTransport
|
|
111
|
+
function createHttpTransport(args, logLvl) {
|
|
116
112
|
let host = '127.0.0.1';
|
|
117
113
|
let port = 9003;
|
|
118
114
|
|
|
@@ -122,7 +118,7 @@ function createHttpTransport (args, logLvl) {
|
|
|
122
118
|
port = parseInt(hostAndPort[1], 10);
|
|
123
119
|
}
|
|
124
120
|
|
|
125
|
-
return new
|
|
121
|
+
return new transports.Http({
|
|
126
122
|
// @ts-expect-error
|
|
127
123
|
name: 'http',
|
|
128
124
|
host,
|
|
@@ -134,14 +130,14 @@ function createHttpTransport (args, logLvl) {
|
|
|
134
130
|
level: logLvl,
|
|
135
131
|
format: format.combine(
|
|
136
132
|
stripColorFormat,
|
|
137
|
-
format.printf(function printInfo
|
|
133
|
+
format.printf(function printInfo(info) {
|
|
138
134
|
return `${info.timestamp} ${info.message}`;
|
|
139
135
|
})
|
|
140
136
|
),
|
|
141
137
|
});
|
|
142
138
|
}
|
|
143
139
|
|
|
144
|
-
async function createTransports
|
|
140
|
+
async function createTransports(args) {
|
|
145
141
|
let transports = [];
|
|
146
142
|
let consoleLogLevel = null;
|
|
147
143
|
let fileLogLevel = null;
|
|
@@ -169,8 +165,9 @@ async function createTransports (args) {
|
|
|
169
165
|
transports.push(createFileTransport(args, fileLogLevel));
|
|
170
166
|
} catch (e) {
|
|
171
167
|
// eslint-disable-next-line no-console
|
|
172
|
-
console.log(
|
|
173
|
-
|
|
168
|
+
console.log(
|
|
169
|
+
`Tried to attach logging to file '${args.logFile}' but an error ` + `occurred: ${e.message}`
|
|
170
|
+
);
|
|
174
171
|
}
|
|
175
172
|
}
|
|
176
173
|
|
|
@@ -179,15 +176,18 @@ async function createTransports (args) {
|
|
|
179
176
|
transports.push(createHttpTransport(args, fileLogLevel));
|
|
180
177
|
} catch (e) {
|
|
181
178
|
// eslint-disable-next-line no-console
|
|
182
|
-
console.log(
|
|
183
|
-
|
|
179
|
+
console.log(
|
|
180
|
+
`Tried to attach logging to Http at ${args.webhook} but ` +
|
|
181
|
+
`an error occurred: ${e.message}`
|
|
182
|
+
);
|
|
184
183
|
}
|
|
185
184
|
}
|
|
186
185
|
|
|
187
186
|
return transports;
|
|
188
187
|
}
|
|
189
188
|
|
|
190
|
-
async function init
|
|
189
|
+
async function init(args) {
|
|
190
|
+
npmlog.level = 'silent';
|
|
191
191
|
// set de facto param passed to timestamp function
|
|
192
192
|
useLocalTimeZone = args.localTimezone;
|
|
193
193
|
|
|
@@ -211,11 +211,10 @@ async function init (args) {
|
|
|
211
211
|
if (args.logHandler && _.isFunction(args.logHandler)) {
|
|
212
212
|
args.logHandler(logObj.level, msg);
|
|
213
213
|
}
|
|
214
|
-
|
|
215
214
|
});
|
|
216
215
|
}
|
|
217
216
|
|
|
218
|
-
function clear
|
|
217
|
+
function clear() {
|
|
219
218
|
if (log) {
|
|
220
219
|
for (let transport of _.keys(log.transports)) {
|
|
221
220
|
log.remove(transport);
|
|
@@ -224,6 +223,5 @@ function clear () {
|
|
|
224
223
|
npmlog.removeAllListeners('log');
|
|
225
224
|
}
|
|
226
225
|
|
|
227
|
-
|
|
228
|
-
export { init, clear };
|
|
226
|
+
export {init, clear};
|
|
229
227
|
export default init;
|