diff --git a/plugins/plugin-bartack/build.mjs b/plugins/plugin-bartack/build.mjs index 9d1da1994da..0f283af1c6d 100644 --- a/plugins/plugin-bartack/build.mjs +++ b/plugins/plugin-bartack/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-bartack/package.json b/plugins/plugin-bartack/package.json index 4bdc6b7b971..5c6d17871d7 100644 --- a/plugins/plugin-bartack/package.json +++ b/plugins/plugin-bartack/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-bartack/src/index.js b/plugins/plugin-bartack/src/index.js deleted file mode 100644 index a096bd4102e..00000000000 --- a/plugins/plugin-bartack/src/index.js +++ /dev/null @@ -1,34 +0,0 @@ -import pkg from '../package.json' -import bartack from './bartack' - -export default { - name: pkg.name, - version: pkg.version, - hooks: { - preRender: (svg) => svg.attributes.setIfUnset('freesewing:plugin-bartack', pkg.version), - }, - macros: { - bartack: function (so) { - const self = this - return bartack(so, self) - }, - bartackAlong: function (so) { - const self = this - so.bartackFractionAlong = false - so.bartackAlong = true - so.anchor = false - so.from = false - so.to = false - return bartack(so, self) - }, - bartackFractionAlong: function (so) { - const self = this - so.bartackFractionAlong = true - so.bartackAlong = false - so.anchor = false - so.from = false - so.to = false - return bartack(so, self) - }, - }, -} diff --git a/plugins/plugin-bartack/src/bartack.js b/plugins/plugin-bartack/src/index.mjs similarity index 66% rename from plugins/plugin-bartack/src/bartack.js rename to plugins/plugin-bartack/src/index.mjs index 99464c4dcc7..fec581f2d86 100644 --- a/plugins/plugin-bartack/src/bartack.js +++ b/plugins/plugin-bartack/src/index.mjs @@ -1,5 +1,9 @@ -const name = (n, so) => `${so.prefix}${n}${so.suffix}` +import { version, name } from '../package.json' assert { type: 'json' } +// Helper method to construct prefixed/suffixed name +const getName = (n, so) => `${so.prefix}${n}${so.suffix}` + +// Method that draws the actual bartack const drawBartack = (points, self) => { let path = new self.Path().move(points.path1[0]) for (const i in points.path1) { @@ -10,6 +14,7 @@ const drawBartack = (points, self) => { return path } +// Helper method to generate the points to draw on later const getPoints = (path, so) => { let path1 = path.offset(so.width / 2) let path2 = path.offset(so.width / -2) @@ -87,10 +92,45 @@ export default function bartack(so, self) { } } - self.paths[name('bartack', so)] = bartackPath(guide, so, self).attr( - 'class', - 'stroke-sm stroke-mark' - ) + self.paths[`${so.prefix}bartack${so.suffix}`] = bartackPath(guide, so, self) + .attr('class', 'stroke-sm stroke-mark') return true } + + + +// The actual plugin +export const plugin = { + name, + version, + macros: { + bartack: function (so) { + const self = this + return bartack(so, self) + }, + bartackAlong: function (so) { + const self = this + so.bartackFractionAlong = false + so.bartackAlong = true + so.anchor = false + so.from = false + so.to = false + return bartack(so, self) + }, + bartackFractionAlong: function (so) { + const self = this + so.bartackFractionAlong = true + so.bartackAlong = false + so.anchor = false + so.from = false + so.to = false + return bartack(so, self) + }, + }, +} + +// More specifically named exports +export const bartackPlugin = plugin +export const pluginBartack = plugin + diff --git a/plugins/plugin-bartack/tests/plugin.test.mjs b/plugins/plugin-bartack/tests/plugin.test.mjs index dff92e1e401..4a11ed3309d 100644 --- a/plugins/plugin-bartack/tests/plugin.test.mjs +++ b/plugins/plugin-bartack/tests/plugin.test.mjs @@ -1,13 +1,12 @@ import chai from 'chai' -import freesewing from '@freesewing/core' -import plugin from '../dist/index.mjs' +import { round, Pattern } from '@freesewing/core' +import { plugin } from '../dist/index.mjs' const expect = chai.expect -const round = freesewing.utils.round describe('Bartack plugin Tests', () => { it('draws a default bartack from a point', function () { - const pattern = new freesewing.Pattern() + const pattern = new Pattern() pattern.use(plugin) pattern.parts.test = new pattern.Part() pattern.parts.test.points.from = new pattern.Point(10, 20) @@ -33,7 +32,7 @@ describe('Bartack plugin Tests', () => { }) it('draws a bartack along a path', function () { - const pattern = new freesewing.Pattern() + const pattern = new Pattern() pattern.use(plugin) pattern.parts.test = new pattern.Part() const from = new pattern.Point(10, 20) @@ -61,7 +60,7 @@ describe('Bartack plugin Tests', () => { }) it('can be called using the bartackFractionAlong syntax', function () { - const pattern = new freesewing.Pattern() + const pattern = new Pattern() pattern.use(plugin) pattern.parts.test = new pattern.Part() const from = new pattern.Point(10, 20) @@ -91,7 +90,7 @@ describe('Bartack plugin Tests', () => { }) it('can be called using the bartackFractionAlong syntax', function () { - const pattern = new freesewing.Pattern() + const pattern = new Pattern() pattern.use(plugin) pattern.parts.test = new pattern.Part() const from = new pattern.Point(10, 20) @@ -121,7 +120,7 @@ describe('Bartack plugin Tests', () => { }) it('has configurable length', function () { - const pattern = new freesewing.Pattern() + const pattern = new Pattern() pattern.use(plugin) pattern.parts.test = new pattern.Part() pattern.parts.test.points.from = new pattern.Point(10, 20) @@ -148,7 +147,7 @@ describe('Bartack plugin Tests', () => { }) it('has configurable width', function () { - const pattern = new freesewing.Pattern() + const pattern = new Pattern() pattern.use(plugin) pattern.parts.test = new pattern.Part() pattern.parts.test.points.from = new pattern.Point(10, 20) @@ -175,7 +174,7 @@ describe('Bartack plugin Tests', () => { }) it('has configurable angle', function () { - const pattern = new freesewing.Pattern() + const pattern = new Pattern() pattern.use(plugin) pattern.parts.test = new pattern.Part() pattern.parts.test.points.from = new pattern.Point(10, 20) @@ -202,7 +201,7 @@ describe('Bartack plugin Tests', () => { }) it('has configurable suffix', function () { - const pattern = new freesewing.Pattern() + const pattern = new Pattern() pattern.use(plugin) pattern.parts.test = new pattern.Part() pattern.parts.test.points.from = new pattern.Point(10, 20) @@ -216,7 +215,7 @@ describe('Bartack plugin Tests', () => { }) it('has configurable prefix', function () { - const pattern = new freesewing.Pattern() + const pattern = new Pattern() pattern.use(plugin) pattern.parts.test = new pattern.Part() pattern.parts.test.points.from = new pattern.Point(10, 20) diff --git a/plugins/plugin-bartack/tests/shared.test.mjs b/plugins/plugin-bartack/tests/shared.test.mjs index 9638f75571e..fdf846844b0 100644 --- a/plugins/plugin-bartack/tests/shared.test.mjs +++ b/plugins/plugin-bartack/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) +