Skip to content

Commit

Permalink
🔧 refactors the API so it accepts a rule set instead of a file with r…
Browse files Browse the repository at this point in the history
…ules

... and:
- 🔧 separates the api package from the cli package
- 🔧 put the fixtures in the packages they belong to (mostly)
- 🔧 rename modules so they're verbs (the modules are mostly
  functions, not classes, so verbs is bettah)
- 🔧 in the returned output renames 'content' to 'dependencies'
  and 'meta' to 'metaData'
  • Loading branch information
sverweij committed Dec 10, 2016
1 parent 6b7a4b1 commit 430c0ae
Show file tree
Hide file tree
Showing 162 changed files with 760 additions and 759 deletions.
2 changes: 1 addition & 1 deletion .dependency-cruiser-custom.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"from": { "path": "^bin" },
"to": { "path": "^src/index\\.js" }
}, {
"from": { "path": "^src/index\\.js" },
"from": { "path": "^src/cli/index\\.js" },
"to": { "path": "^package\\.json$" }
}, {
"comment": "node_modules may depend core modules",
Expand Down
4 changes: 2 additions & 2 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ coverage
tmp
utl
src/report/*.template.js
test/fixtures/**
test/extractor-fixtures/**
test/cli/fixtures/**
test/extract/fixtures/**
2 changes: 1 addition & 1 deletion .istanbul.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
instrumentation:
excludes: ["test/**/*", "src/index.js", "coverage/**/*", "tmp*", "utl/**/*", "src/report/vis**"]
excludes: ["test/**/*", "src/cli/index.js", "coverage/**/*", "tmp*", "utl/**/*", "src/report/vis**"]
include-all-sources: true
6 changes: 6 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,16 @@ npm-debug.log
isolate-*-v8.log
build
.dependency-cruiser.json
doc/api.md
doc/cli.md
doc/output-format.md
doc/real-world-samples.md
doc/real-world-samples/**
doc/assets/ZKH-Dependency-recolored-320.png
doc/assets/ZKH-Dependency-recolored-320.svg
doc/rules.md
doc/rules.starter.json.md
doc/sample-output.md
test/**
utl/**
.bithoundrc
Expand Down
134 changes: 73 additions & 61 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,16 @@ src/report/%.template.js: src/report/%.template.hbs

.npmignore: .gitignore
cp $< $@
echo "doc/api.md" >> $@
echo "doc/cli.md" >> $@
echo "doc/output-format.md" >> $@
echo "doc/real-world-samples.md" >> $@
echo "doc/real-world-samples/**" >> $@
echo "doc/assets/ZKH-Dependency-recolored-320.png" >> $@
echo "doc/assets/ZKH-Dependency-recolored-320.svg" >> $@
echo "doc/rules.md" >> $@
echo "doc/rules.starter.json.md" >> $@
echo "doc/sample-output.md" >> $@
echo "test/**" >> $@
echo "utl/**" >> $@
echo ".bithoundrc" >> $@
Expand Down Expand Up @@ -117,8 +123,16 @@ src/index.js: \

src/cli/index.js: \
src/cli/main.js \
src/cli/optionNormalizer.js \
src/cli/parameterValidator.js
src/cli/normalizeOptions.js \
src/cli/validateParameters.js \
src/validate/readRuleSet.js

src/validate/readRuleSet.js: \
src/validate/normalizeRuleSet.js \
src/validate/validateRuleSet.js

src/validate/validateRuleSet.js: \
src/validate/jsonschema.json

src/cli/main.js: \
src/extract/index.js \
Expand All @@ -130,33 +144,26 @@ src/cli/main.js: \
src/report/visReporter.js

src/extract/index.js: \
src/extract/extractor.js \
src/extract/extract.js \
src/utl/index.js

src/extract/extractor.js: \
src/extract/extractor-AMD.js \
src/extract/extractor-ES6.js \
src/extract/extractor-commonJS.js \
src/extract/extract.js: \
src/extract/extract-AMD.js \
src/extract/extract-ES6.js \
src/extract/extract-commonJS.js \
src/resolve/index.js \
src/utl/index.js \
src/validate/index.js

src/resolve/index.js: \
src/resolve/resolver-AMD.js \
src/resolve/resolver-commonJS.js
src/resolve/resolve-AMD.js \
src/resolve/resolve-commonJS.js

src/resolve/resolver-AMD.js: \
src/resolve/resolve-AMD.js: \
src/utl/index.js

src/validate/index.js: \
src/validate/ruleSetNormalizer.js \
src/validate/ruleSetValidator.js

src/validate/ruleSetValidator.js: \
src/validate/jsonschema.json

src/extract/extractor-AMD.js: \
src/extract/extractor-commonJS.js
src/extract/extract-AMD.js: \
src/extract/extract-commonJS.js

src/report/csvReporter.js: \
src/report/csv.template.js \
Expand All @@ -172,20 +179,20 @@ src/report/htmlReporter.js: \
src/report/visReporter.js: \
src/report/vis.template.js

src/cli/parameterValidator.js: \
src/cli/validateParameters.js: \
src/utl/index.js

# cjs dependencies
ALL_SRC=src/index.js \
package.json \
src/cli/index.js \
src/cli/main.js \
src/cli/optionNormalizer.js \
src/cli/parameterValidator.js \
src/extract/extractor-AMD.js \
src/extract/extractor-ES6.js \
src/extract/extractor-commonJS.js \
src/extract/extractor.js \
src/cli/normalizeOptions.js \
src/cli/validateParameters.js \
src/extract/extract-AMD.js \
src/extract/extract-ES6.js \
src/extract/extract-commonJS.js \
src/extract/extract.js \
src/extract/index.js \
src/report/csv.template.js \
src/report/csvReporter.js \
Expand All @@ -199,22 +206,31 @@ ALL_SRC=src/index.js \
src/report/vis.template.js \
src/report/visReporter.js \
src/resolve/index.js \
src/resolve/resolver-AMD.js \
src/resolve/resolver-commonJS.js \
src/resolve/resolve-AMD.js \
src/resolve/resolve-commonJS.js \
src/utl/index.js \
src/validate/index.js \
src/validate/jsonschema.json \
src/validate/ruleSetNormalizer.js \
src/validate/ruleSetValidator.js
src/validate/normalizeRuleSet.js \
src/validate/readRuleSet.js \
src/validate/validateRuleSet.js
# cjs dependencies
test/cli/index.spec.js: \
src/cli/index.js \
test/utl/testutensils.js

src/cli/index.js: \
src/cli/main.js \
src/cli/optionNormalizer.js \
src/cli/parameterValidator.js
src/cli/normalizeOptions.js \
src/cli/validateParameters.js \
src/validate/readRuleSet.js

src/validate/readRuleSet.js: \
src/validate/normalizeRuleSet.js \
src/validate/validateRuleSet.js

src/validate/validateRuleSet.js: \
src/validate/jsonschema.json

src/cli/main.js: \
src/extract/index.js \
Expand All @@ -226,33 +242,26 @@ src/cli/main.js: \
src/report/visReporter.js

src/extract/index.js: \
src/extract/extractor.js \
src/extract/extract.js \
src/utl/index.js

src/extract/extractor.js: \
src/extract/extractor-AMD.js \
src/extract/extractor-ES6.js \
src/extract/extractor-commonJS.js \
src/extract/extract.js: \
src/extract/extract-AMD.js \
src/extract/extract-ES6.js \
src/extract/extract-commonJS.js \
src/resolve/index.js \
src/utl/index.js \
src/validate/index.js

src/resolve/index.js: \
src/resolve/resolver-AMD.js \
src/resolve/resolver-commonJS.js
src/resolve/resolve-AMD.js \
src/resolve/resolve-commonJS.js

src/resolve/resolver-AMD.js: \
src/resolve/resolve-AMD.js: \
src/utl/index.js

src/validate/index.js: \
src/validate/ruleSetNormalizer.js \
src/validate/ruleSetValidator.js

src/validate/ruleSetValidator.js: \
src/validate/jsonschema.json

src/extract/extractor-AMD.js: \
src/extract/extractor-commonJS.js
src/extract/extract-AMD.js: \
src/extract/extract-commonJS.js

src/report/csvReporter.js: \
src/report/csv.template.js \
Expand All @@ -268,21 +277,21 @@ src/report/htmlReporter.js: \
src/report/visReporter.js: \
src/report/vis.template.js

src/cli/parameterValidator.js: \
src/cli/validateParameters.js: \
src/utl/index.js

test/cli/optionNormalizer.spec.js: \
src/cli/optionNormalizer.js
test/cli/normalizeOptions.spec.js: \
src/cli/normalizeOptions.js

test/cli/parameterValidator.spec.js: \
src/cli/parameterValidator.js
test/cli/validateParameters.spec.js: \
src/cli/validateParameters.js

test/extract/extractor-composite.spec.js: \
test/extract/extract-composite.spec.js: \
src/extract/index.js \
src/extract/jsonschema.json

test/extract/extractor.spec.js: \
src/extract/extractor.js
test/extract/extract.spec.js: \
src/extract/extract.js

test/report/dotReporter.spec.js: \
src/report/dotReporter.js
Expand All @@ -293,9 +302,12 @@ test/report/errReporter.spec.js: \
test/report/htmlReporter.spec.js: \
src/report/htmlReporter.js

test/validate/ruleSetNormalizer.spec.js: \
src/validate/ruleSetNormalizer.js
test/validate/normalizeRuleSet.spec.js: \
src/validate/normalizeRuleSet.js

test/validate/validator.spec.js: \
src/validate/index.js
test/validate/readRuleSet.spec.js: \
src/validate/readRuleSet.js

test/validate/validate.spec.js: \
src/validate/index.js \
src/validate/readRuleSet.js
2 changes: 1 addition & 1 deletion bin/dependency-cruise
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/usr/bin/env node
require("../src");
require("../src/cli");
14 changes: 7 additions & 7 deletions doc/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ let dependencies = depcruise("src");
This will return an object
```
{
content: ... the dependencies
dependencies: ... the dependencies
meta: {}
}
```
Expand All @@ -44,31 +44,31 @@ let dependenciesInAGraphVizDotScript = depcruise(
These are all the options:
```
{
validate : if true, will attempt to validate with the rules in rulesFile.
validate : if true, will attempt to validate with the rules in ruleSet.
Default false.
rulesFile : A string pointing to a file containing rules to validate (NOTE:
we'll change this to a rulesObject in the near future)
ruleSet : An object containing the rules to validate against. The rules
should adhere to the [ruleset schema](../src/validate/jsonschema.json)
exclude : regular expression describing which dependencies the function
should not cruise
system : an array of module systems to use for following dependencies;
defaults to ["es6", "cjs", "amd"]
outputType : one of "json", "html", "dot", "csv", "err" or "vis". When left
out the function will return a javascript object as content
out the function will return a javascript object as dependencies
}
```

### The return value
```
{
content : when outputType is defined: a string containing the dependencies
dependencies : when outputType is defined: a string containing the dependencies
in the format specified in outputType
In all other cases: a javascript with the dependencies
meta : meta data with a summary of
{ error : the number of errors,
warn : the number of warnings,
info : the number of informational messages
}
(currently working for 'err' only - NOTE: we'll change this to
(currently meta is filled for 'err' only - NOTE: we'll change this to
always return this in the near future)
}
```
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"dependency-cruise": "bin/dependency-cruise",
"depcruise": "bin/dependency-cruise"
},
"main": "src/cli/main.js",
"main": "src/main/index.js",
"scripts": {
"cover": "istanbul cover node_modules/mocha/bin/_mocha -- test/*/*.spec.js",
"lint": "eslint src test",
Expand Down
Loading

0 comments on commit 430c0ae

Please sign in to comment.