2016-09-06 15:21:25 +00:00
|
|
|
import plugins = require('./npmts.plugins')
|
|
|
|
import paths = require('./npmts.paths')
|
2016-10-02 18:35:13 +00:00
|
|
|
|
2017-01-17 23:58:09 +00:00
|
|
|
import * as q from 'smartq'
|
2016-10-02 18:35:13 +00:00
|
|
|
|
2017-06-15 23:42:48 +00:00
|
|
|
/**
|
|
|
|
* specifies the different modes available
|
|
|
|
* default -> uses default options no matterm what
|
|
|
|
* merge -> uses merged default + custom options
|
|
|
|
* custom -> only uses specified options
|
|
|
|
*/
|
|
|
|
export type npmtsMode = 'default' | 'custom' | 'merge'
|
2016-03-23 13:12:58 +00:00
|
|
|
|
2016-09-06 15:33:28 +00:00
|
|
|
export interface INpmtsConfig {
|
2017-06-15 23:42:48 +00:00
|
|
|
argv: any
|
|
|
|
coverageTreshold: number
|
|
|
|
checkDependencies: boolean
|
|
|
|
mode: npmtsMode
|
|
|
|
test: boolean
|
|
|
|
testTs: any
|
|
|
|
ts: any
|
|
|
|
tsOptions: any
|
2017-03-31 17:18:18 +00:00
|
|
|
watch: boolean
|
|
|
|
runData: {
|
2017-06-15 23:42:48 +00:00
|
|
|
coverageLcovInfo?: string
|
2017-03-31 17:18:18 +00:00
|
|
|
coverageResult?: number
|
|
|
|
}
|
2017-06-15 23:42:48 +00:00
|
|
|
}
|
2016-08-19 07:46:36 +00:00
|
|
|
|
2017-01-17 23:58:09 +00:00
|
|
|
export let run = function (argvArg) {
|
2017-03-31 17:18:18 +00:00
|
|
|
let done = q.defer()
|
|
|
|
let defaultConfig: INpmtsConfig = {
|
|
|
|
argv: undefined,
|
|
|
|
coverageTreshold: 70,
|
2017-06-15 23:42:48 +00:00
|
|
|
checkDependencies: true,
|
2017-03-31 17:18:18 +00:00
|
|
|
mode: 'default',
|
|
|
|
test: true,
|
|
|
|
testTs: {},
|
|
|
|
ts: {},
|
|
|
|
tsOptions: {},
|
|
|
|
watch: false,
|
|
|
|
runData: {}
|
|
|
|
}
|
2016-08-19 07:46:36 +00:00
|
|
|
|
2017-03-31 17:18:18 +00:00
|
|
|
// mix with configfile
|
|
|
|
plugins.beautylog.ora.text('running npmextra')
|
2016-09-24 14:57:30 +00:00
|
|
|
|
2017-03-31 17:18:18 +00:00
|
|
|
let localNpmextra = new plugins.npmextra.Npmextra(paths.cwd)
|
|
|
|
let config: INpmtsConfig = localNpmextra.dataFor<INpmtsConfig>(
|
|
|
|
'npmts',
|
|
|
|
defaultConfig
|
|
|
|
)
|
2016-08-19 07:46:36 +00:00
|
|
|
|
2017-03-31 17:18:18 +00:00
|
|
|
// add argv
|
|
|
|
config.argv = argvArg
|
2016-08-19 09:16:13 +00:00
|
|
|
|
2017-03-31 17:18:18 +00:00
|
|
|
// check mode
|
|
|
|
switch (config.mode) {
|
|
|
|
case 'default':
|
|
|
|
case 'custom':
|
2017-06-15 23:42:48 +00:00
|
|
|
case 'merge':
|
2017-03-31 17:18:18 +00:00
|
|
|
plugins.beautylog.ok('mode is ' + config.mode)
|
|
|
|
done.resolve(config)
|
|
|
|
break
|
|
|
|
default:
|
2017-06-15 23:42:48 +00:00
|
|
|
plugins.beautylog.error(`mode not recognised! Can be default or custom`)
|
2017-03-31 17:18:18 +00:00
|
|
|
process.exit(1)
|
|
|
|
};
|
2016-03-23 13:12:58 +00:00
|
|
|
|
2017-03-31 17:18:18 +00:00
|
|
|
// handle default mode
|
2017-06-15 23:42:48 +00:00
|
|
|
if (config.mode === 'default' || config.mode === 'merge') {
|
2017-03-31 17:18:18 +00:00
|
|
|
config.ts = {
|
|
|
|
'./ts/**/*.ts': './dist/'
|
|
|
|
}
|
|
|
|
config.testTs = {
|
|
|
|
'./test/**/*.ts': './test/'
|
|
|
|
}
|
|
|
|
};
|
2016-03-23 13:12:58 +00:00
|
|
|
|
2017-03-31 17:18:18 +00:00
|
|
|
// mix with commandline
|
|
|
|
if (config.argv.notest) {
|
|
|
|
config.test = false
|
|
|
|
};
|
|
|
|
if (config.argv.watch) {
|
|
|
|
config.watch = true
|
|
|
|
};
|
2016-03-29 23:32:41 +00:00
|
|
|
|
2017-03-31 17:18:18 +00:00
|
|
|
plugins.beautylog.ok('build options are ready!')
|
|
|
|
done.resolve(config)
|
|
|
|
return done.promise
|
2016-09-06 15:21:25 +00:00
|
|
|
}
|