-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add goodparts to project #46
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
22f8643
symlink the good parts eslint config for now, because we'd need a plu…
eliasmalik d4f8fea
fixing merge conflicts
samhstn a57d5d3
fixing linting errors
samhstn cd802d4
change eslint back to goodparts
eliasmalik d9eefed
auto fix linter errors
eliasmalik ae66662
fix linter errors
eliasmalik cc62b23
add config.env to gitignore
eliasmalik ea3daca
Merge branch 'master' into goodparts
eliasmalik 2098399
remove lint:init and post install scripts (moved to goodparts)
eliasmalik fee9ff5
:arrow_up: Add latest version of goodparts
jrans File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -3,3 +3,4 @@ node_modules | |
coverage | ||
npm-debug.log | ||
.eslintrc* | ||
config.env | ||
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,25 +1,25 @@ | ||
'use strict'; | ||
|
||
/** | ||
* Initialse with the default values the schema if they are not defined Yet | ||
* Write schema in the file if the default values are added | ||
* @param {object} schema - the user schema object | ||
* @return {boolean} - any changes apply to the schema | ||
*/ | ||
var defaultSchema = { | ||
email: { | ||
type: 'email' | ||
}, | ||
password: { | ||
type: 'password' | ||
} | ||
email: { type: 'email' }, | ||
password: { type: 'password' } | ||
}; | ||
|
||
module.exports = function (schema) { | ||
var anyChanges = false; | ||
Object.keys(defaultSchema).forEach(function(field) { | ||
if(!schema.hasOwnProperty(field)){ | ||
|
||
Object.keys(defaultSchema).forEach(function (field) { | ||
if (!schema.hasOwnProperty(field)) { | ||
schema[field] = defaultSchema[field]; | ||
anyChanges = true; | ||
}; | ||
} | ||
}); | ||
|
||
return anyChanges; | ||
}; |
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,28 +1,30 @@ | ||
'use strict'; | ||
|
||
var addDefaultValues = require('./add_default_values.js'); | ||
var loadSchema = require('./load_schema.js'); | ||
var updateSchema = require('./update_schema.js'); | ||
var fs = require('fs'); | ||
|
||
module.exports = function (server, options, next) { | ||
if (!options.hasOwnProperty('user_schema_path')) { | ||
return next('Error: user_schema_path is not defined, please define a user_schema_path'); | ||
return next(new Error('user_schema_path is not defined')); | ||
} | ||
|
||
loadSchema(options.user_schema_path, function(errorLoad, schema) { | ||
return loadSchema(options.user_schema_path, function (errorLoad, schema) { | ||
if (errorLoad) { | ||
return next(errorLoad); | ||
} | ||
|
||
if (addDefaultValues(schema)) { | ||
updateSchema(options.user_schema_path, schema, function(errorUpdateSchema) { | ||
return next(errorUpdateSchema); | ||
}); | ||
} else { | ||
if (!addDefaultValues(schema)) { | ||
return next(); | ||
} | ||
|
||
return updateSchema( | ||
options.user_schema_path, | ||
schema, | ||
function (errorUpdateSchema) { | ||
return next(errorUpdateSchema); | ||
}); | ||
}); | ||
}; | ||
|
||
module.exports.attributes = { | ||
name: 'Abase' | ||
}; | ||
module.exports.attributes = { name: 'Abase' }; |
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,20 +1,30 @@ | ||
'use strict'; | ||
|
||
var fs = require('fs'); | ||
|
||
/** | ||
* load the shema user | ||
* load the schema user | ||
* @param {sting} schemaPath - the file path of the schema | ||
* @param {function} cb - callback with error and the schema object | ||
* @returns {void} | ||
*/ | ||
var fs = require('fs'); | ||
|
||
module.exports = function (schemaPath, cb) { | ||
fs.readFile(schemaPath, function (err, data) { | ||
var schema; | ||
|
||
if (err) { | ||
return cb('Error: sorry impossible to read the file at ' + schemaPath); | ||
} | ||
|
||
try { | ||
var schema = JSON.parse(data); | ||
schema = JSON.parse(data); | ||
} catch (parseError) { | ||
return cb('Error: the schema user file contains unconventianal type, please make sure an schema object is defined'); | ||
return cb( | ||
'Error: the schema user file contains unconventianal type,' | ||
+ 'please make sure an schema object is defined' | ||
); | ||
} | ||
return cb(undefined, schema); | ||
|
||
return cb(null, schema); | ||
}); | ||
}; |
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,11 +1,14 @@ | ||
'use strict'; | ||
|
||
var fs = require('fs'); | ||
|
||
/** | ||
* Update the schema json file | ||
* @param {string} user_schema_path, the path of the schema file | ||
* @param {string} userSchemaPath, the path of the schema file | ||
* @param {object} schema - the schema user object | ||
* @param {function} cb - callback with error | ||
* @returns {void} | ||
*/ | ||
|
||
var fs = require('fs'); | ||
module.exports = function (user_schema_path, schema, cb) { | ||
fs.writeFile(user_schema_path, JSON.stringify(schema), 'utf8', cb); | ||
module.exports = function (userSchemaPath, schema, cb) { | ||
fs.writeFile(userSchemaPath, JSON.stringify(schema), 'utf8', cb); | ||
}; |
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,41 +1,40 @@ | ||
'use strict'; | ||
|
||
var tape = require('tape'); | ||
var addDefaultValues = require('../lib/add_default_values.js'); | ||
|
||
tape('add default values to empty object', function (t) { | ||
var anyChanges = addDefaultValues({}); | ||
|
||
t.ok(anyChanges, 'Default values added to the schema'); | ||
t.end(); | ||
}); | ||
|
||
tape('add email to schema if not defined yet', function (t) { | ||
var obj = { | ||
password: {type: 'password'} | ||
}; | ||
|
||
var obj = { password: { type: 'password' } }; | ||
var anyChanges = addDefaultValues(obj); | ||
|
||
t.ok(anyChanges, 'Changes applied to the schema'); | ||
t.ok(obj.hasOwnProperty('email'), 'email added'); | ||
t.end(); | ||
}); | ||
|
||
tape('add password to schema if not defined yet', function (t) { | ||
var obj = { | ||
email: {type: 'email'} | ||
}; | ||
|
||
var obj = { email: { type: 'email' } }; | ||
var anyChanges = addDefaultValues(obj); | ||
|
||
t.ok(anyChanges, 'Changes applied to the schema'); | ||
t.ok(obj.hasOwnProperty('password'), 'password added'); | ||
t.end(); | ||
}); | ||
|
||
tape('do not add default values if they are already defined', function (t) { | ||
var obj = { | ||
email: {type: 'email'}, | ||
password: {type: 'password'} | ||
email: { type: 'email' }, | ||
password: { type: 'password' } | ||
}; | ||
|
||
var anyChanges = addDefaultValues(obj); | ||
|
||
t.ok(!anyChanges, 'No changes applied to the schema'); | ||
t.end(); | ||
}); | ||
}); |
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,27 +1,48 @@ | ||
'use strict'; | ||
|
||
var tape = require('tape'); | ||
var loadSchema = require('../lib/load_schema.js'); | ||
var path = require('path'); | ||
|
||
tape('attempt to load a schema with a wrong path file', function (t) { | ||
loadSchema('./wrongpathoffile.json', function (error, schema) { | ||
loadSchema('./wrongpathoffile.json', function (error) { | ||
t.ok(error, 'can\'t read a file with a wrong path'); | ||
t.equal(error, 'Error: sorry impossible to read the file at ./wrongpathoffile.json', 'error message is passed to the callback'); | ||
t.equal( | ||
error, | ||
'Error: sorry impossible to read the file at ./wrongpathoffile.json', | ||
'error message is passed to the callback' | ||
); | ||
t.end(); | ||
}); | ||
}); | ||
|
||
tape('the schema is not a json object', function (t) { | ||
loadSchema(path.join(__dirname, 'fixtures', 'wrong_schema.json'), function (error, schema) { | ||
t.ok(error, 'can\'t parse the content of the schema'); | ||
t.equal(error, 'Error: the schema user file contains unconventianal type, please make sure an schema object is defined', 'error schema parse displayed properly'); | ||
t.end(); | ||
}); | ||
loadSchema( | ||
path.join(__dirname, 'fixtures', 'wrong_schema.json'), | ||
function (error) { | ||
t.ok(error, 'can\'t parse the content of the schema'); | ||
t.equal( | ||
error, | ||
'Error: the schema user file contains unconventianal type,' | ||
+ 'please make sure an schema object is defined', | ||
'error schema parse displayed properly' | ||
); | ||
t.end(); | ||
}); | ||
}); | ||
|
||
tape('load the schema', function (t) { | ||
loadSchema(path.join(__dirname, 'fixtures', 'right_schema.json'), function (error, schema) { | ||
t.ok(!error, 'no errors'); | ||
t.deepEqual(schema, {email: {type: "email"}, password: {type: "password"}}, 'the schema is loaded properly'); | ||
t.end(); | ||
}); | ||
}); | ||
loadSchema( | ||
path.join(__dirname, 'fixtures', 'right_schema.json'), | ||
function (error, schema) { | ||
t.ok(!error, 'no errors'); | ||
t.deepEqual( | ||
schema, | ||
{ | ||
email: { type: 'email' }, password: { type: 'password' } | ||
}, | ||
'the schema is loaded properly' | ||
); | ||
t.end(); | ||
}); | ||
}); |
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,11 +1,14 @@ | ||
'use strict'; | ||
|
||
var tape = require('tape'); | ||
var updateSchema = require('../lib/update_schema.js'); | ||
var path = require('path'); | ||
|
||
tape('attempt to update a schema with a wrong schema path', function (t) { | ||
var wrongPath = path.join(__dirname, 'fixtures', 'wrongpath', 'schema.json'); | ||
updateSchema(wrongPath, {}, function (error, response) { | ||
|
||
updateSchema(wrongPath, {}, function (error) { | ||
t.ok(error, 'can\'t write a file with a wrong path'); | ||
t.end(); | ||
}); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
strictly shouldn't be in this PR but will let it slide just this once ;)