Browse files

lock server while compiling assets

  • Loading branch information...
1 parent 0095cc3 commit c5a6164565f16bca5777ae5467119a22f0f2ab30 @fivetanley fivetanley committed Feb 14, 2014
Showing with 33 additions and 5 deletions.
  1. +2 −1 package.json
  2. +11 −0 tasks/lock.js
  3. +1 −1 tasks/options/clean.js
  4. +17 −1 tasks/options/connect.js
  5. +2 −2 tasks/options/watch.js
View
3 package.json
@@ -25,6 +25,7 @@
"grunt-ember-defeatureify": "~0.1.0",
"aws-sdk": "~2.0.0-rc8",
"grunt-cli": "~0.1.13",
- "grunt-contrib-yuidoc": "~0.5.0"
+ "grunt-contrib-yuidoc": "~0.5.0",
+ "lockfile": "~0.4.2"
}
}
View
11 tasks/lock.js
@@ -0,0 +1,11 @@
+var lockFile = require('lockfile');
+var grunt = require('grunt');
+var LOCKFILE = __dirname + "/../tmp/connect.lock";
+
+grunt.registerTask('lock', function(){
+ lockFile.lockSync(LOCKFILE);
+});
+
+grunt.registerTask('unlock', function(){
+ lockFile.unlockSync(LOCKFILE);
+});
View
2 tasks/options/clean.js
@@ -1,3 +1,3 @@
module.exports = {
- main: [ 'tmp/**/*' ]
+ main: [ 'tmp/!connect.lock' ]
};
View
18 tasks/options/connect.js
@@ -1,9 +1,25 @@
+var lockFile = require('lockfile');
+var lockMiddleware = function(req, res, next) {
+ if (!lockFile.checkSync(__dirname + '/../../tmp/connect.lock')) {
+ return next();
+ } else {
+ setTimeout(function(){
+ lockMiddleware(req, res, next);
+ }, 10);
+ }
+};
+
+
var port = process.env.PORT || '9997';
module.exports = {
main: {
options: {
port: port,
- base: '.'
+ base: '.',
+ middleware: function(connect, options){
+ var base = options.base;
+ return [ lockMiddleware, connect.static(base), connect.directory(base) ];
+ }
}
}
};
View
4 tasks/options/watch.js
@@ -2,11 +2,11 @@ module.exports = {
packages: {
files: [ 'packages/**/*.js', '!packages/**/test/**/*.js'],
- tasks: [ 'buildPackages', 'prepareTests', 'qunit:local' ]
+ tasks: [ 'lock', 'buildPackages', 'prepareTests', 'unlock', 'qunit:local' ]
},
tests: {
files: [ 'packages/**/test/**/*.js' ],
- tasks: [ 'prepareTests', 'qunit:local' ]
+ tasks: [ 'lock', 'prepareTests', 'unlock', 'qunit:local' ]
}
};

0 comments on commit c5a6164

Please sign in to comment.