Skip to content

Commit

Permalink
feat(sources): use source files as regex
Browse files Browse the repository at this point in the history
BREAKING CHANGE: srcDirectories is gone and we should now use srcFiles
  • Loading branch information
nivekcode committed Feb 25, 2020
1 parent 43ad694 commit 69547dd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
"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/*.svg",
"start:regex": "ts-node ./src/bin/svg-to-ts.ts -s ./inputfilesRegex/**/*.svg",
"start:kebap": "ts-node ./src/bin/svg-to-ts.ts -s ./inputfiles/*.svg -d KEBAB",
"start:multiple-source": "ts-node ./src/bin/svg-to-ts.ts -s ./inputfiles/*.svg -s ./inputfilesBis",
"start:custom": "ts-node ./src/bin/svg-to-ts.ts -s ./inputfiles/*.svg -o ./dist -t sampleIcon -i SampleIcon -p sampleIcon -f icons",
"start": "ts-node ./src/bin/svg-to-ts.ts -s './inputfiles/*.svg'",
"start:regex": "ts-node ./src/bin/svg-to-ts.ts -s './inputfilesRegex/**/*.svg'",
"start:kebap": "ts-node ./src/bin/svg-to-ts.ts -s './inputfiles/*.svg -d KEBAB'",
"start:multiple-source": "ts-node ./src/bin/svg-to-ts.ts -s './inputfiles/*.svg' -s './inputfilesBis/*.svg'",
"start:custom": "ts-node ./src/bin/svg-to-ts.ts -s './inputfiles/*.svg' -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
25 changes: 10 additions & 15 deletions src/lib/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,35 +34,30 @@ export enum Delimiter {

export const convert = async (convertionOptions: ConvertionOptions): Promise<void> => {
let svgConstants = '';

let types = getTypeDefinition(convertionOptions.typeName);

try {
const typesDelimitor = ' | ';
const srcFiles = convertionOptions.srcFiles;
let filesPath: string[] = [];
for (let i = 0; i < srcFiles.length; i++) {
const directoryFiles = await getFilesFromRegex(srcFiles[i], {
const srcFilesRegexExpressions = convertionOptions.srcFiles;
const filePaths: string[] = [];

for (const regex of srcFilesRegexExpressions) {
const directoryFiles = await getFilesFromRegex(regex, {
nodir: true
});

if (directoryFiles.length === 0) {
console.log(
chalk.blue.bold('svg-to-ts:'),
chalk.green(`No file found for directory ${srcFiles[i]}`),
chalk.green.underline(convertionOptions.outputDirectory)
);
console.log(chalk.blue.bold('svg-to-ts:'), chalk.yellow(`No matching files for regex: "${regex}"`));
} else {
filesPath.push(...directoryFiles);
filePaths.push(...directoryFiles);
}
}

for (let i = 0; i < filesPath.length; i++) {
const fileNameWithEnding = path.basename(filesPath[i]);
for (let i = 0; i < filePaths.length; i++) {
const fileNameWithEnding = path.basename(filePaths[i]);
const [filenameWithoutEnding, extension] = fileNameWithEnding.split('.');

if (extension === 'svg') {
const rawSvg = await extractSvgContent(filesPath[i]);
const rawSvg = await extractSvgContent(filePaths[i]);
const optimizedSvg = await svgo.optimize(rawSvg);
const variableName = getVariableName(convertionOptions, filenameWithoutEnding);
const typeName = getTypeName(filenameWithoutEnding, convertionOptions.delimiter);
Expand Down

0 comments on commit 69547dd

Please sign in to comment.