UNPKG

3.39 kBJavaScriptView Raw
1const task = require('./task/index');
2const folder = require('./config/folder/index');
3const _ = require('lodash');
4const utils = require('corifeus-utils');
5const fs = require('fs');
6
7class loader {
8 constructor(grunt) {
9 this.grunt = grunt
10
11 this.configJit = {
12// jshint: 'grunt-contrib-jshint',
13
14 clean: 'grunt-contrib-clean',
15 watch: 'grunt-contrib-watch',
16// jsdoc: 'grunt-contrib-jsdoc',
17 };
18 }
19
20 load(options) {
21
22 let pkg = JSON.parse(fs.readFileSync(`${process.cwd()}/package.json`, 'utf8'));
23 pkg.corifeus = pkg.corifeus || {};
24 let originalPkg = JSON.stringify(pkg)
25
26 const grunt = this.grunt;
27
28 options = options || {};
29
30 options.jit = _.merge(this.configJit, options.jit || {})
31 options.config = _.merge(require('./config/grunt/js/index')(grunt), options.config)
32 const config = options.config;
33
34 if (options.empty) {
35
36 options.replacer = {
37 type: 'p3x',
38 }
39 }
40
41 require('./replaces')(options, pkg);
42
43 grunt.config.merge(config);
44 Object.keys(task).forEach((taskItem) => task[taskItem](grunt))
45
46 grunt.registerTask('cory:kill', function () {
47 process.exit(1);
48 });
49
50
51 grunt.registerTask('cory:upgrade', function () {
52
53 const upgrade = require('./utils/upgrade')
54 upgrade({
55 grunt: grunt,
56 gruntThis: this,
57 defaultOptions: options,
58 });
59 })
60
61 grunt.registerTask('cory:license', function () {
62
63 const license = require('./utils').license()
64 fs.writeFileSync(`${process.cwd()}/LICENSE`, license)
65 })
66
67
68 grunt.registerTask('cory-test', (target) => {
69 switch (target) {
70
71 case 'angular-protractor':
72 grunt.task.run([
73 'connect:cory-angular',
74 'protractor:cory-angular-chrome',
75
76 ]);
77 break;
78
79 case 'angular-karma':
80 grunt.task.run([
81 'karma:cory-angular-run',
82 'watch:cory-angular-karma'
83 ]);
84 break;
85 }
86 });
87 grunt.registerTask('cory-build-run', (target) => {
88 switch (target) {
89 case 'angular':
90 grunt.task.run(config.task.run.angular);
91 break;
92
93 case 'js':
94 grunt.task.run(config.task.run.js);
95 break;
96 }
97 });
98
99
100 // should be at the end
101 require('jit-grunt')(grunt, options.jit);
102 require('time-grunt')(grunt);
103
104
105 if (originalPkg !== JSON.stringify(pkg)) {
106 fs.writeFileSync(`${process.cwd()}/package.json`, JSON.stringify(pkg, null, 4))
107 }
108 }
109
110 js(options) {
111 options = options || {};
112 this.load(options);
113 }
114
115 empty(options) {
116 options = options || {};
117 options.empty = true;
118 this.load(options);
119 }
120
121 ts(options) {
122 options = options || {};
123 options.config = _.merge(require('./config/grunt/ts/index')(), options.config || {}),
124 this.load(options);
125 }
126
127
128}
129
130module.exports = loader;