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