@commercetools-frontend/cypress-environments 0.0.2 → 0.0.4
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/dist/commercetools-frontend-cypress-environments.cjs.d.ts +1 -11
- package/dist/commercetools-frontend-cypress-environments.cjs.dev.js +180 -0
- package/dist/commercetools-frontend-cypress-environments.cjs.js +6 -15
- package/dist/commercetools-frontend-cypress-environments.cjs.prod.js +180 -0
- package/dist/commercetools-frontend-cypress-environments.esm.js +155 -0
- package/dist/declarations/src/environments.d.ts +3 -0
- package/dist/declarations/src/index.d.ts +2 -0
- package/package.json +8 -4
|
@@ -1,11 +1 @@
|
|
|
1
|
-
|
|
2
|
-
// you should run `yarn` or `yarn preconstruct dev` if preconstruct dev isn't in your postinstall hook
|
|
3
|
-
|
|
4
|
-
// curious why you need to?
|
|
5
|
-
// this file exists so that you can import from the entrypoint normally
|
|
6
|
-
// except that it points to your source file and you don't need to run build constantly
|
|
7
|
-
// which means we need to re-export all of the modules from your source file
|
|
8
|
-
// and since export * doesn't include default exports, we need to read your source file
|
|
9
|
-
// to check for a default export and re-export it if it exists
|
|
10
|
-
// it's not ideal, but it works pretty well ¯\_(ツ)_/¯
|
|
11
|
-
export * from "../src/index";
|
|
1
|
+
export * from "./declarations/src/index";
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
|
|
6
|
+
var _toConsumableArray = require('@babel/runtime-corejs3/helpers/toConsumableArray');
|
|
7
|
+
var _asyncToGenerator = require('@babel/runtime-corejs3/helpers/asyncToGenerator');
|
|
8
|
+
var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
|
|
9
|
+
var _findInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/find');
|
|
10
|
+
var _reduceInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/reduce');
|
|
11
|
+
var _endsWithInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/ends-with');
|
|
12
|
+
var _Object$keys = require('@babel/runtime-corejs3/core-js-stable/object/keys');
|
|
13
|
+
var _Object$getOwnPropertySymbols = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols');
|
|
14
|
+
var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/filter');
|
|
15
|
+
var _Object$getOwnPropertyDescriptor = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor');
|
|
16
|
+
var _forEachInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/for-each');
|
|
17
|
+
var _Object$getOwnPropertyDescriptors = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors');
|
|
18
|
+
var _Object$defineProperties = require('@babel/runtime-corejs3/core-js-stable/object/define-properties');
|
|
19
|
+
var _Object$defineProperty = require('@babel/runtime-corejs3/core-js-stable/object/define-property');
|
|
20
|
+
var _regeneratorRuntime = require('@babel/runtime-corejs3/regenerator');
|
|
21
|
+
var path = require('path');
|
|
22
|
+
var fs = require('fs');
|
|
23
|
+
var util = require('util');
|
|
24
|
+
var glob = require('glob');
|
|
25
|
+
var dotenv = require('dotenv');
|
|
26
|
+
var pkgDir = require('pkg-dir');
|
|
27
|
+
var cosmiconfig = require('cosmiconfig');
|
|
28
|
+
|
|
29
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
30
|
+
|
|
31
|
+
var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
|
|
32
|
+
var _findInstanceProperty__default = /*#__PURE__*/_interopDefault(_findInstanceProperty);
|
|
33
|
+
var _reduceInstanceProperty__default = /*#__PURE__*/_interopDefault(_reduceInstanceProperty);
|
|
34
|
+
var _endsWithInstanceProperty__default = /*#__PURE__*/_interopDefault(_endsWithInstanceProperty);
|
|
35
|
+
var _Object$keys__default = /*#__PURE__*/_interopDefault(_Object$keys);
|
|
36
|
+
var _Object$getOwnPropertySymbols__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertySymbols);
|
|
37
|
+
var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty);
|
|
38
|
+
var _Object$getOwnPropertyDescriptor__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptor);
|
|
39
|
+
var _forEachInstanceProperty__default = /*#__PURE__*/_interopDefault(_forEachInstanceProperty);
|
|
40
|
+
var _Object$getOwnPropertyDescriptors__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptors);
|
|
41
|
+
var _Object$defineProperties__default = /*#__PURE__*/_interopDefault(_Object$defineProperties);
|
|
42
|
+
var _Object$defineProperty__default = /*#__PURE__*/_interopDefault(_Object$defineProperty);
|
|
43
|
+
var _regeneratorRuntime__default = /*#__PURE__*/_interopDefault(_regeneratorRuntime);
|
|
44
|
+
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
45
|
+
var fs__default = /*#__PURE__*/_interopDefault(fs);
|
|
46
|
+
var glob__default = /*#__PURE__*/_interopDefault(glob);
|
|
47
|
+
var dotenv__default = /*#__PURE__*/_interopDefault(dotenv);
|
|
48
|
+
var pkgDir__default = /*#__PURE__*/_interopDefault(pkgDir);
|
|
49
|
+
|
|
50
|
+
function ownKeys(object, enumerableOnly) { var keys = _Object$keys__default["default"](object); if (_Object$getOwnPropertySymbols__default["default"]) { var symbols = _Object$getOwnPropertySymbols__default["default"](object); enumerableOnly && (symbols = _filterInstanceProperty__default["default"](symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor__default["default"](object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
51
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context7, _context8; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty__default["default"](_context7 = ownKeys(Object(source), !0)).call(_context7, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)) : _forEachInstanceProperty__default["default"](_context8 = ownKeys(Object(source))).call(_context8, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } return target; }
|
|
52
|
+
var cypressEnvironmentsConfigExplorer = cosmiconfig.cosmiconfig('cypress-environments');
|
|
53
|
+
var isCI = String(process.env.CI) === 'true';
|
|
54
|
+
var promisifiedGlob = util.promisify(glob__default["default"]);
|
|
55
|
+
function getParsedEnvFileContents(envPath) {
|
|
56
|
+
if (fs__default["default"].existsSync(envPath)) {
|
|
57
|
+
console.log("\u2705 Found and loading environment variables from: '".concat(envPath, "'"));
|
|
58
|
+
var envFileContents = fs__default["default"].readFileSync(envPath, {
|
|
59
|
+
encoding: 'utf8'
|
|
60
|
+
});
|
|
61
|
+
var configuration = dotenv__default["default"].parse(envFileContents);
|
|
62
|
+
return configuration;
|
|
63
|
+
} else {
|
|
64
|
+
console.log("\u2139\uFE0F No environment variables at: '".concat(envPath, "'. If needed create it or duplicate the template file."));
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function loadConfig() {
|
|
69
|
+
return _loadConfig.apply(this, arguments);
|
|
70
|
+
}
|
|
71
|
+
function _loadConfig() {
|
|
72
|
+
_loadConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee() {
|
|
73
|
+
return _regeneratorRuntime__default["default"].wrap(function _callee$(_context) {
|
|
74
|
+
while (1) {
|
|
75
|
+
switch (_context.prev = _context.next) {
|
|
76
|
+
case 0:
|
|
77
|
+
_context.prev = 0;
|
|
78
|
+
_context.next = 3;
|
|
79
|
+
return cypressEnvironmentsConfigExplorer.search();
|
|
80
|
+
case 3:
|
|
81
|
+
return _context.abrupt("return", _context.sent);
|
|
82
|
+
case 6:
|
|
83
|
+
_context.prev = 6;
|
|
84
|
+
_context.t0 = _context["catch"](0);
|
|
85
|
+
throw new Error("Failed loading a Cypress environments configuration. Create a cosmiconfig for 'cypress-environments' for example 'cypress-environments.config.cjs'.");
|
|
86
|
+
case 9:
|
|
87
|
+
case "end":
|
|
88
|
+
return _context.stop();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}, _callee, null, [[0, 6]]);
|
|
92
|
+
}));
|
|
93
|
+
return _loadConfig.apply(this, arguments);
|
|
94
|
+
}
|
|
95
|
+
function getConfigurationForEnvironment(_x) {
|
|
96
|
+
return _getConfigurationForEnvironment.apply(this, arguments);
|
|
97
|
+
}
|
|
98
|
+
function _getConfigurationForEnvironment() {
|
|
99
|
+
_getConfigurationForEnvironment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee2(environmentName) {
|
|
100
|
+
var _context2, _context3, _context4, _context5;
|
|
101
|
+
var ignoredGlobs, ignoredCIGlobs, allIgnoredGlobs, configResult, allEnvironmentConfigs, configForEnvironment, secretsFiles, configFiles, mergedConfigurationAndSecrests, rootDir, sharedEnvironmentConfiguration, pathToSharedEnvironmentConfiguration;
|
|
102
|
+
return _regeneratorRuntime__default["default"].wrap(function _callee2$(_context6) {
|
|
103
|
+
while (1) {
|
|
104
|
+
switch (_context6.prev = _context6.next) {
|
|
105
|
+
case 0:
|
|
106
|
+
// NOTE: On CI the *.ci secrests are not excluded. Locally the are in case
|
|
107
|
+
// decrypted files are available on a developer's machine.
|
|
108
|
+
ignoredGlobs = ['**/*.enc', '**/*.template'];
|
|
109
|
+
ignoredCIGlobs = ['**/*.ci'];
|
|
110
|
+
allIgnoredGlobs = isCI ? ignoredGlobs : _concatInstanceProperty__default["default"](ignoredGlobs).call(ignoredGlobs, ignoredCIGlobs);
|
|
111
|
+
if (isCI) {
|
|
112
|
+
console.log("\u2139\uFE0F 'CI' environment variable is defined. Assuming operating from a CI system.");
|
|
113
|
+
} else {
|
|
114
|
+
console.log("\u2139\uFE0F 'CI' environment variable is not defined. Assuming you are running locally.");
|
|
115
|
+
}
|
|
116
|
+
console.log("\u2139\uFE0F The ignored globs are: ".concat(allIgnoredGlobs.join(', '), "."));
|
|
117
|
+
_context6.next = 7;
|
|
118
|
+
return loadConfig();
|
|
119
|
+
case 7:
|
|
120
|
+
configResult = _context6.sent;
|
|
121
|
+
allEnvironmentConfigs = configResult === null || configResult === void 0 ? void 0 : configResult.config;
|
|
122
|
+
configForEnvironment = _findInstanceProperty__default["default"](_context2 = allEnvironmentConfigs.environments).call(_context2, function (environment) {
|
|
123
|
+
return environment.name === environmentName;
|
|
124
|
+
});
|
|
125
|
+
if (configForEnvironment) {
|
|
126
|
+
_context6.next = 12;
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
throw new Error("No configuration for ".concat(environmentName, " defined in cosmiconfig for 'cypress-environments'. Please make sure it exists."));
|
|
130
|
+
case 12:
|
|
131
|
+
_context6.next = 14;
|
|
132
|
+
return promisifiedGlob(configForEnvironment.secrets.glob, {
|
|
133
|
+
ignore: allIgnoredGlobs
|
|
134
|
+
});
|
|
135
|
+
case 14:
|
|
136
|
+
secretsFiles = _context6.sent;
|
|
137
|
+
_context6.next = 17;
|
|
138
|
+
return promisifiedGlob(configForEnvironment.config.glob, {
|
|
139
|
+
ignore: allIgnoredGlobs
|
|
140
|
+
});
|
|
141
|
+
case 17:
|
|
142
|
+
configFiles = _context6.sent;
|
|
143
|
+
console.log(_concatInstanceProperty__default["default"](_context3 = "\u2139\uFE0F Found ".concat(secretsFiles.length, " secret file(s) and ")).call(_context3, configFiles.length, " config file(s) matching the defined globs."));
|
|
144
|
+
if (secretsFiles.length === 0 || configFiles.length === 0) {
|
|
145
|
+
console.log("\u2139\uFE0F Secrets files glob is: ".concat(configForEnvironment.secrets.glob));
|
|
146
|
+
console.log("\u2139\uFE0F Config files glob is: ".concat(configForEnvironment.config.glob));
|
|
147
|
+
}
|
|
148
|
+
mergedConfigurationAndSecrests = _reduceInstanceProperty__default["default"](_context4 = _concatInstanceProperty__default["default"](_context5 = []).call(_context5, _toConsumableArray(configFiles), _toConsumableArray(secretsFiles))).call(_context4, function (previousParsedEnvFileContents, nextEnvFilePath) {
|
|
149
|
+
var parsedEnvFileContents = getParsedEnvFileContents(nextEnvFilePath);
|
|
150
|
+
var matchingParsedEnvFileContentsForCIOrLocal = null;
|
|
151
|
+
if (!_endsWithInstanceProperty__default["default"](nextEnvFilePath).call(nextEnvFilePath, '.local') && !_endsWithInstanceProperty__default["default"](nextEnvFilePath).call(nextEnvFilePath, '.ci')) {
|
|
152
|
+
matchingParsedEnvFileContentsForCIOrLocal = isCI ? getParsedEnvFileContents("".concat(nextEnvFilePath, ".ci")) : getParsedEnvFileContents("".concat(nextEnvFilePath, ".local"));
|
|
153
|
+
}
|
|
154
|
+
return _objectSpread(_objectSpread(_objectSpread({}, previousParsedEnvFileContents), parsedEnvFileContents), matchingParsedEnvFileContentsForCIOrLocal);
|
|
155
|
+
}, {});
|
|
156
|
+
_context6.next = 23;
|
|
157
|
+
return pkgDir__default["default"](__dirname);
|
|
158
|
+
case 23:
|
|
159
|
+
rootDir = _context6.sent;
|
|
160
|
+
sharedEnvironmentConfiguration = null;
|
|
161
|
+
if (rootDir) {
|
|
162
|
+
pathToSharedEnvironmentConfiguration = path__default["default"].join(rootDir, 'config', ".env.".concat(environmentName, ".config"));
|
|
163
|
+
if (fs__default["default"].existsSync(pathToSharedEnvironmentConfiguration)) {
|
|
164
|
+
sharedEnvironmentConfiguration = getParsedEnvFileContents(pathToSharedEnvironmentConfiguration);
|
|
165
|
+
} else {
|
|
166
|
+
console.log("\u2139\uFE0F No shared configuration for ".concat(environmentName, " defined."));
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return _context6.abrupt("return", _objectSpread(_objectSpread({}, sharedEnvironmentConfiguration), mergedConfigurationAndSecrests));
|
|
170
|
+
case 27:
|
|
171
|
+
case "end":
|
|
172
|
+
return _context6.stop();
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}, _callee2);
|
|
176
|
+
}));
|
|
177
|
+
return _getConfigurationForEnvironment.apply(this, arguments);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
exports.getConfigurationForEnvironment = getConfigurationForEnvironment;
|
|
@@ -1,16 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
// this file might look strange and you might be wondering what it's for
|
|
3
|
-
// it's lets you import your source files by importing this entrypoint
|
|
4
|
-
// as you would import it if it was built with preconstruct build
|
|
5
|
-
// this file is slightly different to some others though
|
|
6
|
-
// it has a require hook which compiles your code with Babel
|
|
7
|
-
// this means that you don't have to set up @babel/register or anything like that
|
|
8
|
-
// but you can still require this module and it'll be compiled
|
|
1
|
+
'use strict';
|
|
9
2
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
unregister();
|
|
3
|
+
if (process.env.NODE_ENV === "production") {
|
|
4
|
+
module.exports = require("./commercetools-frontend-cypress-environments.cjs.prod.js");
|
|
5
|
+
} else {
|
|
6
|
+
module.exports = require("./commercetools-frontend-cypress-environments.cjs.dev.js");
|
|
7
|
+
}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
|
|
6
|
+
var _toConsumableArray = require('@babel/runtime-corejs3/helpers/toConsumableArray');
|
|
7
|
+
var _asyncToGenerator = require('@babel/runtime-corejs3/helpers/asyncToGenerator');
|
|
8
|
+
var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
|
|
9
|
+
var _findInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/find');
|
|
10
|
+
var _reduceInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/reduce');
|
|
11
|
+
var _endsWithInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/ends-with');
|
|
12
|
+
var _Object$keys = require('@babel/runtime-corejs3/core-js-stable/object/keys');
|
|
13
|
+
var _Object$getOwnPropertySymbols = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols');
|
|
14
|
+
var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/filter');
|
|
15
|
+
var _Object$getOwnPropertyDescriptor = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor');
|
|
16
|
+
var _forEachInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/for-each');
|
|
17
|
+
var _Object$getOwnPropertyDescriptors = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors');
|
|
18
|
+
var _Object$defineProperties = require('@babel/runtime-corejs3/core-js-stable/object/define-properties');
|
|
19
|
+
var _Object$defineProperty = require('@babel/runtime-corejs3/core-js-stable/object/define-property');
|
|
20
|
+
var _regeneratorRuntime = require('@babel/runtime-corejs3/regenerator');
|
|
21
|
+
var path = require('path');
|
|
22
|
+
var fs = require('fs');
|
|
23
|
+
var util = require('util');
|
|
24
|
+
var glob = require('glob');
|
|
25
|
+
var dotenv = require('dotenv');
|
|
26
|
+
var pkgDir = require('pkg-dir');
|
|
27
|
+
var cosmiconfig = require('cosmiconfig');
|
|
28
|
+
|
|
29
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
30
|
+
|
|
31
|
+
var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
|
|
32
|
+
var _findInstanceProperty__default = /*#__PURE__*/_interopDefault(_findInstanceProperty);
|
|
33
|
+
var _reduceInstanceProperty__default = /*#__PURE__*/_interopDefault(_reduceInstanceProperty);
|
|
34
|
+
var _endsWithInstanceProperty__default = /*#__PURE__*/_interopDefault(_endsWithInstanceProperty);
|
|
35
|
+
var _Object$keys__default = /*#__PURE__*/_interopDefault(_Object$keys);
|
|
36
|
+
var _Object$getOwnPropertySymbols__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertySymbols);
|
|
37
|
+
var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty);
|
|
38
|
+
var _Object$getOwnPropertyDescriptor__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptor);
|
|
39
|
+
var _forEachInstanceProperty__default = /*#__PURE__*/_interopDefault(_forEachInstanceProperty);
|
|
40
|
+
var _Object$getOwnPropertyDescriptors__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptors);
|
|
41
|
+
var _Object$defineProperties__default = /*#__PURE__*/_interopDefault(_Object$defineProperties);
|
|
42
|
+
var _Object$defineProperty__default = /*#__PURE__*/_interopDefault(_Object$defineProperty);
|
|
43
|
+
var _regeneratorRuntime__default = /*#__PURE__*/_interopDefault(_regeneratorRuntime);
|
|
44
|
+
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
45
|
+
var fs__default = /*#__PURE__*/_interopDefault(fs);
|
|
46
|
+
var glob__default = /*#__PURE__*/_interopDefault(glob);
|
|
47
|
+
var dotenv__default = /*#__PURE__*/_interopDefault(dotenv);
|
|
48
|
+
var pkgDir__default = /*#__PURE__*/_interopDefault(pkgDir);
|
|
49
|
+
|
|
50
|
+
function ownKeys(object, enumerableOnly) { var keys = _Object$keys__default["default"](object); if (_Object$getOwnPropertySymbols__default["default"]) { var symbols = _Object$getOwnPropertySymbols__default["default"](object); enumerableOnly && (symbols = _filterInstanceProperty__default["default"](symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor__default["default"](object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
51
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context7, _context8; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty__default["default"](_context7 = ownKeys(Object(source), !0)).call(_context7, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)) : _forEachInstanceProperty__default["default"](_context8 = ownKeys(Object(source))).call(_context8, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } return target; }
|
|
52
|
+
var cypressEnvironmentsConfigExplorer = cosmiconfig.cosmiconfig('cypress-environments');
|
|
53
|
+
var isCI = String(process.env.CI) === 'true';
|
|
54
|
+
var promisifiedGlob = util.promisify(glob__default["default"]);
|
|
55
|
+
function getParsedEnvFileContents(envPath) {
|
|
56
|
+
if (fs__default["default"].existsSync(envPath)) {
|
|
57
|
+
console.log("\u2705 Found and loading environment variables from: '".concat(envPath, "'"));
|
|
58
|
+
var envFileContents = fs__default["default"].readFileSync(envPath, {
|
|
59
|
+
encoding: 'utf8'
|
|
60
|
+
});
|
|
61
|
+
var configuration = dotenv__default["default"].parse(envFileContents);
|
|
62
|
+
return configuration;
|
|
63
|
+
} else {
|
|
64
|
+
console.log("\u2139\uFE0F No environment variables at: '".concat(envPath, "'. If needed create it or duplicate the template file."));
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function loadConfig() {
|
|
69
|
+
return _loadConfig.apply(this, arguments);
|
|
70
|
+
}
|
|
71
|
+
function _loadConfig() {
|
|
72
|
+
_loadConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee() {
|
|
73
|
+
return _regeneratorRuntime__default["default"].wrap(function _callee$(_context) {
|
|
74
|
+
while (1) {
|
|
75
|
+
switch (_context.prev = _context.next) {
|
|
76
|
+
case 0:
|
|
77
|
+
_context.prev = 0;
|
|
78
|
+
_context.next = 3;
|
|
79
|
+
return cypressEnvironmentsConfigExplorer.search();
|
|
80
|
+
case 3:
|
|
81
|
+
return _context.abrupt("return", _context.sent);
|
|
82
|
+
case 6:
|
|
83
|
+
_context.prev = 6;
|
|
84
|
+
_context.t0 = _context["catch"](0);
|
|
85
|
+
throw new Error("Failed loading a Cypress environments configuration. Create a cosmiconfig for 'cypress-environments' for example 'cypress-environments.config.cjs'.");
|
|
86
|
+
case 9:
|
|
87
|
+
case "end":
|
|
88
|
+
return _context.stop();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}, _callee, null, [[0, 6]]);
|
|
92
|
+
}));
|
|
93
|
+
return _loadConfig.apply(this, arguments);
|
|
94
|
+
}
|
|
95
|
+
function getConfigurationForEnvironment(_x) {
|
|
96
|
+
return _getConfigurationForEnvironment.apply(this, arguments);
|
|
97
|
+
}
|
|
98
|
+
function _getConfigurationForEnvironment() {
|
|
99
|
+
_getConfigurationForEnvironment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee2(environmentName) {
|
|
100
|
+
var _context2, _context3, _context4, _context5;
|
|
101
|
+
var ignoredGlobs, ignoredCIGlobs, allIgnoredGlobs, configResult, allEnvironmentConfigs, configForEnvironment, secretsFiles, configFiles, mergedConfigurationAndSecrests, rootDir, sharedEnvironmentConfiguration, pathToSharedEnvironmentConfiguration;
|
|
102
|
+
return _regeneratorRuntime__default["default"].wrap(function _callee2$(_context6) {
|
|
103
|
+
while (1) {
|
|
104
|
+
switch (_context6.prev = _context6.next) {
|
|
105
|
+
case 0:
|
|
106
|
+
// NOTE: On CI the *.ci secrests are not excluded. Locally the are in case
|
|
107
|
+
// decrypted files are available on a developer's machine.
|
|
108
|
+
ignoredGlobs = ['**/*.enc', '**/*.template'];
|
|
109
|
+
ignoredCIGlobs = ['**/*.ci'];
|
|
110
|
+
allIgnoredGlobs = isCI ? ignoredGlobs : _concatInstanceProperty__default["default"](ignoredGlobs).call(ignoredGlobs, ignoredCIGlobs);
|
|
111
|
+
if (isCI) {
|
|
112
|
+
console.log("\u2139\uFE0F 'CI' environment variable is defined. Assuming operating from a CI system.");
|
|
113
|
+
} else {
|
|
114
|
+
console.log("\u2139\uFE0F 'CI' environment variable is not defined. Assuming you are running locally.");
|
|
115
|
+
}
|
|
116
|
+
console.log("\u2139\uFE0F The ignored globs are: ".concat(allIgnoredGlobs.join(', '), "."));
|
|
117
|
+
_context6.next = 7;
|
|
118
|
+
return loadConfig();
|
|
119
|
+
case 7:
|
|
120
|
+
configResult = _context6.sent;
|
|
121
|
+
allEnvironmentConfigs = configResult === null || configResult === void 0 ? void 0 : configResult.config;
|
|
122
|
+
configForEnvironment = _findInstanceProperty__default["default"](_context2 = allEnvironmentConfigs.environments).call(_context2, function (environment) {
|
|
123
|
+
return environment.name === environmentName;
|
|
124
|
+
});
|
|
125
|
+
if (configForEnvironment) {
|
|
126
|
+
_context6.next = 12;
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
throw new Error("No configuration for ".concat(environmentName, " defined in cosmiconfig for 'cypress-environments'. Please make sure it exists."));
|
|
130
|
+
case 12:
|
|
131
|
+
_context6.next = 14;
|
|
132
|
+
return promisifiedGlob(configForEnvironment.secrets.glob, {
|
|
133
|
+
ignore: allIgnoredGlobs
|
|
134
|
+
});
|
|
135
|
+
case 14:
|
|
136
|
+
secretsFiles = _context6.sent;
|
|
137
|
+
_context6.next = 17;
|
|
138
|
+
return promisifiedGlob(configForEnvironment.config.glob, {
|
|
139
|
+
ignore: allIgnoredGlobs
|
|
140
|
+
});
|
|
141
|
+
case 17:
|
|
142
|
+
configFiles = _context6.sent;
|
|
143
|
+
console.log(_concatInstanceProperty__default["default"](_context3 = "\u2139\uFE0F Found ".concat(secretsFiles.length, " secret file(s) and ")).call(_context3, configFiles.length, " config file(s) matching the defined globs."));
|
|
144
|
+
if (secretsFiles.length === 0 || configFiles.length === 0) {
|
|
145
|
+
console.log("\u2139\uFE0F Secrets files glob is: ".concat(configForEnvironment.secrets.glob));
|
|
146
|
+
console.log("\u2139\uFE0F Config files glob is: ".concat(configForEnvironment.config.glob));
|
|
147
|
+
}
|
|
148
|
+
mergedConfigurationAndSecrests = _reduceInstanceProperty__default["default"](_context4 = _concatInstanceProperty__default["default"](_context5 = []).call(_context5, _toConsumableArray(configFiles), _toConsumableArray(secretsFiles))).call(_context4, function (previousParsedEnvFileContents, nextEnvFilePath) {
|
|
149
|
+
var parsedEnvFileContents = getParsedEnvFileContents(nextEnvFilePath);
|
|
150
|
+
var matchingParsedEnvFileContentsForCIOrLocal = null;
|
|
151
|
+
if (!_endsWithInstanceProperty__default["default"](nextEnvFilePath).call(nextEnvFilePath, '.local') && !_endsWithInstanceProperty__default["default"](nextEnvFilePath).call(nextEnvFilePath, '.ci')) {
|
|
152
|
+
matchingParsedEnvFileContentsForCIOrLocal = isCI ? getParsedEnvFileContents("".concat(nextEnvFilePath, ".ci")) : getParsedEnvFileContents("".concat(nextEnvFilePath, ".local"));
|
|
153
|
+
}
|
|
154
|
+
return _objectSpread(_objectSpread(_objectSpread({}, previousParsedEnvFileContents), parsedEnvFileContents), matchingParsedEnvFileContentsForCIOrLocal);
|
|
155
|
+
}, {});
|
|
156
|
+
_context6.next = 23;
|
|
157
|
+
return pkgDir__default["default"](__dirname);
|
|
158
|
+
case 23:
|
|
159
|
+
rootDir = _context6.sent;
|
|
160
|
+
sharedEnvironmentConfiguration = null;
|
|
161
|
+
if (rootDir) {
|
|
162
|
+
pathToSharedEnvironmentConfiguration = path__default["default"].join(rootDir, 'config', ".env.".concat(environmentName, ".config"));
|
|
163
|
+
if (fs__default["default"].existsSync(pathToSharedEnvironmentConfiguration)) {
|
|
164
|
+
sharedEnvironmentConfiguration = getParsedEnvFileContents(pathToSharedEnvironmentConfiguration);
|
|
165
|
+
} else {
|
|
166
|
+
console.log("\u2139\uFE0F No shared configuration for ".concat(environmentName, " defined."));
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return _context6.abrupt("return", _objectSpread(_objectSpread({}, sharedEnvironmentConfiguration), mergedConfigurationAndSecrests));
|
|
170
|
+
case 27:
|
|
171
|
+
case "end":
|
|
172
|
+
return _context6.stop();
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}, _callee2);
|
|
176
|
+
}));
|
|
177
|
+
return _getConfigurationForEnvironment.apply(this, arguments);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
exports.getConfigurationForEnvironment = getConfigurationForEnvironment;
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import _defineProperty from '@babel/runtime-corejs3/helpers/esm/defineProperty';
|
|
2
|
+
import _toConsumableArray from '@babel/runtime-corejs3/helpers/esm/toConsumableArray';
|
|
3
|
+
import _asyncToGenerator from '@babel/runtime-corejs3/helpers/esm/asyncToGenerator';
|
|
4
|
+
import _concatInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/concat';
|
|
5
|
+
import _findInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/find';
|
|
6
|
+
import _reduceInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/reduce';
|
|
7
|
+
import _endsWithInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/ends-with';
|
|
8
|
+
import _Object$keys from '@babel/runtime-corejs3/core-js-stable/object/keys';
|
|
9
|
+
import _Object$getOwnPropertySymbols from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols';
|
|
10
|
+
import _filterInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/filter';
|
|
11
|
+
import _Object$getOwnPropertyDescriptor from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor';
|
|
12
|
+
import _forEachInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/for-each';
|
|
13
|
+
import _Object$getOwnPropertyDescriptors from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors';
|
|
14
|
+
import _Object$defineProperties from '@babel/runtime-corejs3/core-js-stable/object/define-properties';
|
|
15
|
+
import _Object$defineProperty from '@babel/runtime-corejs3/core-js-stable/object/define-property';
|
|
16
|
+
import _regeneratorRuntime from '@babel/runtime-corejs3/regenerator';
|
|
17
|
+
import path from 'path';
|
|
18
|
+
import fs from 'fs';
|
|
19
|
+
import { promisify } from 'util';
|
|
20
|
+
import glob from 'glob';
|
|
21
|
+
import dotenv from 'dotenv';
|
|
22
|
+
import pkgDir from 'pkg-dir';
|
|
23
|
+
import { cosmiconfig } from 'cosmiconfig';
|
|
24
|
+
|
|
25
|
+
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
26
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context7, _context8; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context7 = ownKeys(Object(source), !0)).call(_context7, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context8 = ownKeys(Object(source))).call(_context8, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
27
|
+
var cypressEnvironmentsConfigExplorer = cosmiconfig('cypress-environments');
|
|
28
|
+
var isCI = String(process.env.CI) === 'true';
|
|
29
|
+
var promisifiedGlob = promisify(glob);
|
|
30
|
+
function getParsedEnvFileContents(envPath) {
|
|
31
|
+
if (fs.existsSync(envPath)) {
|
|
32
|
+
console.log("\u2705 Found and loading environment variables from: '".concat(envPath, "'"));
|
|
33
|
+
var envFileContents = fs.readFileSync(envPath, {
|
|
34
|
+
encoding: 'utf8'
|
|
35
|
+
});
|
|
36
|
+
var configuration = dotenv.parse(envFileContents);
|
|
37
|
+
return configuration;
|
|
38
|
+
} else {
|
|
39
|
+
console.log("\u2139\uFE0F No environment variables at: '".concat(envPath, "'. If needed create it or duplicate the template file."));
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function loadConfig() {
|
|
44
|
+
return _loadConfig.apply(this, arguments);
|
|
45
|
+
}
|
|
46
|
+
function _loadConfig() {
|
|
47
|
+
_loadConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
48
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
49
|
+
while (1) {
|
|
50
|
+
switch (_context.prev = _context.next) {
|
|
51
|
+
case 0:
|
|
52
|
+
_context.prev = 0;
|
|
53
|
+
_context.next = 3;
|
|
54
|
+
return cypressEnvironmentsConfigExplorer.search();
|
|
55
|
+
case 3:
|
|
56
|
+
return _context.abrupt("return", _context.sent);
|
|
57
|
+
case 6:
|
|
58
|
+
_context.prev = 6;
|
|
59
|
+
_context.t0 = _context["catch"](0);
|
|
60
|
+
throw new Error("Failed loading a Cypress environments configuration. Create a cosmiconfig for 'cypress-environments' for example 'cypress-environments.config.cjs'.");
|
|
61
|
+
case 9:
|
|
62
|
+
case "end":
|
|
63
|
+
return _context.stop();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}, _callee, null, [[0, 6]]);
|
|
67
|
+
}));
|
|
68
|
+
return _loadConfig.apply(this, arguments);
|
|
69
|
+
}
|
|
70
|
+
function getConfigurationForEnvironment(_x) {
|
|
71
|
+
return _getConfigurationForEnvironment.apply(this, arguments);
|
|
72
|
+
}
|
|
73
|
+
function _getConfigurationForEnvironment() {
|
|
74
|
+
_getConfigurationForEnvironment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(environmentName) {
|
|
75
|
+
var _context2, _context3, _context4, _context5;
|
|
76
|
+
var ignoredGlobs, ignoredCIGlobs, allIgnoredGlobs, configResult, allEnvironmentConfigs, configForEnvironment, secretsFiles, configFiles, mergedConfigurationAndSecrests, rootDir, sharedEnvironmentConfiguration, pathToSharedEnvironmentConfiguration;
|
|
77
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context6) {
|
|
78
|
+
while (1) {
|
|
79
|
+
switch (_context6.prev = _context6.next) {
|
|
80
|
+
case 0:
|
|
81
|
+
// NOTE: On CI the *.ci secrests are not excluded. Locally the are in case
|
|
82
|
+
// decrypted files are available on a developer's machine.
|
|
83
|
+
ignoredGlobs = ['**/*.enc', '**/*.template'];
|
|
84
|
+
ignoredCIGlobs = ['**/*.ci'];
|
|
85
|
+
allIgnoredGlobs = isCI ? ignoredGlobs : _concatInstanceProperty(ignoredGlobs).call(ignoredGlobs, ignoredCIGlobs);
|
|
86
|
+
if (isCI) {
|
|
87
|
+
console.log("\u2139\uFE0F 'CI' environment variable is defined. Assuming operating from a CI system.");
|
|
88
|
+
} else {
|
|
89
|
+
console.log("\u2139\uFE0F 'CI' environment variable is not defined. Assuming you are running locally.");
|
|
90
|
+
}
|
|
91
|
+
console.log("\u2139\uFE0F The ignored globs are: ".concat(allIgnoredGlobs.join(', '), "."));
|
|
92
|
+
_context6.next = 7;
|
|
93
|
+
return loadConfig();
|
|
94
|
+
case 7:
|
|
95
|
+
configResult = _context6.sent;
|
|
96
|
+
allEnvironmentConfigs = configResult === null || configResult === void 0 ? void 0 : configResult.config;
|
|
97
|
+
configForEnvironment = _findInstanceProperty(_context2 = allEnvironmentConfigs.environments).call(_context2, function (environment) {
|
|
98
|
+
return environment.name === environmentName;
|
|
99
|
+
});
|
|
100
|
+
if (configForEnvironment) {
|
|
101
|
+
_context6.next = 12;
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
throw new Error("No configuration for ".concat(environmentName, " defined in cosmiconfig for 'cypress-environments'. Please make sure it exists."));
|
|
105
|
+
case 12:
|
|
106
|
+
_context6.next = 14;
|
|
107
|
+
return promisifiedGlob(configForEnvironment.secrets.glob, {
|
|
108
|
+
ignore: allIgnoredGlobs
|
|
109
|
+
});
|
|
110
|
+
case 14:
|
|
111
|
+
secretsFiles = _context6.sent;
|
|
112
|
+
_context6.next = 17;
|
|
113
|
+
return promisifiedGlob(configForEnvironment.config.glob, {
|
|
114
|
+
ignore: allIgnoredGlobs
|
|
115
|
+
});
|
|
116
|
+
case 17:
|
|
117
|
+
configFiles = _context6.sent;
|
|
118
|
+
console.log(_concatInstanceProperty(_context3 = "\u2139\uFE0F Found ".concat(secretsFiles.length, " secret file(s) and ")).call(_context3, configFiles.length, " config file(s) matching the defined globs."));
|
|
119
|
+
if (secretsFiles.length === 0 || configFiles.length === 0) {
|
|
120
|
+
console.log("\u2139\uFE0F Secrets files glob is: ".concat(configForEnvironment.secrets.glob));
|
|
121
|
+
console.log("\u2139\uFE0F Config files glob is: ".concat(configForEnvironment.config.glob));
|
|
122
|
+
}
|
|
123
|
+
mergedConfigurationAndSecrests = _reduceInstanceProperty(_context4 = _concatInstanceProperty(_context5 = []).call(_context5, _toConsumableArray(configFiles), _toConsumableArray(secretsFiles))).call(_context4, function (previousParsedEnvFileContents, nextEnvFilePath) {
|
|
124
|
+
var parsedEnvFileContents = getParsedEnvFileContents(nextEnvFilePath);
|
|
125
|
+
var matchingParsedEnvFileContentsForCIOrLocal = null;
|
|
126
|
+
if (!_endsWithInstanceProperty(nextEnvFilePath).call(nextEnvFilePath, '.local') && !_endsWithInstanceProperty(nextEnvFilePath).call(nextEnvFilePath, '.ci')) {
|
|
127
|
+
matchingParsedEnvFileContentsForCIOrLocal = isCI ? getParsedEnvFileContents("".concat(nextEnvFilePath, ".ci")) : getParsedEnvFileContents("".concat(nextEnvFilePath, ".local"));
|
|
128
|
+
}
|
|
129
|
+
return _objectSpread(_objectSpread(_objectSpread({}, previousParsedEnvFileContents), parsedEnvFileContents), matchingParsedEnvFileContentsForCIOrLocal);
|
|
130
|
+
}, {});
|
|
131
|
+
_context6.next = 23;
|
|
132
|
+
return pkgDir(__dirname);
|
|
133
|
+
case 23:
|
|
134
|
+
rootDir = _context6.sent;
|
|
135
|
+
sharedEnvironmentConfiguration = null;
|
|
136
|
+
if (rootDir) {
|
|
137
|
+
pathToSharedEnvironmentConfiguration = path.join(rootDir, 'config', ".env.".concat(environmentName, ".config"));
|
|
138
|
+
if (fs.existsSync(pathToSharedEnvironmentConfiguration)) {
|
|
139
|
+
sharedEnvironmentConfiguration = getParsedEnvFileContents(pathToSharedEnvironmentConfiguration);
|
|
140
|
+
} else {
|
|
141
|
+
console.log("\u2139\uFE0F No shared configuration for ".concat(environmentName, " defined."));
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return _context6.abrupt("return", _objectSpread(_objectSpread({}, sharedEnvironmentConfiguration), mergedConfigurationAndSecrests));
|
|
145
|
+
case 27:
|
|
146
|
+
case "end":
|
|
147
|
+
return _context6.stop();
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}, _callee2);
|
|
151
|
+
}));
|
|
152
|
+
return _getConfigurationForEnvironment.apply(this, arguments);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export { getConfigurationForEnvironment };
|
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.4",
|
|
4
4
|
"description": "Cypress package to setup environment configuration using dotenv files",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
@@ -19,13 +19,17 @@
|
|
|
19
19
|
"README.md"
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"
|
|
23
|
-
"
|
|
22
|
+
"@babel/runtime": "^7.19.0",
|
|
23
|
+
"@babel/runtime-corejs3": "^7.19.0",
|
|
24
|
+
"cosmiconfig": "8.0.0",
|
|
25
|
+
"dotenv": "16.0.3",
|
|
24
26
|
"glob": "8.0.3",
|
|
25
27
|
"pkg-dir": "5.0.0"
|
|
26
28
|
},
|
|
27
29
|
"devDependencies": {
|
|
28
|
-
"
|
|
30
|
+
"@tsconfig/node18": "1.0.1",
|
|
31
|
+
"@types/glob": "8.0.0",
|
|
32
|
+
"typescript": "^4.8.4"
|
|
29
33
|
},
|
|
30
34
|
"engines": {
|
|
31
35
|
"node": ">=14",
|