UNPKG

1.19 kBJavaScriptView Raw
1require('lazy-ass');
2var check = require('check-more-types');
3
4function isValidSource(x) {
5 if (check.not.defined(x)) {
6 return true;
7 }
8 return check.unemptyString(x) ||
9 check.array(x);
10}
11
12var optionsSchema = {
13 plugin: check.unemptyString,
14 target: check.maybe.unemptyString,
15 src: isValidSource,
16 dest: check.maybe.unemptyString
17};
18var isValidOptions = check.schema.bind(null, optionsSchema);
19
20function isMultiTask(options) {
21 return check.object(options) &&
22 check.unemptyString(options.target) &&
23 check.has(options, 'src') &&
24 check.has(options, 'dest');
25}
26
27module.exports = function fakeGruntfileInit(options) {
28 la(check.object(options), 'missing grunty options', options);
29 la(isValidOptions(options), 'invalid options', options);
30
31 function fakeGruntfile(grunt) {
32 console.log('inside fake gruntfile');
33
34 var pkg = grunt.file.readJSON('package.json');
35
36 var config = {
37 pkg: pkg
38 };
39 if (isMultiTask(options)) {
40 config[options.target] = {
41 default: options
42 };
43 }
44
45 grunt.initConfig(config);
46 grunt.task.loadNpmTasks(options.plugin);
47 grunt.registerTask('default', []);
48 }
49
50 return fakeGruntfile;
51};