From 92814351ffbeded7e00d433daf2b22812fa1b41f Mon Sep 17 00:00:00 2001 From: Johan Liesén Date: Tue, 7 Aug 2012 10:13:16 +0200 Subject: Keep main.js when doing `cake clean` --- Cakefile | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Cakefile b/Cakefile index 0a45abac..7506f349 100644 --- a/Cakefile +++ b/Cakefile @@ -15,9 +15,12 @@ task "build", "compile all coffeescript files to javascript", -> task "clean", "removes any js files which were compiled from coffeescript", -> src_directories.forEach (directory) -> - files = fs.readdirSync(directory).filter((filename) -> filename.indexOf(".js") > 0) - files = files.map((filename) -> "#{directory}/#{filename}") - files.forEach((file) -> fs.unlinkSync file if fs.statSync(file).isFile()) + fs.readdirSync(directory).forEach (filename) -> + return if (filename.indexOf ".js", filename.length - ".js".length) == -1 + filepath = "#{directory}/#{filename}" + return if filepath == "background_scripts/main.js" + return unless (fs.statSync filepath).isFile() + fs.unlinkSync filepath task "autobuild", "continually rebuild coffeescript files using coffee --watch", -> coffee = spawn "coffee", ["-cw"].concat(src_directories) -- cgit v1.2.3 From a3ada283711d73737e5de13f5cb5d30f23a8312c Mon Sep 17 00:00:00 2001 From: Johan Liesén Date: Tue, 7 Aug 2012 15:51:09 +0200 Subject: Keep any .js with a corresponding .coffee --- Cakefile | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Cakefile b/Cakefile index 7506f349..a90f7e64 100644 --- a/Cakefile +++ b/Cakefile @@ -18,9 +18,15 @@ task "clean", "removes any js files which were compiled from coffeescript", -> fs.readdirSync(directory).forEach (filename) -> return if (filename.indexOf ".js", filename.length - ".js".length) == -1 filepath = "#{directory}/#{filename}" - return if filepath == "background_scripts/main.js" return unless (fs.statSync filepath).isFile() - fs.unlinkSync filepath + + # Check if there exists a corresponding .coffee file + try + coffeeFile = fs.statSync "#{filepath.slice 0, -".js".length}.coffee" + catch _ + return + + fs.unlinkSync filepath if coffeeFile.isFile() task "autobuild", "continually rebuild coffeescript files using coffee --watch", -> coffee = spawn "coffee", ["-cw"].concat(src_directories) -- cgit v1.2.3 From 57bc52a4fc7b64eb88415fba2e6dd95f499c3b6a Mon Sep 17 00:00:00 2001 From: Johan Liesén Date: Tue, 7 Aug 2012 16:43:48 +0200 Subject: Use path module --- Cakefile | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Cakefile b/Cakefile index a90f7e64..e1434d24 100644 --- a/Cakefile +++ b/Cakefile @@ -1,4 +1,5 @@ fs = require "fs" +path = require "path" {spawn, exec} = require "child_process" spawn_with_opts = (proc_name, opts) -> @@ -16,13 +17,13 @@ task "build", "compile all coffeescript files to javascript", -> task "clean", "removes any js files which were compiled from coffeescript", -> src_directories.forEach (directory) -> fs.readdirSync(directory).forEach (filename) -> - return if (filename.indexOf ".js", filename.length - ".js".length) == -1 - filepath = "#{directory}/#{filename}" + return unless (path.extname filename) == ".js" + filepath = path.join directory, filename return unless (fs.statSync filepath).isFile() # Check if there exists a corresponding .coffee file try - coffeeFile = fs.statSync "#{filepath.slice 0, -".js".length}.coffee" + coffeeFile = fs.statSync path.join directory, "#{path.basename filepath, ".js"}.coffee" catch _ return -- cgit v1.2.3