Color and glyphs are not available
PSalant726 opened this issue · 3 comments
PSalant726 commented
When attempting to set the color and glyph of a shortcut icon, a TypeError
is thrown:
const fs = require('fs');
const { buildShortcut } = require('@joshfarrant/shortcuts-js');
const { COLORS, GLYPHS } = require('@joshfarrant/shortcuts-js/meta');
const actions = [];
const shortcut = buildShortcut(actions, 'My New Shortcut', {
icon: {
color: COLORS.GRAY,
glyph: GLYPHS.ROCKET
}
});
fs.writeFile('myNewShortcut.shortcut', shortcut, err => {
if (err) {
console.error(err);
return;
}
console.log('Shortcut created successfully!');
});
$ node myNewShortcut.js
/myNewShortcut.js:14
color: COLORS.GRAY,
^
TypeError: Cannot read property 'GRAY' of undefined
at Object.<anonymous> (/myNewShortcut.js:14:19)
at Module._compile (internal/modules/cjs/loader.js:816:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:827:10)
at Module.load (internal/modules/cjs/loader.js:685:32)
at Function.Module._load (internal/modules/cjs/loader.js:620:12)
at Function.Module.runMain (internal/modules/cjs/loader.js:877:12)
at internal/main/run_main_module.js:21:11
joshfarrant commented
Hi @PSalant726. I’m on mobile at the moment so I can’t test this, but it appears that the issue is caused by importing COLORS
and GLYPHS
, neither of which are directly exported from /meta
.
An ICON
object is exported (as a named export) from /meta
, which itself has the COLORS
and GLYPHS
properties.
So, to fix this, try changing your import to:
const { ICON } = require(‘@joshfarrant/shortcuts-js/meta’);
const { COLORS, GLYPHS } = ICON;
Hopefully that will work for you!
PSalant726 commented
Thank you! FYI - this documentation is what misled me.
joshfarrant commented
Thank you, I guessed there would be some incorrect documentation somewhere!
Sorry about that, I’ll get that fixed 👍