Skip to content

Commit

Permalink
refactor: Change icons.dart to icons.g.dart
Browse files Browse the repository at this point in the history
docs: Add comments to icons.g.dart
  • Loading branch information
thelukewalton committed Aug 19, 2024
1 parent 7b155b7 commit c70365a
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/update_zeta_flutter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ env:
flutter_branch: update-zeta-icons

jobs:
publish_flutter: #TODO: Rename this to deploy, I think that is a better name
publish_flutter:
uses: ./.github/workflows/copy-content.yml
secrets: inherit
with:
Expand Down
8 changes: 4 additions & 4 deletions scripts/generators/generateDefinitionFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ 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 {GenerateFontResult} fontData - Object containing body lines for generating definition files.
Expand All @@ -21,18 +21,18 @@ export const generateDefinitionFiles = (outputDir: string, fontData: GenerateFon
const tsFile = generateTSFile(fontData);
const iconManifestFile = JSON.stringify(Object.fromEntries(manifest));

writeFileSync(dartOutputDir + "/icons.dart", dartFile);
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
2 changes: 1 addition & 1 deletion scripts/generators/generateFonts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,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
9 changes: 9 additions & 0 deletions 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 Down
2 changes: 1 addition & 1 deletion test/integration/fetchIcons.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe("fetchIcons", () => {
});

it("should write definition files", () => {
assert.equal(existsSync(`${zdsIntegrationOutputDir}/${testDartOutputDir}/icons.dart`), true);
assert.equal(existsSync(`${zdsIntegrationOutputDir}/${testDartOutputDir}/icons.g.dart`), true);
assert.equal(existsSync(`${zdsIntegrationOutputDir}/${testTSOutputDir}/icon-types.ts`), true);
});
});
2 changes: 1 addition & 1 deletion test/integration/generateDefinitionFiles.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe("generateDefinitionFiles", () => {
});

it("should write definition files", () => {
assert.equal(existsSync(`${testDartOutputDir}/icons.dart`), true);
assert.equal(existsSync(`${testDartOutputDir}/icons.g.dart`), true);
assert.equal(existsSync(`${testTSOutputDir}/icon-types.ts`), true);
});

Expand Down

0 comments on commit c70365a

Please sign in to comment.