diff --git a/README.md b/README.md index cd590b9..430813b 100644 --- a/README.md +++ b/README.md @@ -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 | name of the generated type | -| -p | --prefix | prefix for the generated svg constants | -| -i | --interfaceName | name for the generated interface | -| -s | --srcDirectory | name of the source directory (default: ".") | -| -o | --outputDirectory | name of the output directory (default: "./dist") | -| -h | --help | output usage information | +| -v | --version | output the version number | +| --- | -------------------------- | ----------------------------------------------------- | +| -t | --typeName | name of the generated type (myIcons) | +| -p | --prefix | prefix for the generated svg constants (myIcon) | +| -i | --interfaceName | name for the generated interface (MyIcon) | +| -f | --fileName | file name of the generated file (default: "my-icons") | +| -s | --srcDirectory | name of the source directory (default: ".") | +| -o | --outputDirectory | name of the output directory (default: "./dist") | +| -h | --help | output usage information | # Example diff --git a/package.json b/package.json index ad4c424..569cc60 100644 --- a/package.json +++ b/package.json @@ -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" }, diff --git a/src/bin/svg-to-ts.ts b/src/bin/svg-to-ts.ts index eebf7a9..285167d 100755 --- a/src/bin/svg-to-ts.ts +++ b/src/bin/svg-to-ts.ts @@ -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 ', 'name of the generated enumeration type') - .option('-p --prefix ', 'prefix for the generated svg constants') - .option('-i --interfaceName ', 'name for the generated interface') - .option('-s --srcDirectory ', 'name of the source directory', '.') - .option('-o --outputDirectory ', 'name of the output directory', './dist') + .option('-t --typeName ', 'name of the generated enumeration type', DEFAULTS.typeName) + .option('-f --fileName ', 'name of the generated file', DEFAULTS.fileName) + .option('-p --prefix ', 'prefix for the generated svg constants', DEFAULTS.prefix) + .option('-i --interfaceName ', 'name for the generated interface', DEFAULTS.interfaceName) + .option('-s --srcDirectory ', 'name of the source directory', DEFAULTS.sourceDirectory) + .option('-o --outputDirectory ', '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); diff --git a/src/lib/convert.ts b/src/lib/convert.ts index 61e61aa..31424f2 100644 --- a/src/lib/convert.ts +++ b/src/lib/convert.ts @@ -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; @@ -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 => {