Skip to content

Commit

Permalink
handle filesystem errors in cli
Browse files Browse the repository at this point in the history
  • Loading branch information
kbrsh committed Dec 23, 2019
1 parent 6170ffc commit 253e22d
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 7 deletions.
15 changes: 12 additions & 3 deletions packages/moon-cli/dist/moon-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,15 @@
function install(name, archivePath) {
var targetPath = path.join(process.cwd(), name);
exec("mkdir " + targetPath, function (error) {
if (error) logError(error);
if (error !== null) {
logError("Failed directory creation.\n\nAttempted to create directory:\n\t" + targetPath + "\n\nReceived error:\n\t" + error + "\n\nExpected successful directory creation.");
}

exec("tar -xzf " + archivePath + " -C " + targetPath + " --strip=1", function (error) {
if (error) logError(error);
if (error !== null) {
logError("Failed archive extraction.\n\nAttempted to extract archive to target:\n\t" + archivePath + " -> " + targetPath + "\n\nReceived error:\n\t" + error + "\n\nExpected successful archive extraction.");
}

log("installed", targetPath);
clean(name, archivePath, targetPath);
});
Expand All @@ -136,7 +142,10 @@

function clean(name, archivePath, targetPath) {
fs.unlink(archivePath, function (error) {
if (error) logError(error);
if (error !== null) {
logError("Failed archive deletion.\n\nAttempted to delete archive:\n\t" + archivePath + "\n\nReceived error:\n\t" + error + "\n\nExpected successful archive deletion.");
}

log("cleaned", archivePath);
processDirectory(name, targetPath, targetPath);
log("created", "application \x1B[36m" + name + "\x1B[0m\n\nTo start, run:\n\tcd " + name + "\n\tnpm install\n\tnpm run dev");
Expand Down
2 changes: 1 addition & 1 deletion packages/moon-cli/dist/moon-cli.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 33 additions & 3 deletions packages/moon-cli/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,30 @@ function install(name, archivePath) {
const targetPath = path.join(process.cwd(), name);

exec(`mkdir ${targetPath}`, error => {
if (error) logError(error);
if (error !== null) {
logError(`Failed directory creation.
Attempted to create directory:
${targetPath}
Received error:
${error}
Expected successful directory creation.`);
}

exec(`tar -xzf ${archivePath} -C ${targetPath} --strip=1`, error => {
if (error) logError(error);
if (error !== null) {
logError(`Failed archive extraction.
Attempted to extract archive to target:
${archivePath} -> ${targetPath}
Received error:
${error}
Expected successful archive extraction.`);
}

log("installed", targetPath);
clean(name, archivePath, targetPath);
Expand All @@ -160,7 +180,17 @@ function install(name, archivePath) {

function clean(name, archivePath, targetPath) {
fs.unlink(archivePath, error => {
if (error) logError(error);
if (error !== null) {
logError(`Failed archive deletion.
Attempted to delete archive:
${archivePath}
Received error:
${error}
Expected successful archive deletion.`);
}

log("cleaned", archivePath);
processDirectory(name, targetPath, targetPath);
Expand Down

0 comments on commit 253e22d

Please sign in to comment.