Skip to content

Commit

Permalink
feat: add generator submodule
Browse files Browse the repository at this point in the history
OKTA-417465
<<<Jenkins Check-In of Tested SHA: 195793c for [email protected]>>>
Artifact: okta-react
Files changed count: 164
PR Link: "#155"
  • Loading branch information
shuowu authored and eng-prod-CI-bot-okta committed Aug 27, 2021
1 parent 9bd6305 commit 41aa11f
Show file tree
Hide file tree
Showing 164 changed files with 11,019 additions and 261 deletions.
9 changes: 8 additions & 1 deletion .bacon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,16 @@ test_suites:
script_name: e2e
criteria: MERGE
queue_name: small
- name: publish
- name: e2e-samples
script_path: /root/okta/okta-react/scripts
sort_order: '4'
timeout: '15'
script_name: e2e-samples
criteria: MERGE
queue_name: small
- name: publish
script_path: /root/okta/okta-react/scripts
sort_order: '5'
timeout: '60'
script_name: publish
criteria: MERGE
Expand Down
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
generated/**/* linguist-generated=true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
dist
build2
node_modules
.DS_Store
testenv
Expand Down
7 changes: 7 additions & 0 deletions env/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"env": {
"commonjs": true,
"es6": true,
"node": true
}
}
85 changes: 85 additions & 0 deletions env/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*!
* Copyright (c) 2015-present, Okta, Inc. and/or its affiliates. All rights reserved.
* The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.")
*
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
* See the License for the specific language governing permissions and limitations under the License.
*/


const dotenv = require('dotenv');
const yaml = require('js-yaml');
const fs = require('fs');
const path = require('path');
const ROOT_DIR = path.resolve(__dirname, '..');

// Read environment variables from "testenv". Override environment vars if they are already set.
const TESTENV = path.resolve(ROOT_DIR, 'testenv');

// Multiple sets of environment variables can be stored in a file called "testenv.yml"
const TESTENV_YAML = path.resolve(ROOT_DIR, 'testenv.yml');

if (fs.existsSync(TESTENV)) {
setEnvironmentVarsFromTestEnv();
}

function setEnvironmentVars(envConfig) {
Object.keys(envConfig).forEach((k) => {
if (process.env[k] !== envConfig[k]) {
console.log(`Setting a new value for environment variable "${k}"`);
}
process.env[k] = envConfig[k];
});
}

function setEnvironmentVarsFromTestEnv() {
if (!fs.existsSync(TESTENV)) {
return;
}
const envConfig = dotenv.parse(fs.readFileSync(TESTENV));
setEnvironmentVars(envConfig);
}

function loadTestEnvYaml() {
if (!fs.existsSync(TESTENV_YAML)) {
return;
}

return yaml.load(fs.readFileSync(TESTENV_YAML));
}

function getTestEnvironmentNames() {
const doc = loadTestEnvYaml();
if (!doc) {
return;
}
return Object.keys(doc);
}

function setEnvironmentVarsFromTestEnvYaml(name) {
const doc = loadTestEnvYaml();
if (!doc) {
return;
}

if (doc.default) {
console.log(`Loading environment variables from testenv.yml: "default"`);
setEnvironmentVars(doc.default);
}

if (doc[name]) {
console.log(`Loading environment variables from testenv.yml: "${name}"`);
setEnvironmentVars(doc[name]);
}
}

module.exports = {
setEnvironmentVars,
setEnvironmentVarsFromTestEnv,
setEnvironmentVarsFromTestEnvYaml,
getTestEnvironmentNames,
};
10 changes: 10 additions & 0 deletions env/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "@okta/env",
"version": "1.0.0",
"main": "index.js",
"private": true,
"dependencies": {
"dotenv": "^8.2.0",
"js-yaml": "^4.1.0"
}
}
3 changes: 3 additions & 0 deletions generated/samples/custom-login/.env

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions generated/samples/custom-login/.eslintrc.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions generated/samples/custom-login/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

83 changes: 83 additions & 0 deletions generated/samples/custom-login/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 48 additions & 0 deletions generated/samples/custom-login/config-overrides.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions generated/samples/custom-login/env/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 41aa11f

Please sign in to comment.