@eik/common
Advanced tools
Comparing version 1.6.0 to 2.0.0
@@ -0,1 +1,11 @@ | ||
# [2.0.0](https://github.com/eik-lib/common/compare/v1.6.0...v2.0.0) (2021-02-08) | ||
* feat!: add type field to eik config schema ([d9bd0c4](https://github.com/eik-lib/common/commit/d9bd0c4bceee07506fb8e1efc3d2c09715a10062)) | ||
### BREAKING CHANGES | ||
* valid eik config object is now required when instantiating EikConfig class | ||
# [1.6.0](https://github.com/eik-lib/common/compare/v1.5.0...v1.6.0) (2021-01-27) | ||
@@ -2,0 +12,0 @@ |
@@ -6,2 +6,3 @@ const { promisify } = require('util'); | ||
const SingleDestMultipleSourcesError = require('./single-dest-multiple-source-error'); | ||
const { validate, assert } = require('../schemas'); | ||
@@ -14,3 +15,2 @@ const _config = Symbol('config'); | ||
this[_config] = configHash; | ||
this[_tokens] = new Map(tokens); | ||
@@ -30,5 +30,11 @@ this.cwd = configRootDir; | ||
set version(newVersion) { | ||
assert.version(newVersion); | ||
this[_config].version = newVersion; | ||
} | ||
get type() { | ||
const valid = validate.type(this[_config].type); | ||
return valid.value; | ||
} | ||
get server() { | ||
@@ -58,2 +64,6 @@ const configuredServer = this[_config].server; | ||
validate() { | ||
assert.eikJSON(this[_config]); | ||
} | ||
async pathsAndFiles() { | ||
@@ -60,0 +70,0 @@ const resolvedFiles = await Promise.all( |
@@ -8,2 +8,3 @@ const { readFileSync, writeFileSync } = require('fs'); | ||
const MultipleConfigSourcesError = require('../classes/multiple-config-sources-error'); | ||
const InvalidConfigError = require('../classes/invalid-config-error'); | ||
@@ -51,5 +52,16 @@ function readJSONFromDisk(path) { | ||
const eikrc = loadJSONFromDisk(join(homedir, '.eikrc')) || {}; | ||
return new EikConfig(assets, eikrc.tokens, configRootDir); | ||
const config = new EikConfig(assets, eikrc.tokens, configRootDir); | ||
try { | ||
config.validate(); | ||
} catch(err) { | ||
throw new InvalidConfigError(`config.findInDirectory operation failed: ${err.message}`); | ||
} | ||
return config; | ||
}, | ||
persistToDisk(config) { | ||
try { | ||
config.validate(); | ||
} catch(err) { | ||
throw new InvalidConfigError(`config.persistToDisk operation failed: ${err.message}`); | ||
} | ||
const dest = join(config.cwd, 'eik.json'); | ||
@@ -56,0 +68,0 @@ writeFileSync(dest, JSON.stringify(config, null, 2)); |
@@ -18,5 +18,6 @@ 'use strict'; | ||
return data => { | ||
const valid = validate(data); | ||
return { value: data, error: !valid && validate.errors }; | ||
return (data) => { | ||
const cloned = JSON.parse(JSON.stringify(data)); | ||
const valid = validate(cloned); | ||
return { value: cloned, error: !valid && validate.errors }; | ||
}; | ||
@@ -30,53 +31,48 @@ }; | ||
const createNameValidator = (jsonSchemaValidator) => (value) => { | ||
const result = jsonSchemaValidator(value); | ||
if (!result.error) { | ||
const pkvalid = npmPkg(value); | ||
const errors = []; | ||
if (!pkvalid.validForNewPackages) { | ||
errors.push({ | ||
keyword: 'validForNewPackages', | ||
dataPath: '.name', | ||
schemaPath: '', | ||
params: [], | ||
message: 'should be valid for new packages' | ||
}); | ||
} | ||
if (!pkvalid.validForOldPackages) { | ||
errors.push({ | ||
keyword: 'validForOldPackages', | ||
dataPath: '.name', | ||
schemaPath: '', | ||
params: [], | ||
message: 'should be valid for old packages' | ||
}); | ||
} | ||
if (errors.length) { | ||
result.error = errors; | ||
} | ||
const result = jsonSchemaValidator(value); | ||
if (!result.error) { | ||
const pkvalid = npmPkg(value); | ||
const errors = []; | ||
if (!pkvalid.validForNewPackages) { | ||
errors.push({ | ||
keyword: 'validForNewPackages', | ||
dataPath: '.name', | ||
schemaPath: '', | ||
params: [], | ||
message: 'should be valid package name', | ||
}); | ||
} | ||
return result; | ||
if (errors.length) { | ||
result.error = errors; | ||
} | ||
} | ||
return result; | ||
}; | ||
const createVersionValidator = (jsonSchemaValidator) => (value) => { | ||
const result = jsonSchemaValidator(value); | ||
if (!result.error) { | ||
const version = semver.valid(value); | ||
const errors = []; | ||
if (!version) { | ||
errors.push({ | ||
keyword: 'invalidSemverRange', | ||
dataPath: '.version', | ||
schemaPath: '', | ||
params: [], | ||
message: 'should be valid semver range for version' | ||
}); | ||
} | ||
if (errors.length) { | ||
result.error = errors; | ||
} | ||
const result = jsonSchemaValidator(value); | ||
if (!result.error) { | ||
const version = semver.valid(value); | ||
const errors = []; | ||
if (!version) { | ||
errors.push({ | ||
keyword: 'invalidSemverRange', | ||
dataPath: '.version', | ||
schemaPath: '', | ||
params: [], | ||
message: 'should be valid semver range for version', | ||
}); | ||
} | ||
return result; | ||
if (errors.length) { | ||
result.error = errors; | ||
} | ||
} | ||
return result; | ||
}; | ||
const name = createNameValidator(createValidator(eikJSONSchema.properties.name)); | ||
const version = createVersionValidator(createValidator(eikJSONSchema.properties.version)); | ||
const name = createNameValidator( | ||
createValidator(eikJSONSchema.properties.name), | ||
); | ||
const version = createVersionValidator( | ||
createValidator(eikJSONSchema.properties.version), | ||
); | ||
const type = createValidator(eikJSONSchema.properties.type); | ||
@@ -95,2 +91,2 @@ const server = createValidator(eikJSONSchema.properties.server); | ||
module.exports.importMap = importMap; | ||
module.exports.out = out; | ||
module.exports.out = out; |
{ | ||
"name": "@eik/common", | ||
"version": "1.6.0", | ||
"version": "2.0.0", | ||
"description": "Common utilities for Eik modules", | ||
@@ -42,3 +42,3 @@ "main": "lib/index.js", | ||
"@semantic-release/release-notes-generator": "9.0.1", | ||
"eslint": "7.18.0", | ||
"eslint": "7.19.0", | ||
"eslint-config-airbnb-base": "14.2.1", | ||
@@ -49,3 +49,3 @@ "eslint-config-prettier": "7.2.0", | ||
"express": "4.17.1", | ||
"fastify": "3.10.1", | ||
"fastify": "3.11.0", | ||
"prettier": "2.2.1", | ||
@@ -52,0 +52,0 @@ "semantic-release": "17.3.7", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
28725
24
594