Skip to content

Commit

Permalink
feat(filename): accept fileName as input property
Browse files Browse the repository at this point in the history
  • Loading branch information
nivekcode committed Dec 9, 2019
1 parent 1ab1fb5 commit b99809d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 17 deletions.
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,15 @@ Additonally we also optimize the SVG icons with the help of the `svgo` package.

The CLI can be used with the `tsvg` command. This command accepts the following arguments.

| -v | --version | output the version number |
| --- | -------------------------- | ------------------------------------------------ |
| -t | --typeName <string> | name of the generated type |
| -p | --prefix <string> | prefix for the generated svg constants |
| -i | --interfaceName <string> | name for the generated interface |
| -s | --srcDirectory <string> | name of the source directory (default: ".") |
| -o | --outputDirectory <string> | name of the output directory (default: "./dist") |
| -h | --help | output usage information |
| -v | --version | output the version number |
| --- | -------------------------- | ----------------------------------------------------- |
| -t | --typeName <string> | name of the generated type (myIcons) |
| -p | --prefix <string> | prefix for the generated svg constants (myIcon) |
| -i | --interfaceName <string> | name for the generated interface (MyIcon) |
| -f | --fileName <string> | file name of the generated file (default: "my-icons") |
| -s | --srcDirectory <string> | name of the source directory (default: ".") |
| -o | --outputDirectory <string> | name of the output directory (default: "./dist") |
| -h | --help | output usage information |

# Example

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"format:check": "prettier --list-different 'src/**/*.ts'",
"format:write": "prettier --write 'src/**/*.ts'",
"prebuild": "npm run copy:readme",
"start": "ts-node ./src/bin/svg-to-ts.ts -s ./inputfiles -o ./dist -t sampleIcon -i SampleIcon -p sampleIcon",
"start": "ts-node ./src/bin/svg-to-ts.ts -s ./inputfiles",
"start:custom": "ts-node ./src/bin/svg-to-ts.ts -s ./inputfiles -o ./dist -t sampleIcon -i SampleIcon -p sampleIcon -f icons",
"start:help": "ts-node ./src/bin/svg-to-ts.ts -h",
"semantic-release": "semantic-release"
},
Expand Down
24 changes: 17 additions & 7 deletions src/bin/svg-to-ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,33 @@ import * as packgeJSON from '../../package.json';
import commander from 'commander';
import { convert } from '../lib/convert';

const DEFAULTS = {
typeName: 'myIcons',
interfaceName: 'MyIcon',
fileName: 'my-icons',
prefix: 'myIcon',
sourceDirectory: '.',
outputDirectory: './dist'
};

commander
.version(packgeJSON.version)
.option('-t --typeName <string>', 'name of the generated enumeration type')
.option('-p --prefix <string>', 'prefix for the generated svg constants')
.option('-i --interfaceName <string>', 'name for the generated interface')
.option('-s --srcDirectory <string>', 'name of the source directory', '.')
.option('-o --outputDirectory <string>', 'name of the output directory', './dist')
.option('-t --typeName <string>', 'name of the generated enumeration type', DEFAULTS.typeName)
.option('-f --fileName <string>', 'name of the generated file', DEFAULTS.fileName)
.option('-p --prefix <string>', 'prefix for the generated svg constants', DEFAULTS.prefix)
.option('-i --interfaceName <string>', 'name for the generated interface', DEFAULTS.interfaceName)
.option('-s --srcDirectory <string>', 'name of the source directory', DEFAULTS.sourceDirectory)
.option('-o --outputDirectory <string>', 'name of the output directory', DEFAULTS.outputDirectory)
.parse(process.argv);

const { typeName, prefix, interfaceName, srcDirectory, outputDirectory } = commander;
const { typeName, fileName, prefix, interfaceName, srcDirectory, outputDirectory } = commander;

const convertionOptions = {
typeName,
fileName,
prefix,
interfaceName,
srcDirectory,
outputDirectory
};

convert(convertionOptions);
3 changes: 2 additions & 1 deletion src/lib/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const writeFile = util.promisify(fs.writeFile);
export interface ConvertionOptions {
typeName: string;
prefix: string;
fileName: string;
interfaceName: string;
srcDirectory: string;
outputDirectory: string;
Expand Down Expand Up @@ -69,7 +70,7 @@ const writeIconsFile = async (convertionOptions: ConvertionOptions, fileContent:
if (!fs.existsSync(convertionOptions.outputDirectory)) {
fs.mkdirSync(convertionOptions.outputDirectory);
}
await writeFile(path.join(convertionOptions.outputDirectory, 'icons.ts'), fileContent);
await writeFile(path.join(convertionOptions.outputDirectory, `${convertionOptions.fileName}.ts`), fileContent);
};

const getVariableName = (convertionOptions: ConvertionOptions, filenameWithoutEnding): string => {
Expand Down

0 comments on commit b99809d

Please sign in to comment.