Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restructure venus temp #355

Open
wants to merge 1 commit into
base: 2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion Venus.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ var _ = require('underscore'),
prompt = require('cli-prompt'),
wrench = require('wrench'),
fs = require('fs'),
fstools = require('fs-tools'),
path = require('path'),
deferred = require('deferred'),
ps = require('./lib/util/ps');
ps = require('./lib/util/ps'),
constants = require('./lib/constants');

/**
* The Venus application object
Expand Down Expand Up @@ -106,6 +108,11 @@ Venus.prototype.init = function (args) {
.option('--singleton', i18n('Ensures all other Venus processes are killed before starting'))
.action(_.bind(this.command(this.run), this));

program
.command('clean')
.description(i18n('Removes all tempoary directories'))
.action(_.bind(this.command(this.clean), this));

program.parse(args);

// No command (e.g., "init", "demo", "run") was provided in command line arguments, so run venus with defaults
Expand Down Expand Up @@ -289,5 +296,26 @@ Venus.prototype.initProjectDirectory = function (program) {

};

/**
* Removes all temporary directories from the proper location and send a
* message to the logger.
*/
Venus.prototype.clean = function () {
var dir = constants.baseTempDir || constants.tempDir,
def = deferred();

fstools.remove(dir, function(err) {
if (_.isNull(err)) {
logger.warn(i18n('Temp directory at %s does not exist so it could not be removed', dir));
def.reject(new Error('No temp directory was found'));
} else {
logger.info(i18n('Temp directory at %s was removed', dir));
def.resolve(dir);
}
});

return def.promise;
};

module.exports = Venus;
Object.seal(module.exports);
7 changes: 7 additions & 0 deletions lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,19 @@
**/

var os = require('os'),
baseTempDir = '/tmp/venus',
constants;

/**
* Define constants for Venus application
*/
constants = {
baseTempDir: baseTempDir,

tempDir: baseTempDir + '/run-',

port: 2013,

userHome : (process.platform === 'win32') ? process.env['USERPROFILE'] : process.env['HOME'],

/**
Expand Down
Loading