All files / tasks ts.ts

100% Statements 26/26
100% Branches 12/12
100% Functions 3/3
100% Lines 26/26
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 6542x     42x 42x 42x                                             42x 5x   5x 5x 5x 5x         5x   5x 5x 5x   5x   5x 3x 3x 3x   3x 3x 3x 3x   3x   5x   5x      
import * as _ from 'lodash';
import ITask = grunt.task.ITask;
 
export = function(grunt: IGrunt) {
	const distDirectory = grunt.config.get<string>('distDirectory');
	const defaultOptions: any = {
		dist: {
			exclude: ['tests/**/*.ts', 'src/*/tests/**/*.ts', 'src/*/example/**/*.ts'],
			compilerOptions: {
				outDir: distDirectory,
				declaration: true,
				sourceMap: true,
				inlineSources: true
			}
		},
		esm: {
			exclude: ['tests/**/*.ts', 'src/*/tests/**/*.ts', 'src/*/example/**/*.ts'],
			compilerOptions: {
				target: 'es6',
				module: 'es6',
				sourceMap: false,
				outDir: 'dist/esm',
				inlineSourceMap: true,
				inlineSources: true
			}
		}
	};
 
	grunt.registerTask('dojo-ts', <any> function (this: ITask) {
		grunt.loadNpmTasks('grunt-ts');
 
		const flags = this.args && this.args.length ? this.args : [ 'dev' ];
		const tsconfig = grunt.config.get<any>('tsconfig');
		const tsOptions = grunt.config.get<any>('ts') || {};
		const baseOptions = {
			failOnTypeErrors: true,
			fast: 'never'
		};
 
		grunt.config.set('ts.options', baseOptions);
 
		const tasks: string[] = [];
		flags.forEach((target: string) => {
			let tsconfigFileName = 'tsconfig.json';
 
			tasks.push(`ts:${target}`);
			// dev task cannot be configured outside of projects tsconfig
			if (target !== 'dev') {
				const targetTsconfig = _.cloneDeep(tsconfig);
				const targetDefaultOptions = defaultOptions[target] || {};
				const targetTsOptions = tsOptions[target] || {};
 
				_.merge(targetTsconfig, targetDefaultOptions, targetTsOptions);
				tsconfigFileName = `.tsconfig${target}.json`;
				grunt.file.write(tsconfigFileName, JSON.stringify(targetTsconfig));
				grunt.config.set(`clean.${target}Tsconfig`, { src: tsconfigFileName});
 
				tasks.push(`clean:${target}Tsconfig`);
			}
			grunt.config.set(`ts.${target}`, { tsconfig: { passThrough: true, tsconfig: tsconfigFileName }});
		});
		grunt.task.run(tasks);
	});
};