Managing packages
Iconify Tools has several functions to help automate downloading, comparing and updating packages.
Async
Most functions listed below are asynchronous.
If you are not familiar with asynchronous functions in JavaScript, read up on Promise class, async and await keywords.
The simplest way to use asynchronous functions is to wrap all your code in anonymous asynchronous function, then await functions:
const iconSet = await importDirectory('files/svg', {
prefix: 'test',
});
To catch errors, use try and catch:
let iconSet: IconSet;
try {
iconSet = await importDirectory('files/svg', {
prefix: 'test',
});
} catch (err) {
console.error(`Failed to import directory:`, err);
return;
}
Check out various tutorials for async and await. There are many free good tutorials on YouTube.
Downloading packages
These functions download packages from various sources.
Functions can be used to download source for icon sets, which can be imported using importDirectory() function.
Functions can also be used to compare exported data with previously published data, then publish new version if package was changed.
- downloadGitRepo() creates a shallow clone of Git repository.
- downloadGitHubRepo() downloads a GitHub repository using GitHub API. It is similar to downloadGitRepo(), but uses API instead of Git client.
- downloadGitLabRepo() downloads a GitLab repository using GitLab API. It is similar to downloadGitRepo(), but uses API instead of Git client.
- downloadNPMPackage() downloads NPM package from registry.
Additionally, there are few functions to download files by URL:
- sendAPIQuery() is a wrapper for fetch with support for cache. It is used by functions like importFromFigma().
- downloadFile() is also a wrapper for fetch that simplifies downloading of binary files, such as archives. It is used by GitHub, GitLab and NPM downloaders.
Versions
When publishing packages, you might want to change package version. Iconify Tools offers several functions to help you automate process:
- bumpVersion() increases version number.
Functions to get version number or commit hash from local files:
- getPackageVersion() retrieves version number from package.json.
- getGitRepoHash() retrieves hash of local git repository.
Functions to get version number or commit hash from remote package/repository:
- getNPMVersion() retrieves latest version of package from NPM registry.
- getGitHubRepoHash() retrieves hash of last commit from remote GitHub repository.
- getGitLabRepoHash() retrieves hash of last commit from remote GitLab repository.
Comparing directories
When automating build process, publishing new package when nothing was changed makes no sense. There is a function in Iconify Tools to check for changes:
- compareDirectories() compares contents of two directories.
Unlike simple comparison, this function ignores version numbers in package.json, hidden files and different line endings.