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