Skip to content

Commit

Permalink
Improved opacity feature
Browse files Browse the repository at this point in the history
  • Loading branch information
PKief committed May 25, 2018
1 parent 6dcdac1 commit cffaeea
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/icons/generator/iconOpacity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ const getSVGRootElement = (svg: string) => {
* @param opacity Opacity value.
*/
const addOpacityAttribute = (svgRoot: string, opacity: string) => {
const pattern = new RegExp(/opacity="[\d.]+"/);
const pattern = new RegExp(/\sopacity="[\d.]+"/);
// if the opacity attribute already exists
if (pattern.test(svgRoot)) {
return svgRoot.replace(pattern, `opacity="${opacity}"`);
return svgRoot.replace(pattern, ` opacity="${opacity}"`);
} else {
return svgRoot.replace(/^<svg/, `<svg opacity="${opacity}"`);
}
Expand Down
21 changes: 10 additions & 11 deletions src/icons/generator/jsonGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,29 @@ export const generateIconConfigurationObject = (options: IconJsonOptions): IconC
/**
* Create the JSON file that is responsible for the icons in the editor.
*/
export const createIconFile = (jsonOptions?: IconJsonOptions): Promise<string> => {
export const createIconFile = async (jsonOptions?: IconJsonOptions) => {
// override the default options with the new options
const options = merge({}, getDefaultIconOptions(), jsonOptions);

const iconJSONPath = path.join(__dirname, '../../../', 'src', iconJsonName);
const json = generateIconConfigurationObject(options);

return new Promise((resolve, reject) => {
fs.writeFile(iconJSONPath, JSON.stringify(json, undefined, 2), (err) => {
try {
fs.writeFile(iconJSONPath, JSON.stringify(json, undefined, 2), async (err) => {
if (err) {
reject(err);
throw Error(err.message);
}
const promises = [];
if (options.folders.color) {
promises.push(generateFolderIcons(options.folders.color));
await generateFolderIcons(options.folders.color);
}
if (options.opacity) {
promises.push(setIconOpacity(options.opacity));
await setIconOpacity(options.opacity);
}
Promise.all(promises).catch(e => reject(e)).then(() => {
resolve(iconJsonName);
});
});
});
} catch (error) {
throw Error(error);
}
return iconJsonName;
};

/**
Expand Down

0 comments on commit cffaeea

Please sign in to comment.