Go modular

This commit is contained in:
PhilKunz External
2017-05-18 20:40:09 +00:00
committed by Phil Kunz
parent 6edd51c6e6
commit b6a85319b0
64 changed files with 454 additions and 316 deletions

View File

@ -1,106 +1,2 @@
import * as plugins from './npmci.plugins'
import * as paths from './npmci.paths'
let npmciInfo = new plugins.projectinfo.ProjectinfoNpm(paths.NpmciPackageRoot)
plugins.beautylog.log('npmci version: ' + npmciInfo.version)
import './npmci.cli'
import { build } from './npmci.build'
import { clean } from './npmci.clean'
import { command } from './npmci.command'
import { install } from './npmci.install'
import { publish } from './npmci.publish'
import { prepare } from './npmci.prepare'
import { test } from './npmci.test'
import { trigger } from './npmci.trigger'
import * as NpmciEnv from './npmci.env'
export { build } from './npmci.build'
export { install } from './npmci.install';
export { publish } from './npmci.publish';
let smartcli = new plugins.smartcli.Smartcli()
smartcli.addVersion(npmciInfo.version)
// build
smartcli.addCommand('build')
.then((argv) => {
build(argv._[ 1 ])
.then(NpmciEnv.configStore)
.catch(err => {
console.log(err)
process.exit(1)
})
})
// clean
smartcli.addCommand('clean')
.then((argv) => {
clean()
.then(NpmciEnv.configStore)
.catch(err => {
console.log(err)
process.exit(1)
})
})
// command
smartcli.addCommand('command')
.then((argv) => {
command()
.then(NpmciEnv.configStore)
.catch(err => {
console.log(err)
process.exit(1)
})
})
// install
smartcli.addCommand('install')
.then((argv) => {
install(argv._[ 1 ])
.then(NpmciEnv.configStore)
.catch(err => {
console.log(err)
process.exit(1)
})
})
// prepare
smartcli.addCommand('prepare')
.then((argv) => {
prepare(argv._[ 1 ])
.then(NpmciEnv.configStore)
.catch(err => {
console.log(err)
process.exit(1)
})
})
// publish
smartcli.addCommand('publish')
.then((argv) => {
publish(argv._[ 1 ])
.then(NpmciEnv.configStore)
.catch(err => {
console.log(err)
process.exit(1)
})
})
// test
smartcli.addCommand('test')
.then((argv) => {
test(argv._[ 1 ])
.then(NpmciEnv.configStore)
.catch(err => {
console.log(err)
process.exit(1)
})
})
// trigger
smartcli.addCommand('trigger')
.then((argv) => {
trigger()
})
smartcli.startParse()

View File

@ -1,7 +1,7 @@
import * as plugins from './npmci.plugins'
import { bash } from './npmci.bash'
import * as env from './npmci.env'
import * as buildDocker from './npmci.build.docker'
import * as plugins from './mod.plugins'
import { bash } from '../npmci.bash'
import * as env from '../npmci.env'
import * as npmciMods from '../npmci.mods'
/**
* defines possible build services
@ -14,7 +14,8 @@ export type TBuildService = 'docker'
export let build = async (commandArg): Promise<void> => {
switch (commandArg) {
case 'docker':
await buildDocker.build()
let modDocker = await npmciMods.modDocker.load()
await modDocker.build()
break
default:
plugins.beautylog.log('build target ' + commandArg + ' not recognised!')

View File

@ -0,0 +1 @@
export * from '../npmci.plugins'

View File

@ -1,5 +1,5 @@
import * as plugins from './npmci.plugins'
import * as paths from './npmci.paths'
import * as plugins from './mod.plugins'
import * as paths from '../npmci.paths'
/**
* cleans npmci config files

View File

@ -0,0 +1 @@
export * from '../npmci.plugins'

1
ts/mod_docker/index.ts Normal file
View File

@ -0,0 +1 @@
export * from './mod.builddocker'

View File

@ -1,7 +1,7 @@
import * as plugins from './npmci.plugins'
import * as paths from './npmci.paths'
import * as NpmciEnv from './npmci.env'
import { bash } from './npmci.bash'
import * as plugins from './mod.plugins'
import * as paths from '../npmci.paths'
import * as NpmciEnv from '../npmci.env'
import { bash } from '../npmci.bash'
/**
* builds a cwd of Dockerfiles by triggering a promisechain

View File

@ -0,0 +1,3 @@
export * from '../npmci.plugins'

View File

@ -34,7 +34,7 @@ let publishNpm = async () => {
}
/**
* tries to pubish current cwd to Docker registry
* tries to publish current cwd to Docker registry
*/
let publishDocker = async () => {
return await NpmciBuildDocker.readDockerfiles()

View File

@ -1,4 +1,4 @@
import * as plugins from './npmci.plugins'
import * as plugins from '../npmci.plugins'
/**
* servezoneRegex is the regex that parses the servezone connection data
@ -15,18 +15,18 @@ let servezoneRegexResultArray = servezoneRegex.exec(process.env.NPMCI_SERVEZONE)
* the data object that is used for the smartsocket client object
*/
let smartsocketClientConstructorOptions = {
alias: 'npmci',
password: servezoneRegexResultArray[3],
port: parseInt(servezoneRegexResultArray[2]),
role: 'ci',
url: servezoneRegexResultArray[1]
alias: 'npmci',
password: servezoneRegexResultArray[3],
port: parseInt(servezoneRegexResultArray[2]),
role: 'ci',
url: servezoneRegexResultArray[1]
}
/**
* the main run function to submit a service to a servezone
*/
export let run = async (configArg) => {
new plugins.smartsocket.SmartsocketClient(
smartsocketClientConstructorOptions
)
new plugins.smartsocket.SmartsocketClient(
smartsocketClientConstructorOptions
)
}

44
ts/mod_test/index.ts Normal file
View File

@ -0,0 +1,44 @@
import * as plugins from './mod.plugins'
import { bash, yarnAvailable } from '../npmci.bash'
import * as env from '../npmci.env'
import * as npmciMods from '../npmci.mods'
// interfaces
import { Dockerfile } from '../mod_docker/index'
let npmDependencies = async (): Promise<void> => {
plugins.beautylog.info('now installing dependencies:')
if (await yarnAvailable.promise) {
await bash('yarn upgrade')
} else {
await bash('npm install')
}
}
let npmTest = async (): Promise<void> => {
plugins.beautylog.info('now starting tests:')
await bash('npm test')
}
let testDocker = async (): Promise<Dockerfile[]> => {
let modDocker = await npmciMods.modDocker.load()
return await modDocker.readDockerfiles()
.then(modDocker.pullDockerfileImages)
.then(modDocker.testDockerfiles)
}
/**
* the main test function
* @param versionArg
*/
export let test = async (versionArg): Promise<void> => {
if (versionArg === 'docker') {
await testDocker()
} else {
let modInstall = await npmciMods.modInstall.load()
await modInstall.install(versionArg)
.then(npmDependencies)
.then(npmTest)
}
}

View File

@ -0,0 +1 @@
export * from '../npmci.plugins'

View File

102
ts/npmci.cli.ts Normal file
View File

@ -0,0 +1,102 @@
import * as plugins from './npmci.plugins'
import * as paths from './npmci.paths'
let npmciInfo = new plugins.projectinfo.ProjectinfoNpm(paths.NpmciPackageRoot)
plugins.beautylog.log('npmci version: ' + npmciInfo.version)
import * as NpmciEnv from './npmci.env'
import * as npmciMods from './npmci.mods'
let smartcli = new plugins.smartcli.Smartcli()
smartcli.addVersion(npmciInfo.version)
// build
smartcli.addCommand('build')
.then(async (argv) => {
let modBuild = await npmciMods.modBuild.load()
await modBuild.build(argv._[1])
NpmciEnv.configStore()
}).catch(err => {
console.log(err)
process.exit(1)
})
// clean
smartcli.addCommand('clean')
.then(async (argv) => {
let modClean = await npmciMods.modClean.load()
await modClean.clean()
await NpmciEnv.configStore()
}).catch(err => {
console.log(err)
process.exit(1)
})
// command
smartcli.addCommand('command')
.then(async (argv) => {
let modCommand = await npmciMods.modCommand.load()
await modCommand.command()
await NpmciEnv.configStore()
}).catch(err => {
console.log(err)
process.exit(1)
})
// install
smartcli.addCommand('install')
.then(async (argv) => {
let modInstall = await npmciMods.modInstall.load()
await modInstall.install(argv._[1])
await NpmciEnv.configStore()
}).catch(err => {
console.log(err)
process.exit(1)
})
// prepare
smartcli.addCommand('prepare')
.then(async (argv) => {
let modPrepare = await npmciMods.modPrepare.load()
await modPrepare.prepare(argv._[1])
await NpmciEnv.configStore()
}).catch(err => {
console.log(err)
process.exit(1)
})
// publish
smartcli.addCommand('publish')
.then(async (argv) => {
let modPublish = await npmciMods.modPublish.load()
await modPublish.publish(argv._[1])
await NpmciEnv.configStore()
}).catch(err => {
console.log(err)
process.exit(1)
})
// test
smartcli.addCommand('test')
.then(async (argv) => {
let modTest = await npmciMods.modTest.load()
await modTest.test(argv._[1])
await NpmciEnv.configStore()
}).catch(err => {
console.log(err)
process.exit(1)
})
// trigger
smartcli.addCommand('trigger')
.then(async (argv) => {
let modTrigger = await npmciMods.modTrigger.load()
await modTrigger.trigger()
await NpmciEnv.configStore()
}).catch(err => {
console.log(err)
process.exit(1)
})
smartcli.startParse()

View File

@ -1,10 +1,12 @@
import * as plugins from './npmci.plugins'
import * as paths from './npmci.paths'
import { GitRepo } from 'smartstring'
import { Dockerfile } from './npmci.build.docker'
import { Dockerfile } from './mod_docker/index'
export let repo: GitRepo
if (process.env.CI_REPOSITORY_URL) repo = new GitRepo(process.env.CI_REPOSITORY_URL)
if (process.env.CI_REPOSITORY_URL) {
repo = new GitRepo(process.env.CI_REPOSITORY_URL)
}
export let buildStage: string = process.env.CI_BUILD_STAGE
@ -22,7 +24,7 @@ export let config = {
project: undefined
}
export let configStore = () => {
export let configStore = async () => {
config.dockerRegistry = dockerRegistry
plugins.smartfile.memory.toFsSync(
JSON.stringify(config),

View File

@ -0,0 +1,21 @@
import * as _modBuild from './mod_build/index'
import * as _modClean from './mod_clean/index'
import * as _modCommand from './mod_command/index'
import * as _modDocker from './mod_docker/index'
import * as _modInstall from './mod_install/index'
import * as _modPublish from './mod_publish/index'
import * as _modPrepare from './mod_prepare/index'
import * as _modTrigger from './mod_trigger/index'
import * as _modTest from './mod_test/index'
import { LazyModule } from 'smartsystem'
export let modBuild = new LazyModule<typeof _modBuild>('./mod_build/index', __dirname)
export let modClean = new LazyModule<typeof _modClean>('./mod_clean/index', __dirname)
export let modCommand = new LazyModule<typeof _modCommand>('./mod_command/index', __dirname)
export let modDocker = new LazyModule<typeof _modDocker>('./mod_docker/index', __dirname)
export let modInstall = new LazyModule<typeof _modInstall>('./mod_install/index', __dirname)
export let modPublish = new LazyModule<typeof _modPublish>('./mod_publish/index', __dirname)
export let modPrepare = new LazyModule<typeof _modPrepare>('./mod_prepare/index', __dirname)
export let modTrigger = new LazyModule<typeof _modTrigger>('./mod_trigger/index', __dirname)
export let modTest = new LazyModule<typeof _modTest>('./mod_test/index',__dirname)

17
ts/npmci.monitor.ts Normal file
View File

@ -0,0 +1,17 @@
import * as plugins from './npmci.plugins'
import * as env from './npmci.env'
import { Smartmonitor } from 'smartmonitor'
export let npmciMonitor = new Smartmonitor()
if(process.env.SMARTMONITOR) {
npmciMonitor.addInstrumental({
apiKey: process.env.SMARTMONITOR
})
plugins.beautylog.info('Monitoring activated')
} else {
plugins.beautylog.warn('Monitoring could not be enabled due to missing API-KEY')
}
npmciMonitor.increment('lossless-ci.builds', 1)

View File

@ -16,6 +16,7 @@ export import smartparam = require('smartparam')
export import smartq = require('smartq')
export import smartshell = require('smartshell')
export import smartsocket = require('smartsocket')
export import smartsystem = require('smartsystem')
export import smartssh = require('smartssh')
export import smartstring = require('smartstring')
export import through2 = require('through2')

View File

@ -3,6 +3,13 @@ import * as plugins from './npmci.plugins'
let sshRegex = /^(.*)\|(.*)\|(.*)/
let sshInstance: plugins.smartssh.SshInstance
/**
* checks if not undefined
*/
let notUndefined = (stringArg: string) => {
return (stringArg && stringArg !== 'undefined' && stringArg !== '##')
}
/**
* checks for ENV vars in form of NPMCI_SSHKEY_* and deploys any found ones
*/
@ -39,10 +46,3 @@ let evaluateSshEnv = async (sshkeyEnvVarArg) => {
sshInstance.addKey(sshKey)
return
}
/**
* checks if not undefined
*/
let notUndefined = (stringArg: string) => {
return (stringArg && stringArg !== 'undefined' && stringArg !== '##')
}

View File

@ -1,36 +0,0 @@
import * as plugins from './npmci.plugins'
import { bash, yarnAvailable } from './npmci.bash'
import { install } from './npmci.install'
import * as env from './npmci.env'
import * as NpmciBuildDocker from './npmci.build.docker'
export let test = async (versionArg): Promise<void> => {
if (versionArg === 'docker') {
await testDocker()
} else {
await install(versionArg)
.then(npmDependencies)
.then(npmTest)
}
}
let npmDependencies = async (): Promise<void> => {
plugins.beautylog.info('now installing dependencies:')
if (await yarnAvailable.promise) {
await bash('yarn upgrade')
} else {
await bash('npm install')
}
}
let npmTest = async (): Promise<void> => {
plugins.beautylog.info('now starting tests:')
await bash('npm test')
}
let testDocker = async (): Promise<NpmciBuildDocker.Dockerfile[]> => {
return await NpmciBuildDocker.readDockerfiles()
.then(NpmciBuildDocker.pullDockerfileImages)
.then(NpmciBuildDocker.testDockerfiles)
}