From 54c8d4078d9acf67f5d0f20418c1c717d817a699 Mon Sep 17 00:00:00 2001 From: CokaKoala <31664583+AdrianGonz97@users.noreply.github.com> Date: Mon, 29 Jan 2024 13:48:14 -0500 Subject: [PATCH] fix: Add the license banner inside of the script tag instead of an HTML comment (#1811) * add banner inside of the script tag instead * renamed script * Update packages/lucide-svelte/scripts/license.mjs Co-authored-by: Jakob Guddas * Update packages/lucide-svelte/scripts/appendLicense.mjs Co-authored-by: Eric Fennis * renamed file --------- Co-authored-by: Jakob Guddas Co-authored-by: Eric Fennis --- packages/lucide-svelte/package.json | 2 +- ...addLicense.mjs => appendBlockComments.mjs} | 41 +++++-------------- .../lucide-svelte/scripts/exportTemplate.mjs | 2 + packages/lucide-svelte/scripts/license.mjs | 11 +++++ 4 files changed, 24 insertions(+), 32 deletions(-) rename packages/lucide-svelte/scripts/{addLicense.mjs => appendBlockComments.mjs} (64%) create mode 100644 packages/lucide-svelte/scripts/license.mjs diff --git a/packages/lucide-svelte/package.json b/packages/lucide-svelte/package.json index 6c1d42c4cb..4a0c1b64eb 100644 --- a/packages/lucide-svelte/package.json +++ b/packages/lucide-svelte/package.json @@ -50,7 +50,7 @@ "clean": "rm -rf dist && rm -rf stats && rm -rf ./src/icons/*.svelte && rm -f index.js", "build:icons": "build-icons --output=./src --templateSrc=./scripts/exportTemplate.mjs --exportFileName=index.ts --iconFileExtension=.svelte --importImportFileExtension=.svelte --withAliases --aliasesFileExtension=.ts --aliasImportFileExtension=.svelte --pretty=false", "build:package": "svelte-package --input ./src", - "build:license": "node ./scripts/addLicense.mjs", + "build:license": "node ./scripts/appendBlockComments.mjs", "test": "vitest run", "version": "pnpm version --git-tag-version=false" }, diff --git a/packages/lucide-svelte/scripts/addLicense.mjs b/packages/lucide-svelte/scripts/appendBlockComments.mjs similarity index 64% rename from packages/lucide-svelte/scripts/addLicense.mjs rename to packages/lucide-svelte/scripts/appendBlockComments.mjs index b31c87e8b3..d6d6e3ae1a 100644 --- a/packages/lucide-svelte/scripts/addLicense.mjs +++ b/packages/lucide-svelte/scripts/appendBlockComments.mjs @@ -1,13 +1,8 @@ -import { getCurrentDirPath } from '../../../scripts/helpers.mjs'; import { lstatSync } from 'fs'; import { readdir, readFile, writeFile } from 'fs/promises'; import path from 'path'; -import pkg from '../package.json' assert { type: 'json' }; - -const BANNER = `@license ${pkg.name} v${pkg.version} - ${pkg.license} - -This source code is licensed under the ${pkg.license} license. -See the LICENSE file in the root directory of this source tree.`; +import { getCurrentDirPath } from '../../../scripts/helpers.mjs'; +import { getJSBanner } from './license.mjs'; const currentDir = getCurrentDirPath(import.meta.url); const targetDirectory = path.join(currentDir, '../dist'); @@ -32,21 +27,16 @@ for (const file of files) { license = getJSBanner(); } - if (/\.svelte/.test(ext)) { - license = getSvelteBanner(); - } - if (license) { newContents = license + contents; - } // Places icon block comment at the top of the Svelte component class - if(/icons\/(.*?)\.svelte\.d\.ts/.test(filepath)) { - const svelteFilepath = filepath.replace('.d.ts', '') + if (/icons\/(.*?)\.svelte\.d\.ts/.test(filepath)) { + const svelteFilepath = filepath.replace('.d.ts', ''); let svelteFileContents = await readFile(svelteFilepath, { encoding: 'utf-8' }); - const blockCommentRegex = /\/\*\*[\s\S]*?\*\//; + const blockCommentRegex = /\/\*\*\n\s\*\s(@component\s@name)[\s\S]*?\*\//; const blockCommentMatch = blockCommentRegex.exec(svelteFileContents); if (blockCommentMatch !== null) { @@ -55,26 +45,15 @@ for (const file of files) { const exportClassRegex = /export default class (\w+) extends SvelteComponentTyped<(.*?)> {/; if (exportClassRegex.test(newContents)) { - newContents = newContents.replace(exportClassRegex, `${blockComment}\nexport default class $1 extends SvelteComponentTyped<$2> {`); + newContents = newContents.replace( + exportClassRegex, + `${blockComment}\nexport default class $1 extends SvelteComponentTyped<$2> {` + ); } } } - if(newContents !== contents) { + if (newContents !== contents) { await writeFile(filepath, newContents, { encoding: 'utf-8' }); } } - -function getJSBanner() { - return `/** - * ${BANNER} - */ -\n`; -} - -function getSvelteBanner() { - return ` -\n`; -} diff --git a/packages/lucide-svelte/scripts/exportTemplate.mjs b/packages/lucide-svelte/scripts/exportTemplate.mjs index 131a9c3974..afeff30a36 100644 --- a/packages/lucide-svelte/scripts/exportTemplate.mjs +++ b/packages/lucide-svelte/scripts/exportTemplate.mjs @@ -1,5 +1,6 @@ /* eslint-disable import/no-extraneous-dependencies */ import base64SVG from '@lucide/build-icons/utils/base64SVG.mjs'; +import { getJSBanner } from './license.mjs'; export default ({ iconName, children, componentName, getSvg, deprecated }) => { const svgContents = getSvg(); @@ -7,6 +8,7 @@ export default ({ iconName, children, componentName, getSvg, deprecated }) => { return `\