appium 2.0.0-beta.6 → 2.0.0-beta.60
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 +156 -65
- 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 -319
- 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 -54
- 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 +240 -128
- 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 +267 -202
- 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 +190 -187
- 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 +339 -229
- 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 +217 -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 +277 -422
- package/lib/cli/driver-command.js +132 -24
- package/lib/cli/extension-command.js +751 -272
- package/lib/cli/extension.js +49 -18
- package/lib/cli/parser.js +263 -83
- 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 +246 -111
- 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 +64 -38
- package/lib/main.js +318 -103
- package/lib/schema/arg-spec.js +229 -0
- package/lib/schema/cli-args.js +238 -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 -84
- 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 -3515
- package/bin/ios-webkit-debug-proxy-launcher.js +0 -71
- package/build/lib/cli/npm.js +0 -208
- 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 -184
- 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,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,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,
|
|
@@ -35,17 +33,20 @@ const npmToWinstonLevels = {
|
|
|
35
33
|
error: 'error',
|
|
36
34
|
};
|
|
37
35
|
|
|
36
|
+
const encounteredPrefixes = [];
|
|
37
|
+
|
|
38
38
|
let log = null;
|
|
39
|
-
let
|
|
39
|
+
let useLocalTimeZone = false;
|
|
40
40
|
|
|
41
41
|
// add the timestamp in the correct format to the log info object
|
|
42
42
|
const timestampFormat = format.timestamp({
|
|
43
|
-
format
|
|
43
|
+
format() {
|
|
44
44
|
let date = new Date();
|
|
45
|
-
if (
|
|
46
|
-
date = new Date(date.valueOf()
|
|
45
|
+
if (useLocalTimeZone) {
|
|
46
|
+
date = new Date(date.valueOf() - date.getTimezoneOffset() * 60000);
|
|
47
47
|
}
|
|
48
|
-
|
|
48
|
+
// '2012-11-04T14:51:06.157Z' -> '2012-11-04 14:51:06:157'
|
|
49
|
+
return date.toISOString().replace(/[TZ]/g, ' ').replace(/\./g, ':').trim();
|
|
49
50
|
},
|
|
50
51
|
});
|
|
51
52
|
|
|
@@ -55,14 +56,16 @@ const colorizeFormat = format.colorize({
|
|
|
55
56
|
});
|
|
56
57
|
|
|
57
58
|
// Strip the color marking within messages
|
|
58
|
-
const stripColorFormat = format(function stripColor
|
|
59
|
+
const stripColorFormat = format(function stripColor(info) {
|
|
59
60
|
const code = /\u001b\[(\d+(;\d+)*)?m/g; // eslint-disable-line no-control-regex
|
|
60
61
|
info.message = info.message.replace(code, '');
|
|
61
62
|
return info;
|
|
62
63
|
})();
|
|
63
64
|
|
|
64
|
-
function createConsoleTransport
|
|
65
|
-
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
|
|
66
69
|
name: 'console',
|
|
67
70
|
handleExceptions: true,
|
|
68
71
|
exitOnError: false,
|
|
@@ -70,7 +73,7 @@ function createConsoleTransport (args, logLvl) {
|
|
|
70
73
|
level: logLvl,
|
|
71
74
|
stderrLevels: ['error'],
|
|
72
75
|
format: format.combine(
|
|
73
|
-
format(function adjustDebug
|
|
76
|
+
format(function adjustDebug(info) {
|
|
74
77
|
// prepend debug marker, and shift to `info` log level
|
|
75
78
|
if (info.level === 'debug') {
|
|
76
79
|
info.level = 'info';
|
|
@@ -80,15 +83,16 @@ function createConsoleTransport (args, logLvl) {
|
|
|
80
83
|
})(),
|
|
81
84
|
timestampFormat,
|
|
82
85
|
args.logNoColors ? stripColorFormat : colorizeFormat,
|
|
83
|
-
format.printf(function printInfo
|
|
86
|
+
format.printf(function printInfo(info) {
|
|
84
87
|
return `${args.logTimestamp ? `${info.timestamp} - ` : ''}${info.message}`;
|
|
85
88
|
})
|
|
86
89
|
),
|
|
87
90
|
});
|
|
88
91
|
}
|
|
89
92
|
|
|
90
|
-
function createFileTransport
|
|
91
|
-
return new
|
|
93
|
+
function createFileTransport(args, logLvl) {
|
|
94
|
+
return new transports.File({
|
|
95
|
+
// @ts-expect-error
|
|
92
96
|
name: 'file',
|
|
93
97
|
filename: args.logFile,
|
|
94
98
|
maxFiles: 1,
|
|
@@ -99,14 +103,14 @@ function createFileTransport (args, logLvl) {
|
|
|
99
103
|
format: format.combine(
|
|
100
104
|
stripColorFormat,
|
|
101
105
|
timestampFormat,
|
|
102
|
-
format.printf(function printInfo
|
|
106
|
+
format.printf(function printInfo(info) {
|
|
103
107
|
return `${info.timestamp} ${info.message}`;
|
|
104
108
|
})
|
|
105
|
-
)
|
|
109
|
+
),
|
|
106
110
|
});
|
|
107
111
|
}
|
|
108
112
|
|
|
109
|
-
function createHttpTransport
|
|
113
|
+
function createHttpTransport(args, logLvl) {
|
|
110
114
|
let host = '127.0.0.1';
|
|
111
115
|
let port = 9003;
|
|
112
116
|
|
|
@@ -116,7 +120,8 @@ function createHttpTransport (args, logLvl) {
|
|
|
116
120
|
port = parseInt(hostAndPort[1], 10);
|
|
117
121
|
}
|
|
118
122
|
|
|
119
|
-
return new
|
|
123
|
+
return new transports.Http({
|
|
124
|
+
// @ts-expect-error
|
|
120
125
|
name: 'http',
|
|
121
126
|
host,
|
|
122
127
|
port,
|
|
@@ -127,14 +132,14 @@ function createHttpTransport (args, logLvl) {
|
|
|
127
132
|
level: logLvl,
|
|
128
133
|
format: format.combine(
|
|
129
134
|
stripColorFormat,
|
|
130
|
-
format.printf(function printInfo
|
|
135
|
+
format.printf(function printInfo(info) {
|
|
131
136
|
return `${info.timestamp} ${info.message}`;
|
|
132
137
|
})
|
|
133
138
|
),
|
|
134
139
|
});
|
|
135
140
|
}
|
|
136
141
|
|
|
137
|
-
async function createTransports
|
|
142
|
+
async function createTransports(args) {
|
|
138
143
|
let transports = [];
|
|
139
144
|
let consoleLogLevel = null;
|
|
140
145
|
let fileLogLevel = null;
|
|
@@ -162,8 +167,9 @@ async function createTransports (args) {
|
|
|
162
167
|
transports.push(createFileTransport(args, fileLogLevel));
|
|
163
168
|
} catch (e) {
|
|
164
169
|
// eslint-disable-next-line no-console
|
|
165
|
-
console.log(
|
|
166
|
-
|
|
170
|
+
console.log(
|
|
171
|
+
`Tried to attach logging to file '${args.logFile}' but an error ` + `occurred: ${e.message}`
|
|
172
|
+
);
|
|
167
173
|
}
|
|
168
174
|
}
|
|
169
175
|
|
|
@@ -172,17 +178,33 @@ async function createTransports (args) {
|
|
|
172
178
|
transports.push(createHttpTransport(args, fileLogLevel));
|
|
173
179
|
} catch (e) {
|
|
174
180
|
// eslint-disable-next-line no-console
|
|
175
|
-
console.log(
|
|
176
|
-
|
|
181
|
+
console.log(
|
|
182
|
+
`Tried to attach logging to Http at ${args.webhook} but ` +
|
|
183
|
+
`an error occurred: ${e.message}`
|
|
184
|
+
);
|
|
177
185
|
}
|
|
178
186
|
}
|
|
179
187
|
|
|
180
188
|
return transports;
|
|
181
189
|
}
|
|
182
190
|
|
|
183
|
-
|
|
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
|
+
|
|
184
206
|
// set de facto param passed to timestamp function
|
|
185
|
-
|
|
207
|
+
useLocalTimeZone = args.localTimezone;
|
|
186
208
|
|
|
187
209
|
// clean up in case we have initiated before since npmlog is a global object
|
|
188
210
|
clear();
|
|
@@ -198,17 +220,22 @@ async function init (args) {
|
|
|
198
220
|
let msg = logObj.message;
|
|
199
221
|
if (logObj.prefix) {
|
|
200
222
|
const prefix = `[${logObj.prefix}]`;
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
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
|
+
}
|
|
206
234
|
}
|
|
207
|
-
|
|
208
235
|
});
|
|
209
236
|
}
|
|
210
237
|
|
|
211
|
-
function clear
|
|
238
|
+
function clear() {
|
|
212
239
|
if (log) {
|
|
213
240
|
for (let transport of _.keys(log.transports)) {
|
|
214
241
|
log.remove(transport);
|
|
@@ -217,6 +244,5 @@ function clear () {
|
|
|
217
244
|
npmlog.removeAllListeners('log');
|
|
218
245
|
}
|
|
219
246
|
|
|
220
|
-
|
|
221
|
-
export { init, clear };
|
|
247
|
+
export {init, clear};
|
|
222
248
|
export default init;
|