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

handle error based on exit code #2 #77

Merged
merged 3 commits into from
Jul 13, 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
9 changes: 8 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
{
"extends": "es/2015/server",
"extends": [
"es/2015/server",
"plugin:jest/recommended"
],
"rules": {
"no-console" :"off"
},
"plugins": ["jest"],
"env": {
"jest/globals": true
}
}
46 changes: 23 additions & 23 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1,49 @@
export declare function upAll(options: IDockerComposeOptions): Promise<IDockerComposeResult>;
export declare function upAll(options?: IDockerComposeOptions): Promise<IDockerComposeResult>;

export declare function upMany(services: String[], options: IDockerComposeOptions): Promise<IDockerComposeResult>;
export declare function upMany(services: String[], options?: IDockerComposeOptions): Promise<IDockerComposeResult>;

export declare function upOne(service: String, options: IDockerComposeOptions): Promise<IDockerComposeResult>;
export declare function upOne(service: String, options?: IDockerComposeOptions): Promise<IDockerComposeResult>;

export declare function kill(options: IDockerComposeOptions): Promise<IDockerComposeResult>;
export declare function kill(options?: IDockerComposeOptions): Promise<IDockerComposeResult>;

export declare function down(options: IDockerComposeOptions): Promise<IDockerComposeResult>;
export declare function down(options?: IDockerComposeOptions): Promise<IDockerComposeResult>;

export declare function stop(options: IDockerComposeOptions): Promise<IDockerComposeResult>;
export declare function stop(options?: IDockerComposeOptions): Promise<IDockerComposeResult>;

export declare function restartAll(options: IDockerComposeOptions): Promise<IDockerComposeResult>;
export declare function restartAll(options?: IDockerComposeOptions): Promise<IDockerComposeResult>;

export declare function restartMany(services: String[], options: IDockerComposeOptions): Promise<IDockerComposeResult>;
export declare function restartMany(services: String[], options?: IDockerComposeOptions): Promise<IDockerComposeResult>;

export declare function restartOne(service: String, options: IDockerComposeOptions): Promise<IDockerComposeResult>;
export declare function restartOne(service: String, options?: IDockerComposeOptions): Promise<IDockerComposeResult>;

export declare function rm(options: IDockerComposeOptions): Promise<IDockerComposeResult>;
export declare function rm(options?: IDockerComposeOptions): Promise<IDockerComposeResult>;

export declare function exec(container: String, command: String | String[], options: IDockerComposeOptions): Promise<IDockerComposeResult>;
export declare function exec(container: String, command: String | String[], options?: IDockerComposeOptions): Promise<IDockerComposeResult>;

export declare function logs(services: String[], options: IDockerComposeLogOptions): Promise<IDockerComposeResult>;
export declare function logs(services: String[], options?: IDockerComposeLogOptions): Promise<IDockerComposeResult>;

export declare function run(service: String, command: String | String[], options: IDockerComposeOptions): Promise<IDockerComposeResult>;
export declare function run(service: String, command: String | String[], options?: IDockerComposeOptions): Promise<IDockerComposeResult>;

export declare function buildAll(options: IDockerComposeBuildOptions): Promise<IDockerComposeResult>;
export declare function buildAll(options?: IDockerComposeBuildOptions): Promise<IDockerComposeResult>;

export declare function buildMany(services: String[], options: IDockerComposeBuildOptions): Promise<IDockerComposeResult>;
export declare function buildMany(services: String[], options?: IDockerComposeBuildOptions): Promise<IDockerComposeResult>;

export declare function buildOne(service: String, options: IDockerComposeOptions): Promise<IDockerComposeResult>;
export declare function buildOne(service: String, options?: IDockerComposeOptions): Promise<IDockerComposeResult>;

export declare function config(options: IDockerComposeOptions): Promise<IDockerComposeResult>;
export declare function config(options?: IDockerComposeOptions): Promise<IDockerComposeResult>;

export declare function configServices(options: IDockerComposeOptions): Promise<IDockerComposeResult>;
export declare function configServices(options?: IDockerComposeOptions): Promise<IDockerComposeResult>;

export declare function configVolumes(options: IDockerComposeOptions): Promise<IDockerComposeResult>;
export declare function configVolumes(options?: IDockerComposeOptions): Promise<IDockerComposeResult>;

export declare function ps(options: IDockerComposeOptions): Promise<IDockerComposeResult>;
export declare function ps(options?: IDockerComposeOptions): Promise<IDockerComposeResult>;

export declare function push(options: IDockerComposePushOptions): Promise<IDockerComposeResult>;
export declare function push(options?: IDockerComposePushOptions): Promise<IDockerComposeResult>;

export declare function port(service: String, containerPort: String | Number, options: IDockerComposeOptions): Promise<IDockerComposeResult>;
export declare function port(service: String, containerPort: String | Number, options?: IDockerComposeOptions): Promise<IDockerComposeResult>;

interface IDockerComposeOptions {
cwd: string;
cwd?: string;
config?: string | string[];
log?: boolean;
composeOptions?: string[] | Array<string | string[]>;
Expand Down
9 changes: 8 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ const composeOptionsToArgs = function (composeOptions) {
* @param {?(string[]|Array<string|string[]>)} [options.composeOptions]
*/
const execCompose = (command, args, options) => new Promise((resolve, reject) => {
if (typeof options === 'undefined') {
options = {};
}
const composeOptions = options.composeOptions || [];
const commandOptions = options.commandOptions || [];
let composeArgs = composeOptionsToArgs(composeOptions);
Expand Down Expand Up @@ -82,7 +85,11 @@ const execCompose = (command, args, options) => new Promise((resolve, reject) =>

childProc.on('exit', exitCode => {
result.exitCode = exitCode;
resolve(result);
if (exitCode === 0) {
resolve(result);
} else {
reject(result);
}
});

if (options.log) {
Expand Down
Loading