Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify Dependency Injection, remove framework #251

Merged
merged 21 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
moduleDirectories: ['node_modules', 'src'],
setupFilesAfterEnv: ['<rootDir>/src/test-tool/jest.setup.ts'],
transform: {
'\\.sh$': '<rootDir>/src/test-tool/jest-raw-loader.js',
'\\.yml$': '<rootDir>/src/test-tool/jest-raw-loader.js'
Expand Down
26 changes: 0 additions & 26 deletions package-lock.json

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

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -305,14 +305,12 @@
"eslint-plugin-prettier": "^4.0.0",
"glob": "^8.0.3",
"husky": "^8.0.1",
"inversify": "^6.0.1",
"jest": "^29.2.2",
"jest-raw-loader": "^1.0.1",
"js-yaml": "^4.1.0",
"npm-run-all": "^4.1.5",
"prettier": "^2.6.1",
"raw-loader": "^4.0.2",
"reflect-metadata": "^0.1.13",
"shellcheck": "^1.1.0",
"ts-jest": "^29.0.3",
"ts-loader": "^9.2.8",
Expand Down
236 changes: 236 additions & 0 deletions src/CompositionRoot.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,236 @@
import ChildProcessGateway from 'gateway/ChildProcessGateway';
import EditorGateway from 'gateway/EditorGateway';
import EnvVar from 'process/EnvVar';
import FsGateway from 'gateway/FsGateway';
import HttpGateway from 'gateway/HttpGateway';
import OsGateway from 'gateway/OsGateway';
import ProcessGateway from 'gateway/ProcessGateway';
import ReporterGateway from 'gateway/ReporterGateway';
import AllConfigFiles from 'config/AllConfigFiles';
import AllJobs from 'job/AllJobs';
import BuildAgentSettings from 'config/BuildAgentSettings';
import Children from 'job/Children';
import Images from 'containerization/Images';
import CommandDecorators from 'terminal/CommandDecorators';
import CommandFactory from 'job/ComandFactory';
import Complain from 'command/Complain';
import Config from 'config/Config';
import ConfigFile from 'config/ConfigFile';
import CreateConfigFile from 'command/CreateConfigFile';
import DebugRepo from 'command/DebugRepo';
import Docker from 'containerization/Docker';
import Email from 'license/Email';
import EnterLicense from 'command/EnterLicense';
import EnterToken from 'command/EnterToken';
import EnvPath from 'common/EnvPath';
import ExitAllJobs from 'command/ExitAllJobs';
import ExitJob from 'command/ExitJob';
import FinalTerminal from 'terminal/FinalTerminal';
import FirstActivation from 'job/FirstActivation';
import GetLicense from 'command/GetLicense';
import Help from 'command/Help';
import JobFactory from 'job/JobFactory';
import JobListener from 'job/JobListener';
import JobProviderFactory from 'job/JobProviderFactory';
import JobRunner from 'job/JobRunner';
import JobTerminals from 'terminal/JobTerminals';
import LatestCommittedImage from 'containerization/LatestCommittedImage';
import LocalCi from './common/LocalCi';
import License from 'license/License';
import LicenseInput from 'license/LicenseInput';
import LicensePresenter from 'license/LicensePresenter';
import LicenseProviderFactory from 'license/LicenseProviderFactory';
import LogFactory from 'log/LogFactory';
import LogFile from 'log/LogFile';
import LogProviderFactory from 'log/LogProviderFactory';
import NativeCommandFactory from 'job/NativeComandFactory';
import ParsedConfig from 'config/ParsedConfig';
import Persistence from 'process/Persistence';
import PipelineParameter from 'config/PipelineParameter';
import ProcessFile from 'process/ProcessFile';
import Refresh from 'command/Refresh';
import RefreshLicenseTree from 'command/RefreshLicenseTree';
import RegistrarFactory from 'common/RegistrarFactory';
import ReRunJob from 'command/ReRunJob';
import Retryer from 'job/Retryer';
import RunJob from 'command/RunJob';
import RunningContainer from 'containerization/RunningContainer';
import RunWalkthroughJob from 'command/RunWalkthroughJob';
import SelectRepo from 'command/SelectRepo';
import ShowLogFile from 'command/ShowLogFile';
import Spawn from 'common/Spawn';
import StartDocker from 'command/StartDocker';
import TryProcessAgain from 'command/TryProcessAgain';
import UncommittedFile from 'containerization/UncommittedFile';
import Volume from 'containerization/Volume';
import WarningCommandFactory from 'job/WarningCommandFactory';
import WarningFactory from 'job/WarningFactory';
import Workspace from 'common/Workspace';

const childProcessGateway = new ChildProcessGateway();
const editorGateway = new EditorGateway();
const fsGateway = new FsGateway();
const httpGateway = new HttpGateway();
const osGateway = new OsGateway();
const processGateway = new ProcessGateway();
const reporterGateway = new ReporterGateway(editorGateway);

const parsedConfig = new ParsedConfig(fsGateway);
const allJobs = new AllJobs(parsedConfig);
const envPath = new EnvPath(osGateway, processGateway);
const workspace = new Workspace(editorGateway);
const commandFactory = new CommandFactory(editorGateway);
const jobFactory = new JobFactory(editorGateway);
const logFactory = new LogFactory(editorGateway);
const warningFactory = new WarningFactory(editorGateway);
const warningCommandFactory = new WarningCommandFactory(warningFactory);
const spawn = new Spawn(envPath, processGateway, workspace);
const buildAgentSettings = new BuildAgentSettings(
childProcessGateway,
osGateway,
spawn
);
const children = new Children(
commandFactory,
editorGateway,
jobFactory,
logFactory,
new NativeCommandFactory(),
warningCommandFactory,
warningFactory
);
const pipelineParameter = new PipelineParameter(fsGateway);
const envVar = new EnvVar(childProcessGateway, spawn);
const volume = new Volume(fsGateway);
const persistence = new Persistence(volume);
const processFile = new ProcessFile(envVar, fsGateway, persistence);

const config = new Config(
childProcessGateway,
editorGateway,
fsGateway,
pipelineParameter,
processFile,
spawn
);
const allConfigFiles = new AllConfigFiles(editorGateway);
const configFile = new ConfigFile(
allConfigFiles,
editorGateway,
reporterGateway
);

const createConfigFile = new CreateConfigFile(editorGateway, reporterGateway);
const debugRepo = new DebugRepo(editorGateway, reporterGateway);
const docker = new Docker(childProcessGateway, spawn);
const email = new Email(editorGateway, httpGateway, reporterGateway);
const enterToken = new EnterToken(editorGateway);
const images = new Images(childProcessGateway, spawn);
const exitAllJobs = new ExitAllJobs(images, editorGateway, reporterGateway);
const finalTerminal = new FinalTerminal(
childProcessGateway,
editorGateway,
spawn
);
const logFile = new LogFile(editorGateway);
const jobListener = new JobListener(
childProcessGateway,
images,
configFile,
editorGateway,
fsGateway,
logFile,
parsedConfig,
spawn
);

const latestCommittedImage = new LatestCommittedImage(
spawn,
childProcessGateway
);
const runningContainer = new RunningContainer(spawn, childProcessGateway);
const uncommittedFile = new UncommittedFile(
childProcessGateway,
editorGateway,
spawn
);

const jobRunner = new JobRunner(
buildAgentSettings,
new CommandDecorators(editorGateway),
configFile,
editorGateway,
finalTerminal,
fsGateway,
images,
jobFactory,
jobListener,
latestCommittedImage,
parsedConfig,
runningContainer,
uncommittedFile
);
const jobTerminals = new JobTerminals(editorGateway);
const exitJob = new ExitJob(jobFactory, jobRunner, jobTerminals);
const getLicense = new GetLicense(editorGateway);
const license = new License(editorGateway, httpGateway);
const retryer = new Retryer();
const jobProviderFactory = new JobProviderFactory(
allConfigFiles,
children,
configFile,
commandFactory,
docker,
editorGateway,
fsGateway,
license,
config,
jobFactory,
logFactory,
reporterGateway,
retryer,
warningFactory,
allJobs
);

const licenseInput = new LicenseInput(editorGateway, license);
const licensePresenter = new LicensePresenter(license);
const licenseProviderFactory = new LicenseProviderFactory(
license,
licenseInput,
licensePresenter,
editorGateway
);
const registrarFactory = new RegistrarFactory(
new Complain(editorGateway),
configFile,
createConfigFile,
debugRepo,
new EnterLicense(licenseInput),
enterToken,
exitAllJobs,
exitJob,
new FirstActivation(editorGateway, reporterGateway, email),
getLicense,
new Help(editorGateway, reporterGateway),
licenseInput,
new LogProviderFactory(fsGateway),
new Refresh(),
new RefreshLicenseTree(editorGateway),
new ReRunJob(editorGateway, jobRunner, jobTerminals, reporterGateway),
new RunJob(editorGateway, jobRunner, reporterGateway),
new RunWalkthroughJob(config, configFile, editorGateway, reporterGateway),
new SelectRepo(allConfigFiles, images, editorGateway, reporterGateway),
new ShowLogFile(logFile),
new StartDocker(childProcessGateway, envPath, spawn),
new TryProcessAgain(configFile, fsGateway),
editorGateway
);

export const app = new LocalCi(
fsGateway,
jobProviderFactory,
licenseProviderFactory,
registrarFactory,
reporterGateway
);
8 changes: 1 addition & 7 deletions src/command/Complain.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
import { inject, injectable } from 'inversify';
import type { Command } from '.';
import Types from 'common/Types';
import EditorGateway from 'gateway/EditorGateway';
import { COMPLAIN_COMMAND, COMPLAIN_URL } from 'constant';

@injectable()
export default class Complain implements Command {
@inject(Types.IEditorGateway)
editorGateway!: EditorGateway;

commandName: string;

constructor() {
constructor(public editorGateway: EditorGateway) {
this.commandName = COMPLAIN_COMMAND;
}

Expand Down
14 changes: 4 additions & 10 deletions src/command/CreateConfigFile.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
import { inject, injectable } from 'inversify';
import * as path from 'path';
import type vscode from 'vscode';
import type { Command } from './';
import EditorGateway from 'gateway/EditorGateway';
import getStarterConfig from 'config/getStarterConfig';
import JobProvider from 'job/JobProvider';
import ReporterGateway from 'gateway/ReporterGateway';
import Types from 'common/Types';
import { CREATE_CONFIG_FILE_COMMAND } from 'constant';

@injectable()
export default class CreateConfigFile implements Command {
@inject(Types.IEditorGateway)
editorGateway!: EditorGateway;

@inject(Types.IReporterGateway)
reporterGateway!: ReporterGateway;

commandName: string;

constructor() {
constructor(
public editorGateway: EditorGateway,
public reporterGateway: ReporterGateway
) {
this.commandName = CREATE_CONFIG_FILE_COMMAND;
}

Expand Down
Loading