Skip to content

Commit

Permalink
feat(status): check git installation (closes #249)
Browse files Browse the repository at this point in the history
  • Loading branch information
Izak88 authored and jkuri committed Oct 23, 2017
1 parent aa76406 commit d389d6d
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 14 deletions.
31 changes: 19 additions & 12 deletions src/api/server-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,7 @@ export function setupRoutes(): express.Router {

router.get('/ready', (req: express.Request, res: express.Response) => {
Observable.merge(...[
system.isGitInstalled(),
system.isSQLiteInstalled(),
docker.isDockerInstalled(),
docker.isDockerRunning(),
Expand Down Expand Up @@ -588,18 +589,24 @@ export function setupRoutes(): express.Router {
});

router.get('/status', (req: express.Request, res: express.Response) => {
system.isSQLiteInstalled().subscribe(sqlite => {
docker.isDockerInstalled().subscribe(dockerInstalled => {
if (dockerInstalled) {
docker.isDockerRunning().subscribe(dockerRunning => {
const data = { sqlite: sqlite, docker: dockerInstalled, dockerRunning: dockerRunning };
res.status(200).json({ data: data });
});
} else {
const data = { sqlite: sqlite, docker: false, dockerRunning: false };
res.status(200).json({ data: data });
}
});
Observable.concat(...[
system.isGitInstalled(),
system.isSQLiteInstalled(),
docker.isDockerInstalled()
])
.toArray()
.subscribe(data => {
if (data[2]) {
docker.isDockerRunning().subscribe(dockerRunning => {
const status = {
sqlite: data[1], docker: data[2], dockerRunning: dockerRunning, git: data[0] };
res.status(200).json({ data: status });
});
} else {
const status = {
sqlite: data[1], docker: false, dockerRunning: false, git: data[0] };
res.status(200).json({ data: status });
}
});
});

Expand Down
15 changes: 15 additions & 0 deletions src/api/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,18 @@ export function isSQLiteInstalled(): Observable<boolean> {
});
});
}

export function isGitInstalled(): Observable<boolean> {
return new Observable((observer: Observer<boolean>) => {
const git = spawn('which', ['git']);
git.on('close', code => {
if (code === 0) {
observer.next(true);
} else {
observer.next(false);
}

observer.complete();
});
});
}
3 changes: 3 additions & 0 deletions src/app/components/app-setup/app-setup.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ <h2>
<div class="setup-list-item">
<img class="icon" [src]="serverStatus.sqlite ? 'images/icons/check-true.svg' : 'images/icons/check-false.svg'" name="sqlite3-installed-icon"> SQLite3 Installed
</div>
<div class="setup-list-item">
<img class="icon" [src]="serverStatus.git ? 'images/icons/check-true.svg' : 'images/icons/check-false.svg'" name="git-installed-icon"> Git Installed
</div>
</div>
<hr/>
<p *ngIf="!readyToSetup">Please make sure that all of the above checkmarks are green as it is mandatory to run Abstruse on this server.</p>
Expand Down
4 changes: 3 additions & 1 deletion src/app/components/app-setup/app-setup.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface ServerStatus {
sqlite: boolean;
docker: boolean;
dockerRunning: boolean;
git: boolean;
}

export interface User {
Expand Down Expand Up @@ -40,7 +41,8 @@ export class AppSetupComponent implements OnInit {
this.serverStatus = {
sqlite: false,
docker: false,
dockerRunning: false
dockerRunning: false,
git: false
};

this.readyToSetup = false;
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/050_new-server-api-routes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,9 @@ describe('Api Server Routes Unit Tests', () => {

it(`status should return true`, () => {
return sendGetRequest({}, `api/setup/status`).then(res => {
expect(res).to.deep.equal({ data: { docker: true, dockerRunning: true, sqlite: true } });
expect(res).to.deep.equal({
data: { docker: true, dockerRunning: true, sqlite: true, git: true }
});
});
});

Expand Down

0 comments on commit d389d6d

Please sign in to comment.