-
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(converting): add new convertion option to convert svg-icons to o…
…bjects
- Loading branch information
Showing
8 changed files
with
227 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,34 @@ | ||
#!/usr/bin/env node | ||
import { convertToSingleFile } from '../lib/converters/single-file.converter'; | ||
import { convertToMultipleFiles } from '../lib/converters/multiple-files.converter'; | ||
import { getOptions, MultiFileConvertionOptions, SingleFileConvertionOptions } from '../lib/options/convertion-options'; | ||
import { printLogo } from '../lib/helpers/log-helper'; | ||
import { | ||
ConvertionType, | ||
getOptions, | ||
MultiFileConvertionOptions, | ||
ObjectConvertionOptions, | ||
SingleFileConvertionOptions | ||
} from '../lib/options/convertion-options'; | ||
import { info, printLogo } from '../lib/helpers/log-helper'; | ||
import { setupCommander } from '../lib/options/args-collector'; | ||
import { convertToSingleObject } from '../lib/converters/object.converter'; | ||
|
||
(async () => { | ||
setupCommander(); | ||
printLogo(); | ||
const convertionOptions = await getOptions(); | ||
|
||
if (convertionOptions.optimizeForLazyLoading) { | ||
if (convertionOptions.convertionType === ConvertionType.MULTIPLE_FILES) { | ||
info('We are using the convertiontype "multiple-files"'); | ||
await convertToMultipleFiles(convertionOptions as MultiFileConvertionOptions); | ||
} else { | ||
} | ||
|
||
if (convertionOptions.convertionType === ConvertionType.SINGLE_FILE) { | ||
info('We are using the convertiontype "single-file"'); | ||
await convertToSingleFile(convertionOptions as SingleFileConvertionOptions); | ||
} | ||
|
||
if (convertionOptions.convertionType === ConvertionType.OBJECT) { | ||
info('We are using the convertiontype "single-object"'); | ||
await convertToSingleObject(convertionOptions as ObjectConvertionOptions); | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { ObjectConvertionOptions } from '../options/convertion-options'; | ||
import { writeFile } from '../helpers/file-helpers'; | ||
import { error, success, underlineSuccess } from '../helpers/log-helper'; | ||
|
||
import { filesProcessor, SvgDefinition } from './shared.converter'; | ||
|
||
export const convertToSingleObject = async (convertionOptions: ObjectConvertionOptions): Promise<void> => { | ||
const { outputDirectory, fileName } = convertionOptions; | ||
try { | ||
const svgObject = {}; | ||
const svgDefinitions = await filesProcessor(convertionOptions); | ||
svgDefinitions.forEach( | ||
(svgDefinition: SvgDefinition) => (svgObject[svgDefinition.filenameWithoutEnding] = svgDefinition.data) | ||
); | ||
await writeFile(outputDirectory, fileName, `export const icons = ${JSON.stringify(svgObject)}`); | ||
success(`Icons file successfully generated under ${underlineSuccess(outputDirectory)}`); | ||
} catch (exception) { | ||
error(`Something went wrong: ${exception}`); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.