1
0
Fork 0

chore(plugin-title): Ported to v3

This commit is contained in:
Joost De Cock 2022-08-28 14:06:01 +02:00
parent 7b3b26da41
commit 5ce24d49a1
5 changed files with 22 additions and 22 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,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

View file

@ -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();

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)