Skip to content

Commit

Permalink
feat(conversion): use snake case instead of camel case
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Generate types and variable names in snake case instead of camel case
  • Loading branch information
nivekcode committed Dec 10, 2019
1 parent b3cefe9 commit 8963ce7
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"dependencies": {
"chalk": "^3.0.0",
"commander": "^4.0.1",
"lodash.camelcase": "^4.3.0",
"lodash.snakecase": "^4.1.1",
"prettier": "^1.19.1",
"svgo": "^1.3.2"
},
Expand Down
6 changes: 3 additions & 3 deletions src/lib/convert.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { svgo } from './svgo';
import { getInterfaceDefinition, getSvgConstant, getTypeDefinition } from './definitions';
import camelCase from 'lodash.camelcase';
import snakeCase from 'lodash.snakecase';
import * as prettier from 'prettier/standalone';
import chalk from 'chalk';
import typescriptParser from 'prettier/parser-typescript';
Expand Down Expand Up @@ -31,7 +31,7 @@ export const convert = async (convertionOptions: ConvertionOptions): Promise<voi
const files = await readdir(directoryPath);
for (let i = 0; i < files.length; i++) {
const fileNameWithEnding = files[i];
const filenameWithoutEnding = fileNameWithEnding.split('.')[0];
const filenameWithoutEnding = snakeCase(fileNameWithEnding.split('.')[0]);
const rawSvg = await extractSvgContent(fileNameWithEnding, directoryPath);
const optimizedSvg = await svgo.optimize(rawSvg);
const variableName = getVariableName(convertionOptions, filenameWithoutEnding);
Expand Down Expand Up @@ -75,7 +75,7 @@ const writeIconsFile = async (convertionOptions: ConvertionOptions, fileContent:
};

const getVariableName = (convertionOptions: ConvertionOptions, filenameWithoutEnding): string => {
return `${convertionOptions.prefix}${capitalize(camelCase(filenameWithoutEnding))}`;
return `${convertionOptions.prefix}${capitalize(filenameWithoutEnding)}`;
};

const extractSvgContent = async (fileName: string, directoryPath: string): Promise<string> => {
Expand Down
2 changes: 0 additions & 2 deletions src/lib/definitions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { ConvertionOptions } from './convert';

export const getInterfaceDefinition = (interfaceName: string, typeName: string) => {
return `export interface ${interfaceName}{
name: ${typeName};
Expand Down

0 comments on commit 8963ce7

Please sign in to comment.