mirror of
https://github.com/bitwarden/browser
synced 2025-12-15 15:53:27 +00:00
[AC-2579] Set up bit-cli folder (#9092)
* Create bit-cli folder with configs * Add bit-cli to workspace * Refactor CLI app structure * services are managed by the ServiceContainer * programs are registered by register(Oss|Bit)Program * the app is bootstrapped by Main * Reapply changes from #9099 * Reapply changes from #8604 * Reapply changes from #9115
This commit is contained in:
5
bitwarden_license/bit-cli/.eslintrc.json
Normal file
5
bitwarden_license/bit-cli/.eslintrc.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"env": {
|
||||
"node": true
|
||||
}
|
||||
}
|
||||
16
bitwarden_license/bit-cli/jest.config.js
Normal file
16
bitwarden_license/bit-cli/jest.config.js
Normal file
@@ -0,0 +1,16 @@
|
||||
const { pathsToModuleNameMapper } = require("ts-jest");
|
||||
|
||||
const { compilerOptions } = require("./tsconfig");
|
||||
|
||||
const sharedConfig = require("../../libs/shared/jest.config.ts");
|
||||
|
||||
/** @type {import('jest').Config} */
|
||||
module.exports = {
|
||||
...sharedConfig,
|
||||
preset: "ts-jest",
|
||||
testEnvironment: "node",
|
||||
setupFilesAfterEnv: ["<rootDir>/../../apps/cli/test.setup.ts"],
|
||||
moduleNameMapper: pathsToModuleNameMapper(compilerOptions?.paths || {}, {
|
||||
prefix: "<rootDir>/",
|
||||
}),
|
||||
};
|
||||
5
bitwarden_license/bit-cli/src/bw.spec.ts
Normal file
5
bitwarden_license/bit-cli/src/bw.spec.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
describe("Jest", () => {
|
||||
it("is set up", () => {
|
||||
expect(true).toBeTruthy();
|
||||
});
|
||||
});
|
||||
20
bitwarden_license/bit-cli/src/bw.ts
Normal file
20
bitwarden_license/bit-cli/src/bw.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { program } from "commander";
|
||||
|
||||
import { registerOssPrograms } from "@bitwarden/cli/register-oss-programs";
|
||||
|
||||
import { registerBitPrograms } from "./register-bit-programs";
|
||||
import { ServiceContainer } from "./service-container";
|
||||
|
||||
async function main() {
|
||||
const serviceContainer = new ServiceContainer();
|
||||
await serviceContainer.init();
|
||||
|
||||
await registerOssPrograms(serviceContainer);
|
||||
await registerBitPrograms(serviceContainer);
|
||||
|
||||
program.parse(process.argv);
|
||||
}
|
||||
|
||||
// Node does not support top-level await statements until ES2022, esnext, etc which we don't use yet
|
||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||
main();
|
||||
10
bitwarden_license/bit-cli/src/register-bit-programs.ts
Normal file
10
bitwarden_license/bit-cli/src/register-bit-programs.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { ServiceContainer } from "./service-container";
|
||||
|
||||
/**
|
||||
* All Bitwarden-licensed programs should be registered here.
|
||||
* @example
|
||||
* const myProgram = new myProgram(serviceContainer);
|
||||
* myProgram.register();
|
||||
* @param serviceContainer A class that instantiates services and makes them available for dependency injection
|
||||
*/
|
||||
export async function registerBitPrograms(serviceContainer: ServiceContainer) {}
|
||||
7
bitwarden_license/bit-cli/src/service-container.spec.ts
Normal file
7
bitwarden_license/bit-cli/src/service-container.spec.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { ServiceContainer } from "./service-container";
|
||||
|
||||
describe("ServiceContainer", () => {
|
||||
it("instantiates", async () => {
|
||||
expect(() => new ServiceContainer()).not.toThrow();
|
||||
});
|
||||
});
|
||||
7
bitwarden_license/bit-cli/src/service-container.ts
Normal file
7
bitwarden_license/bit-cli/src/service-container.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { ServiceContainer as OssServiceContainer } from "@bitwarden/cli/service-container";
|
||||
|
||||
/**
|
||||
* Instantiates services and makes them available for dependency injection.
|
||||
* Any Bitwarden-licensed services should be registered here.
|
||||
*/
|
||||
export class ServiceContainer extends OssServiceContainer {}
|
||||
28
bitwarden_license/bit-cli/tsconfig.json
Normal file
28
bitwarden_license/bit-cli/tsconfig.json
Normal file
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"pretty": true,
|
||||
"moduleResolution": "node",
|
||||
"target": "ES2016",
|
||||
"module": "es6",
|
||||
"noImplicitAny": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"emitDecoratorMetadata": true,
|
||||
"experimentalDecorators": true,
|
||||
"allowJs": true,
|
||||
"sourceMap": true,
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"@bitwarden/cli/*": ["../../apps/cli/src/*"],
|
||||
"@bitwarden/common/spec": ["../../libs/common/spec"],
|
||||
"@bitwarden/auth/common": ["../../libs/auth/src/common"],
|
||||
"@bitwarden/auth/angular": ["../../libs/auth/src/angular"],
|
||||
"@bitwarden/common/*": ["../../libs/common/src/*"],
|
||||
"@bitwarden/importer/core": ["../../libs/importer/src"],
|
||||
"@bitwarden/vault-export-core": [
|
||||
"../../libs/tools/export/vault-export/vault-export-core/src"
|
||||
],
|
||||
"@bitwarden/node/*": ["../../libs/node/src/*"]
|
||||
}
|
||||
},
|
||||
"include": ["src", "src/**/*.spec.ts"]
|
||||
}
|
||||
4
bitwarden_license/bit-cli/tsconfig.spec.json
Normal file
4
bitwarden_license/bit-cli/tsconfig.spec.json
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"files": ["../../apps/cli/test.setup.ts"]
|
||||
}
|
||||
12
bitwarden_license/bit-cli/webpack.config.js
Normal file
12
bitwarden_license/bit-cli/webpack.config.js
Normal file
@@ -0,0 +1,12 @@
|
||||
const TsconfigPathsPlugin = require("tsconfig-paths-webpack-plugin");
|
||||
|
||||
// Re-use the OSS CLI webpack config
|
||||
const webpackConfig = require("../../apps/cli/webpack.config");
|
||||
|
||||
// Update paths to use the bit-cli entrypoint and tsconfig
|
||||
webpackConfig.entry = { bw: "../../bitwarden_license/bit-cli/src/bw.ts" };
|
||||
webpackConfig.resolve.plugins = [
|
||||
new TsconfigPathsPlugin({ configFile: "../../bitwarden_license/bit-cli/tsconfig.json" }),
|
||||
];
|
||||
|
||||
module.exports = webpackConfig;
|
||||
Reference in New Issue
Block a user