-
-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: fonts command * handle missing fonts folder Co-authored-by: Igor Randjelovic <rigor789@gmail.com> * handle missing custom fonts Co-authored-by: Igor Randjelovic <rigor789@gmail.com>
- Loading branch information
1 parent
ee6bfb5
commit a6b0e3c
Showing
6 changed files
with
182 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
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) | ||
); | ||
|
||
if (!fontsFolderPath) { | ||
this.$logger.warn("No fonts folder found."); | ||
return; | ||
} | ||
|
||
const files = this.$fs | ||
.readDirectory(fontsFolderPath) | ||
.map((entry) => path.parse(entry)) | ||
.filter((entry) => { | ||
return supportedExtensions.includes(entry.ext); | ||
}); | ||
|
||
if (!files.length) { | ||
this.$logger.warn("No custom fonts found."); | ||
return; | ||
} | ||
|
||
const table: any = createTable(["Font", "CSS Properties"], []); | ||
|
||
for (const file of files) { | ||
const font = await fontFinder.get(fontsFolderPath + "/" + file.base); | ||
table.push([ | ||
file.base, | ||
`font-family: "${font.name}", "${file.name}"; font-weight: ${font.weight};`, | ||
]); | ||
} | ||
|
||
this.$logger.info(table.toString()); | ||
} | ||
} | ||
|
||
injector.registerCommand("fonts", FontsCommand); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.