Skip to content

Commit

Permalink
fix: resolve local schemas properly
Browse files Browse the repository at this point in the history
  • Loading branch information
marionebl committed Feb 11, 2016
1 parent 7d12b40 commit fb345be
Show file tree
Hide file tree
Showing 5 changed files with 186 additions and 34 deletions.
89 changes: 56 additions & 33 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const jjv = require('jjv');
const request = require('sync-request');
const mkdirp = require('mkdirp');
var memoize = require('lodash.memoize');
var minimatch = require('minimatch');

const read = denodeify(fs.readFile);
const rc = denodeify(rcNodeBack);
Expand Down Expand Up @@ -300,21 +301,26 @@ function readStdin() {
});
}

function getSettings(options, path) {
function getSettings(options, file) {
const filePath = path.extname(file) ?
path.dirname(file) :
file;

const loaders = [
{
name: '.jsonlintrc',
path: [path],
append: true
path: [filePath],
prepend: [filePath]
},
{
name: '.jsonlintignore',
path: [path],
path: [filePath],
type: 'ini',
append: true
prepend: [filePath]
}
].map(loader => {
return rc(loader)
.then(config => Object.assign(config))
.catch(error => {
setTimeout(() => {
throw error;
Expand All @@ -325,8 +331,18 @@ function getSettings(options, path) {
return Promise.all(loaders)
.then(results => {
const configuration = results[0];
const ignore = Object.keys(results[1]);
return Object.assign({}, defaults, configuration, options, {
configuration._file = file;

const ignore = (options.ignore || [])
.concat(results[0].ignore || [])
.concat(Object.keys(results[1]));

const parsed = url.parse(configuration.validate);
configuration.validate = parsed.protocol && parsed.host ?
configuration.validate :
path.resolve(file, configuration.validate);

return Object.assign({}, defaults, options, configuration, {
ignore
});
});
Expand All @@ -347,36 +363,43 @@ function execute(settings) {

// read the glob if files are given
return globby(glob).then(paths => {
if (paths.length > 0) {
return Promise.all(
paths
.map(file => {
return Promise.all([
read(file)
.then(buffer => {
Promise
.all(paths.map(file => {
return getSettings(settings, file);
}))
.then(configurations => {
return Promise.all(
configurations.map(configuration => {
// ignore could be changed by config files
const ignored = configuration.ignore
.filter(pattern => {
return minimatch(configuration._file, pattern) ||
path.basename(configuration._file) === pattern;
}).length > 0;

if (ignored) {
return null;
}
return read(configuration._file)
.then(content => {
return {
content: buffer.toString('utf-8'),
path: file
content: content.toString('utf-8'),
path: configuration._file,
configuration: configuration
};
}),
getSettings(settings, file)
]);
})
.map(payload => {
return payload
.then(results => {
const shipment = results[0];
const fileConfiguration = results[1];

return lint(
shipment.content.toString('utf-8'),
shipment.path,
fileConfiguration
);
});
})
);
}
).then(payload => {
if (!payload) {
return;
}
lint(
payload.content,
payload.path,
payload.configuration
);
});
});
});
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"changelog": "conventional-changelog --preset angular --infile changelog.md --same-file --output-unreleased",
"push": "git push && git push --tags && hub release create \"v$(cat .git/RELEASE_VERSION.tmp)\" --message=\"v$(cat .git/RELEASE_VERSION.tmp)\n$(cat .git/COMMITMSG.tmp)\" && npm publish && rm .git/RELEASE_VERSION.tmp && rm .git/COMMITMSG.tmp",
"release": "npm version $(conventional-recommended-bump -p angular)",
"test": "parallelshell \"eslint index.js\" \"node index.js package.json\" ",
"test": "parallelshell \"eslint index.js\" \"node index.js **/*.json *.json\" ",
"preversion": "npm test",
"version": "npm run changelog && git add . && echo \"$(conventional-changelog -p angular)\" > .git/COMMITMSG.tmp",
"postversion": "echo $(git log -1 --pretty=%B HEAD^..HEAD) > .git/RELEASE_VERSION.tmp && git tag -d v$(cat .git/RELEASE_VERSION.tmp) && git commit --amend -m \"chore(release): $(cat .git/RELEASE_VERSION.tmp)\n$(cat .git/COMMITMSG.tmp)\" && git tag -a v$(cat .git/RELEASE_VERSION.tmp) -m \"$(cat .git/COMMITMSG.tmp)\""
Expand Down
4 changes: 4 additions & 0 deletions pattern/.jsonlintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"validate": "./pattern-schema.json",
"ignore": ["pattern-schema.json"]
}
121 changes: 121 additions & 0 deletions pattern/pattern-schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "pattern manifest",
"type": "object",
"additionalProperties": false,
"required": [
"name",
"version"
],
"properties": {
"id": {
"description": "Unique id of this pattern",
"type": "string",
"minLength": 1
},
"name": {
"description": "Machine readable name of the pattern",
"type": "string",
"minLength": 1,
"pattern": "^[[a-z]*[-]?[a-z]*]*$"
},
"displayName": {
"description": "Human readable name of the pattern",
"type": "string",
"minLength": 1
},
"version": {
"description": "Semantic version of the pattern",
"type": "string",
"pattern": "^\\d\\.\\d\\.\\d(-[a-z]*){0,1}$"
},
"versions": {
"description": "Available semantic versions of the pattern",
"type": "array",
"minItems": 1,
"items": {
"description": "Semantic version of the pattern",
"type": "string",
"pattern": "^\\d\\.\\d\\.\\d(-[a-z]*){0,1}$"
}
},
"flag": {
"description": "Stability flag of the pattern",
"type": "string",
"pattern": "^alpha|beta|rc|stable$"
},
"tags": {
"description": "Array of tags describing the pattern",
"type": "array",
"minItems": 1,
"items": {
"description": "Tag describing the pattern",
"type": "string",
"minLength": 1
},
"uniqueItems": true
},
"data": {
"description": "Custom data object supplied by user",
"type": "object",
"minProperties": 1
},
"meta": {
"description": "Custom meta data object supplied by user",
"type": "object",
"minProperties": 1
},
"options": {
"description": "Custom options object supplied by user",
"type": "object",
"minProperties": 1
},
"patterns": {
"description": "Dependencies of the pattern",
"type": "object",
"minProperties": 1,
"patternProperties": {
"^.+$": {
"type": "string",
"pattern": "^(/)?([^/\u0000]+(/)?)+$"
}
}
},
"demoPatterns": {
"description": "Dependencies of the pattern used for demo purposes",
"minProperties": 1,
"patternProperties": {
"^.+$": {
"type": "string",
"pattern": "^(/)?([^/\u0000]+(/)?)+$"
}
}
},
"overrides": {
"description": "Options for overriding of core pattern behaviour",
"type": "object",
"minProperties": 1,
"properties": {
"files": {
"description": "Custom mapping between patternplate files and paths to use in exchange for this pattern",
"type": "object",
"minProperties": 1,
"patternProperties": {
"^.+$": {
"type": "string",
"pattern": "^(/)?([^/\u0000]+(/)?)+$"
}
}
},
"demo": {
"description": "Custom url to use as demo for this pattern",
"type": "string"
}
}
},
"_patternplate": {
"description": "Technical values saved by patternplate core",
"type": "object"
}
}
}
4 changes: 4 additions & 0 deletions pattern/pattern.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "pattern",
"version": "0.1.0"
}

0 comments on commit fb345be

Please sign in to comment.