coffeescript 컴파일러에 대한 --watch 지시문이 node.js와 작동하지 않습니다. 0.4.7. 어떻게 고치는 지?Coffeescript - 노드 0.4.7에서 워치 스위치가 작동하지 않습니다.
(노드 0.4.7 현재 Heroku가에 배포해야합니다.)
coffeescript 컴파일러에 대한 --watch 지시문이 node.js와 작동하지 않습니다. 0.4.7. 어떻게 고치는 지?Coffeescript - 노드 0.4.7에서 워치 스위치가 작동하지 않습니다.
(노드 0.4.7 현재 Heroku가에 배포해야합니다.)
는 Node.js를 0.4.7에는 fs.watch 방법이 없습니다. 다음과 command.js에 라인 (198)의 시계 기능을 대체 : 당신이 노드 0.6로 업그레이드 할 수없는 경우, Jitter을 시도
watch = function(source, base) {
return fs.stat(source, function(err, prevStats) {
if (err) throw err;
return fs.watchFile(source, function(curr, prev) {
return fs.stat(source, function(err, stats) {
if (err) throw err;
if (stats.size === prevStats.size && stats.mtime.getTime() === prevStats.mtime.getTime()) {
return;
}
prevStats = stats;
return fs.readFile(source, function(err, code) {
if (err) throw err;
return compileScript(source, code.toString(), base);
});
});
});
});
};
두 가지를 모두 지원하는 공개 요청이 있습니다. https://github.com/jashkenas/coffee-script/pull/1846 –
업데이트 : 위의 풀 요청이 닫혔습니다. 'coffee'는'fs.watchFile'을 지원하지 않습니다. –
. 이것은 coffee -cw
이 CoffeeScript 1.1.3 이전에했던 일을 수행하는 단일 목적의 명령 행 유틸리티입니다. 게다가 컴파일에 실패 할 때 Growl 알림과 같은 몇 가지 작은 추가 기능이 있습니다.
Trevor에게 감사의 말 - Jitter가 좋아 보인다. 불행히도 그 이름은 내가 일해온 기존의 프로그래밍 제품과 충돌합니다! 전에 본 적이 있는지 궁금해 : http://cycling74.com/products/max/video-jitter/ – mainsocial
다음은 coffeescript -w 옵션이 작동하지 않아 동일한 경험을 한 후 작성한 watchscript입니다. .coffee, .less, .jade 파일을 찾아서 감시하고 해당 컴파일러를 응답으로 트리거합니다. 컴파일이 실패한시기를 쉽게 감지 할 수 있도록 컬러 출력을 생성합니다.
/*
* Tested on node 0.6, Ubuntu
*/
#!/usr/bin/node
COLOR_GREEN="\033[01;32m"
COLOR_RED="\033[01;31m"
COLOR_YELLOW="\033[01;33m"
COLOR_BLUE="\033[01;34m"
COLOR_NORMAL="\033[00m"
var fs = require('fs');
var coffeescript, jade, less;
try {
coffeescript = require('/usr/lib/node_modules/coffee-script'); // after npm -g install coffee-script
} catch(e) {
console.log(COLOR_RED,String(e),COLOR_NORMAL);
}
try {
jade = require('/usr/lib/node_modules/jade'); // after npm -g install jade
} catch(e) {
console.log(COLOR_RED,String(e),COLOR_NORMAL);
}
try {
less = require('/usr/lib/node_modules/less'); // after npm -g install less
} catch(e) {
console.log(COLOR_RED,String(e),COLOR_NORMAL);
}
console.log(
'Watch Support',
(coffeescript ? COLOR_GREEN : COLOR_RED),' coffeescript ',COLOR_NORMAL,
(jade ? COLOR_GREEN : COLOR_RED),' jade ',COLOR_NORMAL,
(less ? COLOR_GREEN : COLOR_RED),' less ',COLOR_NORMAL
);
var compile = function (fname) {
var source = fs.readFileSync(fname).toString();
try {
if(/\.jade$/.test(fname)) {
var html = jade.compile(source,{pretty:true})();
var htmlfname = fname.replace(/\.jade$/,'.html');
fs.writeFileSync(htmlfname, html);
console.log(COLOR_GREEN,'Success ',fname,new Date(),COLOR_NORMAL)
} else if(/\.coffee$/.test(fname)) {
var js = coffeescript.compile(source);
var jsfname = fname.replace(/\.coffee$/,'.js');
fs.writeFileSync(jsfname, js);
console.log(COLOR_GREEN,'Success ',fname,new Date(),COLOR_NORMAL)
} else if(/\.less$/.test(fname)) {
var lessparser = new(less.Parser);
var cssfname = fname.replace(/\.less$/,'.css');
lessparser.parse(source, function (e, tree) {
if(e) {
console.log(COLOR_RED,'Failed ',fname,String(e),COLOR_NORMAL);
} else {
fs.writeFileSync(cssfname, tree.toCSS());
console.log(COLOR_GREEN,'Success ',fname,new Date(),COLOR_NORMAL)
}
});
}
} catch(e) {
console.log(COLOR_RED,'Failed ',fname,String(e),COLOR_NORMAL)
}
}
var walk = function(dir, done) {
var results = [];
fs.readdir(dir, function(err, list) {
if (err) return done(err);
var pending = list.length;
if (!pending) return done(null, results);
list.forEach(function(file) {
file = dir + '/' + file;
fs.stat(file, function(err, stat) {
if (stat && stat.isDirectory()) {
walk(file, function(err, res) {
results = results.concat(res);
if (!--pending) done(null, results);
});
} else {
results.push(file);
if (!--pending) done(null, results);
}
});
});
});
};
function main() {
if(process.argv.length > 2) {
dirName = process.argv[2];
} else {
dirName = '.';
}
stats = fs.statSync(dirName);
if(stats.isDirectory()) {
walk(dirName,function (err, files) {
var watching = 0;
files.forEach(function (fname) {
if(/\.coffee$|\.less$|\.jade$/.test(fname)) {
fs.watchFile(fname,{persistent:true,interval:500},
function (cur,prev) {
if(cur.mtime.getTime() != prev.mtime.getTime()) {
compile(fname);
}
}
);
watching++;
}
});
if(watching) {
console.log('Watching '+watching+' file(s) in '+
COLOR_YELLOW+dirName+COLOR_NORMAL);
} else {
console.log('No coffee/jade/less files found to watch');
}
});
} else {
// It's a file
var fname = dirName;
if(/\.coffee$|\.less$|\.jade$/.test(fname)) {
fs.watchFile(fname,{persistent:true,interval:500},
function (cur,prev) {
if(cur.mtime.getTime() != prev.mtime.getTime()) {
compile(fname);
}
}
);
console.log('Watching '+COLOR_YELLOW+fname+COLOR_NORMAL);
} else {
console.log('No coffee/jade/less files found to watch');
}
}
}
main();
당신이 요점 선호하는 경우 : https://gist.github.com/3083080
내가 궁금 : 왜 당신이 오히려 개발 시스템에보다, Heroku가에'커피 --watch'를 실행? –
Trevor - Heroku에서 커피를 사용하지 않습니다. 나는 0.4.7 노드를 로컬로 사용하고있다. – mainsocial