3c4afecf6bb0d5d94b8dedf3398bfb4924e6136a.svn-base
848 Bytes
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
/**
* 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 detector = require('./detector');
var existsSync = fs.existsSync || path.existsSync;
/**
* Generator namespace.
*
* @type {Object}
*/
var generator = module.exports;
/**
* Generates random name.
*
* @returns {String}
*/
generator.name = function() {
var id = null;
var tmp = detector.tmp();
do {
id = Date.now() + Math.random();
} while(existsSync(tmp + '/' + id));
return id + '';
};
/**
* Buld a full name. (tmp dir + name).
*
* @param {String} name
* @returns {String}
*/
generator.build = function(name) {
var filename = detector.tmp();
if (name) filename += name + '.';
return filename + this.name();
};