2018-04-08 23:03:39 +00:00
|
|
|
import plugins = require('./npmts.plugins');
|
|
|
|
import paths = require('./npmts.paths');
|
2016-10-02 18:35:13 +00:00
|
|
|
|
2018-04-08 23:03:39 +00:00
|
|
|
import * as smartq from 'smartq';
|
2016-10-02 18:35:13 +00:00
|
|
|
|
2017-07-27 23:21:37 +00:00
|
|
|
// interfaces
|
2018-04-08 23:03:39 +00:00
|
|
|
import { ITapbufferConfig } from 'tapbuffer';
|
2017-07-27 23:21:37 +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
|
|
|
|
*/
|
2018-04-08 23:03:39 +00:00
|
|
|
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 {
|
2018-04-08 23:03:39 +00:00
|
|
|
argv: any;
|
|
|
|
coverageTreshold: number;
|
|
|
|
checkDependencies: boolean;
|
|
|
|
mode: npmtsMode;
|
|
|
|
test: boolean;
|
|
|
|
testTs: any;
|
|
|
|
testConfig: ITapbufferConfig;
|
|
|
|
ts: any;
|
|
|
|
tsOptions: any;
|
|
|
|
watch: boolean;
|
2017-03-31 17:18:18 +00:00
|
|
|
runData: {
|
2018-04-08 23:03:39 +00:00
|
|
|
coverageLcovInfo?: string;
|
|
|
|
coverageResult?: number;
|
|
|
|
};
|
2017-06-15 23:42:48 +00:00
|
|
|
}
|
2016-08-19 07:46:36 +00:00
|
|
|
|
2018-04-08 23:03:39 +00:00
|
|
|
export let run = function(argvArg) {
|
2018-05-03 10:35:41 +00:00
|
|
|
let done = smartq.defer<INpmtsConfig>();
|
2017-03-31 17:18:18 +00:00
|
|
|
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: {},
|
2017-06-17 08:47:07 +00:00
|
|
|
testConfig: {
|
2017-07-27 23:21:37 +00:00
|
|
|
parallel: true,
|
|
|
|
coverage: true
|
2017-06-17 08:47:07 +00:00
|
|
|
},
|
2017-03-31 17:18:18 +00:00
|
|
|
ts: {},
|
|
|
|
tsOptions: {},
|
|
|
|
watch: false,
|
|
|
|
runData: {}
|
2018-04-08 23:03:39 +00:00
|
|
|
};
|
2016-08-19 07:46:36 +00:00
|
|
|
|
2017-03-31 17:18:18 +00:00
|
|
|
// mix with configfile
|
2018-04-08 23:03:39 +00:00
|
|
|
plugins.beautylog.ora.text('running npmextra');
|
2016-09-24 14:57:30 +00:00
|
|
|
|
2018-04-08 23:03:39 +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
|
2018-04-08 23:03:39 +00:00
|
|
|
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':
|
2018-04-08 23:03:39 +00:00
|
|
|
plugins.beautylog.ok('mode is ' + config.mode);
|
|
|
|
done.resolve(config);
|
|
|
|
break;
|
2017-03-31 17:18:18 +00:00
|
|
|
default:
|
2018-04-08 23:03:39 +00:00
|
|
|
plugins.beautylog.error(`mode not recognised! Can be default or custom`);
|
|
|
|
process.exit(1);
|
2017-06-16 14:08:36 +00:00
|
|
|
}
|
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/'
|
2018-04-08 23:03:39 +00:00
|
|
|
};
|
2017-03-31 17:18:18 +00:00
|
|
|
config.testTs = {
|
|
|
|
'./test/**/*.ts': './test/'
|
2018-04-08 23:03:39 +00:00
|
|
|
};
|
2017-06-16 14:08:36 +00:00
|
|
|
}
|
2016-03-23 13:12:58 +00:00
|
|
|
|
2017-03-31 17:18:18 +00:00
|
|
|
// mix with commandline
|
|
|
|
if (config.argv.notest) {
|
2018-04-08 23:03:39 +00:00
|
|
|
config.test = false;
|
2017-06-16 14:08:36 +00:00
|
|
|
}
|
2017-06-16 14:12:42 +00:00
|
|
|
|
|
|
|
if (config.argv.nocoverage) {
|
2018-04-08 23:03:39 +00:00
|
|
|
config.testConfig.coverage = false;
|
2017-06-16 14:12:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (config.argv.nochecks) {
|
2018-04-08 23:03:39 +00:00
|
|
|
config.checkDependencies = false;
|
2017-06-16 14:12:42 +00:00
|
|
|
}
|
|
|
|
|
2017-03-31 17:18:18 +00:00
|
|
|
if (config.argv.watch) {
|
2018-04-08 23:03:39 +00:00
|
|
|
config.watch = true;
|
2017-06-16 14:08:36 +00:00
|
|
|
}
|
2016-03-29 23:32:41 +00:00
|
|
|
|
2018-04-08 23:03:39 +00:00
|
|
|
plugins.beautylog.ok('build options are ready!');
|
|
|
|
done.resolve(config);
|
|
|
|
configDeferred.resolve(config);
|
|
|
|
return done.promise;
|
|
|
|
};
|
2017-08-29 14:15:24 +00:00
|
|
|
|
|
|
|
// config deferred usage
|
2018-04-08 23:03:39 +00:00
|
|
|
let configDeferred = smartq.defer<INpmtsConfig>();
|
|
|
|
export let configPromise = configDeferred.promise;
|