1
0
Fork 0

chore(plugin-scalebox): Ported to v3

This commit is contained in:
Joost De Cock 2022-08-28 13:43:02 +02:00
parent 3e59f830fd
commit 60c5533e0e
8 changed files with 30 additions and 29 deletions

View file

@ -14,7 +14,7 @@ const banner = `/**
const options = {
banner: { js: banner },
bundle: true,
entryPoints: ['src/index.js'],
entryPoints: ['src/index.mjs'],
format: 'esm',
outfile: 'dist/index.mjs',
external: ["@freesewing"],

View file

@ -38,7 +38,7 @@
"vbuild": "VERBOSE=1 node --experimental-json-modules build.mjs",
"lab": "cd ../../sites/lab && yarn start",
"tips": "node ../../scripts/help.mjs",
"prettier": "npx prettier --write 'src/*.js' 'tests/*.mjs'",
"prettier": "npx prettier --write 'src/*.mjs' 'tests/*.mjs'",
"testci": "npx mocha tests/*.test.mjs --reporter ../../tests/reporters/terse.js",
"cibuild_step1": "node --experimental-json-modules build.mjs"
},

View file

@ -1,12 +0,0 @@
import pkg from '../package.json'
import scalebox from './scalebox'
import miniscale from './miniscale'
export default {
name: pkg.name,
version: pkg.version,
hooks: {
preRender: (svg) => svg.attributes.setIfUnset('freesewing:plugin-scalebox', pkg.version),
},
macros: { scalebox, miniscale },
}

View file

@ -0,0 +1,14 @@
import { name, version } from '../package.json'
import { scalebox } from './scalebox.mjs'
import { miniscale } from './miniscale.mjs'
export const plugin = {
name,
version,
macros: { scalebox, miniscale },
}
// More specifically named exports
export const scaleboxPlugin = plugin
export const pluginScalebox = plugin

View file

@ -1,4 +1,4 @@
export default function (so) {
export function miniscale(so) {
// Passing `false` will remove the miniscale
if (so === false) {
for (let id of [

View file

@ -1,4 +1,4 @@
export default function (so) {
export function scalebox(so) {
// Passing `false` will remove the scalebox
if (so === false) {
for (let id of [
@ -182,3 +182,4 @@ export default function (so) {
.attr('data-text', `${imperialDisplayHeight}`)
.attr('data-text-class', 'text-xs center ')
}

View file

@ -1,13 +1,12 @@
import chai from 'chai'
import freesewing from '@freesewing/core'
import plugin from '../dist/index.mjs'
import { Pattern, round } from '@freesewing/core'
import { plugin } from '../dist/index.mjs'
const expect = chai.expect
const round = freesewing.utils.round
describe('Scalebox Plugin Tests', () => {
it("Should run the default scalebox macro", () => {
const pattern = new freesewing.Pattern().use(plugin)
const pattern = new Pattern().use(plugin)
pattern.parts.test = new pattern.Part();
pattern.parts.test.points.anchor = new pattern.Point(100, 200);
const { macro } = pattern.parts.test.shorthand()
@ -74,7 +73,7 @@ describe('Scalebox Plugin Tests', () => {
});
it("Should run the scalebox macro with rotation", () => {
const pattern = new freesewing.Pattern().use(plugin)
const pattern = new Pattern().use(plugin)
pattern.parts.test = new pattern.Part();
pattern.parts.test.points.anchor = new pattern.Point(100, 200);
const { macro } = pattern.parts.test.shorthand()
@ -114,7 +113,7 @@ describe('Scalebox Plugin Tests', () => {
});
it("Should run the scalebox macro with default text", () => {
const pattern = new freesewing.Pattern().use(plugin)
const pattern = new Pattern().use(plugin)
pattern.parts.test = new pattern.Part();
pattern.parts.test.points.anchor = new pattern.Point(100, 200);
const { macro } = pattern.parts.test.shorthand()
@ -134,7 +133,7 @@ describe('Scalebox Plugin Tests', () => {
});
it("Should run the scalebox macro with custom text", () => {
const pattern = new freesewing.Pattern().use(plugin)
const pattern = new Pattern().use(plugin)
pattern.parts.test = new pattern.Part();
pattern.parts.test.points.anchor = new pattern.Point(100, 200);
const { macro } = pattern.parts.test.shorthand()
@ -157,7 +156,7 @@ describe('Scalebox Plugin Tests', () => {
})
it("Should apply scale to the scalebox macro", () => {
const pattern = new freesewing.Pattern().use(plugin)
const pattern = new Pattern().use(plugin)
pattern.settings.scale = 0.5
pattern.parts.test = new pattern.Part();
pattern.parts.test.points.anchor = new pattern.Point(100, 200);
@ -189,7 +188,7 @@ describe('Scalebox Plugin Tests', () => {
});
it("Should apply scale to the miniscale macro", () => {
const pattern = new freesewing.Pattern().use(plugin)
const pattern = new Pattern().use(plugin)
pattern.settings.scale = 0.5
pattern.parts.test = new pattern.Part();
pattern.parts.test.points.anchor = new pattern.Point(100, 200);

View file

@ -1,8 +1,7 @@
// This file is auto-generated.
// Changes you make will be overwritten.
import plugin from './dist/index.mjs'
// This file is auto-generated | Any changes you make will be overwritten.
import { plugin } from './dist/index.mjs'
import { sharedPluginTests } from '../../../tests/plugins/shared.mjs'
// Run shared tests
sharedPluginTests(plugin)