sparkles: Fixed merge conflict
This commit is contained in:
parent
c89f7c66a1
commit
88118b8899
7 changed files with 5773 additions and 1090 deletions
4
packages/plugin-debug/.gitignore
vendored
4
packages/plugin-debug/.gitignore
vendored
|
@ -1,4 +1,7 @@
|
|||
# Compiled code
|
||||
dist
|
||||
tests/dist
|
||||
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
|
@ -17,6 +20,7 @@ lib-cov
|
|||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
coverage.lcov
|
||||
|
||||
# nyc test coverage
|
||||
.nyc_output
|
||||
|
|
9
packages/plugin-debug/.travis.yml
Normal file
9
packages/plugin-debug/.travis.yml
Normal file
|
@ -0,0 +1,9 @@
|
|||
language: node_js
|
||||
node_js:
|
||||
- "node"
|
||||
install:
|
||||
- npm install
|
||||
- npm run build
|
||||
script:
|
||||
- npm run test
|
||||
- npm run coverage
|
|
@ -4,10 +4,19 @@
|
|||
<h4 align="center"><em> <a title="Go to freesewing.org" href="https://freesewing.org/">freesewing</a></em>
|
||||
<br><sup>a library for made-to-measure sewing patterns</sup>
|
||||
</h4>
|
||||
<p align="center">
|
||||
<a href="https://travis-ci.org/freesewing/plugin-debug"><img src="https://badgen.net/travis/freesewing/plugin-debug/master" alt="Travis build"></a>
|
||||
<a href="https://www.npmjs.com/package/@freesewing/plugin-debug"><img src="https://badgen.net/npm/v/@freesewing/plugin-debug" alt="Version"></a>
|
||||
<a href="https://www.npmjs.com/package/@freesewing/plugin-debug"><img src="https://badgen.net/npm/license/@freesewing/plugin-debug" alt="License"></a>
|
||||
<a href="https://codecov.io/gh/freesewing/plugin-debug"><img src="https://badgen.net/codecov/c/github/freesewing/plugin-debug/master" alt="Code coverage"></a>
|
||||
<a href="https://deepscan.io/dashboard#view=project&pid=3255&bid=27565"><img src="https://deepscan.io/api/projects/3255/branches/27565/badge/grade.svg" alt="DeepScan grade"></a>
|
||||
<a href="https://gitter.im/freesewing/freesewing"><img src="https://badgen.net/badge/chat/on%20Gitter/cyan" alt="Chat on Gitter"></a>
|
||||
<a href="https://freesewing.org/patrons/join"><img src="https://badgen.net/badge/become/a%20Patron/FF5B77" alt="Become a Patron"></a>
|
||||
</p>
|
||||
|
||||
# plugin-debug
|
||||
|
||||
A freesewing plugin to display debug information in your browser console.
|
||||
A freesewing plugin to log debug information to the console.
|
||||
|
||||
## Usage
|
||||
|
||||
|
@ -35,13 +44,6 @@ var pattern = freesewing.patterns.brian
|
|||
</script>
|
||||
```
|
||||
|
||||
## Example
|
||||
|
||||
This plugin will gather debug info and log it to your browser console:
|
||||
|
||||

|
||||
|
||||
|
||||
## Install
|
||||
|
||||
To install, run:
|
||||
|
|
6639
packages/plugin-debug/package-lock.json
generated
6639
packages/plugin-debug/package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@freesewing/plugin-debug",
|
||||
"version": "0.3.0",
|
||||
"version": "0.4.3",
|
||||
"description": "A freesewing plugin to log debug info to your browser console",
|
||||
"author": "Joost De Cock <joost@decock.org> (https://github.com/joostdecock)",
|
||||
"license": "MIT",
|
||||
|
@ -24,13 +24,15 @@
|
|||
"minor": "npm version minor -m ':bookmark: v%s' && npm run build",
|
||||
"major": "npm version major -m ':bookmark: v%s' && npm run build",
|
||||
"precommit": "npm run pretty && lint-staged",
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"test": "nyc mocha --require @babel/register tests/*.test.js",
|
||||
"report": "nyc report --reporter=html mocha --require @babel/register tests/*.test.js",
|
||||
"coverage": "nyc npm test && nyc report --reporter=text-lcov > coverage.lcov && ./node_modules/.bin/codecov",
|
||||
"clean": "rimraf dist",
|
||||
"pretty": "npx prettier --write \"src/*.js\"",
|
||||
"lint": "eslint --fix \"src/*.js\"",
|
||||
"browserbuild": "rollup -c rollup.js --file dist/browser.js --format iife --name freesewing.plugins.debug",
|
||||
"nodebuild": "rollup -c rollup.js --file dist/index.js --format cjs",
|
||||
"modulebuild": "rollup -c rollup.js --file dist/index.mjs --format es",
|
||||
"browserbuild": "rollup -c rollup.js --file dist/browser.js --format iife -m true --name freesewing.plugins.debug",
|
||||
"nodebuild": "rollup -c rollup.js --file dist/index.js --format cjs -m true",
|
||||
"modulebuild": "rollup -c rollup.js --file dist/index.mjs --format es -m true",
|
||||
"build": "npm run clean && npm run browserbuild && npm run nodebuild && npm run modulebuild"
|
||||
},
|
||||
"husky": {
|
||||
|
@ -45,16 +47,24 @@
|
|||
]
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-core": "^6.26.3",
|
||||
"babel-eslint": "^8.2.6",
|
||||
"@babel/core": "^7.1.0",
|
||||
"@babel/preset-env": "^7.1.0",
|
||||
"@babel/register": "^7.0.0",
|
||||
"chai": "^4.1.2",
|
||||
"chai-string": "1.4.0",
|
||||
"codecov": "^3.1.0",
|
||||
"eslint": "^5.2.0",
|
||||
"eslint-config-prettier": "^2.9.0",
|
||||
"eslint-plugin-prettier": "^2.6.2",
|
||||
"freesewing": "^0.18.3",
|
||||
"husky": "^0.14.3",
|
||||
"lint-staged": "^7.2.0",
|
||||
"mocha": "^5.2.0",
|
||||
"nyc": "12.0.2",
|
||||
"prettier": "^1.13.7",
|
||||
"rimraf": "^2.6.2",
|
||||
"rollup-plugin-babel": "^3.0.7",
|
||||
"rollup": "^0.66.2",
|
||||
"rollup-plugin-babel": "^4.0.3",
|
||||
"rollup-plugin-filesize": "^4.0.1",
|
||||
"rollup-plugin-json": "^3.0.0",
|
||||
"rollup-plugin-node-resolve": "^3.3.0",
|
||||
|
@ -65,5 +75,6 @@
|
|||
"README.md",
|
||||
"package-lock.json",
|
||||
"package.json"
|
||||
]
|
||||
],
|
||||
"dependencies": {}
|
||||
}
|
||||
|
|
|
@ -1,38 +1,47 @@
|
|||
import { version, name } from "../package.json";
|
||||
|
||||
const color = {
|
||||
info: "#29ABE0",
|
||||
warning: "#F47C3C",
|
||||
error: "#d9534f",
|
||||
success: "#4caf50"
|
||||
const colors = {
|
||||
info: "RoyalBlue",
|
||||
warning: "Tomato",
|
||||
error: "Red",
|
||||
success: "OliveDrab",
|
||||
debug: "Magenta"
|
||||
};
|
||||
|
||||
/* Returns an object to style debug output */
|
||||
function debugStyle(type, text) {
|
||||
let style = `color: ${color[type]};`;
|
||||
style += "font-weight: 600;";
|
||||
style += "padding: 0 5px;";
|
||||
style += "border-radius: 3px;";
|
||||
var debug = {
|
||||
name: name,
|
||||
version: version
|
||||
};
|
||||
|
||||
return style;
|
||||
debug.log = function(label="", style="", data="") {
|
||||
// This allows us to stub console.log()
|
||||
// in unit tests without side-effects
|
||||
console.log(label, style, data);
|
||||
};
|
||||
|
||||
debug.style = function(type) {
|
||||
return `font-weight: bold; padding: 0 5px; color: ${colors[type]};`;
|
||||
}
|
||||
|
||||
export default {
|
||||
name: name,
|
||||
version: version,
|
||||
hooks: {
|
||||
debug: function(data, more) {
|
||||
if(
|
||||
typeof data === "object" &&
|
||||
typeof data.type === "string" &&
|
||||
typeof data.label === "string" &&
|
||||
typeof data.msg === "string" &&
|
||||
Object.keys(data).length === 3) {
|
||||
// Make it pretty
|
||||
console.log("%c"+data.label, debugStyle(data.type), data.msg);
|
||||
} else {
|
||||
console.log(data);
|
||||
}
|
||||
debug.hooks = {
|
||||
preRender: function(svg) {
|
||||
if(svg.attributes.get("freesewing:plugin-debug") === false) {
|
||||
svg.attributes.set("freesewing:plugin-debug", version);
|
||||
}
|
||||
},
|
||||
debug: function(data, more) {
|
||||
if(
|
||||
typeof data === "object" &&
|
||||
typeof data.type === "string" &&
|
||||
typeof data.label === "string" &&
|
||||
typeof data.msg === "string" &&
|
||||
Object.keys(data).length === 3) {
|
||||
// Make it pretty
|
||||
debug.log("%c"+data.label, debug.style(data.type), data.msg);
|
||||
} else {
|
||||
debug.log("%cdebug", debug.style('debug'), data);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default debug;
|
||||
|
|
99
packages/plugin-debug/tests/debug.test.js
Normal file
99
packages/plugin-debug/tests/debug.test.js
Normal file
|
@ -0,0 +1,99 @@
|
|||
import freesewing from "freesewing";
|
||||
import { version } from "../package.json";
|
||||
let expect = require("chai").expect;
|
||||
let debugPlugin = require("../dist/index.js");
|
||||
|
||||
let output;
|
||||
let debug = debugPlugin.hooks.debug;
|
||||
|
||||
function next() {}
|
||||
|
||||
debugPlugin.log = function(d = "", e = "", b = "", u = "", g = "", gg = "") {
|
||||
output = { d, e, b, u, g, gg };
|
||||
};
|
||||
|
||||
it("Should set the plugin name:version attribute", () => {
|
||||
let pattern = new freesewing.Pattern().with(debugPlugin);
|
||||
pattern.render();
|
||||
expect(pattern.svg.attributes.get("freesewing:plugin-debug")).to.equal(
|
||||
version
|
||||
);
|
||||
});
|
||||
|
||||
it("Should log empty", () => {
|
||||
output = {};
|
||||
debug(next);
|
||||
expect(output.d).to.equal("%cdebug");
|
||||
expect(output.e).to.equal("color: Magenta;");
|
||||
expect(output.b).to.equal("");
|
||||
expect(output.u).to.equal("");
|
||||
expect(output.g).to.equal("");
|
||||
expect(output.gg).to.equal("");
|
||||
});
|
||||
|
||||
it("Should log default debug", () => {
|
||||
output = {};
|
||||
debug(next, "Debug message", "more info");
|
||||
expect(output.d).to.equal("%cdebug");
|
||||
expect(output.e).to.equal("color: Magenta;");
|
||||
expect(output.b).to.equal("Debug message");
|
||||
expect(output.u).to.equal("more info");
|
||||
expect(output.g).to.equal("");
|
||||
expect(output.gg).to.equal("");
|
||||
});
|
||||
|
||||
it("Should log styled debug for node", () => {
|
||||
output = {};
|
||||
debug(next, "debug", "label", "Debug message", "more info");
|
||||
expect(output.d).to.equal("%clabel");
|
||||
expect(output.e).to.equal("color: Magenta;");
|
||||
expect(output.b).to.equal("Debug message");
|
||||
expect(output.u).to.equal("more info");
|
||||
expect(output.g).to.equal("");
|
||||
expect(output.gg).to.equal("");
|
||||
});
|
||||
|
||||
it("Should log styled info for node", () => {
|
||||
output = {};
|
||||
debug(next, "info", "label", "Debug message", "more info");
|
||||
expect(output.d).to.equal("%clabel");
|
||||
expect(output.e).to.equal("color: RoyalBlue;");
|
||||
expect(output.b).to.equal("Debug message");
|
||||
expect(output.u).to.equal("more info");
|
||||
expect(output.g).to.equal("");
|
||||
expect(output.gg).to.equal("");
|
||||
});
|
||||
|
||||
it("Should log styled success for node", () => {
|
||||
output = {};
|
||||
debug(next, "success", "label", "Debug message", "more info");
|
||||
expect(output.d).to.equal("%clabel");
|
||||
expect(output.e).to.equal("color: OliveDrab;");
|
||||
expect(output.b).to.equal("Debug message");
|
||||
expect(output.u).to.equal("more info");
|
||||
expect(output.g).to.equal("");
|
||||
expect(output.gg).to.equal("");
|
||||
expect(output.g).to.equal("");
|
||||
});
|
||||
|
||||
it("Should log styled warning for node", () => {
|
||||
output = {};
|
||||
debug(next, "warning", "label", "Debug message", "more info");
|
||||
expect(output.d).to.equal("%clabel");
|
||||
expect(output.e).to.equal("color: Tomato;");
|
||||
expect(output.b).to.equal("Debug message");
|
||||
expect(output.u).to.equal("more info");
|
||||
expect(output.g).to.equal("");
|
||||
expect(output.gg).to.equal("");
|
||||
});
|
||||
|
||||
it("Should log styled error for node", () => {
|
||||
output = {};
|
||||
debug(next, "error", "label", "Debug message", "more info");
|
||||
expect(output.d).to.equal("%clabel");
|
||||
expect(output.e).to.equal("color: Red;");
|
||||
expect(output.b).to.equal("Debug message");
|
||||
expect(output.u).to.equal("more info");
|
||||
expect(output.g).to.equal("");
|
||||
expect(output.gg).to.equal("");
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue