@commercetools-frontend/cypress-environments 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -7,6 +7,7 @@ var fs = require('fs');
|
|
|
7
7
|
var util = require('util');
|
|
8
8
|
var glob = require('glob');
|
|
9
9
|
var dotenv = require('dotenv');
|
|
10
|
+
var pkgDir = require('pkg-dir');
|
|
10
11
|
var cosmiconfig = require('cosmiconfig');
|
|
11
12
|
|
|
12
13
|
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
@@ -15,6 +16,7 @@ var path__default = /*#__PURE__*/_interopDefault(path);
|
|
|
15
16
|
var fs__default = /*#__PURE__*/_interopDefault(fs);
|
|
16
17
|
var glob__default = /*#__PURE__*/_interopDefault(glob);
|
|
17
18
|
var dotenv__default = /*#__PURE__*/_interopDefault(dotenv);
|
|
19
|
+
var pkgDir__default = /*#__PURE__*/_interopDefault(pkgDir);
|
|
18
20
|
|
|
19
21
|
const cypressEnvironmentsConfigExplorer = cosmiconfig.cosmiconfig('cypress-environments');
|
|
20
22
|
const isCI = String(process.env.CI) === 'true';
|
|
@@ -29,7 +31,7 @@ function getParsedEnvFileContents(envPath) {
|
|
|
29
31
|
const configuration = dotenv__default["default"].parse(envFileContents);
|
|
30
32
|
return configuration;
|
|
31
33
|
} else {
|
|
32
|
-
console.log(`ℹ️
|
|
34
|
+
console.log(`ℹ️ No environment variables at: '${envPath}'. If needed create it or duplicate the template file.`);
|
|
33
35
|
return null;
|
|
34
36
|
}
|
|
35
37
|
}
|
|
@@ -43,17 +45,19 @@ async function loadConfig() {
|
|
|
43
45
|
}
|
|
44
46
|
|
|
45
47
|
async function getConfigurationForEnvironment(environmentName) {
|
|
46
|
-
|
|
47
|
-
console.log(`ℹ️ 'CI' environment variable is defined. Assuming operating from a CI system.`);
|
|
48
|
-
} else {
|
|
49
|
-
console.log(`ℹ️ 'CI' environment variable is not defined. Assuming you are running locally.`);
|
|
50
|
-
} // NOTE: On CI the *.ci secrests are not excluded. Locally the are in case
|
|
48
|
+
// NOTE: On CI the *.ci secrests are not excluded. Locally the are in case
|
|
51
49
|
// decrypted files are available on a developer's machine.
|
|
52
|
-
|
|
53
|
-
|
|
54
50
|
const ignoredGlobs = ['**/*.enc', '**/*.template'];
|
|
55
51
|
const ignoredCIGlobs = ['**/*.ci'];
|
|
56
|
-
const allIgnoredGlobs = isCI ? ignoredGlobs.concat(ignoredCIGlobs)
|
|
52
|
+
const allIgnoredGlobs = isCI ? ignoredGlobs : ignoredGlobs.concat(ignoredCIGlobs);
|
|
53
|
+
|
|
54
|
+
if (isCI) {
|
|
55
|
+
console.log(`ℹ️ 'CI' environment variable is defined. Assuming operating from a CI system.`);
|
|
56
|
+
} else {
|
|
57
|
+
console.log(`ℹ️ 'CI' environment variable is not defined. Assuming you are running locally.`);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
console.log(`ℹ️ The ignored globs are: ${allIgnoredGlobs.join(', ')}.`);
|
|
57
61
|
const configResult = await loadConfig();
|
|
58
62
|
const allEnvironmentConfigs = configResult?.config;
|
|
59
63
|
const configForEnvironment = allEnvironmentConfigs.environments.find(environment => environment.name === environmentName);
|
|
@@ -68,11 +72,11 @@ async function getConfigurationForEnvironment(environmentName) {
|
|
|
68
72
|
const configFiles = await promisifiedGlob(configForEnvironment.config.glob, {
|
|
69
73
|
ignore: allIgnoredGlobs
|
|
70
74
|
});
|
|
71
|
-
console.log(`ℹ️
|
|
75
|
+
console.log(`ℹ️ Found ${secretsFiles.length} secret file(s) and ${configFiles.length} config file(s) matching the defined globs.`);
|
|
72
76
|
|
|
73
77
|
if (secretsFiles.length === 0 || configFiles.length === 0) {
|
|
74
|
-
console.log(`ℹ️
|
|
75
|
-
console.log(`ℹ️
|
|
78
|
+
console.log(`ℹ️ Secrets files glob is: ${configForEnvironment.secrets.glob}`);
|
|
79
|
+
console.log(`ℹ️ Config files glob is: ${configForEnvironment.config.glob}`);
|
|
76
80
|
}
|
|
77
81
|
|
|
78
82
|
const mergedConfigurationAndSecrests = [...configFiles, ...secretsFiles].reduce((previousParsedEnvFileContents, nextEnvFilePath) => {
|
|
@@ -88,13 +92,17 @@ async function getConfigurationForEnvironment(environmentName) {
|
|
|
88
92
|
...matchingParsedEnvFileContentsForCIOrLocal
|
|
89
93
|
};
|
|
90
94
|
}, {});
|
|
91
|
-
const
|
|
95
|
+
const rootDir = await pkgDir__default["default"](__dirname);
|
|
92
96
|
let sharedEnvironmentConfiguration = null;
|
|
93
97
|
|
|
94
|
-
if (
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
+
if (rootDir) {
|
|
99
|
+
const pathToSharedEnvironmentConfiguration = path__default["default"].join(rootDir, 'config', `.env.${environmentName}.config`);
|
|
100
|
+
|
|
101
|
+
if (fs__default["default"].existsSync(pathToSharedEnvironmentConfiguration)) {
|
|
102
|
+
sharedEnvironmentConfiguration = getParsedEnvFileContents(pathToSharedEnvironmentConfiguration);
|
|
103
|
+
} else {
|
|
104
|
+
console.log(`ℹ️ No shared configuration for ${environmentName} defined.`);
|
|
105
|
+
}
|
|
98
106
|
}
|
|
99
107
|
|
|
100
108
|
return { ...sharedEnvironmentConfiguration,
|
|
@@ -7,6 +7,7 @@ var fs = require('fs');
|
|
|
7
7
|
var util = require('util');
|
|
8
8
|
var glob = require('glob');
|
|
9
9
|
var dotenv = require('dotenv');
|
|
10
|
+
var pkgDir = require('pkg-dir');
|
|
10
11
|
var cosmiconfig = require('cosmiconfig');
|
|
11
12
|
|
|
12
13
|
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
@@ -15,6 +16,7 @@ var path__default = /*#__PURE__*/_interopDefault(path);
|
|
|
15
16
|
var fs__default = /*#__PURE__*/_interopDefault(fs);
|
|
16
17
|
var glob__default = /*#__PURE__*/_interopDefault(glob);
|
|
17
18
|
var dotenv__default = /*#__PURE__*/_interopDefault(dotenv);
|
|
19
|
+
var pkgDir__default = /*#__PURE__*/_interopDefault(pkgDir);
|
|
18
20
|
|
|
19
21
|
const cypressEnvironmentsConfigExplorer = cosmiconfig.cosmiconfig('cypress-environments');
|
|
20
22
|
const isCI = String(process.env.CI) === 'true';
|
|
@@ -29,7 +31,7 @@ function getParsedEnvFileContents(envPath) {
|
|
|
29
31
|
const configuration = dotenv__default["default"].parse(envFileContents);
|
|
30
32
|
return configuration;
|
|
31
33
|
} else {
|
|
32
|
-
console.log(`ℹ️
|
|
34
|
+
console.log(`ℹ️ No environment variables at: '${envPath}'. If needed create it or duplicate the template file.`);
|
|
33
35
|
return null;
|
|
34
36
|
}
|
|
35
37
|
}
|
|
@@ -43,17 +45,19 @@ async function loadConfig() {
|
|
|
43
45
|
}
|
|
44
46
|
|
|
45
47
|
async function getConfigurationForEnvironment(environmentName) {
|
|
46
|
-
|
|
47
|
-
console.log(`ℹ️ 'CI' environment variable is defined. Assuming operating from a CI system.`);
|
|
48
|
-
} else {
|
|
49
|
-
console.log(`ℹ️ 'CI' environment variable is not defined. Assuming you are running locally.`);
|
|
50
|
-
} // NOTE: On CI the *.ci secrests are not excluded. Locally the are in case
|
|
48
|
+
// NOTE: On CI the *.ci secrests are not excluded. Locally the are in case
|
|
51
49
|
// decrypted files are available on a developer's machine.
|
|
52
|
-
|
|
53
|
-
|
|
54
50
|
const ignoredGlobs = ['**/*.enc', '**/*.template'];
|
|
55
51
|
const ignoredCIGlobs = ['**/*.ci'];
|
|
56
|
-
const allIgnoredGlobs = isCI ? ignoredGlobs.concat(ignoredCIGlobs)
|
|
52
|
+
const allIgnoredGlobs = isCI ? ignoredGlobs : ignoredGlobs.concat(ignoredCIGlobs);
|
|
53
|
+
|
|
54
|
+
if (isCI) {
|
|
55
|
+
console.log(`ℹ️ 'CI' environment variable is defined. Assuming operating from a CI system.`);
|
|
56
|
+
} else {
|
|
57
|
+
console.log(`ℹ️ 'CI' environment variable is not defined. Assuming you are running locally.`);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
console.log(`ℹ️ The ignored globs are: ${allIgnoredGlobs.join(', ')}.`);
|
|
57
61
|
const configResult = await loadConfig();
|
|
58
62
|
const allEnvironmentConfigs = configResult?.config;
|
|
59
63
|
const configForEnvironment = allEnvironmentConfigs.environments.find(environment => environment.name === environmentName);
|
|
@@ -68,11 +72,11 @@ async function getConfigurationForEnvironment(environmentName) {
|
|
|
68
72
|
const configFiles = await promisifiedGlob(configForEnvironment.config.glob, {
|
|
69
73
|
ignore: allIgnoredGlobs
|
|
70
74
|
});
|
|
71
|
-
console.log(`ℹ️
|
|
75
|
+
console.log(`ℹ️ Found ${secretsFiles.length} secret file(s) and ${configFiles.length} config file(s) matching the defined globs.`);
|
|
72
76
|
|
|
73
77
|
if (secretsFiles.length === 0 || configFiles.length === 0) {
|
|
74
|
-
console.log(`ℹ️
|
|
75
|
-
console.log(`ℹ️
|
|
78
|
+
console.log(`ℹ️ Secrets files glob is: ${configForEnvironment.secrets.glob}`);
|
|
79
|
+
console.log(`ℹ️ Config files glob is: ${configForEnvironment.config.glob}`);
|
|
76
80
|
}
|
|
77
81
|
|
|
78
82
|
const mergedConfigurationAndSecrests = [...configFiles, ...secretsFiles].reduce((previousParsedEnvFileContents, nextEnvFilePath) => {
|
|
@@ -88,13 +92,17 @@ async function getConfigurationForEnvironment(environmentName) {
|
|
|
88
92
|
...matchingParsedEnvFileContentsForCIOrLocal
|
|
89
93
|
};
|
|
90
94
|
}, {});
|
|
91
|
-
const
|
|
95
|
+
const rootDir = await pkgDir__default["default"](__dirname);
|
|
92
96
|
let sharedEnvironmentConfiguration = null;
|
|
93
97
|
|
|
94
|
-
if (
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
+
if (rootDir) {
|
|
99
|
+
const pathToSharedEnvironmentConfiguration = path__default["default"].join(rootDir, 'config', `.env.${environmentName}.config`);
|
|
100
|
+
|
|
101
|
+
if (fs__default["default"].existsSync(pathToSharedEnvironmentConfiguration)) {
|
|
102
|
+
sharedEnvironmentConfiguration = getParsedEnvFileContents(pathToSharedEnvironmentConfiguration);
|
|
103
|
+
} else {
|
|
104
|
+
console.log(`ℹ️ No shared configuration for ${environmentName} defined.`);
|
|
105
|
+
}
|
|
98
106
|
}
|
|
99
107
|
|
|
100
108
|
return { ...sharedEnvironmentConfiguration,
|
|
@@ -3,6 +3,7 @@ import fs from 'fs';
|
|
|
3
3
|
import { promisify } from 'util';
|
|
4
4
|
import glob from 'glob';
|
|
5
5
|
import dotenv from 'dotenv';
|
|
6
|
+
import pkgDir from 'pkg-dir';
|
|
6
7
|
import { cosmiconfig } from 'cosmiconfig';
|
|
7
8
|
|
|
8
9
|
const cypressEnvironmentsConfigExplorer = cosmiconfig('cypress-environments');
|
|
@@ -18,7 +19,7 @@ function getParsedEnvFileContents(envPath) {
|
|
|
18
19
|
const configuration = dotenv.parse(envFileContents);
|
|
19
20
|
return configuration;
|
|
20
21
|
} else {
|
|
21
|
-
console.log(`ℹ️
|
|
22
|
+
console.log(`ℹ️ No environment variables at: '${envPath}'. If needed create it or duplicate the template file.`);
|
|
22
23
|
return null;
|
|
23
24
|
}
|
|
24
25
|
}
|
|
@@ -32,17 +33,19 @@ async function loadConfig() {
|
|
|
32
33
|
}
|
|
33
34
|
|
|
34
35
|
async function getConfigurationForEnvironment(environmentName) {
|
|
35
|
-
|
|
36
|
-
console.log(`ℹ️ 'CI' environment variable is defined. Assuming operating from a CI system.`);
|
|
37
|
-
} else {
|
|
38
|
-
console.log(`ℹ️ 'CI' environment variable is not defined. Assuming you are running locally.`);
|
|
39
|
-
} // NOTE: On CI the *.ci secrests are not excluded. Locally the are in case
|
|
36
|
+
// NOTE: On CI the *.ci secrests are not excluded. Locally the are in case
|
|
40
37
|
// decrypted files are available on a developer's machine.
|
|
41
|
-
|
|
42
|
-
|
|
43
38
|
const ignoredGlobs = ['**/*.enc', '**/*.template'];
|
|
44
39
|
const ignoredCIGlobs = ['**/*.ci'];
|
|
45
|
-
const allIgnoredGlobs = isCI ? ignoredGlobs.concat(ignoredCIGlobs)
|
|
40
|
+
const allIgnoredGlobs = isCI ? ignoredGlobs : ignoredGlobs.concat(ignoredCIGlobs);
|
|
41
|
+
|
|
42
|
+
if (isCI) {
|
|
43
|
+
console.log(`ℹ️ 'CI' environment variable is defined. Assuming operating from a CI system.`);
|
|
44
|
+
} else {
|
|
45
|
+
console.log(`ℹ️ 'CI' environment variable is not defined. Assuming you are running locally.`);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
console.log(`ℹ️ The ignored globs are: ${allIgnoredGlobs.join(', ')}.`);
|
|
46
49
|
const configResult = await loadConfig();
|
|
47
50
|
const allEnvironmentConfigs = configResult?.config;
|
|
48
51
|
const configForEnvironment = allEnvironmentConfigs.environments.find(environment => environment.name === environmentName);
|
|
@@ -57,11 +60,11 @@ async function getConfigurationForEnvironment(environmentName) {
|
|
|
57
60
|
const configFiles = await promisifiedGlob(configForEnvironment.config.glob, {
|
|
58
61
|
ignore: allIgnoredGlobs
|
|
59
62
|
});
|
|
60
|
-
console.log(`ℹ️
|
|
63
|
+
console.log(`ℹ️ Found ${secretsFiles.length} secret file(s) and ${configFiles.length} config file(s) matching the defined globs.`);
|
|
61
64
|
|
|
62
65
|
if (secretsFiles.length === 0 || configFiles.length === 0) {
|
|
63
|
-
console.log(`ℹ️
|
|
64
|
-
console.log(`ℹ️
|
|
66
|
+
console.log(`ℹ️ Secrets files glob is: ${configForEnvironment.secrets.glob}`);
|
|
67
|
+
console.log(`ℹ️ Config files glob is: ${configForEnvironment.config.glob}`);
|
|
65
68
|
}
|
|
66
69
|
|
|
67
70
|
const mergedConfigurationAndSecrests = [...configFiles, ...secretsFiles].reduce((previousParsedEnvFileContents, nextEnvFilePath) => {
|
|
@@ -77,13 +80,17 @@ async function getConfigurationForEnvironment(environmentName) {
|
|
|
77
80
|
...matchingParsedEnvFileContentsForCIOrLocal
|
|
78
81
|
};
|
|
79
82
|
}, {});
|
|
80
|
-
const
|
|
83
|
+
const rootDir = await pkgDir(__dirname);
|
|
81
84
|
let sharedEnvironmentConfiguration = null;
|
|
82
85
|
|
|
83
|
-
if (
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
86
|
+
if (rootDir) {
|
|
87
|
+
const pathToSharedEnvironmentConfiguration = path.join(rootDir, 'config', `.env.${environmentName}.config`);
|
|
88
|
+
|
|
89
|
+
if (fs.existsSync(pathToSharedEnvironmentConfiguration)) {
|
|
90
|
+
sharedEnvironmentConfiguration = getParsedEnvFileContents(pathToSharedEnvironmentConfiguration);
|
|
91
|
+
} else {
|
|
92
|
+
console.log(`ℹ️ No shared configuration for ${environmentName} defined.`);
|
|
93
|
+
}
|
|
87
94
|
}
|
|
88
95
|
|
|
89
96
|
return { ...sharedEnvironmentConfiguration,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commercetools-frontend/cypress-environments",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "Cypress package to setup environment configuration using dotenv files",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
@@ -21,11 +21,10 @@
|
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"cosmiconfig": "7.0.1",
|
|
23
23
|
"dotenv": "16.0.2",
|
|
24
|
-
"glob": "8.0.3"
|
|
24
|
+
"glob": "8.0.3",
|
|
25
|
+
"pkg-dir": "5.0.0"
|
|
25
26
|
},
|
|
26
27
|
"devDependencies": {
|
|
27
|
-
"@babel/core": "7.19.1",
|
|
28
|
-
"@babel/preset-typescript": "7.18.6",
|
|
29
28
|
"typescript": "^4.8.2"
|
|
30
29
|
},
|
|
31
30
|
"engines": {
|