fabiospampinato / icon-font-buildr

Build custom icon fonts, it supports remote and local icons sources.
MIT License
55 stars 5 forks source link

Build font with API example #4

Closed tijmenvangurp closed 5 years ago

tijmenvangurp commented 5 years ago

Hey, first of all, nice work on the script. This is the only one that I found that supports ligatures nicely.

The command line works, but on you API example from the readme file I get a few warnings that I cannot easily resolve myself.

SyntaxError: await is only valid in async function

Would it be possible for you to add an API example to the repo?

fabiospampinato commented 5 years ago

I'll try to improve upon our current example. Unfortunately I'm not using the API in any project that I can link to.

Your specific error is about the await keyword, which is used at the "top level", and not inside an async function. This isn't supported by your Node.js version (I'm not sure if any version of Node supports this yet, but there's a stage-2 proposal about this) so you're getting an error.

tijmenvangurp commented 5 years ago

Changed it to

async function asyncCall() {
    console.log('calling');
    var result = await  builder.build()
    console.log('done')
    const codepoints = builder.getIconsCodepoints (); // Get a map of icon names to codepoints, useful for generating HTML/CSS/SCSS etc.

    console.log(codepoints);
  }

  asyncCall();

Getting error now (node:48079) UnhandledPromiseRejectionWarning: TypeError: this.config.icons.reduce is not a function

using node v10.15.3

tijmenvangurp commented 5 years ago

One of the reasons why I want to use the API is to create css file for development with css classes and their codepoints. Was hoping I could use the getIconsCodePoints for this.

fabiospampinato commented 5 years ago

I'll make sure the example in the readme actually works. In the meantime you can check the code used for testing here: https://github.com/fabiospampinato/icon-font-buildr/blob/master/test/index.js

tijmenvangurp commented 5 years ago

console.log(builder.config.icons);

Returns

{ backup:
   { icon: 'backup',
     name: 'backup',
     codepoints: [ '' ],
     ligatures: [ 'backup' ] },
  bug_report:
   { icon: 'bug_report',
     name: 'bug_report',
     codepoints: [ '' ],
     ligatures: [ 'bug_report' ] },
  amazon:
   { icon: 'amazon',
     name: 'amazon',
     codepoints: [ '' ],
     ligatures: [ 'amazon' ] },
  'android-debug-bridge':
   { icon: 'android-debug-bridge',
     name: 'android debug icon',
     codepoints: [ '', '' ],
     ligatures: [ 'debug', 'debug_alt' ] } }

how is builder.getIconsCodepoints(); different from this object?

tijmenvangurp commented 5 years ago

Not pritty but this works to create codepoint overview. Only need to write it to a scss file.

async function asyncCall() {
    console.log('starting to compile');
    var result = await builder.build();
    console.log('done!');
    // const codepoints = builder.getIconsCodepoints(); // Get a map of icon names to codepoints, useful for generating HTML/CSS/SCSS etc.
    console.log(builder.config.output.icons);

    for (const iconName in builder.config.icons) {
        if (builder.config.icons.hasOwnProperty(iconName)) {
            const iconObject = builder.config.icons[iconName];
            console.log(iconName);
            for (let i = 0; i < iconObject.codepoints.length; i++) {
                const element = iconObject.codepoints[i];
                console.log(element.charCodeAt(0).toString(16));

            }
        }
    }
}

asyncCall();

output:

backup
e000
bug_report
e001
amazon
e002
android-debug-bridge
e042
e064
fabiospampinato commented 5 years ago

I've fixed the issues in v1.3.3.

how is builder.getIconsCodepoints(); different from this object?

It returns this:

{ 
  backup: [ '' ],
  bug_report: [ '' ],
  amazon: [ '' ],
  'android-debug-bridge': [ '', '' ] 
}

Or hex values for those codepoints if it's called like this: getIconsCodepoints ( true );. It provides a stable API that doesn't rely on the internals of the library.