Skip to content

Support windows #28

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

Merged
merged 6 commits into from
Sep 9, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
64 changes: 10 additions & 54 deletions .github/workflows/flutter-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,79 +4,35 @@ on:
pull_request: { }
push:
branches:
- '*'
tags:
- '*'
- 'main'

jobs:
build:
name: Run on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- uses: actions/checkout@v2
- uses: subosito/flutter-action@v1
with:
channel: 'stable'

- name: Cache Gradle modules
uses: actions/cache@v2
env:
cache-number: ${{ secrets.CACHE_NUMBER }}
with:
path: |
~/android/.gradle
~/.gradle/cache
# ~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ env.cache-number }}-${{ hashFiles('example/android/build.gradle') }}-${{ hashFiles('example/android/app/build.gradle') }}
restore-keys: |
${{ runner.os }}-gradle-${{ env.cache-name }}-${{ hashFiles('example/android/build.gradle') }}
${{ runner.os }}-gradle-${{ env.cache-name }}-
${{ runner.os }}-gradle-
${{ runner.os }}-

- name: Cache CocoaPods modules
uses: actions/cache@v2
env:
cache-number: ${{ secrets.CACHE_NUMBER }}
with:
path: Pods
key: ${{ runner.os }}-pods-${{ env.cache-number }}-${{ hashFiles('example/ios/Podfile.lock') }}
restore-keys: |
${{ runner.os }}-pods-${{ env.cache-name }}-
${{ runner.os }}-pods-
${{ runner.os }}-

- name: Cache Flutter modules
uses: actions/cache@v2
env:
cache-number: ${{ secrets.CACHE_NUMBER }}
with:
path: |
/Users/runner/hostedtoolcache/flutter
# ~/.pub-cache
key: ${{ runner.os }}-pub-${{ env.cache-number }}-${{ env.flutter_version }}-${{ hashFiles('pubspec.lock') }}
restore-keys: |
${{ runner.os }}-pub-${{ env.flutter_version }}-
${{ runner.os }}-pub-
${{ runner.os }}-

- name: Get flutter dependencies.
- name: Get dart dependencies.
run: make dependencies

- name: Run tests for our flutter project.
- name: Run tests for our dart project.
run: |
make unit-test
make coverage

- name: Build
- name: Generate example
run: |
make run-example
make build-runner
make generate-with-command
make generate-with-runner

- name: Check for any formatting and statically analyze the code.
run: |
make format
make analyze

make analyze
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ analyze:
format:
dartfmt -w lib/ bin/

build-runner:
cd example && flutter packages pub run build_runner build --delete-conflicting-outputs cd ..

build:
cd example && flutter build apk && cd ..

run-example:
generate-with-command:
dart bin/flutter_gen_command.dart --config example/pubspec.yaml

generate-with-runner:
cd example && flutter packages pub run build_runner build --delete-conflicting-outputs cd ..

unit-test:
pub run test

Expand All @@ -42,4 +42,4 @@ setup-ubuntu:
setup-macos:
brew tap dart-lang/dart
brew install dart
pub get
pub get
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.0.21"
version: "1.0.1"
flutter_svg:
dependency: "direct main"
description:
Expand Down
16 changes: 8 additions & 8 deletions lib/flutter_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,34 +47,34 @@ class FlutterGenerator {
if (config.hasFlutterGen) {
output = config.flutterGen.output;
lineLength = config.flutterGen.lineLength;
final formatter = DartFormatter(pageWidth: lineLength);
final formatter = DartFormatter(pageWidth: lineLength, lineEnding: '\n');

if (config.flutterGen.hasColors) {
final generated =
generateColors(pubspecFile, formatter, config.flutterGen.colors);
final colors =
File(join(pubspecFile.parent.path, output, 'colors.gen.dart'));
final colors = File(normalize(
join(pubspecFile.parent.path, output, 'colors.gen.dart')));
writeAsString(generated, file: colors);
print('Generated: ${colors.absolute.path}');
}
}

if (config.hasFlutter) {
final formatter = DartFormatter(pageWidth: lineLength);
final formatter = DartFormatter(pageWidth: lineLength, lineEnding: '\n');

if (config.flutter.hasAssets) {
final generated = generateAssets(
pubspecFile, formatter, config.flutterGen, config.flutter.assets);
final assets =
File(join(pubspecFile.parent.path, output, 'assets.gen.dart'));
final assets = File(normalize(
join(pubspecFile.parent.path, output, 'assets.gen.dart')));
writeAsString(generated, file: assets);
print('Generated: ${assets.absolute.path}');
}

if (config.flutter.hasFonts) {
final generated = generateFonts(formatter, config.flutter.fonts);
final fonts =
File(join(pubspecFile.parent.path, output, 'fonts.gen.dart'));
final fonts = File(
normalize(join(pubspecFile.parent.path, output, 'fonts.gen.dart')));
writeAsString(generated, file: fonts);
print('Generated: ${fonts.absolute.path}');
}
Expand Down
6 changes: 3 additions & 3 deletions lib/src/generators/assets_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ List<_Statement> _createDirectoryClassGenStatements(
statement = _Statement(
type: 'AssetGenImage',
name: child.baseName.camelCase(),
value: 'AssetGenImage\(\'${child.path}\'\)',
value: 'AssetGenImage\(\'${posixStyle(child.path)}\'\)',
isConstConstructor: true,
);
} else if (FileSystemEntity.isDirectorySync(childAssetAbsolutePath)) {
Expand All @@ -156,15 +156,15 @@ List<_Statement> _createDirectoryClassGenStatements(
statement ??= _Statement(
type: 'String',
name: child.baseName.camelCase(),
value: '\'${child.path}\'',
value: '\'${posixStyle(child.path)}\'',
isConstConstructor: false,
);
} else {
integration.isEnabled = true;
statement = _Statement(
type: integration.className,
name: child.baseName.camelCase(),
value: integration.classInstantiate(child.path),
value: integration.classInstantiate(posixStyle(child.path)),
isConstConstructor: integration.isConstConstructor,
);
}
Expand Down
3 changes: 3 additions & 0 deletions lib/src/generators/generator_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ String get header {
}

String import(String package) => 'import \'$package\';';

// Replace to Posix style for Windows separator.
String posixStyle(String path) => path.replaceAll(r'\', r'/');
2 changes: 1 addition & 1 deletion lib/src/settings/flutter_gen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class FlutterGen {
_output = safeCast<String>(flutterGenMap['output']);
if (flutterGenMap.containsKey('integrations')) {
integrations = FlutterGenIntegrations(
safeCast<YamlMap>(flutterGenMap['integrations']));
safeCast<YamlMap>(flutterGenMap['integrations']));
}
_lineLength = safeCast<int>(flutterGenMap['lineLength']);
if (flutterGenMap.containsKey('colors')) {
Expand Down
13 changes: 10 additions & 3 deletions lib/src/utils/camel_case.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,14 @@ extension StringExt on String {
}

List<String> _intoWords(String path) {
final _symbolRegex = RegExp(r'[ ./_\-]');
final _symbols = [
' ',
'.',
'/',
'_',
'\\',
'-',
];
final _upperAlphaRegex = RegExp(r'[A-Z]');
final _lowerAlphaRegex = RegExp(r'[a-z]');
final buffer = StringBuffer();
Expand All @@ -26,7 +33,7 @@ List<String> _intoWords(String path) {
? null
: String.fromCharCode(path.codeUnitAt(i + 1));

if (_symbolRegex.hasMatch(char)) {
if (_symbols.contains(char)) {
continue;
}

Expand All @@ -35,7 +42,7 @@ List<String> _intoWords(String path) {
final isEndOfWord = nextChar == null ||
(_upperAlphaRegex.hasMatch(nextChar) &&
path.contains(_lowerAlphaRegex)) ||
_symbolRegex.hasMatch(nextChar);
_symbols.contains(nextChar);

if (isEndOfWord) {
words.add(buffer.toString());
Expand Down
39 changes: 23 additions & 16 deletions test/flutter_gen_test.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@TestOn('vm')
import 'dart:io';

import 'package:dart_style/dart_style.dart';
Expand All @@ -8,9 +9,6 @@ import 'package:flutter_gen/src/generators/fonts_generator.dart';
import 'package:flutter_gen/src/settings/config.dart';
import 'package:test/test.dart';

Directory savedCurrentDirectory;

@TestOn('vm')
void main() {
setUp(() {
final dir = Directory('test_resources/lib/');
Expand Down Expand Up @@ -133,14 +131,15 @@ void main() {

test('Assets on pubspec.yaml', () async {
final pubspec = File('test_resources/pubspec_assets.yaml');
final pubstri = pubspec.readAsStringSync();
final config = await Config(pubspec).load();
final formatter = DartFormatter(pageWidth: config.flutterGen.lineLength);
final formatter = DartFormatter(
pageWidth: config.flutterGen.lineLength, lineEnding: '\n');

final actual = generateAssets(
pubspec, formatter, config.flutterGen, config.flutter.assets);
final expected =
File('test_resources/actual_data/assets.gen.dart').readAsStringSync();
final expected = File('test_resources/actual_data/assets.gen.dart')
.readAsStringSync()
.replaceAll('\r\n', '\n');

expect(actual, expected);
});
Expand All @@ -154,39 +153,47 @@ void main() {
isNotEmpty,
);

final pubspec = File('test_resources/pubspec_assets_no_integrations.yaml');
final pubspec =
File('test_resources/pubspec_assets_no_integrations.yaml');
final config = await Config(pubspec).load();
final formatter = DartFormatter(pageWidth: config.flutterGen.lineLength);
final formatter = DartFormatter(
pageWidth: config.flutterGen.lineLength, lineEnding: '\n');

final actual = generateAssets(
pubspec, formatter, config.flutterGen, config.flutter.assets);
final expected =
File('test_resources/actual_data/assets_no_integrations.gen.dart').readAsStringSync();
File('test_resources/actual_data/assets_no_integrations.gen.dart')
.readAsStringSync()
.replaceAll('\r\n', '\n');

expect(actual, expected);
});

test('Fonts on pubspec.yaml', () async {
final config =
await Config(File('test_resources/pubspec_fonts.yaml')).load();
final formatter = DartFormatter(pageWidth: config.flutterGen.lineLength);
final formatter = DartFormatter(
pageWidth: config.flutterGen.lineLength, lineEnding: '\n');

final actual = generateFonts(formatter, config.flutter.fonts);
final expected =
File('test_resources/actual_data/fonts.gen.dart').readAsStringSync();
final expected = File('test_resources/actual_data/fonts.gen.dart')
.readAsStringSync()
.replaceAll('\r\n', '\n');

expect(actual, expected);
});

test('Colors on pubspec.yaml', () async {
final pubspec = File('test_resources/pubspec_colors.yaml');
final config = await Config(pubspec).load();
final formatter = DartFormatter(pageWidth: config.flutterGen.lineLength);
final formatter = DartFormatter(
pageWidth: config.flutterGen.lineLength, lineEnding: '\n');

final actual =
generateColors(pubspec, formatter, config.flutterGen.colors);
final expected =
File('test_resources/actual_data/colors.gen.dart').readAsStringSync();
final expected = File('test_resources/actual_data/colors.gen.dart')
.readAsStringSync()
.replaceAll('\r\n', '\n');

expect(actual, expected);
});
Expand Down