Skip to content

Commit

Permalink
Consolidate configuration setup across repository (#685)
Browse files Browse the repository at this point in the history
* Update use of configuration to consistently use .env file. Deprecate use of default.json.

- Add new custom Rush command, 'copy:config', to copy a shared `.env` file to each directory necessary
- Enhance the internal-tools copyConfig script to allow a custom path for `.env` file
- Mark main IModelJsConfig class as deprecated
  • Loading branch information
calebmshafer committed Feb 10, 2021
1 parent 7aca9fa commit e2a2e97
Show file tree
Hide file tree
Showing 78 changed files with 404 additions and 242 deletions.
4 changes: 3 additions & 1 deletion clients/context-registry/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"test:integration": "npm run webpackTests && npm run test:integration:chrome",
"test:integration:chrome": "certa -r chrome --grep \"#integration\"",
"test:integration:electron": "certa -r electron --grep \"#integration\"",
"copy:config": "internal-tools copy-config",
"cover": ""
},
"keywords": [
Expand Down Expand Up @@ -54,6 +55,7 @@
"@types/node": "10.14.1",
"chai": "^4.1.2",
"eslint": "^6.8.0",
"internal-tools": "0.0.0",
"mocha": "^5.2.0",
"nyc": "^14.0.0",
"rimraf": "^3.0.2",
Expand All @@ -70,4 +72,4 @@
],
"extends": "plugin:@bentley/imodeljs-recommended"
}
}
}
10 changes: 4 additions & 6 deletions clients/context-registry/src/test/utils/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
const path = require("path");
const glob = require("glob");
const webpack = require("webpack");
const raw = require("@bentley/config-loader/lib/IModelJsConfig").IModelJsConfig.init(true /*suppress error*/, true);
require("@bentley/config-loader").loadEnv(path.join(__dirname, "..", "..", "..", ".env"));

const clientsLib = path.resolve(__dirname, "../../../lib");

Expand Down Expand Up @@ -51,16 +51,14 @@ function createConfig(shouldInstrument) {
// Makes some environment variables available to the JS code, for example:
// if (process.env.NODE_ENV === "development") { ... }. See `./env.js`.
new webpack.DefinePlugin({
"process.env": Object.keys(raw)
"process.env": Object.keys(process.env)
.filter((key) => {
return key.match(/^imjs_/i);
})
.reduce((env, key) => {
env[key] = JSON.stringify(raw[key]);
env[key] = JSON.stringify(process.env[key]);
return env;
}, {
IMODELJS_CORE_DIRNAME: JSON.stringify(path.join(__dirname, "../..")),
}),
}, {}),
})
]
};
Expand Down
4 changes: 3 additions & 1 deletion clients/extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"test:integration:chrome": "certa -r chrome",
"test:integration:electron": "certa -r electron",
"test:integration:node": "certa -r node",
"copy:config": "internal-tools copy-config",
"webpackTests": "webpack --config ./src/test/utils/webpack.config.js 1>&2"
},
"keywords": [
Expand Down Expand Up @@ -51,6 +52,7 @@
"@types/node": "10.14.1",
"chai": "^4.1.2",
"eslint": "^6.8.0",
"internal-tools": "0.0.0",
"mocha": "^5.2.0",
"nyc": "^14.0.0",
"rimraf": "^3.0.2",
Expand All @@ -67,4 +69,4 @@
],
"extends": "plugin:@bentley/imodeljs-recommended"
}
}
}
10 changes: 4 additions & 6 deletions clients/extension/src/test/utils/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
const path = require("path");
const glob = require("glob");
const webpack = require("webpack");
const raw = require("@bentley/config-loader/lib/IModelJsConfig").IModelJsConfig.init(true /*suppress error*/, true);
require("@bentley/config-loader").loadEnv(path.join(__dirname, "..", "..", "..", ".env"));

const clientsLib = path.resolve(__dirname, "../../../lib");

Expand Down Expand Up @@ -51,16 +51,14 @@ function createConfig(shouldInstrument) {
// Makes some environment variables available to the JS code, for example:
// if (process.env.NODE_ENV === "development") { ... }. See `./env.js`.
new webpack.DefinePlugin({
"process.env": Object.keys(raw)
"process.env": Object.keys(process.env)
.filter((key) => {
return key.match(/^imjs_/i);
})
.reduce((env, key) => {
env[key] = JSON.stringify(raw[key]);
env[key] = JSON.stringify(process.env[key]);
return env;
}, {
IMODELJS_CORE_DIRNAME: JSON.stringify(path.join(__dirname, "../..")),
}),
}, {}),
})
]
};
Expand Down
4 changes: 3 additions & 1 deletion clients/forms-data-management/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"test:integration": "npm run webpackTests && npm run test:integration:chrome",
"test:integration:chrome": "certa -r chrome --grep \"#integration\"",
"test:integration:electron": "certa -r electron --grep \"#integration\"",
"copy:config": "internal-tools copy-config",
"cover": ""
},
"keywords": [
Expand Down Expand Up @@ -53,6 +54,7 @@
"@types/node": "10.14.1",
"chai": "^4.1.2",
"eslint": "^6.8.0",
"internal-tools": "0.0.0",
"mocha": "^5.2.0",
"nyc": "^14.0.0",
"rimraf": "^3.0.2",
Expand All @@ -69,4 +71,4 @@
],
"extends": "plugin:@bentley/imodeljs-recommended"
}
}
}
35 changes: 0 additions & 35 deletions clients/forms-data-management/src/test/TestConfig.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,30 @@
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import * as chai from "chai";
import { assert } from "chai";
import { ContextRegistryClient, Project } from "@bentley/context-registry-client";
import { AuthorizedClientRequestContext } from "@bentley/itwin-client";
import { AccessToken, AuthorizedClientRequestContext } from "@bentley/itwin-client";
import { getAccessTokenFromBackend, TestUsers } from "@bentley/oidc-signin-tool/lib/frontend";
import { FormDataManagementClient, FormDefinition } from "../../FormDataManagementClient";
import { TestConfig } from "../TestConfig";

/* eslint-disable @typescript-eslint/naming-convention */

chai.should();

describe("FormDataManagementClient", () => {
let requestContext: AuthorizedClientRequestContext;
const formDataManagementClient: FormDataManagementClient = new FormDataManagementClient();
let projectId: string;

before(async function () {
if (TestConfig.enableMocks) return;
this.enableTimeouts(false);

requestContext = await TestConfig.getAuthorizedClientRequestContext();
const accessToken = await getAccessTokenFromBackend(TestUsers.super);
requestContext = new AuthorizedClientRequestContext((accessToken as any) as AccessToken);

const contextRegistry = new ContextRegistryClient();
const projectName = "iModelJsIntegrationTest";
const project: Project | undefined = await contextRegistry.getProject(requestContext, {
$select: "*",
$filter: `Name+eq+'${TestConfig.projectName}'`,
$filter: `Name+eq+'${projectName}'`,
});
chai.assert(project, `Project ${TestConfig.projectName} not found for user.`);
assert(project, `Project ${projectName} not found for user.`);
projectId = project.wsgId;
});

Expand All @@ -37,6 +34,6 @@ describe("FormDataManagementClient", () => {
requestContext,
projectId
);
chai.assert(formDefinitions);
assert(formDefinitions);
});
});
10 changes: 4 additions & 6 deletions clients/forms-data-management/src/test/utils/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
const path = require("path");
const glob = require("glob");
const webpack = require("webpack");
const raw = require("@bentley/config-loader/lib/IModelJsConfig").IModelJsConfig.init(true /*suppress error*/, true);
require("@bentley/config-loader").loadEnv(path.join(__dirname, "..", "..", "..", ".env"));

const clientsLib = path.resolve(__dirname, "../../../lib");

Expand Down Expand Up @@ -48,16 +48,14 @@ function createConfig(shouldInstrument) {
// Makes some environment variables available to the JS code, for example:
// if (process.env.NODE_ENV === "development") { ... }. See `./env.js`.
new webpack.DefinePlugin({
"process.env": Object.keys(raw)
"process.env": Object.keys(process.env)
.filter((key) => {
return key.match(/^imjs_/i);
})
.reduce((env, key) => {
env[key] = JSON.stringify(raw[key]);
env[key] = JSON.stringify(process.env[key]);
return env;
}, {
IMODELJS_CORE_DIRNAME: JSON.stringify(path.join(__dirname, "../..")),
}),
}, {}),
})
]
};
Expand Down
4 changes: 3 additions & 1 deletion clients/product-settings/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"test:integration": "npm run webpackTests && npm run test:integration:chrome",
"test:integration:chrome": "certa -r chrome --grep \"#integration\"",
"test:integration:electron": "certa -r electron --grep \"#integration\"",
"copy:config": "internal-tools copy-config",
"webpackTests": "webpack --config ./src/test/utils/webpack.config.js 1>&2"
},
"keywords": [
Expand Down Expand Up @@ -52,6 +53,7 @@
"@types/node": "10.14.1",
"chai": "^4.1.2",
"eslint": "^6.8.0",
"internal-tools": "0.0.0",
"mocha": "^5.2.0",
"nyc": "^14.0.0",
"rimraf": "^3.0.2",
Expand All @@ -68,4 +70,4 @@
],
"extends": "plugin:@bentley/imodeljs-recommended"
}
}
}
10 changes: 4 additions & 6 deletions clients/product-settings/src/test/utils/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
const path = require("path");
const glob = require("glob");
const webpack = require("webpack");
const raw = require("@bentley/config-loader/lib/IModelJsConfig").IModelJsConfig.init(true /*suppress error*/, true);
require("@bentley/config-loader").loadEnv(path.join(__dirname, "..", ".."));

const clientsLib = path.resolve(__dirname, "../../../lib");

Expand Down Expand Up @@ -51,16 +51,14 @@ function createConfig(shouldInstrument) {
// Makes some environment variables available to the JS code, for example:
// if (process.env.NODE_ENV === "development") { ... }. See `./env.js`.
new webpack.DefinePlugin({
"process.env": Object.keys(raw)
"process.env": Object.keys(process.env)
.filter((key) => {
return key.match(/^imjs_/i);
})
.reduce((env, key) => {
env[key] = JSON.stringify(raw[key]);
env[key] = JSON.stringify(process.env[key]);
return env;
}, {
IMODELJS_CORE_DIRNAME: JSON.stringify(path.join(__dirname, "../..")),
}),
}, {}),
})
]
};
Expand Down
4 changes: 3 additions & 1 deletion clients/projectshare/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"test:integration": "npm run webpackTests && npm run test:integration:chrome",
"test:integration:chrome": "certa -r chrome --grep \"#integration\"",
"test:integration:electron": "certa -r electron --grep \"#integration\"",
"copy:config": "internal-tools copy-config",
"webpackTests": "webpack --config ./src/test/utils/webpack.config.js 1>&2"
},
"keywords": [
Expand Down Expand Up @@ -52,6 +53,7 @@
"@types/node": "10.14.1",
"chai": "^4.1.2",
"eslint": "^6.8.0",
"internal-tools": "0.0.0",
"mocha": "^5.2.0",
"nyc": "^14.0.0",
"rimraf": "^3.0.2",
Expand All @@ -68,4 +70,4 @@
],
"extends": "plugin:@bentley/imodeljs-recommended"
}
}
}
10 changes: 4 additions & 6 deletions clients/projectshare/src/test/utils/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
const path = require("path");
const glob = require("glob");
const webpack = require("webpack");
const raw = require("@bentley/config-loader/lib/IModelJsConfig").IModelJsConfig.init(true /*suppress error*/, true);
require("@bentley/config-loader").loadEnv(path.join(__dirname, "..", "..", "..", ".env"));

const clientsLib = path.resolve(__dirname, "../../../lib");

Expand Down Expand Up @@ -51,16 +51,14 @@ function createConfig(shouldInstrument) {
// Makes some environment variables available to the JS code, for example:
// if (process.env.NODE_ENV === "development") { ... }. See `./env.js`.
new webpack.DefinePlugin({
"process.env": Object.keys(raw)
"process.env": Object.keys(process.env)
.filter((key) => {
return key.match(/^imjs_/i);
})
.reduce((env, key) => {
env[key] = JSON.stringify(raw[key]);
env[key] = JSON.stringify(process.env[key]);
return env;
}, {
IMODELJS_CORE_DIRNAME: JSON.stringify(path.join(__dirname, "../..")),
}),
}, {}),
})
]
};
Expand Down
4 changes: 3 additions & 1 deletion clients/rbac/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"test:integration": "npm run webpackTests && npm run test:integration:chrome",
"test:integration:chrome": "certa -r chrome --grep \"#integration\"",
"test:integration:electron": "certa -r electron --grep \"#integration\"",
"copy:config": "internal-tools copy-config",
"webpackTests": "webpack --config ./src/test/utils/webpack.config.js 1>&2"
},
"keywords": [
Expand Down Expand Up @@ -53,6 +54,7 @@
"@types/node": "10.14.1",
"chai": "^4.1.2",
"eslint": "^6.8.0",
"internal-tools": "0.0.0",
"mocha": "^5.2.0",
"nyc": "^14.0.0",
"rimraf": "^3.0.2",
Expand All @@ -69,4 +71,4 @@
],
"extends": "plugin:@bentley/imodeljs-recommended"
}
}
}
10 changes: 4 additions & 6 deletions clients/rbac/src/test/utils/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
const path = require("path");
const glob = require("glob");
const webpack = require("webpack");
const raw = require("@bentley/config-loader/lib/IModelJsConfig").IModelJsConfig.init(true /*suppress error*/, true);
require("@bentley/config-loader").loadEnv(path.join(__dirname, "..", "..", "..", ".env"));

const clientsLib = path.resolve(__dirname, "../../../lib");

Expand Down Expand Up @@ -51,16 +51,14 @@ function createConfig(shouldInstrument) {
// Makes some environment variables available to the JS code, for example:
// if (process.env.NODE_ENV === "development") { ... }. See `./env.js`.
new webpack.DefinePlugin({
"process.env": Object.keys(raw)
"process.env": Object.keys(process.env)
.filter((key) => {
return key.match(/^imjs_/i);
})
.reduce((env, key) => {
env[key] = JSON.stringify(raw[key]);
env[key] = JSON.stringify(process.env[key]);
return env;
}, {
IMODELJS_CORE_DIRNAME: JSON.stringify(path.join(__dirname, "../..")),
}),
}, {}),
})
]
};
Expand Down

0 comments on commit e2a2e97

Please sign in to comment.