-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add exit handling, lerna-debug.log, and improve log messages
- Loading branch information
1 parent
39ddc5f
commit 9509cf9
Showing
8 changed files
with
113 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
var fsUtils = require("./fsUtils"); | ||
var logger = require("./logger"); | ||
var path = require("path"); | ||
var pad = require("pad") | ||
|
||
function formatType(type) { | ||
return pad("lerna(" + type + ")", 15, " "); | ||
} | ||
|
||
var errorsSeen = []; | ||
|
||
function formatError(error) { | ||
var message = []; | ||
var hasSeen = errorsSeen.indexOf(error) > -1; | ||
|
||
if (!error) { | ||
return ""; | ||
} | ||
|
||
if (!hasSeen) { | ||
errorsSeen.push(error); | ||
if (error.message) message.push(error.message); | ||
if (error.stack) message.push(error.stack); | ||
if (!message.length) message.push(error); | ||
} | ||
|
||
message = message.join("\n").split("\n").map(function(line) { | ||
return " " + line; | ||
}).join("\n"); | ||
|
||
return "\n" + message; | ||
} | ||
|
||
function formatLog(log) { | ||
return formatType(log.type) + log.message + formatError(log.error); | ||
} | ||
|
||
module.exports = function exit(code) { | ||
if (!code || code === 0) { | ||
process.exit(0); | ||
} | ||
|
||
var filePath = path.join(process.cwd(), "lerna-debug.log"); | ||
var fileContent = logger.getLogs().map(formatLog).join("\n"); | ||
|
||
fsUtils.writeFileSync(filePath, fileContent); | ||
|
||
process.exit(code); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters