Skip to content

Commit

Permalink
refactor: correct prepare icons (#8534)
Browse files Browse the repository at this point in the history
  • Loading branch information
splincode authored Aug 14, 2024
1 parent 8b00807 commit afef958
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 77 deletions.
9 changes: 4 additions & 5 deletions .github/workflows/auto-update-icons.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ jobs:
- uses: taiga-family/ci/actions/setup/[email protected]
- uses: taiga-family/ci/actions/setup/[email protected]
- uses: taiga-family/ci/actions/setup/[email protected]
- name: Copy flags from design tokens icons
run: |
rm -rf ./projects/icons/src/flags && mkdir -p ./projects/icons/src/flags
cp -R ./node_modules/@taiga-ui/design-tokens/icons/flags/* ./projects/icons/src/flags
npx prettier ./projects/icons/src/flags --write
- name: Lucide icons
run: |
npx nx prebuild icons
Expand All @@ -24,6 +19,10 @@ jobs:
run: |
npx nx prebuild icons-material
npx nx build icons-material
- name: FontAwesome icons
run: |
npx nx prebuild icons-fontawesome
npx nx build icons-fontawesome
- run: |
npx ts-node ./scripts/generate-used-icons.ts
npx eslint ./projects/cdk/constants/used-icons.ts --fix || echo "no file matching"
Expand Down
2 changes: 1 addition & 1 deletion projects/icons-fontawesome/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"parallel": false,
"commands": [
"ts-node ./{projectRoot}/scripts/prepare-icons.ts",
"prettier ./{projectRoot}/src/* --write"
"prettier ./{projectRoot}/src/* --write --log-level silent"
]
}
},
Expand Down
43 changes: 10 additions & 33 deletions projects/icons-fontawesome/scripts/prepare-icons.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
/// <reference lib="es2021" />
import fs from 'node:fs';
import path from 'node:path';

import {PAYMENTS_ICONS} from '../../../scripts/custom-icons';
import {tuiIsCI} from '../../cdk/schematics';

const verbose = !tuiIsCI();

(function main(): void {
const dest =
process.argv[2] ||
Expand Down Expand Up @@ -32,7 +38,7 @@ import path from 'node:path';
fs.mkdirSync(path.dirname(filePath), {recursive: true});
fs.writeFileSync(filePath, content);

console.info('copied:', filePath);
verbose && console.info('copied:', filePath);
});
});

Expand All @@ -47,47 +53,18 @@ import path from 'node:path';
fs.mkdirSync(path.dirname(filePath), {recursive: true});
fs.writeFileSync(filePath, content);

console.info('copied:', filePath);
verbose && console.info('copied:', filePath);
});

// 3. copy payment icons
[
'electron-mono',
'maestro-mono',
'mastercard-mono',
'mir-mono',
'visa-mono',
'electron',
'cirrus',
'maestro',
'mastercard',
'mir',
'visa',
'union-pay',
'jcb',
'pay-pal',
'amex',
'diners-club',
'discover',
'humo',
'ru-pay',
'uzcard',
'verve',
'apple-pay',
'google-pay',
'samsung-pay',
'world-pay',
'ali-pay',
'amazon-pay',
'android-pay',
].forEach((filename) => {
PAYMENTS_ICONS.forEach((filename) => {
const filePath = path.join('projects/icons/src', `${filename}.svg`);

fs.writeFileSync(
path.join(dest, `${filename}.svg`),
fs.readFileSync(path.join(filePath), 'utf-8'),
);

console.info('copied:', filePath);
verbose && console.info('copied:', filePath);
});
})();
2 changes: 1 addition & 1 deletion projects/icons-material/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"parallel": false,
"commands": [
"ts-node ./{projectRoot}/scripts/prepare-icons.ts",
"prettier ./{projectRoot}/src/* --write"
"prettier ./{projectRoot}/src/* --write --log-level silent"
]
}
},
Expand Down
43 changes: 10 additions & 33 deletions projects/icons-material/scripts/prepare-icons.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
/// <reference lib="es2021" />
import fs from 'node:fs';
import path from 'node:path';

import {PAYMENTS_ICONS} from '../../../scripts/custom-icons';
import {tuiIsCI} from '../../cdk/schematics';

const verbose = !tuiIsCI();

(function main(): void {
const dest =
process.argv[2] || path.join(process.cwd(), 'projects', 'icons-material', 'src');
Expand Down Expand Up @@ -29,7 +35,7 @@ import path from 'node:path';
fs.mkdirSync(path.dirname(filePath), {recursive: true});
fs.writeFileSync(filePath, content);

console.info('copied:', filePath);
verbose && console.info('copied:', filePath);
});
});

Expand All @@ -43,47 +49,18 @@ import path from 'node:path';
fs.mkdirSync(path.dirname(filePath), {recursive: true});
fs.writeFileSync(filePath, content);

console.info('copied:', filePath);
verbose && console.info('copied:', filePath);
});

// 3. copy payment icons
[
'electron-mono',
'maestro-mono',
'mastercard-mono',
'mir-mono',
'visa-mono',
'electron',
'cirrus',
'maestro',
'mastercard',
'mir',
'visa',
'union-pay',
'jcb',
'pay-pal',
'amex',
'diners-club',
'discover',
'humo',
'ru-pay',
'uzcard',
'verve',
'apple-pay',
'google-pay',
'samsung-pay',
'world-pay',
'ali-pay',
'amazon-pay',
'android-pay',
].forEach((filename) => {
PAYMENTS_ICONS.forEach((filename) => {
const filePath = path.join('projects/icons/src', `${filename}.svg`);

fs.writeFileSync(
path.join(dest, `${filename}.svg`),
fs.readFileSync(path.join(filePath), 'utf-8'),
);

console.info('copied:', filePath);
verbose && console.info('copied:', filePath);
});
})();
2 changes: 1 addition & 1 deletion projects/icons/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"parallel": false,
"commands": [
"ts-node ./{projectRoot}/scripts/prepare-icons.ts",
"npx prettier ./{projectRoot}/src/* --write"
"prettier ./{projectRoot}/src/* --write --log-level silent"
]
}
},
Expand Down
29 changes: 26 additions & 3 deletions projects/icons/scripts/prepare-icons.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,46 @@
/// <reference lib="es2021" />
import fs from 'node:fs';
import path from 'node:path';

import {tuiIsCI} from '../../cdk/schematics';

const verbose = !tuiIsCI();

(function main(): void {
const src = path.join(process.cwd(), 'node_modules', 'lucide-static', 'icons');
const dest = process.argv[2] || path.join(process.cwd(), 'projects', 'icons', 'src');

fs.readdirSync(src).forEach((filename: string) => {
const filledFilename = renameToFilled(filename);
const content = fs
.readFileSync(path.join(src, filename), 'utf-8')
.replace(/class="[a-zA-Z0-9:;.\s()\-,]*"/, '')
.replaceAll(
/<(circle|ellipse|line|polygon|polyline|path|rect)/g,
'<$1 vector-effect="non-scaling-stroke"',
);

const filled = content.replaceAll('fill="none"', 'fill="currentColor"');
const filePath = path.join(dest, filename);
const fileFilledPath = path.join(dest, filledFilename);

fs.writeFileSync(filePath, content);
verbose && console.info('copied:', filePath);

fs.writeFileSync(fileFilledPath, filled);
verbose && console.info('copied:', fileFilledPath);
});

// 2. copy flags from design tokens
// noinspection DuplicatedCode
const flagsDir = path.resolve('node_modules/@taiga-ui/design-tokens/icons/flags');

fs.readdirSync(flagsDir).forEach((filename: string) => {
const content = fs.readFileSync(path.join(flagsDir, filename), 'utf-8');
const filePath = path.join(dest, 'flags', filename);

fs.writeFileSync(path.join(dest, filename), content);
fs.writeFileSync(path.join(dest, renameToFilled(filename)), filled);
fs.mkdirSync(path.dirname(filePath), {recursive: true});
fs.writeFileSync(filePath, content);
verbose && console.info('copied:', filePath);
});
})();

Expand Down
30 changes: 30 additions & 0 deletions scripts/custom-icons.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
export const PAYMENTS_ICONS = [
'electron-mono',
'maestro-mono',
'mastercard-mono',
'mir-mono',
'visa-mono',
'electron',
'cirrus',
'maestro',
'mastercard',
'mir',
'visa',
'union-pay',
'jcb',
'pay-pal',
'amex',
'diners-club',
'discover',
'humo',
'ru-pay',
'uzcard',
'verve',
'apple-pay',
'google-pay',
'samsung-pay',
'world-pay',
'ali-pay',
'amazon-pay',
'android-pay',
] as const;

0 comments on commit afef958

Please sign in to comment.