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

fix: Change output dir #19

Merged
merged 8 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
5 changes: 3 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,10 @@ jobs:
git push --set-upstream origin ${{steps.branch_name.outputs.BRANCH_NAME}} -f
- name: Check if PR exists
run: echo "pr_exists=$(gh pr list -H ${{steps.branch_name.outputs.BRANCH_NAME}} --json number -q length)" >> $GITHUB_ENV
env:
GITHUB_TOKEN: ${{ github.token }}
- name: Create Pull Request
if: ${{env.pr_exists == 0 && steps.fetch_icons.outputs.files_changed == 'true'}}
run: |
gh pr create -B main -H ${{steps.branch_name.outputs.BRANCH_NAME}} --title "${{steps.title.outputs.TITLE}}" --body 'Created by the Zeta Icons bot'
run: gh pr create -B main -H ${{steps.branch_name.outputs.BRANCH_NAME}} --title "${{steps.title.outputs.TITLE}}" --body 'Created by the Zeta Icons bot'
env:
GITHUB_TOKEN: ${{ github.token }}
87 changes: 87 additions & 0 deletions .github/workflows/copy-content.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: Copy content to other repository

on:
workflow_call:
inputs:
repo:
required: true
type: string
branch:
required: true
type: string
source_dir:
required: true
type: string
destination_dir:
required: true
type: string
commit_msg:
required: true
type: string
secrets:
PAT:
required: true

jobs:
copy_content:
runs-on: ubuntu-latest
steps:
- name: Check if existing tokens branch exists
id: check_branch
env:
GH_TOKEN: ${{ secrets.PAT }}
run: echo "branch_exists=$(gh api repos/${{ inputs.repo }}/branches/${{ inputs.branch }} --jq '.name' | wc -l | xargs)" >> $GITHUB_OUTPUT
- name: Check if open PR exists
id: check_pr
env:
GH_TOKEN: ${{ secrets.PAT }}
run: echo "pr_exists=$(gh pr list -R ${{ inputs.repo }} -H ${{ inputs.branch }} --json number -q length)" >> $GITHUB_OUTPUT
- name: Checkout code
uses: actions/checkout@v4
- name: Pull latest changes
run: git pull
- name: Get current date
id: date
run: echo "date=$(date +%Y-%m-%d)" >> $GITHUB_OUTPUT
- name: Push files if branch exists
uses: dmnemec/copy_file_to_another_repo_action@main
if: ${{ steps.check_branch.outputs.branch_exists != 0 }}
env:
API_TOKEN_GITHUB: ${{ secrets.PAT }}
with:
source_file: ${{ inputs.source_dir }}
destination_repo: ${{ inputs.repo }}
destination_folder: ${{ inputs.destination_dir }}
destination_branch: ${{ inputs.branch }}
user_email: "[email protected]"
user_name: "Zeta Tokens Bot"
commit_message: "deps(automated): ${{inputs.commit_msg}} ${{ steps.date.outputs.date }}"
- name: Push files if branch does not exist
uses: dmnemec/copy_file_to_another_repo_action@main
if: ${{ steps.check_branch.outputs.branch_exists == 0 }}
env:
API_TOKEN_GITHUB: ${{ secrets.PAT }}
with:
source_file: ${{ inputs.source_dir }}
destination_repo: ${{ inputs.repo }}
destination_folder: ${{ inputs.destination_dir }}
destination_branch_create: ${{ inputs.branch }}
user_email: "[email protected]"
user_name: "Zeta Tokens Bot"
commit_message: "deps(automated): ${{inputs.commit_msg}} ${{ steps.date.outputs.date }}"
- name: Open PR
uses: thecanadianroot/[email protected]
if: ${{ steps.check_pr.outputs.pr_exists == 0 }}
with:
token: ${{ secrets.PAT }}
base: main
head: ${{ inputs.branch }}
title: "deps(automated): ${{inputs.commit_msg}}"
labels: tokens
body: "${{inputs.commit_msg}} ${{ steps.date.outputs.date }}"
repository: ${{ inputs.repo }}
- name: Add comment to existing PR
env:
GH_TOKEN: ${{ secrets.PAT }}
if: ${{ steps.check_pr.outputs.pr_exists != 0 }}
run: gh pr comment -R ${{ inputs.repo }} ${{ inputs.branch }} --body "${{inputs.commit_msg}} ${{ steps.date.outputs.date }}"
94 changes: 8 additions & 86 deletions .github/workflows/update_zeta_flutter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,92 +9,14 @@ on:

env:
flutter_branch: update-zeta-icons
flutter_repo: ZebraDevs/zeta_flutter

jobs:
publish_flutter:
runs-on: ubuntu-latest
name: Commit and raise PR in Zeta Flutter
steps:
- name: Check if existing icons branch exists
run: echo "branch_exists=$(git ls-remote --heads https://github.com/${{env.flutter_repo}}.git refs/heads/${{env.flutter_branch}} | wc -l)" >> $GITHUB_ENV
- name: Check if open PR exists
run: echo "pr_exists=$(gh pr list -R ${{env.flutter_repo}} -H ${{env.flutter_branch}} --json number -q length)" >> $GITHUB_ENV
- name: Checkout
uses: actions/checkout@v4
with:
token: ${{ secrets.PAT }}
ref: ${{github.ref_name}}
- name: Get package version
id: package-version
uses: martinbeentjes/[email protected]
- name: Inject version
run: sed -i 's/VERSION_NUM/${{steps.package-version.outputs.current-version}}/g' outputs/definitions/icons.dart
- name: Push dart file to Zeta Flutter (branch exists)
uses: dmnemec/copy_file_to_another_repo_action@main
if: ${{env.branch_exists == 1}}
env:
API_TOKEN_GITHUB: ${{ secrets.PAT }}
with:
#TODO: pass file paths as inputs
source_file: "./outputs/definitions/icons.dart"
destination_repo: "${{env.flutter_repo}}"
destination_folder: "lib/src/assets"
destination_branch: "${{env.flutter_branch}}"
user_email: "[email protected]"
user_name: "zeta-icons-bot"
commit_message: "icons.dart"
- name: Push dart file to Zeta Flutter (branch does not exist)
if: ${{env.branch_exists == 0}}
uses: dmnemec/copy_file_to_another_repo_action@main
env:
API_TOKEN_GITHUB: ${{ secrets.PAT }}
with:
#TODO: pass file paths as inputs
source_file: "./outputs/definitions/icons.dart"
destination_repo: "${{env.flutter_repo}}"
destination_folder: "lib/src/assets"
destination_branch_create: "${{env.flutter_branch}}"
user_email: "[email protected]"
user_name: "zeta-icons-bot"
commit_message: "icons.dart"
- name: Push round icon font file to Zeta Flutter
uses: dmnemec/copy_file_to_another_repo_action@main
env:
API_TOKEN_GITHUB: ${{ secrets.PAT }}
with:
source_file: "./outputs/font/zeta-icons-round.ttf"
destination_repo: "${{env.flutter_repo}}"
destination_folder: "lib/src/assets/fonts"
destination_branch: "${{env.flutter_branch}}"
user_email: "[email protected]"
user_name: "zeta-icons-bot"
commit_message: "rounded font file"
- name: Push sharp icon font file to Zeta Flutter
uses: dmnemec/copy_file_to_another_repo_action@main
env:
API_TOKEN_GITHUB: ${{ secrets.PAT }}
with:
source_file: "./outputs/font/zeta-icons-sharp.ttf"
destination_repo: "${{env.flutter_repo}}"
destination_folder: "lib/src/assets/fonts"
destination_branch: "${{env.flutter_branch}}"
user_email: "[email protected]"
user_name: "zeta-icons-bot"
commit_message: "sharp font file"
- name: Create PR message
run: echo "pr_message=Updating to icons version ${{ steps.package-version.outputs.current-version }}" >> $GITHUB_ENV
- name: Open Zeta Flutter PR
uses: thecanadianroot/[email protected]
if: ${{env.pr_exists == 0}}
with:
token: ${{ secrets.PAT }}
base: main
head: ${{env.flutter_branch}}
title: "deps: Update zeta-icon library"
labels: icons
body: "${{env.pr_message}}"
repository: ${{env.flutter_repo}}
- name: Add comment to existing PR
if: ${{env.pr_exists != 0}}
run: gh pr comment -R ${{env.flutter_repo}} ${{env.flutter_branch}} --body '${{env.pr_message}}'
uses: ./.github/workflows/copy-content.yml
secrets: inherit
with:
repo: ZebraDevs/zeta_flutter
branch: "update-zeta-icons"
source_dir: "./outputs/dart/."
destination_dir: "lib/generated/icons"
commit_msg: "Update icons"
2 changes: 1 addition & 1 deletion outputs/definitions/icons.dart → outputs/dart/icons.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3242,7 +3242,7 @@ abstract class ZetaIcons {
static const IconData zoom_out_sharp = IconData(0xe219, fontFamily: familySharp, fontPackage: package);
}

// List of all rounded icons.
// List of all icons.
const Map<String, IconData> icons = {
'activity': ZetaIcons.activity,
'add_alert': ZetaIcons.add_alert,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
13 changes: 7 additions & 6 deletions scripts/fetchIcons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ import { generateHash } from "./utils/hash.js";
import { ComponentSets } from "./types/figmaTypes.js";
import { generatePNGs } from "./generators/generatePNGs.js";

export const fontDir = "/font";
export const iconsDir = "/icons";
export const definitionsDir = "/definitions";
export const tempDir = "/temp";
export const pngDir = "/png";
export const dartDir = "/dart";
export const tsDir = "/ts";

/**
* Main function to run icons action. For slightly more information, see {@link https://miro.com/app/board/uXjVKUMv1ME=/?share_link_id=952145602435 | Miro }
*
Expand All @@ -35,11 +36,11 @@ export default async function main(
outputDir: string,
verboseLogs: boolean
): Promise<string | undefined> {
const fontOutputDir = outputDir + fontDir;
const iconsOutputDir = outputDir + iconsDir;
const definitionsOutputDir = outputDir + definitionsDir;
const tempOutputDir = outputDir + tempDir;
const pngOutputDir = outputDir + pngDir;
const dartOutputDir = outputDir + dartDir;
const tsOutputDir = outputDir + tsDir;

const response = await getFigmaDocument(figmaFileId, figmaToken);
console.log("✅ - Fetched figma document");
Expand Down Expand Up @@ -79,10 +80,10 @@ export default async function main(
await optimizeSVGs(iconsOutputDir, tempOutputDir, categoryNames);
console.log("✅ - Optimized SVGs");

const generateFontResult = await generateFonts(tempOutputDir, fontOutputDir, "zeta-icons");
const generateFontResult = await generateFonts(tempOutputDir, "zeta-icons", dartOutputDir, tsOutputDir);
console.log("✅ - Generated fonts");

generateDefinitionFiles(outputDir, definitionsOutputDir, generateFontResult, manifest);
generateDefinitionFiles(outputDir, generateFontResult, manifest);
console.log("✅ - Generated definition files.");

generatePNGs(iconsOutputDir, pngOutputDir, categoryNames);
Expand Down
25 changes: 12 additions & 13 deletions scripts/generators/generateDefinitionFiles.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,38 @@
import { createFolder } from "../utils/fileUtils.js";
import { GenerateFontResult, IconManifest } from "../types/customTypes.js";
import { readFileSync, writeFileSync } from "fs";
import { dartDir, tsDir } from "../fetchIcons.js";

/**
* Writes out `icon-manifest.json`, `icons.dart` and `icon-types.ts`.
* Writes out `icon-manifest.json`, `icons.g.dart` and `icon-types.ts`.
*
* @param {String} outputDir - Location of output directory. Icon manifest is saved here.
* @param {String} definitionsOutputDir - Location of definitions output.
* @param {GenerateFontResult} fontData - Object containing body lines for generating definition files.
* @param {IconManifest} manifest - data to be written to `icon-manifest.json`
*/
export const generateDefinitionFiles = (
outputDir: string,
definitionsOutputDir: string,
fontData: GenerateFontResult,
manifest: IconManifest
) => {
createFolder(definitionsOutputDir);
export const generateDefinitionFiles = (outputDir: string, fontData: GenerateFontResult, manifest: IconManifest) => {
const dartOutputDir = outputDir + dartDir;
const tsOutputDir = outputDir + tsDir;

createFolder(dartOutputDir);
createFolder(tsOutputDir);

const dartFile = generateDartFile(fontData);
const tsFile = generateTSFile(fontData);
const iconManifestFile = JSON.stringify(Object.fromEntries(manifest));

writeFileSync(definitionsOutputDir + "/icons.dart", dartFile);
writeFileSync(definitionsOutputDir + "/icon-types.ts", tsFile);
writeFileSync(dartOutputDir + "/icons.g.dart", dartFile);
writeFileSync(tsOutputDir + "/icon-types.ts", tsFile);
writeFileSync(outputDir + "/icon-manifest.json", iconManifestFile);
};

/**
* Builds out contents of `icons.dart`.
* Builds out contents of `icons.g.dart`.
*
* Inserts new icon data into template file: `scripts/src/templates/icons.dart.template`.
*
* @param {GenerateFontResult} fontData - Object containing body lines for generating definition files.
* @returns {string} Content of `icons.dart`.
* @returns {string} Content of `icons.g.dart`.
*/
const generateDartFile = (fontData: GenerateFontResult): string => {
let dartTemplate = readFileSync("./scripts/templates/icons.dart.template").toString();
Expand Down
25 changes: 15 additions & 10 deletions scripts/generators/generateFonts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@ const GITHUB_URL = "https://raw.githubusercontent.com/ZebraDevs/zeta-icons/main/
* as this data needs to link up to unicode values generated in this step.
*
* @param {string} inputDir - Location of temporary directory containing optimized SVG files.
* @param {String} fontOutputDir - Location of font output directory.
* @param {string} fontName - Name of font to be generated.
* @param {string} ttfDir - Location to save TTF font files.
* @param {string} woff2Dir - Location to save WOFF2 font files.
* @returns {Promise<GenerateFontResult>} Object containing body lines for generating definition files.
* @throws If any font file was not generated.
*/
export const generateFonts = async (
inputDir: string,
fontOutputDir: string,
fontName: string
fontName: string,
ttfDir: string,
woff2Dir: string
): Promise<GenerateFontResult> => {
const fontResult: GenerateFontResult = {
dartDefinitions: [],
Expand All @@ -28,13 +31,15 @@ export const generateFonts = async (
iconNames: [],
};

const baseFontPath = `${fontOutputDir}/${fontName}`;
createFolder(fontOutputDir);
const ttfPath = `${ttfDir}/${fontName}`;
const woff2Path = `${woff2Dir}/${fontName}`;
createFolder(ttfDir);
createFolder(woff2Dir);
const roundFonts = await buildFontFile("round", fontResult, inputDir);

if (roundFonts.ttf && roundFonts.woff2) {
writeFileSync(`${baseFontPath}-round.ttf`, roundFonts.ttf);
writeFileSync(`${baseFontPath}-round.woff2`, roundFonts.woff2);
writeFileSync(`${ttfPath}-round.ttf`, roundFonts.ttf);
writeFileSync(`${woff2Path}-round.woff2`, roundFonts.woff2);
} else {
throw new Error(
"Failed to build round fonts: " + (!roundFonts.ttf ? "ttf " : "") + !roundFonts.woff2 ? "woff2" : ""
Expand All @@ -43,8 +48,8 @@ export const generateFonts = async (

const sharpFonts = await buildFontFile("sharp", fontResult, inputDir);
if (sharpFonts.ttf && sharpFonts.woff2) {
writeFileSync(`${baseFontPath}-sharp.ttf`, sharpFonts.ttf);
writeFileSync(`${baseFontPath}-sharp.woff2`, sharpFonts.woff2);
writeFileSync(`${ttfPath}-sharp.ttf`, sharpFonts.ttf);
writeFileSync(`${woff2Path}-sharp.woff2`, sharpFonts.woff2);
} else {
throw new Error(
"Failed to build sharp fonts: " + (!sharpFonts.ttf ? "ttf " : "") + !sharpFonts.woff2 ? "woff2" : ""
Expand Down Expand Up @@ -104,7 +109,7 @@ const buildFontFile = async (type: FontType, fontResult: GenerateFontResult, inp
* @param {string} iconName - snake_case formatted name for icon.
* @param {string} unicode - Unicode value to link icon to font.
* @param {FontType} type - Round or sharp.
* @returns {string} Dart definition line used in body of `Icons.dart`.
* @returns {string} Dart definition line used in body of `icons.g.dart`.
*/
function getDartIconDefinition(iconName: string, unicode: string, type: FontType | undefined): string {
const iconPreview = getIconPreview(iconName, type);
Expand Down
11 changes: 10 additions & 1 deletion scripts/templates/icons.dart.template
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,22 @@ import 'package:flutter/material.dart';
// This file is automatically generated by the zeta-icons repository
// DO NOT MODIFY

/// Current version of Zeta Icons
const zetaIconsVersion = 'VERSION_NUM';

/// Zeta Icons. Full list of icons can be found at [Zeta Icons](https://zeta-icons.web.app/).
/// {@category Assets}
abstract class ZetaIcons {
/// Default icon font name
static const String family = 'zeta-icons';

/// Icon font name for round icons
static const String familyRound = 'zeta-icons-round';

/// Icon font name for sharp icons
static const String familySharp = 'zeta-icons-sharp';

/// Package name for zeta flutter
static const String package = 'zeta_flutter';

// Icons
Expand All @@ -23,7 +32,7 @@ abstract class ZetaIcons {
{{sharpIcons}}
}

// List of all rounded icons.
// List of all icons.
const Map<String, IconData> icons = {
{{iconNames}}
};
2 changes: 1 addition & 1 deletion test/data/categoryNodes.json

Large diffs are not rendered by default.

Loading