update to use better command recognition

This commit is contained in:
2017-07-27 14:20:56 +02:00
parent 1c0331524d
commit a8571827b9
14 changed files with 98 additions and 82 deletions

View File

@ -20,6 +20,6 @@ export let build = async (argvArg): Promise<void> => {
break
default:
plugins.beautylog.log('build target ' + whatToPublish + ' not recognised!')
};
}
return
}

View File

@ -11,7 +11,7 @@ let modArgvArg // will be set through the build command
export let build = async (argvArg: any) => {
modArgvArg = argvArg
plugins.beautylog.log('now building Dockerfiles...')
await readDockerfiles()
await readDockerfiles(argvArg)
.then(sortDockerfiles)
.then(mapDockerfiles)
.then(buildDockerfiles)
@ -22,7 +22,8 @@ export let build = async (argvArg: any) => {
* creates instance of class Dockerfile for all Dockerfiles in cwd
* @returns Promise<Dockerfile[]>
*/
export let readDockerfiles = async (): Promise<Dockerfile[]> => {
export let readDockerfiles = async (argvArg): Promise<Dockerfile[]> => {
modArgvArg = argvArg
let fileTree = await plugins.smartfile.fs.listFileTree(paths.cwd, 'Dockerfile*')
// create the Dockerfile array
@ -89,7 +90,7 @@ export let mapDockerfiles = async (sortedArray: Dockerfile[]): Promise<Dockerfil
dockerfileArg.localBaseDockerfile = dockfile2
}
})
};
}
})
return sortedArray
}
@ -172,10 +173,10 @@ export class Dockerfile {
this.containerName = 'dockerfile-' + this.version
if (options.filePath && options.read) {
this.content = plugins.smartfile.fs.toStringSync(plugins.path.resolve(options.filePath))
};
}
this.baseImage = dockerBaseImage(this.content)
this.localBaseImageDependent = false
};
}
/**
* builds the Dockerfile
@ -186,7 +187,7 @@ export class Dockerfile {
await bash(buildCommand)
NpmciEnv.dockerFilesBuilt.push(this)
return
};
}
/**
* pushes the Dockerfile to a registry
@ -209,7 +210,7 @@ export class Dockerfile {
await bash(`docker push ${this.gitlabTestTag}`)
break
}
};
}
/**
* pulls the Dockerfile from a registry
@ -218,7 +219,7 @@ export class Dockerfile {
let pullTag = this.gitlabTestTag
await bash('docker pull ' + pullTag)
await bash('docker tag ' + pullTag + ' ' + this.buildTag)
};
}
/**
* tests the Dockerfile;
@ -237,7 +238,7 @@ export class Dockerfile {
} else {
plugins.beautylog.warn('skipping tests for ' + this.cleanTag + ' because no testfile was found!')
}
};
}
/**
* gets the id of a Dockerfile
@ -245,7 +246,7 @@ export class Dockerfile {
async getId () {
let containerId = await bash('docker inspect --type=image --format=\"{{.Id}}\" ' + this.buildTag)
return containerId
};
}
}
/**
@ -265,7 +266,7 @@ export let dockerFileVersion = (dockerfileNameArg: string): string => {
}
/**
*
* returns the docker base image for a Dockerfile
*/
export let dockerBaseImage = function (dockerfileContentArg: string) {
let baseImageRegex = /FROM\s([a-zA-z0-9\/\-\:]*)\n?/
@ -274,7 +275,7 @@ export let dockerBaseImage = function (dockerfileContentArg: string) {
}
/**
*
* returns the docker tag
*/
export let dockerTag = function (registryArg: string, repoArg: string, versionArg: string, suffixArg?: string): string {
let tagString: string
@ -283,7 +284,7 @@ export let dockerTag = function (registryArg: string, repoArg: string, versionAr
let version = versionArg
if (suffixArg) {
version = versionArg + '_' + suffixArg
};
}
tagString = registry + '/' + repo + ':' + version
return tagString
}

View File

@ -17,19 +17,20 @@ export type TPubService = 'npm' | 'docker'
* the main exported publish function.
* @param pubServiceArg references targeted service to publish to
*/
export let publish = async (pubServiceArg: TPubService = 'npm') => {
switch (pubServiceArg) {
export let publish = async (argvArg: any) => {
let whatToPublish = argvArg._[1]
switch (whatToPublish) {
case 'npm':
return await publishNpm()
return await publishNpm(argvArg)
case 'docker':
return await publishDocker()
return await publishDocker(argvArg)
}
}
/**
* tries to publish current cwd to NPM registry
*/
let publishNpm = async () => {
let publishNpm = async (argvArg) => {
let modPrepare = await npmciMods.modPrepare.load()
await modPrepare.prepare('npm')
await bash('npm publish')
@ -39,9 +40,9 @@ let publishNpm = async () => {
/**
* tries to publish current cwd to Docker registry
*/
let publishDocker = async () => {
let publishDocker = async (argvArg) => {
let modDocker = await npmciMods.modDocker.load()
return await modDocker.readDockerfiles()
return await modDocker.readDockerfiles(argvArg)
.then(modDocker.pullDockerfileImages)
.then(modDocker.pushDockerfiles)
.then(dockerfileArray => {

View File

@ -20,9 +20,9 @@ let npmTest = async (): Promise<void> => {
await bash('npm test')
}
let testDocker = async (): Promise<Dockerfile[]> => {
let testDocker = async (argvArg): Promise<Dockerfile[]> => {
let modDocker = await npmciMods.modDocker.load()
return await modDocker.readDockerfiles()
return await modDocker.readDockerfiles(argvArg)
.then(modDocker.pullDockerfileImages)
.then(modDocker.testDockerfiles)
}
@ -31,12 +31,13 @@ let testDocker = async (): Promise<Dockerfile[]> => {
* the main test function
* @param versionArg
*/
export let test = async (versionArg): Promise<void> => {
if (versionArg === 'docker') {
await testDocker()
export let test = async (argvArg): Promise<void> => {
let whatToTest = argvArg._[1]
if (whatToTest === 'docker') {
await testDocker(argvArg)
} else {
let modInstall = await npmciMods.modInstall.load()
await modInstall.install(versionArg)
await modInstall.install(whatToTest)
.then(npmDependencies)
.then(npmTest)
}

View File

@ -12,9 +12,9 @@ smartcli.addVersion(npmciInfo.version)
// build
smartcli.addCommand('build')
.then(async (argv) => {
.then(async (argvArg) => {
let modBuild = await npmciMods.modBuild.load()
await modBuild.build(argv._[1])
await modBuild.build(argvArg)
NpmciEnv.configStore()
}).catch(err => {
console.log(err)
@ -90,7 +90,7 @@ smartcli.addCommand('publish')
smartcli.addCommand('test')
.then(async (argv) => {
let modTest = await npmciMods.modTest.load()
await modTest.test(argv._[1])
await modTest.test(argv)
await NpmciEnv.configStore()
}).catch(err => {
console.log(err)