From 5ce24d49a19b4517270fb0954cc57ab0fff7f05b Mon Sep 17 00:00:00 2001 From: Joost De Cock Date: Sun, 28 Aug 2022 14:06:01 +0200 Subject: [PATCH] chore(plugin-title): Ported to v3 --- plugins/plugin-title/build.mjs | 2 +- plugins/plugin-title/package.json | 2 +- .../plugin-title/src/{index.js => index.mjs} | 21 ++++++++++--------- plugins/plugin-title/tests/plugin.test.mjs | 12 +++++------ plugins/plugin-title/tests/shared.test.mjs | 7 +++---- 5 files changed, 22 insertions(+), 22 deletions(-) rename plugins/plugin-title/src/{index.js => index.mjs} (91%) diff --git a/plugins/plugin-title/build.mjs b/plugins/plugin-title/build.mjs index 9d1da1994da..0f283af1c6d 100644 --- a/plugins/plugin-title/build.mjs +++ b/plugins/plugin-title/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-title/package.json b/plugins/plugin-title/package.json index cbfe3de593b..e802f6aedf1 100644 --- a/plugins/plugin-title/package.json +++ b/plugins/plugin-title/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-title/src/index.js b/plugins/plugin-title/src/index.mjs similarity index 91% rename from plugins/plugin-title/src/index.js rename to plugins/plugin-title/src/index.mjs index 7bf5d068404..058fa8a6dc0 100644 --- a/plugins/plugin-title/src/index.js +++ b/plugins/plugin-title/src/index.mjs @@ -1,4 +1,4 @@ -import pkg from '../package.json' +import { name, version } from '../package.json' const style = ` text.title-nr { @@ -22,21 +22,17 @@ text.title-pattern { } ` -export default { - name: pkg.name, - version: pkg.version, +export const plugin = { + name, + version, hooks: { preRender: (svg) => { - if (svg.attributes.get('freesewing:plugin-title') === false) { - svg.attributes.set('freesewing:plugin-title', pkg.version) - svg.style += style - } + if (svg.style.indexOf(`test.title-nr`) === -1) svg.style += style }, }, macros: { title: function (so) { - let prefix = '' - if (so.prefix) prefix = so.prefix + const prefix = so.prefix || '' // Passing `false` will remove the title if (so === false) { @@ -111,3 +107,8 @@ export default { }, }, } + +// More specifically named exports +export const titlePlugin = plugin +export const pluginTitle = plugin + diff --git a/plugins/plugin-title/tests/plugin.test.mjs b/plugins/plugin-title/tests/plugin.test.mjs index 84948682f71..f4c8949c821 100644 --- a/plugins/plugin-title/tests/plugin.test.mjs +++ b/plugins/plugin-title/tests/plugin.test.mjs @@ -1,15 +1,15 @@ 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('Title Plugin Tests', () => { - const pattern = new freesewing.Pattern().use(plugin) + const pattern = new Pattern().use(plugin) pattern.draft().render() it("Should run the title macro", () => { - let pattern = new freesewing.Pattern({ name: "testPattern", version: 99 }); + let pattern = new Pattern({ name: "testPattern", version: 99 }); pattern.draft = function() {}; pattern.use(plugin); pattern.parts.test = new pattern.Part(); @@ -45,7 +45,7 @@ describe('Title Plugin Tests', () => { }); it("Should run the title macro with append flag", () => { - let pattern = new freesewing.Pattern({ name: "testPattern", version: 99 }); + let pattern = new Pattern({ name: "testPattern", version: 99 }); pattern.draft = function() {}; pattern.use(plugin); pattern.parts.test = new pattern.Part(); @@ -73,7 +73,7 @@ describe('Title Plugin Tests', () => { }); it("Should run the title macro with point prefix", () => { - let pattern = new freesewing.Pattern({ name: "testPattern", version: 99 }); + let pattern = new Pattern({ name: "testPattern", version: 99 }); pattern.draft = function() {}; pattern.use(plugin); pattern.parts.test = new pattern.Part(); diff --git a/plugins/plugin-title/tests/shared.test.mjs b/plugins/plugin-title/tests/shared.test.mjs index 9638f75571e..fdf846844b0 100644 --- a/plugins/plugin-title/tests/shared.test.mjs +++ b/plugins/plugin-title/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) +