Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve license notice in packages #1657

Merged
merged 6 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/lucide-preact.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
paths:
- packages/lucide-preact/**
- tools/build-icons/**
- tools/rollup-plugins/**
- pnpm-lock.yaml

jobs:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/lucide-react-native.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
paths:
- packages/lucide-react-native/**
- tools/build-icons/**
- tools/rollup-plugins/**
- pnpm-lock.yaml

jobs:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/lucide-react.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
paths:
- packages/lucide-react/**
- tools/build-icons/**
- tools/rollup-plugins/**
- scripts/generateNextJSAliases.mjs
- pnpm-lock.yaml

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/lucide-solid.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
paths:
- packages/lucide-solid/**
- tools/build-icons/**
- tools/rollup-plugins/**
- pnpm-lock.yaml

jobs:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/lucide-svelte.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
paths:
- packages/lucide-svelte/**
- tools/build-icons/**
- tools/rollup-plugins/**
- pnpm-lock.yaml

jobs:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/lucide-vue-next.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
paths:
- packages/lucide-vue-next/**
- tools/build-icons/**
- tools/rollup-plugins/**
- pnpm-lock.yaml

jobs:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/lucide-vue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
paths:
- packages/lucide-vue/**
- tools/build-icons/**
- tools/rollup-plugins/**
- pnpm-lock.yaml

jobs:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/lucide.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
paths:
- packages/lucide/**
- tools/build-icons/**
- tools/rollup-plugins/**
- pnpm-lock.yaml

jobs:
Expand Down
3 changes: 1 addition & 2 deletions packages/lucide-static/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@
],
"main": "lib/index.js",
"scripts": {
"copy:icons": "cp -r ../../icons icons",
"copy:license": "cp ../../LICENSE ./LICENSE",
"build:tags": "node ../../scripts/migrateIconsToTags.mjs",
"build": "pnpm clean && pnpm copy:license && pnpm copy:icons && pnpm build:lib && pnpm build:tags",
"build": "pnpm clean && pnpm copy:license && pnpm build:lib && pnpm build:tags",
"build:lib": "node ./scripts/buildLib.mjs",
"clean": "rm -rf lib && rm -rf build && rm -rf icons && rm -f sprite.svg",
"version": "pnpm version --git-tag-version=false"
Expand Down
27 changes: 21 additions & 6 deletions packages/lucide-static/scripts/buildLib.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,51 @@ import path from 'path';
import getArgumentOptions from 'minimist';
import { parseSync } from 'svgson';

import { appendFile, readSvgDirectory, toCamelCase, getCurrentDirPath } from '../../../scripts/helpers.mjs';
import {
appendFile,
readSvgDirectory,
toCamelCase,
getCurrentDirPath,
} from '../../../scripts/helpers.mjs';
import readSvgs from './readSvgs.mjs';
import generateSprite from './generateSprite.mjs';
import generateIconNodes from './generateIconNodes.mjs';
import copyIcons from './copyIcons.mjs';

import pkg from '../package.json' assert { type: 'json' };

const cliArguments = getArgumentOptions(process.argv.slice(2));
const createDirectory = dir => {
const createDirectory = (dir) => {
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir);
}
};

const currentDir = getCurrentDirPath(import.meta.url)
const currentDir = getCurrentDirPath(import.meta.url);

const PACKAGE_DIR = path.resolve(currentDir, '../');
const ICONS_DIR = path.join(PACKAGE_DIR, 'icons');
const ICONS_DIR = path.join(PACKAGE_DIR, '../../icons');
const LIB_DIR = path.join(PACKAGE_DIR, cliArguments.output || 'lib');
const ICON_MODULE_DIR = path.join(LIB_DIR, 'icons');

const license = `@license ${pkg.name} v${pkg.version} - ${pkg.license}`;

createDirectory(LIB_DIR);
createDirectory(ICON_MODULE_DIR);

const svgFiles = readSvgDirectory(ICONS_DIR);
const svgs = readSvgs(svgFiles, ICONS_DIR);

const jsLicense = `/**\n * ${license}\n */\n`;

appendFile(jsLicense, `index.js`, LIB_DIR);

svgs.forEach(({ name, contents }) => {
const componentName = toCamelCase(name);
const importString = `module.exports.${componentName} = require('./icons/${name}');\n`;
appendFile(importString, `index.js`, LIB_DIR);

const exportString = `module.exports = \`${contents}\`;\n`;
const exportString = `${jsLicense}module.exports = \`${contents}\`;\n`;
appendFile(exportString, `${name}.js`, ICON_MODULE_DIR);
});

Expand All @@ -44,5 +58,6 @@ const parsedSvgs = svgs.map(({ name, contents }) => ({
parsedSvg: parseSync(contents),
}));

generateSprite(parsedSvgs, PACKAGE_DIR);
generateSprite(parsedSvgs, PACKAGE_DIR, license);
generateIconNodes(parsedSvgs, PACKAGE_DIR);
copyIcons(parsedSvgs, PACKAGE_DIR, license);
22 changes: 22 additions & 0 deletions packages/lucide-static/scripts/copyIcons.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { writeFile } from 'fs/promises';
import { existsSync, unlinkSync, mkdirSync } from 'fs';

export default async function copyIcons(parsedSvgs, packageDir, license) {
const iconsDirectory = `${packageDir}/icons`;

if (existsSync(iconsDirectory)) {
unlinkSync(iconsDirectory);
}

if (!existsSync(iconsDirectory)) {
mkdirSync(iconsDirectory);
}
// eslint-disable-next-line arrow-body-style
const writeIconPromises = parsedSvgs.map(({ name, contents }) => {
const content = `<!-- ${license} -->\n${contents}`;

return writeFile(`${iconsDirectory}/${name}.svg`, content);
});

await Promise.all(writeIconPromises);
}
4 changes: 2 additions & 2 deletions packages/lucide-static/scripts/generateSprite.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { stringify } from 'svgson';
import { format } from 'prettier';
import { appendFile } from '../../../scripts/helpers.mjs';

export default function generateSprite(svgs, packageDir) {
export default function generateSprite(svgs, packageDir, license) {
const symbols = svgs.map(({ name, parsedSvg }) => ({
name: 'symbol',
type: 'element',
Expand Down Expand Up @@ -32,7 +32,7 @@ export default function generateSprite(svgs, packageDir) {
const spriteSvg = stringify(spriteSvgObject);
const prettifiedSprite = format(spriteSvg, { parser: 'babel' }).replace(/;/g, '');

const xmlMeta = `<?xml version="1.0" encoding="utf-8"?>\n`;
const xmlMeta = `<?xml version="1.0" encoding="utf-8"?>\n<!-- ${license} -->\n`;

appendFile(xmlMeta, `sprite.svg`, packageDir);
appendFile(prettifiedSprite, `sprite.svg`, packageDir);
Expand Down
5 changes: 3 additions & 2 deletions packages/lucide-static/scripts/readSvgs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import { readSvg } from '../../../scripts/helpers.mjs';
* @param {Function} getSvg - A function that returns the contents of an SVG file given a filename.
* @returns {Object}
*/
export default (svgFiles, iconsDirectory) =>
svgFiles.map(svgFile => {
export default function readSVGs(svgFiles, iconsDirectory) {
return svgFiles.map((svgFile) => {
const name = basename(svgFile, '.svg');
const contents = readSvg(svgFile, iconsDirectory);

return { name, contents };
});
}
Loading