Skip to content

Commit b51290f

Browse files
committed
adding nodejs builder to project
1 parent 0000d04 commit b51290f

File tree

6 files changed

+277
-2
lines changed

6 files changed

+277
-2
lines changed

build.node.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
(function() {
2+
'use strict';
3+
const hound = require("./lib/node-hound");
4+
const { spawn, exec } = require('child_process');
5+
6+
/*
7+
* Watch JavaScript files
8+
*/
9+
10+
var jsWatcher = hound.watch('./app/js');
11+
12+
var compileJSFiles = function() {
13+
var compileJS = spawn('node', ['./r.js', '-o', 'require.build.js']);
14+
console.log('\n------------------- Start compiling RequireJS -------------------');
15+
16+
compileJS.stdout.on('data', function(data) {
17+
console.log('stdout:' + data);
18+
});
19+
20+
compileJS.stderr.on('data', function(data) {
21+
console.log('stderr: ' + data);
22+
});
23+
24+
compileJS.on('close', (code) => {
25+
console.log('------------------- Stop compiling RequireJS -------------------');
26+
});
27+
};
28+
29+
jsWatcher.on('create', function(file, stats) {
30+
file = file.replace("\\", "/");
31+
console.log('------------------- ' + file.replace("\\", "/") + ' was created -------------------');
32+
compileJSFiles();
33+
});
34+
jsWatcher.on('change', function(file, stats) {
35+
file = file.replace("\\", "/");
36+
console.log('------------------- ' + file.replace("\\", "/") + ' was changed -------------------');
37+
compileJSFiles();
38+
});
39+
jsWatcher.on('delete', function(file) {
40+
file = file.replace("\\", "/");
41+
console.log('------------------- ' + file.replace("\\", "/") + ' was deleted -------------------');
42+
compileJSFiles();
43+
});
44+
45+
/*
46+
* Watch less files
47+
*/
48+
49+
var lessWatcher = hound.watch('./app/style');
50+
51+
var compileLESSFiles = function() {
52+
console.log('\n------------------- Start compiling LESS -------------------');
53+
exec('lessc ./app/style/main.less ./dist/main.css', (error, stdout, stderr) => {
54+
if (error) {
55+
console.error('exec error: ' + error);
56+
return;
57+
}
58+
if (stdout.trim())
59+
console.log('stdout:' + stdout);
60+
if (stderr.trim())
61+
console.log('stderr: ' + stderr);
62+
console.log('------------------- Stop compiling LESS -------------------');
63+
});
64+
};
65+
66+
lessWatcher.on('create', function(file, stats) {
67+
file = file.replace("\\", "/");
68+
console.log('------------------- ' + file.replace("\\", "/") + ' was created -------------------');
69+
compileLESSFiles();
70+
});
71+
lessWatcher.on('change', function(file, stats) {
72+
file = file.replace("\\", "/");
73+
console.log('------------------- ' + file.replace("\\", "/") + ' was changed -------------------');
74+
compileLESSFiles();
75+
});
76+
lessWatcher.on('delete', function(file) {
77+
file = file.replace("\\", "/");
78+
console.log('------------------- ' + file.replace("\\", "/") + ' was deleted -------------------');
79+
compileLESSFiles();
80+
});
81+
82+
}());

build.sh

Lines changed: 0 additions & 2 deletions
This file was deleted.

lib/node-hound/LICENSE

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Copyright (c) 2012, Michael Alexander
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions are met:
6+
7+
1. Redistributions of source code must retain the above copyright notice, this
8+
list of conditions and the following disclaimer.
9+
2. Redistributions in binary form must reproduce the above copyright notice,
10+
this list of conditions and the following disclaimer in the documentation
11+
and/or other materials provided with the distribution.
12+
13+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
17+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
20+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23+
24+
The views and conclusions contained in the software and documentation are those
25+
of the authors and should not be interpreted as representing official policies,
26+
either expressed or implied, of the hound Project.

lib/node-hound/README.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
hound - directory tree watcher for node.js
2+
=============================================
3+
4+
Cross platform directory tree watcher that works, even on Windows
5+
-----------------------------------------------------------------
6+
7+
The philosophy of hound is:
8+
9+
* **Be reliable, work on every platform**
10+
* **Be fast**
11+
* **Be simple**
12+
13+
hound is designed to be very reliable, fast, and simple. There are no runtime
14+
dependencies outside of the standard node.js libraries. There is a development
15+
dependency on [Jasmine](http://pivotal.github.com/jasmine/), which is required
16+
to run the tests.
17+
18+
Installation
19+
------------
20+
21+
Install using npm:
22+
23+
```
24+
npm install hound
25+
```
26+
27+
Because hound has no runtime dependencies, it is also possible to download the
28+
library manually and require it directly.
29+
30+
Usage
31+
-----
32+
33+
```javascript
34+
hound = require('hound')
35+
36+
// Create a directory tree watcher.
37+
watcher = hound.watch('/tmp')
38+
39+
// Create a file watcher.
40+
watcher = hound.watch('/tmp/file.txt')
41+
42+
// Add callbacks for file and directory events. The change event only applies
43+
// to files.
44+
watcher.on('create', function(file, stats) {
45+
console.log(file + ' was created')
46+
})
47+
watcher.on('change', function(file, stats) {
48+
console.log(file + ' was changed')
49+
})
50+
watcher.on('delete', function(file) {
51+
console.log(file + ' was deleted')
52+
})
53+
54+
// Unwatch specific files or directories.
55+
watcher.unwatch('/tmp/another_file')
56+
57+
// Unwatch all watched files and directories.
58+
watcher.clear()
59+
```
60+
61+
Testing
62+
-------
63+
64+
To run the tests, use `npm test`. The tests work on actual directory trees that
65+
are generated in the tmp directory.

lib/node-hound/hound.js

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
var fs = require('fs')
2+
, util = require('util')
3+
, events = require('events')
4+
, path = require('path')
5+
6+
/**
7+
* Watch one or more files or directories for changes.
8+
*
9+
* Options:
10+
* - watchFn: Specify a custom filesystem watch function (eg: `fs.watchFile`)
11+
*
12+
* @param {string|array} src The file or directory to watch.
13+
* @param {array} options
14+
* @return {Hound}
15+
*/
16+
exports.watch = function(src, options) {
17+
var watcher = new Hound(options)
18+
watcher.watch(src)
19+
return watcher
20+
}
21+
22+
/**
23+
* The Hound class tracks watchers and changes and emits events.
24+
*/
25+
function Hound(options) {
26+
events.EventEmitter.call(this)
27+
this.options = options || {}
28+
}
29+
util.inherits(Hound, events.EventEmitter)
30+
Hound.prototype.watchers = []
31+
32+
/**
33+
* Watch a file or directory tree for changes, and fire events when they happen.
34+
* Fires the following events:
35+
* 'create' (file, stats)
36+
* 'change' (file, stats)
37+
* 'delete' (file)
38+
* @param {string} src
39+
* @return {Hound}
40+
*/
41+
Hound.prototype.watch = function(src) {
42+
var self = this
43+
var stats = fs.statSync(src)
44+
var lastChange = null
45+
var watchFn = self.options.watchFn || fs.watch
46+
if (stats.isDirectory()) {
47+
var files = fs.readdirSync(src)
48+
for (var i = 0, len = files.length; i < len; i++) {
49+
self.watch(src + path.sep + files[i])
50+
}
51+
}
52+
self.watchers[src] = watchFn(src, function(event, filename) {
53+
if (fs.existsSync(src)) {
54+
stats = fs.statSync(src)
55+
if (stats.isFile()) {
56+
if (lastChange === null || stats.mtime.getTime() > lastChange)
57+
self.emit('change', src, stats)
58+
lastChange = stats.mtime.getTime()
59+
} else if (stats.isDirectory()) {
60+
// Check if the dir is new
61+
if (self.watchers[src] === undefined) {
62+
self.emit('create', src, stats)
63+
}
64+
// Check files to see if there are any new files
65+
var dirFiles = fs.readdirSync(src)
66+
for (var i = 0, len = dirFiles.length; i < len; i++) {
67+
var file = src + path.sep + dirFiles[i]
68+
if (self.watchers[file] === undefined) {
69+
self.watch(file)
70+
self.emit('create', file, fs.statSync(file))
71+
}
72+
}
73+
}
74+
} else {
75+
self.unwatch(src)
76+
self.emit('delete', src)
77+
}
78+
})
79+
self.emit('watch', src)
80+
}
81+
82+
/**
83+
* Unwatch a file or directory tree.
84+
* @param {string} src
85+
*/
86+
Hound.prototype.unwatch = function(src) {
87+
var self = this
88+
if (self.watchers[src] !== undefined) {
89+
self.watchers[src].close()
90+
delete self.watchers[src]
91+
}
92+
self.emit('unwatch', src)
93+
}
94+
95+
/**
96+
* Unwatch all currently watched files and directories in this watcher.
97+
*/
98+
Hound.prototype.clear = function() {
99+
var self = this
100+
for (var file in this.watchers) {
101+
self.unwatch(file)
102+
}
103+
}

js.build.js renamed to require.build.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
insertRequire: ['main'],
55
out: './dist/main.js',
66
wrap: true,
7+
optimize: 'none',
78
paths: {
89
init: './init.config',
910
consts: './consts.config',

0 commit comments

Comments
 (0)