Skip to content

Commit b99844d

Browse files
committed
feat(run): add OS variable to use case context (#3)
1 parent 666ac15 commit b99844d

10 files changed

Lines changed: 22 additions & 11 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ All steps are working with a context object that is empty initially. Whenever
317317
a use case starts, the context is filled with the following properties.
318318
Throughout execution, steps can add or modify properties in the context object.
319319

320+
- `OS`: the operating system where the CLI is executed on; represents the result of [`process.platform`](https://nodejs.org/api/process.html#process_process_platform)
320321
- `WORKSPACE_PATH`: the absolute path to the workspace
321322
- `WORKING_DIR`: the absolute path to the working directory, see [Workspace structure](#workspace-structure)
322323
- `SERVERS`: the list of all servers, see [Server configuration](#server-configuration)

assets/templates/config/use-cases/check-requirements.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
"name": "Check requirements",
55
"description": "This use case checks the requirements to develop locally.",
66
"steps": [
7+
{
8+
"type": "FORMULA",
9+
"description": "Print OS info",
10+
"formula": "console.log(`Running on ${OS}`)"
11+
},
712
{
813
"type": "COMMAND",
914
"description": "Execute commands",

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/templates/config/use-cases/check-requirements.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
"name": "Check requirements",
55
"description": "This use case checks the requirements to develop locally.",
66
"steps": [
7+
{
8+
"type": "FORMULA",
9+
"description": "Print OS info",
10+
"formula": "console.log(`Running on ${OS}`)"
11+
},
712
{
813
"type": "COMMAND",
914
"description": "Execute commands",

src/services/repositories.repository.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ describe('RepositoriesRepository', () => {
1313
let sut: RepositoriesRepository;
1414

1515
beforeEach(() => {
16-
const config = initConfig(path, 'acme', null);
16+
const config = initConfig(path, 'acme', null).store;
1717

18-
sut = RepositoriesRepository.create(config, TemplatesAccess.create(config));
18+
sut = RepositoriesRepository.create(TemplatesAccess.create(config));
1919
});
2020

2121
it('should load repositories; empty list', async () => {

src/services/servers.repository.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe('ServersRepository', () => {
1313
let sut: ServersRepository;
1414

1515
beforeEach(() => {
16-
const config = initConfig(path, 'acme', null);
16+
const config = initConfig(path, 'acme', null).store;
1717

1818
sut = ServersRepository.create(TemplatesAccess.create(config));
1919
});

src/services/use-cases.repository.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe('UseCasesRepository', () => {
1313
let sut: UseCasesRepository;
1414

1515
beforeEach(() => {
16-
const config = initConfig(path, 'acme', null);
16+
const config = initConfig(path, 'acme', null).store;
1717

1818
sut = UseCasesRepository.create(TemplatesAccess.create(config));
1919
});

src/services/use-cases/context-creator.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Context } from '../../types/index.js';
2+
import { OS } from '../../utils/index.js';
23
import { TemplatesAccess } from '../access/index.js';
34
import { RepositoriesRepository } from '../repositories.repository.js';
45
import { ServersRepository } from '../servers.repository.js';
@@ -25,6 +26,7 @@ export class ContextCreator {
2526
WORKING_DIR: this.templatesAccess.getWorkingDir(),
2627
SERVERS: await this.serversRepository.loadServers(),
2728
REPOSITORIES: await this.repositoriesRepository.loadRepositories(),
29+
OS,
2830
};
2931
}
3032
}

src/services/use-cases/use-case-runner.test.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,10 @@ describe('UseCaseRunner', () => {
1616
let sut: UseCaseRunner;
1717

1818
beforeEach(() => {
19-
const config = initConfig(path, 'acme', null);
19+
const config = initConfig(path, 'acme', null).store;
2020

2121
scriptExecutor = ScriptExecutor.create();
22-
sut = UseCaseRunner.create(
23-
config,
24-
TemplatesAccess.create(config),
25-
scriptExecutor
26-
);
22+
sut = UseCaseRunner.create(TemplatesAccess.create(config), scriptExecutor);
2723
});
2824

2925
afterEach(() => {

src/utils/processes.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { execSync } from 'node:child_process';
22

3+
export const OS = process.platform;
4+
35
export async function execCommand(command: string, cwd: string) {
46
return execSync(command, {
57
cwd,

0 commit comments

Comments
 (0)