diff --git a/plugins/plugin-scalebox/build.mjs b/plugins/plugin-scalebox/build.mjs index 9d1da1994da..0f283af1c6d 100644 --- a/plugins/plugin-scalebox/build.mjs +++ b/plugins/plugin-scalebox/build.mjs @@ -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"], diff --git a/plugins/plugin-scalebox/package.json b/plugins/plugin-scalebox/package.json index 94d01badace..7fa330d4252 100644 --- a/plugins/plugin-scalebox/package.json +++ b/plugins/plugin-scalebox/package.json @@ -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" }, diff --git a/plugins/plugin-scalebox/src/index.js b/plugins/plugin-scalebox/src/index.js deleted file mode 100644 index f4d2dd8518a..00000000000 --- a/plugins/plugin-scalebox/src/index.js +++ /dev/null @@ -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 }, -} diff --git a/plugins/plugin-scalebox/src/index.mjs b/plugins/plugin-scalebox/src/index.mjs new file mode 100644 index 00000000000..e7a7b36c1b5 --- /dev/null +++ b/plugins/plugin-scalebox/src/index.mjs @@ -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 + diff --git a/plugins/plugin-scalebox/src/miniscale.js b/plugins/plugin-scalebox/src/miniscale.mjs similarity index 99% rename from plugins/plugin-scalebox/src/miniscale.js rename to plugins/plugin-scalebox/src/miniscale.mjs index 59212063155..533beeb5645 100644 --- a/plugins/plugin-scalebox/src/miniscale.js +++ b/plugins/plugin-scalebox/src/miniscale.mjs @@ -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 [ diff --git a/plugins/plugin-scalebox/src/scalebox.js b/plugins/plugin-scalebox/src/scalebox.mjs similarity index 99% rename from plugins/plugin-scalebox/src/scalebox.js rename to plugins/plugin-scalebox/src/scalebox.mjs index d5eff717062..58bd47a59b5 100644 --- a/plugins/plugin-scalebox/src/scalebox.js +++ b/plugins/plugin-scalebox/src/scalebox.mjs @@ -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 ') } + diff --git a/plugins/plugin-scalebox/tests/plugin.test.mjs b/plugins/plugin-scalebox/tests/plugin.test.mjs index 97c0f8b22a0..32ecdfa7991 100644 --- a/plugins/plugin-scalebox/tests/plugin.test.mjs +++ b/plugins/plugin-scalebox/tests/plugin.test.mjs @@ -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); diff --git a/plugins/plugin-scalebox/tests/shared.test.mjs b/plugins/plugin-scalebox/tests/shared.test.mjs index 9638f75571e..fdf846844b0 100644 --- a/plugins/plugin-scalebox/tests/shared.test.mjs +++ b/plugins/plugin-scalebox/tests/shared.test.mjs @@ -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) +