Skip to content

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:

tsconst iconSet = await importDirectory('files/svg', {
   prefix: 'test',
});

To catch errors, use try and catch:

tslet 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.

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:

Functions to get version number or commit hash from local files:

Functions to get version number or commit hash from remote package/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:

Unlike simple comparison, this function ignores version numbers in package.json, hidden files and different line endings.

Released under the Apache 2.0 License.