-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #93 from oss-specs/feature/goingBeta
Going beta
- Loading branch information
Showing
18 changed files
with
311 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,9 @@ | |
.idea | ||
public/feature-files/* | ||
|
||
# Repo meta data | ||
project-data | ||
|
||
# Logs | ||
logs | ||
*.log | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,29 @@ | ||
"use strict"; | ||
|
||
var path = require('path'); | ||
|
||
var getProjectUsingGit = require('./getProjectUsingGit'); | ||
var projectMetaData = require('./projectMetaData'); | ||
|
||
// TODO: Remove magic knowledge of where feature files are, injection? | ||
var featureFileRoot = path.join(__dirname, '..', '..', 'public', 'feature-files'); | ||
|
||
/** | ||
* Get a copy of the project. | ||
* Get a copy of the project, derive metadata, store metadata. | ||
* | ||
* @return a promise for the completion of the operation. | ||
* @return a promise for the completion of repo metadata storage. | ||
*/ | ||
module.exports = function getProject(repoUrl) { | ||
var repoName = /\/([^\/]+?)(?:\.git)?\/?$/.exec(repoUrl); | ||
repoName = (repoName && repoName.length ? repoName[1] : false); | ||
if (!repoName) throw new TypeError("Could not determine repository name."); | ||
if (!repoName) { | ||
throw new TypeError("Could not determine repository name."); | ||
} | ||
|
||
// Path for local cloning. | ||
var localName = path.join(featureFileRoot, repoName); | ||
|
||
return getProjectUsingGit(repoUrl, repoName); | ||
// Clone or update the repo then derive and store the project metadata. | ||
return getProjectUsingGit(repoUrl, repoName, localName) | ||
.then(projectMetaData.deriveAndStore(featureFileRoot)); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
'use strict'; | ||
|
||
var fs = require('fs'); | ||
var qfs = require('q-io/fs'); // https://github.com/kriskowal/q-io | ||
var path = require('path'); | ||
|
||
// TODO: don't like hardcoding this. | ||
var appRoot = path.join(__dirname, '..', '..'); | ||
|
||
// Stick the data in a project-data subdirectory. | ||
var projectDataDirectory = path.join(appRoot, 'project-data'); | ||
|
||
module.exports = { | ||
|
||
// Return promise for write completion. | ||
persist: function(projectData) { | ||
|
||
// Ensure project data directory exists and write the file. | ||
fs.existsSync(projectDataDirectory) || fs.mkdirSync(projectDataDirectory); | ||
return qfs.write(path.join(projectDataDirectory, projectData.name + '.data'), JSON.stringify(projectData)); | ||
}, | ||
|
||
// Return promise for an array of paths in data directory | ||
// with the .data file extension. | ||
getNames: function() { | ||
return qfs.listTree(projectDataDirectory, function guard(path) { | ||
return /\.(data)$/.test(path); | ||
}); | ||
}, | ||
|
||
// Return promise for data. | ||
get: function(dataFilePath) { | ||
return qfs.read(dataFilePath) | ||
.then(function(metaDataJsonString) { | ||
return JSON.parse(metaDataJsonString); | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
"use strict"; | ||
|
||
var path = require('path'); | ||
|
||
var getFeatureFilePaths = require('./getFeatureFilePaths'); | ||
var projectDataStorage = require('./projectDataStorage'); | ||
|
||
// Get a function for use with Array.prototype.map to | ||
// convert file paths for feature files to express routes. | ||
function pathsToRoutes(featureFileRoot) { | ||
return function(featurePath) { | ||
|
||
// Remove the filesystem root. | ||
featurePath = featurePath.replace(featureFileRoot, ''); | ||
|
||
// Prefix with the 'features' route, always use backslashes. | ||
featurePath = path.posix.join('features', featurePath); | ||
|
||
return { | ||
featureRoute: featurePath, | ||
featureName: featurePath.replace('.feature', '').replace('features/', '') | ||
}; | ||
} | ||
} | ||
|
||
|
||
/** | ||
* Takes an object of repo data and returns a promise for that | ||
* data decorated with feature file routes. | ||
* | ||
* Feature file routes are taken from disk via `getFeatureFilePaths`. | ||
* | ||
* @return A promise for the decorated data object. | ||
*/ | ||
function deriveProjectData(featureFileRoot, repoData) { | ||
var projectData = { | ||
name: repoData.repoName, | ||
url: repoData.repoUrl, | ||
commit: repoData.commit, | ||
shortCommit: repoData.shortCommit, | ||
localName: repoData.localName, | ||
featureFilePaths: [] | ||
} | ||
|
||
// Get the paths to the feature files. | ||
return getFeatureFilePaths(featureFileRoot) | ||
.then(function(featureFilePaths) { | ||
|
||
// Map from the storage directory to the Express route for creating links. | ||
projectData.featureFilePaths = featureFilePaths.map(pathsToRoutes(featureFileRoot)); | ||
return projectData; | ||
}); | ||
} | ||
|
||
|
||
/** | ||
* Return a function which takes the repo data, derives the project data and stores it. | ||
* | ||
* @return A promise for completion of the storage of the project data. | ||
*/ | ||
function deriveAndStore(featureFileRoot) { | ||
return function(repoData) { | ||
return deriveProjectData(featureFileRoot, repoData) | ||
.then(projectDataStorage.persist); | ||
} | ||
} | ||
|
||
module.exports = { | ||
deriveAndStore: deriveAndStore | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.