npmci/ts/npmci.env.ts

75 lines
2.0 KiB
TypeScript
Raw Normal View History

2016-11-24 23:07:20 +00:00
import * as plugins from './npmci.plugins'
import * as paths from './npmci.paths'
2017-03-08 13:50:41 +00:00
import { GitRepo } from 'smartstring'
2017-05-18 20:40:09 +00:00
import { Dockerfile } from './mod_docker/index'
/**
* a info instance about the git respoitory at cwd :)
*/
2016-11-24 23:07:20 +00:00
export let repo: GitRepo
2017-05-18 20:40:09 +00:00
if (process.env.CI_REPOSITORY_URL) {
repo = new GitRepo(process.env.CI_REPOSITORY_URL)
2017-07-19 07:40:48 +00:00
}
2016-06-05 19:11:30 +00:00
2017-07-19 07:40:48 +00:00
/**
* the build stage
*/
2016-11-24 23:07:20 +00:00
export let buildStage: string = process.env.CI_BUILD_STAGE
2016-06-03 01:44:24 +00:00
// handling config between commands
2016-11-24 23:07:20 +00:00
export let dockerRegistry: string // will be set by npmci.prepare
export let setDockerRegistry = (dockerRegistryArg: string) => {
2017-03-08 13:50:41 +00:00
dockerRegistry = dockerRegistryArg
}
2016-11-24 23:07:20 +00:00
export let dockerFilesBuilt: Dockerfile[] = []
export let dockerFiles: Dockerfile[] = []
2017-07-19 07:40:48 +00:00
/**
* the config
*/
export let config = {
2017-03-08 13:50:41 +00:00
dockerRegistry: undefined, // this will be set later on store
dockerFilesBuilt: dockerFilesBuilt,
dockerFiles: dockerFiles,
project: undefined
2016-11-24 23:07:20 +00:00
}
/**
* the configuration store
*/
2017-05-18 20:40:09 +00:00
export let configStore = async () => {
2017-03-08 13:50:41 +00:00
config.dockerRegistry = dockerRegistry
plugins.smartfile.memory.toFsSync(
JSON.stringify(config),
paths.NpmciPackageConfig
)
2016-06-05 21:53:01 +00:00
}
/**
* load the config in case a previous run has stored it
*/
2016-06-19 00:30:50 +00:00
let configLoad = () => {
2017-03-08 13:50:41 +00:00
// internal config to transfer information in between npmci shell calls
try {
plugins.lodash.assign(config, plugins.smartfile.fs.toObjectSync(paths.NpmciPackageConfig, 'json'))
} catch (err) {
configStore()
plugins.beautylog.log('config initialized!')
}
2016-06-19 00:30:50 +00:00
2017-03-08 13:50:41 +00:00
// project config
try {
if (!config.project) {
config.project = plugins.smartfile.fs.toObjectSync(paths.NpmciProjectDir, 'npmci.json')
plugins.beautylog.ok('project config found!')
2017-05-15 16:27:13 +00:00
}
} catch (err) {
2017-03-08 13:50:41 +00:00
config.project = {}
plugins.beautylog.log('no project config found, so proceeding with default behaviour!')
}
2016-11-24 23:07:20 +00:00
2017-03-08 13:50:41 +00:00
config.dockerRegistry ? dockerRegistry = config.dockerRegistry : void (0)
config.dockerFilesBuilt ? dockerFilesBuilt = config.dockerFilesBuilt : void (0)
}
2016-11-24 23:07:20 +00:00
configLoad()