Skip to content
This repository was archived by the owner on Dec 20, 2023. It is now read-only.

Reuse IMongoDBDownloadOptions from mongodb-download #56

Merged
merged 1 commit into from
Jan 24, 2019
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: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ node_modules
dist
*.log
*.swp
.idea
15 changes: 5 additions & 10 deletions src/mongo-bins.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,30 @@
const Debug: any = require('debug');
import { resolve as resolvePath } from 'path';
import { SpawnOptions, ChildProcess, spawn as spawnChild } from 'child_process';
import { IMongoDBDownloadOpts } from './mongod-helper';
import { IMongoDBDownloadOptions } from 'mongodb-download';
import { MongoDBPrebuilt } from './mongodb-prebuilt';
import { MongoSupervise } from './mongodb-supervise';
import { MongoDBDownload } from 'mongodb-download';

export class MongoBins {
command: string;
execPath: string;
debug: any;
childProcess: ChildProcess;
mongoSupervice: MongoSupervise;
mongoDBPrebuilt: MongoDBPrebuilt;

constructor(
command: string,
public command: string,
public commandArguments: string[] = [],
public spawnOptions: SpawnOptions = {},

downloadOptions?: IMongoDBDownloadOpts
downloadOptions?: Partial<IMongoDBDownloadOptions>
) {

this.debug = Debug(`mongodb-prebuilt-MongoBins`);
this.command = command;

if (downloadOptions) {
this.mongoDBPrebuilt = new MongoDBPrebuilt(downloadOptions);
} else {
this.mongoDBPrebuilt = new MongoDBPrebuilt();
}

}

run(): Promise<boolean> {
Expand Down Expand Up @@ -87,4 +82,4 @@ export class MongoBins {
});
}

}
}
11 changes: 2 additions & 9 deletions src/mongod-helper.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
import { MongoBins } from './mongo-bins';
import { IMongoDBDownloadOptions } from 'mongodb-download';
const Debug: any = require('debug');

const COMMAND: string = "mongod";

export interface IMongoDBDownloadOpts {
platform?: string;
arch?: string;
version?: string;
downloadDir?: string;
http?: any;
}

export class MongodHelper {
mongoBin: MongoBins;
debug: any;

private resolveLink: (response: boolean) => void = () => { };
private rejectLink: (response: string) => void = () => { };

constructor(commandArguments: string[] = [], downloadOptions?: IMongoDBDownloadOpts) {
constructor(commandArguments: string[] = [], downloadOptions?: Partial<IMongoDBDownloadOptions>) {
if (downloadOptions) {
this.mongoBin = new MongoBins(COMMAND, commandArguments, {}, downloadOptions);
} else {
Expand Down
9 changes: 3 additions & 6 deletions src/mongodb-prebuilt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@ const Debug: any = require('debug');
const { Glob } = require("glob");
import { resolve as resolvePath } from 'path';
import { homedir as osHomeDir } from 'os';
import { MongoDBDownload } from 'mongodb-download';
import { IMongoDBDownloadOpts } from './mongod-helper';

import { IMongoDBDownloadOptions, MongoDBDownload } from 'mongodb-download';

export class MongoDBPrebuilt {
private debug: any;
private binPath: string;

constructor(public mongoDBDownload?: MongoDBDownload | IMongoDBDownloadOpts) {
constructor(public mongoDBDownload?: MongoDBDownload | Partial<IMongoDBDownloadOptions>) {
this.debug = Debug('mongodb-prebuilt-MongoDBPrebuilt');

if (!this.mongoDBDownload || !(this.mongoDBDownload instanceof MongoDBDownload)) {
const downloadOpts: IMongoDBDownloadOpts = this.mongoDBDownload as IMongoDBDownloadOpts || {
const downloadOpts: Partial<IMongoDBDownloadOptions> = this.mongoDBDownload as Partial<IMongoDBDownloadOptions> || {
downloadDir: this.getHomeDirectory()
};
downloadOpts.downloadDir = downloadOpts.downloadDir || this.getHomeDirectory();
Expand Down Expand Up @@ -77,4 +75,3 @@ export class MongoDBPrebuilt {
}

}