From 6f8cc6e75347f367468e2c6a3e05dcc739404b72 Mon Sep 17 00:00:00 2001 From: Joost De Cock Date: Sun, 28 Aug 2022 12:33:06 +0200 Subject: [PATCH] chore(plugin-flip): Ported to v3 --- plugins/plugin-flip/build.mjs | 2 +- plugins/plugin-flip/package.json | 2 +- plugins/plugin-flip/src/{index.js => index.mjs} | 17 ++++++++++------- plugins/plugin-flip/tests/plugin.test.mjs | 12 ++++++------ plugins/plugin-flip/tests/shared.test.mjs | 7 +++---- 5 files changed, 21 insertions(+), 19 deletions(-) rename plugins/plugin-flip/src/{index.js => index.mjs} (89%) diff --git a/plugins/plugin-flip/build.mjs b/plugins/plugin-flip/build.mjs index 9d1da1994da..0f283af1c6d 100644 --- a/plugins/plugin-flip/build.mjs +++ b/plugins/plugin-flip/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-flip/package.json b/plugins/plugin-flip/package.json index 4c214d90bf0..0c84c7ef8a5 100644 --- a/plugins/plugin-flip/package.json +++ b/plugins/plugin-flip/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-flip/src/index.js b/plugins/plugin-flip/src/index.mjs similarity index 89% rename from plugins/plugin-flip/src/index.js rename to plugins/plugin-flip/src/index.mjs index b64563bb8d6..1769ec6b1fb 100644 --- a/plugins/plugin-flip/src/index.js +++ b/plugins/plugin-flip/src/index.mjs @@ -1,11 +1,8 @@ -import pkg from '../package.json' +import { name, version } from '../package.json' assert { type: 'json' } -export default { - name: pkg.name, - version: pkg.version, - hooks: { - preRender: (svg) => svg.attributes.setIfUnset('freesewing:plugin-flip', pkg.version), - }, +export const plugin = { + name, + version, macros: { flip: function (so) { const axis = so?.axis === 'y' ? 'y' : 'x' @@ -49,3 +46,9 @@ export default { }, }, } + + +// More specifically named exports +export const flipPlugin = plugin +export const pluginFlip = plugin + diff --git a/plugins/plugin-flip/tests/plugin.test.mjs b/plugins/plugin-flip/tests/plugin.test.mjs index 0162f945202..7404368cf30 100644 --- a/plugins/plugin-flip/tests/plugin.test.mjs +++ b/plugins/plugin-flip/tests/plugin.test.mjs @@ -1,11 +1,11 @@ import chai from 'chai' -import freesewing from '@freesewing/core' -import plugin from '../dist/index.mjs' +import { Pattern } from '@freesewing/core' +import { plugin } from './dist/index.mjs' const expect = chai.expect describe('Flip Plugin Tests', () => { - const pattern = new freesewing.Pattern().use(plugin); + const pattern = new Pattern().use(plugin); pattern.parts.test = new pattern.Part() pattern.parts.test.points.from = new pattern.Point(10, 20) pattern.parts.test.points.to = new pattern.Point(30, 40) @@ -44,7 +44,7 @@ describe('Flip Plugin Tests', () => { }) it('Should flip points in a part on their vertical axis', () => { - let pattern = new freesewing.Pattern() + let pattern = new Pattern() pattern.use(plugin) pattern.parts.test = new pattern.Part() pattern.parts.test.points.from = new pattern.Point(10,20) @@ -58,7 +58,7 @@ describe('Flip Plugin Tests', () => { }) it('Should flip points in a path on their vertical axis', () => { - let pattern = new freesewing.Pattern() + let pattern = new Pattern() pattern.use(plugin) pattern.parts.test = new pattern.Part() pattern.parts.test.points.from = new pattern.Point(10,20) @@ -82,7 +82,7 @@ describe('Flip Plugin Tests', () => { }) it('Should flip points in snippets on their vertical axis', () => { - let pattern = new freesewing.Pattern() + let pattern = new Pattern() pattern.use(plugin) pattern.parts.test = new pattern.Part() let anchorPoint = new pattern.Point(40,0) diff --git a/plugins/plugin-flip/tests/shared.test.mjs b/plugins/plugin-flip/tests/shared.test.mjs index 9638f75571e..fdf846844b0 100644 --- a/plugins/plugin-flip/tests/shared.test.mjs +++ b/plugins/plugin-flip/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) +