Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add option --out-dir to packge vector_graphics_compiler #215

Merged
merged 4 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:vector_graphics_compiler/src/svg/colors.dart';
import 'package:vector_graphics_compiler/vector_graphics_compiler.dart';

import 'util/isolate_processor.dart';
import 'package:path/path.dart' as p;

final ArgParser argParser = ArgParser()
..addOption(
Expand Down Expand Up @@ -68,6 +69,11 @@ final ArgParser argParser = ArgParser()
'Only includes files that end with .svg. '
'Cannot be combined with --input or --output.',
)
..addOption(
'out-dir',
help: 'The output directory path '
'use it with --input-dir to specific the output dirictory',
)
..addOption(
'input',
abbr: 'i',
Expand Down Expand Up @@ -144,7 +150,19 @@ Future<void> main(List<String> args) async {
if (!file.path.endsWith('.svg')) {
continue;
}
final String outputPath = '${file.path}.vec';

String outputPath = '${file.path}.vec';

// to specfic the output directory when parse multi svg
if (results.wasParsed('out-dir')) {
final Directory outDir = Directory(results['out-dir'] as String);
//to add the output dirctory if it exist
if (!outDir.existsSync()) {
outDir.createSync();
}
outputPath = p.join(outDir.path, '${p.basename(file.path)}.vec');
}

pairs.add(Pair(file.path, outputPath));
}
} else {
Expand Down
1 change: 1 addition & 0 deletions packages/vector_graphics_compiler/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ dependencies:
path_parsing: ^1.0.1
xml: ^6.3.0
vector_graphics_codec: 1.1.8
path: ^1.8.3
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this add a dependency on path to all users of flutter_svg?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahhh I think we cheated on this before and put it in dev_dependencies...

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also use a more relaxed constraint?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can cheat if its only used in the bin directory, might want to double check. I'd be fine with that.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If that doesn't work, I'd be fine with a loose constraint like we have

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed this to ^1.8.0. I'll fix up the analysis issues unrelated to this patch separately.


dev_dependencies:
flutter_lints: ^1.0.0
Expand Down
50 changes: 50 additions & 0 deletions packages/vector_graphics_compiler/test/cli_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@

import 'dart:io';

import 'package:flutter/foundation.dart';
import 'package:flutter_test/flutter_test.dart';
import '../bin/util/isolate_processor.dart';
import '../bin/vector_graphics_compiler.dart' as cli;
import 'package:path/path.dart' as p;
import 'package:collection/collection.dart';

void main() {
final File output = File('test_data/example.vec');
Expand Down Expand Up @@ -86,4 +89,51 @@ void main() {
}
}
});

test('out-dir option works', () async {
const String inputTestDir = 'test_data';

const String outTestDir = 'output_vec';

try {
await cli.main(<String>[
'--input-dir',
inputTestDir,
'--out-dir',
outTestDir,
]);

bool passed = false;

final Directory inputDir = Directory(inputTestDir);
final Directory outDir = Directory(outTestDir);

if (inputDir.existsSync() && outDir.existsSync()) {
final List<String> inputTestFiles = inputDir
.listSync(recursive: true)
.whereType<File>()
.where((File element) => element.path.endsWith('svg'))
.map((File e) => p.basenameWithoutExtension(e.path))
.toList();

final List<String> outTestFiles = outDir
.listSync(recursive: true)
.whereType<File>()
.where((File element) => element.path.endsWith('vec'))
.map((File e) =>
p.withoutExtension(p.basenameWithoutExtension(e.path)))
.toList();

if (listEquals(inputTestFiles, outTestFiles)) {
passed = true;
}
}

expect(passed, true);
} finally {
if (Directory(outTestDir).existsSync()) {
Directory(outTestDir).deleteSync(recursive: true);
}
}
});
}
Loading