Skip to content

Commit

Permalink
fix: Add the license banner inside of the script tag instead of an HT…
Browse files Browse the repository at this point in the history
…ML comment (#1811)

* add banner inside of the script tag instead

* renamed script

* Update packages/lucide-svelte/scripts/license.mjs

Co-authored-by: Jakob Guddas <github@jguddas.de>

* Update packages/lucide-svelte/scripts/appendLicense.mjs

Co-authored-by: Eric Fennis <eric.fennis@gmail.com>

* renamed file

---------

Co-authored-by: Jakob Guddas <github@jguddas.de>
Co-authored-by: Eric Fennis <eric.fennis@gmail.com>
  • Loading branch information
3 people committed Jan 29, 2024
1 parent 3302870 commit 54c8d40
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 32 deletions.
2 changes: 1 addition & 1 deletion packages/lucide-svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -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) {
Expand All @@ -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 `<!--
${BANNER}
-->
\n`;
}
2 changes: 2 additions & 0 deletions packages/lucide-svelte/scripts/exportTemplate.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
/* 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();
const svgBase64 = base64SVG(svgContents);

return `\
<script lang="ts">
${getJSBanner()}
import Icon from '../Icon.svelte';
import type { IconNode, IconProps } from '../types.js';
Expand Down
11 changes: 11 additions & 0 deletions packages/lucide-svelte/scripts/license.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import pkg from '../package.json' assert { type: 'json' };

export function getJSBanner() {
return `/**
* @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.
*/
`;
}

0 comments on commit 54c8d40

Please sign in to comment.