npmci/ts/mod_publish/index.ts

52 lines
1.2 KiB
TypeScript

import * as plugins from './mod.plugins'
import { bash } from '../npmci.bash'
import * as NpmciEnv from '../npmci.env'
import * as npmciMods from '../npmci.mods'
// import interfaces
import { Dockerfile } from '../mod_docker/index'
/**
* type of supported services
*/
export type TPubService = 'npm' | 'docker'
/**
* the main exported publish function.
* @param pubServiceArg references targeted service to publish to
*/
export let publish = async (argvArg: any) => {
let whatToPublish = argvArg._[1]
switch (whatToPublish) {
case 'npm':
return await publishNpm(argvArg)
case 'docker':
return await publishDocker(argvArg)
}
}
/**
* tries to publish current cwd to NPM registry
*/
let publishNpm = async (argvArg) => {
let modPrepare = await npmciMods.modPrepare.load()
await modPrepare.prepare('npm')
await bash('npm publish')
plugins.beautylog.ok('Done!')
}
/**
* tries to publish current cwd to Docker registry
*/
let publishDocker = async (argvArg) => {
let modDocker = await npmciMods.modDocker.load()
return await modDocker.readDockerfiles(argvArg)
.then(modDocker.pullDockerfileImages)
.then(modDocker.pushDockerfiles)
.then(dockerfileArray => {
return dockerfileArray
})
}