171ab184732af0c2252fa7ccef210da33442f672.svn-base
1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/**
* Temporary - The lord of tmp.
*
* Author: Veselin Todorov <hi@vesln.com>
* Licensed under the MIT License.
*/
/**
* Dependencies.
*/
var fs = require('fs');
var path = require('path');
var generator = require('./generator');
var detector = require('./detector');
/**
* Base constructor.
*
* @param {String|null} name
*/
function Base(name) {
this.init(name);
};
/**
* Initializes the class.
*
* @param {String|null} name
*/
Base.prototype.init = function(name) {
var filename = generator.build(name);
this.create(filename);
this.path = filename;
};
/**
* Converts the arguments object to array and
* append `this.path` as first element.
*
* @returns {Array}
*/
Base.prototype.prepareArgs = function(args) {
args = Array.prototype.slice.call(args);
args.unshift(this.path);
return args;
};
/**
* Renames the dir/file.
*
* @param {String} name
* @param {Function} cb Callback.
*/
Base.prototype.rename = function(name, cb) {
var self = this;
var args = arguments;
var tmp = path.normalize(path.dirname(self.path) + '/' + name);
fs.rename(this.path, tmp, function(err) {
self.path = tmp;
if (args.length === 2) cb(err);
});
};
/**
* Renames the dir/file sync.
*
* @param {String} name
*/
Base.prototype.renameSync = function(name) {
var tmp = path.normalize(path.dirname(this.path) + '/' + name);
var result = fs.renameSync(this.path, tmp);
this.path = tmp;
return result;
};
/**
* Exporting the lib.
*/
module.exports = Base;