1 | var gaze = require('gaze');
|
2 | var coffee = require('coffee-script');
|
3 | var fs = require('fs');
|
4 | var path = require('path')
|
5 | var childProcess = require('child_process');
|
6 |
|
7 |
|
8 |
|
9 | module.exports = function(grunt) {
|
10 | 'use strict';
|
11 |
|
12 |
|
13 | var path = require('path');
|
14 | var _ = grunt.util._;
|
15 |
|
16 | var icoffeeProcess = function(dirArr) {
|
17 | var childProcess = require('child_process');
|
18 |
|
19 | var dirname = path.dirname(__filename)
|
20 | var wr = path.resolve(dirname, 'lib/watcher.js');
|
21 | var child = childProcess.fork(wr, ['12312', 'arafdf'])
|
22 | child.on('message', function(e) {
|
23 | if(e.type === 'success') {
|
24 | grunt.log.ok(e.msg)
|
25 | }else if (e.type === 'error') {
|
26 | grunt.log.error(e.msg)
|
27 | }
|
28 | });
|
29 | child.send(dirArr)
|
30 | }
|
31 |
|
32 | grunt.registerMultiTask('icoffee', 'icoffee task', function() {
|
33 | var options = this.options({});
|
34 | var done = this.async();
|
35 |
|
36 | icoffeeProcess(this.data.src)
|
37 | return
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 | var dirname = path.dirname(__filename)
|
44 | var wr = path.resolve(dirname, 'lib/watcher.js');
|
45 | console.log(wr)
|
46 | var child = grunt.util.spawn({
|
47 | cmd: process.argv[0],
|
48 | args: [wr],
|
49 | opts: {
|
50 | stdio: 'inherit'
|
51 | }
|
52 | });
|
53 | child.on('data', function(buf) {
|
54 | console.log(String(buf));
|
55 | });
|
56 |
|
57 | return
|
58 |
|
59 |
|
60 | return
|
61 | gaze('./Gruntfile.coffee', function(err, watch) {
|
62 | console.log(err)
|
63 | console.log('wacthed files: ', this.watched());
|
64 | this.on('changed', function(filepath) {
|
65 | content = fs.readFileSync(filepath, 'utf8')
|
66 | a = coffee.compile(content, options)
|
67 | console.log(a)
|
68 | });
|
69 | });
|
70 | });
|
71 |
|
72 | function watcher(dirArr, options) {
|
73 | gaze(dirArr, function(err, watch) {
|
74 | console.log(err)
|
75 | console.log('wacthed files: ', this.watched());
|
76 | this.on('changed', function(filepath) {
|
77 | content = fs.readFileSync(filepath, 'utf8')
|
78 | a = coffee.compile(content, options)
|
79 | console.log(a)
|
80 | });
|
81 | });
|
82 | };
|
83 |
|
84 | }; |
\ | No newline at end of file |