Skip to content

feat: fonts command #5452

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

Merged
merged 3 commits into from
Dec 29, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 lib/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ injector.requireCommand("preview", "./commands/preview");

injector.requireCommand("debug|ios", "./commands/debug");
injector.requireCommand("debug|android", "./commands/debug");
injector.requireCommand("fonts", "./commands/fonts");

injector.requireCommand("prepare", "./commands/prepare");
injector.requireCommand("build|ios", "./commands/build");
Expand Down
58 changes: 58 additions & 0 deletions lib/commands/fonts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { IProjectConfigService, IProjectData } from "../definitions/project";
import { ICommand, ICommandParameter } from "../common/definitions/commands";
import { injector } from "../common/yok";
import { IFileSystem } from "../common/declarations";
import * as constants from "../constants";
import * as fontFinder from "font-finder";
import { createTable } from "../common/helpers";
import * as path from "path";

export class FontsCommand implements ICommand {
public allowedParameters: ICommandParameter[] = [];

constructor(
private $projectData: IProjectData,
private $fs: IFileSystem,
private $logger: ILogger,
private $projectConfigService: IProjectConfigService
) {
this.$projectData.initializeProjectData();
}

public async execute(args: string[]): Promise<void> {
const supportedExtensions = [".ttf", ".otf"];

const defaultFontsFolderPaths = [
path.join(
this.$projectConfigService.getValue("appPath") ?? "",
constants.FONTS_DIR
),
path.join(constants.APP_FOLDER_NAME, constants.FONTS_DIR),
path.join(constants.SRC_DIR, constants.FONTS_DIR),
].map((entry) => path.resolve(this.$projectData.projectDir, entry));

const fontsFolderPath = defaultFontsFolderPaths.find((entry) =>
this.$fs.exists(entry)
);

const table: any = createTable(["Font", "CSS Properties"], []);

for (const entry of this.$fs.readDirectory(fontsFolderPath)) {
const file = path.parse(entry);

if (!supportedExtensions.includes(file.ext)) {
continue;
}

const font = await fontFinder.get(fontsFolderPath + "/" + entry);
table.push([
entry,
`font-family: "${font.name}", "${file.name}"; font-weight: ${font.weight};`,
]);
}

this.$logger.info(table.toString());
}
}

injector.registerCommand("fonts", FontsCommand);
1 change: 1 addition & 0 deletions lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const AWAIT_NOTIFICATION_TIMEOUT_SECONDS = 9;
export const SRC_DIR = "src";
export const MAIN_DIR = "main";
export const ASSETS_DIR = "assets";
export const FONTS_DIR = "fonts";
export const ANDROID_ANALYTICS_DATA_DIR = "analytics";
export const ANDROID_ANALYTICS_DATA_FILE = "build-statistics.json";
export const MANIFEST_FILE_NAME = "AndroidManifest.xml";
Expand Down
19 changes: 19 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"detect-newline": "3.1.0",
"email-validator": "2.0.4",
"esprima": "4.0.1",
"font-finder": "1.1.0",
"glob": "7.1.6",
"ios-device-lib": "0.8.0-rc.1",
"ios-mobileprovision-finder": "1.0.11",
Expand Down
Loading