appium 2.0.0-beta.7 → 2.0.0-beta.70
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/LICENSE +1 -1
- package/README.md +149 -58
- package/build/lib/appium.d.ts +229 -0
- package/build/lib/appium.d.ts.map +1 -0
- package/build/lib/appium.js +678 -439
- package/build/lib/appium.js.map +1 -0
- 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 +263 -300
- package/build/lib/cli/args.js.map +1 -0
- package/build/lib/cli/driver-command.d.ts +102 -0
- package/build/lib/cli/driver-command.d.ts.map +1 -0
- package/build/lib/cli/driver-command.js +131 -81
- package/build/lib/cli/driver-command.js.map +1 -0
- package/build/lib/cli/extension-command.d.ts +402 -0
- package/build/lib/cli/extension-command.d.ts.map +1 -0
- package/build/lib/cli/extension-command.js +799 -383
- package/build/lib/cli/extension-command.js.map +1 -0
- package/build/lib/cli/extension.d.ts +23 -0
- package/build/lib/cli/extension.d.ts.map +1 -0
- package/build/lib/cli/extension.js +71 -60
- package/build/lib/cli/extension.js.map +1 -0
- 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 +252 -148
- package/build/lib/cli/parser.js.map +1 -0
- package/build/lib/cli/plugin-command.d.ts +99 -0
- package/build/lib/cli/plugin-command.d.ts.map +1 -0
- package/build/lib/cli/plugin-command.js +125 -81
- package/build/lib/cli/plugin-command.js.map +1 -0
- 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 +72 -51
- package/build/lib/cli/utils.js.map +1 -0
- 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 +207 -0
- package/build/lib/config-file.js.map +1 -0
- package/build/lib/config.d.ts +49 -0
- package/build/lib/config.d.ts.map +1 -0
- package/build/lib/config.js +262 -223
- package/build/lib/config.js.map +1 -0
- package/build/lib/constants.d.ts +56 -0
- package/build/lib/constants.d.ts.map +1 -0
- package/build/lib/constants.js +73 -0
- package/build/lib/constants.js.map +1 -0
- package/build/lib/extension/driver-config.d.ts +82 -0
- package/build/lib/extension/driver-config.d.ts.map +1 -0
- package/build/lib/extension/driver-config.js +210 -0
- package/build/lib/extension/driver-config.js.map +1 -0
- package/build/lib/extension/extension-config.d.ts +270 -0
- package/build/lib/extension/extension-config.d.ts.map +1 -0
- package/build/lib/extension/extension-config.js +601 -0
- package/build/lib/extension/extension-config.js.map +1 -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 +105 -0
- package/build/lib/extension/index.js.map +1 -0
- package/build/lib/extension/manifest-migrations.d.ts +27 -0
- package/build/lib/extension/manifest-migrations.d.ts.map +1 -0
- package/build/lib/extension/manifest-migrations.js +134 -0
- package/build/lib/extension/manifest-migrations.js.map +1 -0
- package/build/lib/extension/manifest.d.ts +145 -0
- package/build/lib/extension/manifest.d.ts.map +1 -0
- package/build/lib/extension/manifest.js +528 -0
- package/build/lib/extension/manifest.js.map +1 -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 +62 -0
- package/build/lib/extension/package-changed.js.map +1 -0
- package/build/lib/extension/plugin-config.d.ts +56 -0
- package/build/lib/extension/plugin-config.d.ts.map +1 -0
- package/build/lib/extension/plugin-config.js +102 -0
- package/build/lib/extension/plugin-config.js.map +1 -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 +122 -144
- package/build/lib/grid-register.js.map +1 -0
- package/build/lib/logger.d.ts +3 -0
- package/build/lib/logger.d.ts.map +1 -0
- package/build/lib/logger.js +5 -17
- package/build/lib/logger.js.map +1 -0
- package/build/lib/logsink.d.ts +4 -0
- package/build/lib/logsink.d.ts.map +1 -0
- package/build/lib/logsink.js +189 -184
- package/build/lib/logsink.js.map +1 -0
- package/build/lib/main.d.ts +62 -0
- package/build/lib/main.d.ts.map +1 -0
- package/build/lib/main.js +388 -234
- package/build/lib/main.js.map +1 -0
- 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 +164 -0
- package/build/lib/schema/arg-spec.js.map +1 -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 +220 -0
- package/build/lib/schema/cli-args.js.map +1 -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 +124 -0
- package/build/lib/schema/cli-transformers.js.map +1 -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 +19 -0
- package/build/lib/schema/index.js.map +1 -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 +128 -0
- package/build/lib/schema/keywords.js.map +1 -0
- package/build/lib/schema/schema.d.ts +260 -0
- package/build/lib/schema/schema.d.ts.map +1 -0
- package/build/lib/schema/schema.js +640 -0
- package/build/lib/schema/schema.js.map +1 -0
- package/build/lib/utils.d.ts +266 -0
- package/build/lib/utils.d.ts.map +1 -0
- package/build/lib/utils.js +349 -273
- package/build/lib/utils.js.map +1 -0
- package/build/types/cli.d.ts +134 -0
- package/build/types/cli.d.ts.map +1 -0
- package/build/types/cli.js +3 -0
- package/build/types/cli.js.map +1 -0
- package/build/types/index.d.ts +15 -0
- package/build/types/index.d.ts.map +1 -0
- package/build/types/index.js +19 -0
- package/build/types/index.js.map +1 -0
- package/build/types/manifest/base.d.ts +135 -0
- package/build/types/manifest/base.d.ts.map +1 -0
- package/build/types/manifest/base.js +3 -0
- package/build/types/manifest/base.js.map +1 -0
- package/build/types/manifest/index.d.ts +21 -0
- package/build/types/manifest/index.d.ts.map +1 -0
- package/build/types/manifest/index.js +42 -0
- package/build/types/manifest/index.js.map +1 -0
- package/build/types/manifest/v3.d.ts +139 -0
- package/build/types/manifest/v3.d.ts.map +1 -0
- package/build/types/manifest/v3.js +3 -0
- package/build/types/manifest/v3.js.map +1 -0
- package/build/types/manifest/v4.d.ts +139 -0
- package/build/types/manifest/v4.d.ts.map +1 -0
- package/build/types/manifest/v4.js +3 -0
- package/build/types/manifest/v4.js.map +1 -0
- package/driver.d.ts +1 -0
- package/driver.js +14 -0
- package/index.js +11 -0
- package/lib/appium.js +558 -186
- package/lib/cli/args.js +275 -407
- package/lib/cli/driver-command.js +132 -24
- package/lib/cli/extension-command.js +751 -272
- package/lib/cli/extension.js +47 -20
- package/lib/cli/parser.js +267 -95
- package/lib/cli/plugin-command.js +122 -22
- package/lib/cli/utils.js +24 -10
- package/lib/config-file.js +220 -0
- package/lib/config.js +243 -132
- package/lib/constants.js +79 -0
- package/lib/extension/driver-config.js +247 -0
- package/lib/extension/extension-config.js +709 -0
- package/lib/extension/index.js +116 -0
- package/lib/extension/manifest-migrations.js +136 -0
- package/lib/extension/manifest.js +580 -0
- package/lib/extension/package-changed.js +64 -0
- package/lib/extension/plugin-config.js +112 -0
- package/lib/grid-register.js +49 -35
- package/lib/logger.js +1 -2
- package/lib/logsink.js +59 -36
- package/lib/main.js +369 -104
- package/lib/schema/arg-spec.js +229 -0
- package/lib/schema/cli-args.js +241 -0
- package/lib/schema/cli-transformers.js +119 -0
- package/lib/schema/index.js +2 -0
- package/lib/schema/keywords.js +136 -0
- package/lib/schema/schema.js +725 -0
- package/lib/utils.js +289 -167
- package/package.json +84 -83
- package/plugin.d.ts +1 -0
- package/plugin.js +13 -0
- package/scripts/autoinstall-extensions.js +243 -0
- package/support.d.ts +1 -0
- package/support.js +13 -0
- package/tsconfig.json +25 -0
- package/types/cli.ts +193 -0
- package/types/index.ts +20 -0
- package/types/manifest/README.md +30 -0
- package/types/manifest/base.ts +158 -0
- package/types/manifest/index.ts +28 -0
- package/types/manifest/v3.ts +161 -0
- package/types/manifest/v4.ts +161 -0
- package/CHANGELOG.md +0 -3594
- package/bin/ios-webkit-debug-proxy-launcher.js +0 -71
- package/build/lib/cli/argparse-actions.js +0 -104
- package/build/lib/cli/npm.js +0 -200
- package/build/lib/cli/parser-helpers.js +0 -93
- package/build/lib/driver-config.js +0 -77
- package/build/lib/drivers.js +0 -99
- 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/argparse-actions.js +0 -77
- package/lib/cli/npm.js +0 -175
- package/lib/cli/parser-helpers.js +0 -91
- package/lib/driver-config.js +0 -46
- package/lib/drivers.js +0 -84
- package/lib/extension-config.js +0 -209
- package/lib/plugin-config.js +0 -34
- package/lib/plugins.js +0 -10
|
@@ -0,0 +1,112 @@
|
|
|
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 import('appium/types').ExtRecord<PluginType>)[]} 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').PluginType} PluginType
|
|
110
|
+
* @typedef {import('appium/types').ExtMetadata<PluginType>} PluginMetadata
|
|
111
|
+
* @typedef {import('./manifest').Manifest} Manifest
|
|
112
|
+
*/
|
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,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,
|
|
@@ -34,21 +33,20 @@ const npmToWinstonLevels = {
|
|
|
34
33
|
error: 'error',
|
|
35
34
|
};
|
|
36
35
|
|
|
36
|
+
const encounteredPrefixes = [];
|
|
37
|
+
|
|
37
38
|
let log = null;
|
|
38
39
|
let useLocalTimeZone = false;
|
|
39
40
|
|
|
40
41
|
// add the timestamp in the correct format to the log info object
|
|
41
42
|
const timestampFormat = format.timestamp({
|
|
42
|
-
format
|
|
43
|
+
format() {
|
|
43
44
|
let date = new Date();
|
|
44
45
|
if (useLocalTimeZone) {
|
|
45
46
|
date = new Date(date.valueOf() - date.getTimezoneOffset() * 60000);
|
|
46
47
|
}
|
|
47
48
|
// '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();
|
|
49
|
+
return date.toISOString().replace(/[TZ]/g, ' ').replace(/\./g, ':').trim();
|
|
52
50
|
},
|
|
53
51
|
});
|
|
54
52
|
|
|
@@ -58,14 +56,16 @@ const colorizeFormat = format.colorize({
|
|
|
58
56
|
});
|
|
59
57
|
|
|
60
58
|
// Strip the color marking within messages
|
|
61
|
-
const stripColorFormat = format(function stripColor
|
|
59
|
+
const stripColorFormat = format(function stripColor(info) {
|
|
62
60
|
const code = /\u001b\[(\d+(;\d+)*)?m/g; // eslint-disable-line no-control-regex
|
|
63
61
|
info.message = info.message.replace(code, '');
|
|
64
62
|
return info;
|
|
65
63
|
})();
|
|
66
64
|
|
|
67
|
-
function createConsoleTransport
|
|
68
|
-
return new
|
|
65
|
+
function createConsoleTransport(args, logLvl) {
|
|
66
|
+
return new transports.Console({
|
|
67
|
+
// `name` is unsupported per winston's type declarations
|
|
68
|
+
// @ts-expect-error
|
|
69
69
|
name: 'console',
|
|
70
70
|
handleExceptions: true,
|
|
71
71
|
exitOnError: false,
|
|
@@ -73,7 +73,7 @@ function createConsoleTransport (args, logLvl) {
|
|
|
73
73
|
level: logLvl,
|
|
74
74
|
stderrLevels: ['error'],
|
|
75
75
|
format: format.combine(
|
|
76
|
-
format(function adjustDebug
|
|
76
|
+
format(function adjustDebug(info) {
|
|
77
77
|
// prepend debug marker, and shift to `info` log level
|
|
78
78
|
if (info.level === 'debug') {
|
|
79
79
|
info.level = 'info';
|
|
@@ -83,15 +83,16 @@ function createConsoleTransport (args, logLvl) {
|
|
|
83
83
|
})(),
|
|
84
84
|
timestampFormat,
|
|
85
85
|
args.logNoColors ? stripColorFormat : colorizeFormat,
|
|
86
|
-
format.printf(function printInfo
|
|
86
|
+
format.printf(function printInfo(info) {
|
|
87
87
|
return `${args.logTimestamp ? `${info.timestamp} - ` : ''}${info.message}`;
|
|
88
88
|
})
|
|
89
89
|
),
|
|
90
90
|
});
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
function createFileTransport
|
|
94
|
-
return new
|
|
93
|
+
function createFileTransport(args, logLvl) {
|
|
94
|
+
return new transports.File({
|
|
95
|
+
// @ts-expect-error
|
|
95
96
|
name: 'file',
|
|
96
97
|
filename: args.logFile,
|
|
97
98
|
maxFiles: 1,
|
|
@@ -102,14 +103,14 @@ function createFileTransport (args, logLvl) {
|
|
|
102
103
|
format: format.combine(
|
|
103
104
|
stripColorFormat,
|
|
104
105
|
timestampFormat,
|
|
105
|
-
format.printf(function printInfo
|
|
106
|
+
format.printf(function printInfo(info) {
|
|
106
107
|
return `${info.timestamp} ${info.message}`;
|
|
107
108
|
})
|
|
108
|
-
)
|
|
109
|
+
),
|
|
109
110
|
});
|
|
110
111
|
}
|
|
111
112
|
|
|
112
|
-
function createHttpTransport
|
|
113
|
+
function createHttpTransport(args, logLvl) {
|
|
113
114
|
let host = '127.0.0.1';
|
|
114
115
|
let port = 9003;
|
|
115
116
|
|
|
@@ -119,7 +120,8 @@ function createHttpTransport (args, logLvl) {
|
|
|
119
120
|
port = parseInt(hostAndPort[1], 10);
|
|
120
121
|
}
|
|
121
122
|
|
|
122
|
-
return new
|
|
123
|
+
return new transports.Http({
|
|
124
|
+
// @ts-expect-error
|
|
123
125
|
name: 'http',
|
|
124
126
|
host,
|
|
125
127
|
port,
|
|
@@ -130,14 +132,14 @@ function createHttpTransport (args, logLvl) {
|
|
|
130
132
|
level: logLvl,
|
|
131
133
|
format: format.combine(
|
|
132
134
|
stripColorFormat,
|
|
133
|
-
format.printf(function printInfo
|
|
135
|
+
format.printf(function printInfo(info) {
|
|
134
136
|
return `${info.timestamp} ${info.message}`;
|
|
135
137
|
})
|
|
136
138
|
),
|
|
137
139
|
});
|
|
138
140
|
}
|
|
139
141
|
|
|
140
|
-
async function createTransports
|
|
142
|
+
async function createTransports(args) {
|
|
141
143
|
let transports = [];
|
|
142
144
|
let consoleLogLevel = null;
|
|
143
145
|
let fileLogLevel = null;
|
|
@@ -165,8 +167,9 @@ async function createTransports (args) {
|
|
|
165
167
|
transports.push(createFileTransport(args, fileLogLevel));
|
|
166
168
|
} catch (e) {
|
|
167
169
|
// eslint-disable-next-line no-console
|
|
168
|
-
console.log(
|
|
169
|
-
|
|
170
|
+
console.log(
|
|
171
|
+
`Tried to attach logging to file '${args.logFile}' but an error ` + `occurred: ${e.message}`
|
|
172
|
+
);
|
|
170
173
|
}
|
|
171
174
|
}
|
|
172
175
|
|
|
@@ -175,15 +178,31 @@ async function createTransports (args) {
|
|
|
175
178
|
transports.push(createHttpTransport(args, fileLogLevel));
|
|
176
179
|
} catch (e) {
|
|
177
180
|
// eslint-disable-next-line no-console
|
|
178
|
-
console.log(
|
|
179
|
-
|
|
181
|
+
console.log(
|
|
182
|
+
`Tried to attach logging to Http at ${args.webhook} but ` +
|
|
183
|
+
`an error occurred: ${e.message}`
|
|
184
|
+
);
|
|
180
185
|
}
|
|
181
186
|
}
|
|
182
187
|
|
|
183
188
|
return transports;
|
|
184
189
|
}
|
|
185
190
|
|
|
186
|
-
|
|
191
|
+
function getColorizedPrefix(prefix) {
|
|
192
|
+
let prefixId = prefix.split('@')[0].trim();
|
|
193
|
+
prefixId = prefixId.split(' (')[0].trim();
|
|
194
|
+
if (encounteredPrefixes.indexOf(prefixId) < 0) {
|
|
195
|
+
encounteredPrefixes.push(prefixId);
|
|
196
|
+
}
|
|
197
|
+
// using a multiple of 16 should cause 16 colors to be created
|
|
198
|
+
const colorNumber = encounteredPrefixes.indexOf(prefixId) * 16;
|
|
199
|
+
// use the modulus to cycle around color wheel
|
|
200
|
+
return `\x1b[38;5;${colorNumber % 256}m${prefix}\x1b[0m`;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
async function init(args) {
|
|
204
|
+
npmlog.level = 'silent';
|
|
205
|
+
|
|
187
206
|
// set de facto param passed to timestamp function
|
|
188
207
|
useLocalTimeZone = args.localTimezone;
|
|
189
208
|
|
|
@@ -201,17 +220,22 @@ async function init (args) {
|
|
|
201
220
|
let msg = logObj.message;
|
|
202
221
|
if (logObj.prefix) {
|
|
203
222
|
const prefix = `[${logObj.prefix}]`;
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
223
|
+
if (args.logNoColors) {
|
|
224
|
+
msg = `${prefix} ${msg}`;
|
|
225
|
+
} if (prefix === '[Appium]') {
|
|
226
|
+
msg = `${prefix.magenta} ${msg}`;
|
|
227
|
+
} else {
|
|
228
|
+
msg = `${getColorizedPrefix(prefix)} ${msg}`;
|
|
229
|
+
}
|
|
230
|
+
log[winstonLevel](msg);
|
|
231
|
+
if (args.logHandler && _.isFunction(args.logHandler)) {
|
|
232
|
+
args.logHandler(logObj.level, msg);
|
|
233
|
+
}
|
|
209
234
|
}
|
|
210
|
-
|
|
211
235
|
});
|
|
212
236
|
}
|
|
213
237
|
|
|
214
|
-
function clear
|
|
238
|
+
function clear() {
|
|
215
239
|
if (log) {
|
|
216
240
|
for (let transport of _.keys(log.transports)) {
|
|
217
241
|
log.remove(transport);
|
|
@@ -220,6 +244,5 @@ function clear () {
|
|
|
220
244
|
npmlog.removeAllListeners('log');
|
|
221
245
|
}
|
|
222
246
|
|
|
223
|
-
|
|
224
|
-
export { init, clear };
|
|
247
|
+
export {init, clear};
|
|
225
248
|
export default init;
|