8
8
var fs = require ( 'fs' ) ;
9
9
var cp = require ( 'child_process' ) ;
10
10
var es = require ( 'execSync' ) ;
11
- var greppyBinPath = __dirname + '/../../bin/greppy' ;
11
+ var path = require ( 'path' ) ;
12
+ var root = path . resolve ( __dirname + '/../../' ) ;
13
+ var paths = require ( root + '/tests/paths' ) ;
14
+ var greppyBinPath = root + '/bin/greppy' ;
12
15
13
16
/**
14
17
* @constructor
18
+ *
19
+ * @param {String } [path] The path used for creating the project
15
20
*/
16
21
var Project = function ( path )
17
22
{
18
- this . path = path || '/tmp/greppy-test/' ;
19
- this . directoryName = 'project' ;
23
+ this . path = path || paths . temp + '/test-project/' ;
20
24
this . showOutput = false ;
21
25
22
26
// Create the given path
23
- ( require ( 'node-fs' ) ) . mkdirSync ( this . getTargetPath ( ) , '0744' , true ) ;
24
- } ;
25
-
26
- /**
27
- * Get the name of the project directory.
28
- *
29
- * @returns {String }
30
- */
31
- Project . prototype . getDirectoryName = function ( )
32
- {
33
- return this . directoryName ;
27
+ ( require ( 'node-fs' ) ) . mkdirSync ( this . getPath ( ) , '0744' , true ) ;
34
28
} ;
35
29
36
30
/**
37
31
* Get the builded target path.
38
32
*
39
33
* @returns {String }
40
34
*/
41
- Project . prototype . getTargetPath = function ( )
35
+ Project . prototype . getPath = function ( )
42
36
{
43
- return this . path + this . directoryName + '/' ;
37
+ return path . resolve ( this . path ) + '/' ;
44
38
} ;
45
39
46
40
/**
@@ -50,7 +44,7 @@ Project.prototype.getTargetPath = function()
50
44
*/
51
45
Project . prototype . exists = function ( )
52
46
{
53
- return fs . existsSync ( this . getTargetPath ( ) ) ;
47
+ return fs . existsSync ( this . getPath ( ) ) ;
54
48
} ;
55
49
56
50
/**
@@ -60,7 +54,7 @@ Project.prototype.exists = function()
60
54
*/
61
55
Project . prototype . remove = function ( )
62
56
{
63
- es . run ( 'rm -rf ' + this . getTargetPath ( ) ) ;
57
+ es . run ( 'rm -rf ' + this . getPath ( ) ) ;
64
58
} ;
65
59
66
60
/**
@@ -70,8 +64,8 @@ Project.prototype.remove = function()
70
64
*/
71
65
Project . prototype . clean = function ( )
72
66
{
73
- es . run ( 'rm -rf ' + this . getTargetPath ( ) ) ;
74
- es . run ( 'mkdir ' + this . getTargetPath ( ) ) ;
67
+ es . run ( 'rm -rf ' + this . getPath ( ) ) ;
68
+ es . run ( 'mkdir ' + this . getPath ( ) ) ;
75
69
} ;
76
70
77
71
/**
@@ -88,7 +82,7 @@ Project.prototype.createProject = function(callback)
88
82
}
89
83
90
84
var ps = cp . spawn ( greppyBinPath , [ '--new=.' ] , {
91
- cwd : this . getTargetPath ( )
85
+ cwd : this . getPath ( )
92
86
} ) ;
93
87
94
88
if ( this . showOutput ) {
@@ -120,7 +114,7 @@ Project.prototype.createProjectSync = function()
120
114
var cwd = process . cwd ( ) ;
121
115
var result ;
122
116
123
- process . chdir ( this . getTargetPath ( ) ) ;
117
+ process . chdir ( this . getPath ( ) ) ;
124
118
result = es [ cmd ] ( greppyBinPath + ' --new=.' ) ;
125
119
result = ( cmd === 'run' ) ? result : result . code ;
126
120
process . chdir ( cwd ) ;
0 commit comments