improve confighandling

This commit is contained in:
Philipp Kunz 2016-07-19 00:59:57 +02:00
parent e222456431
commit 8c5cf3485a
3 changed files with 30 additions and 7 deletions

View File

@ -1,7 +1,12 @@
import * as plugins from "./npmdocker.plugins"; import * as plugins from "./npmdocker.plugins";
import * as paths from "./npmdocker.paths"; import * as paths from "./npmdocker.paths";
let config = plugins.npmextra.dataFor({ export interface IConfig {
baseImage:string;
command:string;
}
let config:IConfig = plugins.npmextra.dataFor({
toolName:"npmdocker", toolName:"npmdocker",
defaultSettings: {}, defaultSettings: {},
cwd: "" cwd: ""

View File

@ -1,13 +1,16 @@
import * as plugins from "./npmdocker.plugins"; import * as plugins from "./npmdocker.plugins";
import * as paths from "./npmdocker.paths"; import * as paths from "./npmdocker.paths";
import * as snippets from "./npmdocker.snippets";
let config;
/** /**
* check if docker is available * check if docker is available
*/ */
let checkDocker = (configArg) => { let checkDocker = () => {
let done = plugins.q.defer(); let done = plugins.q.defer();
if(plugins.shelljs.which("docker")){ if(plugins.shelljs.which("docker")){
done.resolve(configArg); done.resolve();
} else { } else {
done.reject(new Error("docker not found on this machine")); done.reject(new Error("docker not found on this machine"));
} }
@ -19,6 +22,10 @@ let checkDocker = (configArg) => {
*/ */
let buildDockerFile = () => { let buildDockerFile = () => {
let done = plugins.q.defer(); let done = plugins.q.defer();
let dockerfile = snippets.dockerfileSnippet({
baseImage:config.baseImage,
command:config.command
});
return done.promise return done.promise
}; };
@ -52,12 +59,15 @@ let deleteDockerImage = () => {
export let run = (configArg) => { export let run = (configArg) => {
let done = plugins.q.defer(); let done = plugins.q.defer();
checkDocker(configArg) config = configArg;
checkDocker()
.then(buildDockerFile) .then(buildDockerFile)
.then(buildDockerImage) .then(buildDockerImage)
.then(runDockerImage) .then(runDockerImage)
.then(deleteDockerContainter) .then(deleteDockerContainter)
.then(deleteDockerImage) .then(deleteDockerImage)
.then(done.resolve) .then(() => {
done.resolve(configArg);
})
return done.promise; return done.promise;
} }

View File

@ -5,9 +5,17 @@ export interface IDockerfileSnippet {
command:string; command:string;
} }
export let dockerfileSnippet = (optionsArg:IDockerfileSnippet) => { export let dockerfileSnippet = (optionsArg:IDockerfileSnippet):string => {
let commandArray = optionsArg.command.split(" ");
let commandString:string = "";
for(let stringItem of commandArray){
if(!(commandString == "")){
commandString = commandString + ",";
}
commandString = commandString + '"' + stringItem + '"';
}
return ` return `
FROM ${optionsArg.baseImage} FROM ${optionsArg.baseImage}
cmd[${commandString}];
` `
} }