All files / tasks postcss.ts

100% Statements 12/12
100% Branches 4/4
100% Functions 2/2
100% Lines 12/12
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 6342x   42x 42x 42x 42x 42x   42x 42x   42x                       84x               42x             42x                                                
import { createProcessors } from './util/postcss';
 
export = function init(grunt: IGrunt) {
	const path = require('path');
	const postCssImport = require('postcss-import');
	const postCssNext = require('postcss-cssnext');
	grunt.loadNpmTasks('grunt-postcss');
 
	const distDirectory = grunt.config.get<string>('distDirectory') || '';
	const devDirectory = grunt.config.get<string>('devDirectory') || '';
 
	const variablesProcessors: any = [
		postCssImport,
		postCssNext({
			features: {
				customProperties: {
					preserve: 'computed'
				}
			}
		})
	];
 
	function moduleFiles(dest: string) {
		return [{
			expand: true,
			src: ['**/*.m.css'],
			dest: dest,
			cwd: 'src'
		}];
	}
 
	const cssFiles = [{
		expand: true,
		src: ['**/*.css', '!**/*.m.css'],
		dest: distDirectory,
		cwd: 'src'
	}];
 
	grunt.config.set('postcss', {
		options: {
			map: true
		},
		'modules-dev': {
			files: moduleFiles(path.join(devDirectory, 'src')),
			options: {
				processors: createProcessors(devDirectory)
			}
		},
		'modules-dist': {
			files: moduleFiles(distDirectory),
			options: {
				processors: createProcessors(distDirectory, 'src', true)
			}
		},
		variables: {
			files: cssFiles,
			options: {
				processors: variablesProcessors
			}
		}
	});
};