Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 85688c8

Browse files
committed
feat(helpers): add methods to get path to database directories
database directories will include migrations,seeds and factories. Add helper methods to get access to these directories
1 parent 3095839 commit 85688c8

File tree

2 files changed

+65
-4
lines changed

2 files changed

+65
-4
lines changed

src/Helpers/index.js

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ Helpers.resourcesPath = function (toFile) {
157157
}
158158

159159
/**
160-
* returns absolute path to migrations directory.
160+
* returns absolute path to database/migrations directory.
161161
*
162162
* @method migrationsPath
163163
*
@@ -167,7 +167,52 @@ Helpers.resourcesPath = function (toFile) {
167167
* @public
168168
*/
169169
Helpers.migrationsPath = function (toFile) {
170-
const toDir = './migrations'
170+
const toDir = toFile ? `./migrations/${toFile}` : './migrations'
171+
return Helpers.databasePath(toDir)
172+
}
173+
174+
/**
175+
* returns absolute path to database/seeds directory.
176+
*
177+
* @method seedsPath
178+
*
179+
* @param {String} [toFile] - filename to return path for
180+
* @return {String}
181+
*
182+
* @public
183+
*/
184+
Helpers.seedsPath = function (toFile) {
185+
const toDir = toFile ? `./seeds/${toFile}` : './seeds'
186+
return Helpers.databasePath(toDir)
187+
}
188+
189+
/**
190+
* returns absolute path to database/factories directory.
191+
*
192+
* @method factoriesPath
193+
*
194+
* @param {String} [toFile] - filename to return path for
195+
* @return {String}
196+
*
197+
* @public
198+
*/
199+
Helpers.factoriesPath = function (toFile) {
200+
const toDir = toFile ? `./factories/${toFile}` : './factories'
201+
return Helpers.databasePath(toDir)
202+
}
203+
204+
/**
205+
* returns path to the database directory.
206+
*
207+
* @method databasePath
208+
*
209+
* @param {String} toFile [description]
210+
* @return {String} [description]
211+
*
212+
* @public
213+
*/
214+
Helpers.databasePath = function (toFile) {
215+
const toDir = './database'
171216
return Helpers._makePath(rootPath, toDir, toFile)
172217
}
173218

test/unit/helpers.spec.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,27 @@ describe("Helpers", function () {
8888
})
8989

9090
it('should return project migrations directory path', function () {
91-
expect(Helpers.migrationsPath()).to.equal(path.join(basePath,'./migrations'))
91+
expect(Helpers.migrationsPath()).to.equal(path.join(basePath,'./database/migrations'))
9292
})
9393

9494
it('should return migrations path to a given file', function () {
95-
expect(Helpers.migrationsPath('1234.js')).to.equal(path.join(basePath,'./migrations/1234.js'))
95+
expect(Helpers.migrationsPath('1234.js')).to.equal(path.join(basePath,'./database/migrations/1234.js'))
96+
})
97+
98+
it('should return project seeds directory path', function () {
99+
expect(Helpers.seedsPath()).to.equal(path.join(basePath,'./database/seeds'))
100+
})
101+
102+
it('should return migrations path to a given file', function () {
103+
expect(Helpers.seedsPath('1234.js')).to.equal(path.join(basePath,'./database/seeds/1234.js'))
104+
})
105+
106+
it('should return project factories directory path', function () {
107+
expect(Helpers.factoriesPath()).to.equal(path.join(basePath,'./database/factories'))
108+
})
109+
110+
it('should return migrations path to a given file', function () {
111+
expect(Helpers.factoriesPath('1234.js')).to.equal(path.join(basePath,'./database/factories/1234.js'))
96112
})
97113

98114
it('should return project views directory path', function () {

0 commit comments

Comments
 (0)