Skip to content

Commit 3df19fe

Browse files
authored
Merge pull request #28 from FlutterGen/support-windows
Support windows
2 parents ca7ccb7 + a10c3b1 commit 3df19fe

File tree

9 files changed

+64
-91
lines changed

9 files changed

+64
-91
lines changed

.github/workflows/flutter-ci.yml

Lines changed: 10 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -4,79 +4,35 @@ on:
44
pull_request: { }
55
push:
66
branches:
7-
- '*'
8-
tags:
9-
- '*'
7+
- 'main'
108

119
jobs:
1210
build:
11+
name: Run on ${{ matrix.os }}
12+
runs-on: ${{ matrix.os }}
1313
strategy:
1414
matrix:
15-
os: [ubuntu-latest, macos-latest]
16-
runs-on: ${{ matrix.os }}
15+
os: [ubuntu-latest, windows-latest, macos-latest]
1716
steps:
1817
- uses: actions/checkout@v2
1918
- uses: subosito/flutter-action@v1
2019
with:
2120
channel: 'stable'
2221

23-
- name: Cache Gradle modules
24-
uses: actions/cache@v2
25-
env:
26-
cache-number: ${{ secrets.CACHE_NUMBER }}
27-
with:
28-
path: |
29-
~/android/.gradle
30-
~/.gradle/cache
31-
# ~/.gradle/wrapper
32-
key: ${{ runner.os }}-gradle-${{ env.cache-number }}-${{ hashFiles('example/android/build.gradle') }}-${{ hashFiles('example/android/app/build.gradle') }}
33-
restore-keys: |
34-
${{ runner.os }}-gradle-${{ env.cache-name }}-${{ hashFiles('example/android/build.gradle') }}
35-
${{ runner.os }}-gradle-${{ env.cache-name }}-
36-
${{ runner.os }}-gradle-
37-
${{ runner.os }}-
38-
39-
- name: Cache CocoaPods modules
40-
uses: actions/cache@v2
41-
env:
42-
cache-number: ${{ secrets.CACHE_NUMBER }}
43-
with:
44-
path: Pods
45-
key: ${{ runner.os }}-pods-${{ env.cache-number }}-${{ hashFiles('example/ios/Podfile.lock') }}
46-
restore-keys: |
47-
${{ runner.os }}-pods-${{ env.cache-name }}-
48-
${{ runner.os }}-pods-
49-
${{ runner.os }}-
50-
51-
- name: Cache Flutter modules
52-
uses: actions/cache@v2
53-
env:
54-
cache-number: ${{ secrets.CACHE_NUMBER }}
55-
with:
56-
path: |
57-
/Users/runner/hostedtoolcache/flutter
58-
# ~/.pub-cache
59-
key: ${{ runner.os }}-pub-${{ env.cache-number }}-${{ env.flutter_version }}-${{ hashFiles('pubspec.lock') }}
60-
restore-keys: |
61-
${{ runner.os }}-pub-${{ env.flutter_version }}-
62-
${{ runner.os }}-pub-
63-
${{ runner.os }}-
64-
65-
- name: Get flutter dependencies.
22+
- name: Get dart dependencies.
6623
run: make dependencies
6724

68-
- name: Run tests for our flutter project.
25+
- name: Run tests for our dart project.
6926
run: |
7027
make unit-test
7128
make coverage
7229
73-
- name: Build
30+
- name: Generate example
7431
run: |
75-
make run-example
76-
make build-runner
32+
make generate-with-command
33+
make generate-with-runner
7734
7835
- name: Check for any formatting and statically analyze the code.
7936
run: |
8037
make format
81-
make analyze
82-
38+
make analyze

Makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ analyze:
1414
format:
1515
dartfmt -w lib/ bin/
1616

17-
build-runner:
18-
cd example && flutter packages pub run build_runner build --delete-conflicting-outputs cd ..
19-
2017
build:
2118
cd example && flutter build apk && cd ..
2219

23-
run-example:
20+
generate-with-command:
2421
dart bin/flutter_gen_command.dart --config example/pubspec.yaml
2522

23+
generate-with-runner:
24+
cd example && flutter packages pub run build_runner build --delete-conflicting-outputs cd ..
25+
2626
unit-test:
2727
pub run test
2828

@@ -42,4 +42,4 @@ setup-ubuntu:
4242
setup-macos:
4343
brew tap dart-lang/dart
4444
brew install dart
45-
pub get
45+
pub get

example/pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ packages:
201201
path: ".."
202202
relative: true
203203
source: path
204-
version: "0.0.21"
204+
version: "1.0.1"
205205
flutter_svg:
206206
dependency: "direct main"
207207
description:

lib/flutter_generator.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,34 +47,34 @@ class FlutterGenerator {
4747
if (config.hasFlutterGen) {
4848
output = config.flutterGen.output;
4949
lineLength = config.flutterGen.lineLength;
50-
final formatter = DartFormatter(pageWidth: lineLength);
50+
final formatter = DartFormatter(pageWidth: lineLength, lineEnding: '\n');
5151

5252
if (config.flutterGen.hasColors) {
5353
final generated =
5454
generateColors(pubspecFile, formatter, config.flutterGen.colors);
55-
final colors =
56-
File(join(pubspecFile.parent.path, output, 'colors.gen.dart'));
55+
final colors = File(normalize(
56+
join(pubspecFile.parent.path, output, 'colors.gen.dart')));
5757
writeAsString(generated, file: colors);
5858
print('Generated: ${colors.absolute.path}');
5959
}
6060
}
6161

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

6565
if (config.flutter.hasAssets) {
6666
final generated = generateAssets(
6767
pubspecFile, formatter, config.flutterGen, config.flutter.assets);
68-
final assets =
69-
File(join(pubspecFile.parent.path, output, 'assets.gen.dart'));
68+
final assets = File(normalize(
69+
join(pubspecFile.parent.path, output, 'assets.gen.dart')));
7070
writeAsString(generated, file: assets);
7171
print('Generated: ${assets.absolute.path}');
7272
}
7373

7474
if (config.flutter.hasFonts) {
7575
final generated = generateFonts(formatter, config.flutter.fonts);
76-
final fonts =
77-
File(join(pubspecFile.parent.path, output, 'fonts.gen.dart'));
76+
final fonts = File(
77+
normalize(join(pubspecFile.parent.path, output, 'fonts.gen.dart')));
7878
writeAsString(generated, file: fonts);
7979
print('Generated: ${fonts.absolute.path}');
8080
}

lib/src/generators/assets_generator.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ List<_Statement> _createDirectoryClassGenStatements(
136136
statement = _Statement(
137137
type: 'AssetGenImage',
138138
name: child.baseName.camelCase(),
139-
value: 'AssetGenImage\(\'${child.path}\'\)',
139+
value: 'AssetGenImage\(\'${posixStyle(child.path)}\'\)',
140140
isConstConstructor: true,
141141
);
142142
} else if (FileSystemEntity.isDirectorySync(childAssetAbsolutePath)) {
@@ -156,15 +156,15 @@ List<_Statement> _createDirectoryClassGenStatements(
156156
statement ??= _Statement(
157157
type: 'String',
158158
name: child.baseName.camelCase(),
159-
value: '\'${child.path}\'',
159+
value: '\'${posixStyle(child.path)}\'',
160160
isConstConstructor: false,
161161
);
162162
} else {
163163
integration.isEnabled = true;
164164
statement = _Statement(
165165
type: integration.className,
166166
name: child.baseName.camelCase(),
167-
value: integration.classInstantiate(child.path),
167+
value: integration.classInstantiate(posixStyle(child.path)),
168168
isConstConstructor: integration.isConstConstructor,
169169
);
170170
}

lib/src/generators/generator_helper.dart

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/src/settings/flutter_gen.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class FlutterGen {
1010
_output = safeCast<String>(flutterGenMap['output']);
1111
if (flutterGenMap.containsKey('integrations')) {
1212
integrations = FlutterGenIntegrations(
13-
safeCast<YamlMap>(flutterGenMap['integrations']));
13+
safeCast<YamlMap>(flutterGenMap['integrations']));
1414
}
1515
_lineLength = safeCast<int>(flutterGenMap['lineLength']);
1616
if (flutterGenMap.containsKey('colors')) {

lib/src/utils/camel_case.dart

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,14 @@ extension StringExt on String {
1414
}
1515

1616
List<String> _intoWords(String path) {
17-
final _symbolRegex = RegExp(r'[ ./_\-]');
17+
final _symbols = [
18+
' ',
19+
'.',
20+
'/',
21+
'_',
22+
'\\',
23+
'-',
24+
];
1825
final _upperAlphaRegex = RegExp(r'[A-Z]');
1926
final _lowerAlphaRegex = RegExp(r'[a-z]');
2027
final buffer = StringBuffer();
@@ -26,7 +33,7 @@ List<String> _intoWords(String path) {
2633
? null
2734
: String.fromCharCode(path.codeUnitAt(i + 1));
2835

29-
if (_symbolRegex.hasMatch(char)) {
36+
if (_symbols.contains(char)) {
3037
continue;
3138
}
3239

@@ -35,7 +42,7 @@ List<String> _intoWords(String path) {
3542
final isEndOfWord = nextChar == null ||
3643
(_upperAlphaRegex.hasMatch(nextChar) &&
3744
path.contains(_lowerAlphaRegex)) ||
38-
_symbolRegex.hasMatch(nextChar);
45+
_symbols.contains(nextChar);
3946

4047
if (isEndOfWord) {
4148
words.add(buffer.toString());

test/flutter_gen_test.dart

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@TestOn('vm')
12
import 'dart:io';
23

34
import 'package:dart_style/dart_style.dart';
@@ -8,9 +9,6 @@ import 'package:flutter_gen/src/generators/fonts_generator.dart';
89
import 'package:flutter_gen/src/settings/config.dart';
910
import 'package:test/test.dart';
1011

11-
Directory savedCurrentDirectory;
12-
13-
@TestOn('vm')
1412
void main() {
1513
setUp(() {
1614
final dir = Directory('test_resources/lib/');
@@ -133,14 +131,15 @@ void main() {
133131

134132
test('Assets on pubspec.yaml', () async {
135133
final pubspec = File('test_resources/pubspec_assets.yaml');
136-
final pubstri = pubspec.readAsStringSync();
137134
final config = await Config(pubspec).load();
138-
final formatter = DartFormatter(pageWidth: config.flutterGen.lineLength);
135+
final formatter = DartFormatter(
136+
pageWidth: config.flutterGen.lineLength, lineEnding: '\n');
139137

140138
final actual = generateAssets(
141139
pubspec, formatter, config.flutterGen, config.flutter.assets);
142-
final expected =
143-
File('test_resources/actual_data/assets.gen.dart').readAsStringSync();
140+
final expected = File('test_resources/actual_data/assets.gen.dart')
141+
.readAsStringSync()
142+
.replaceAll('\r\n', '\n');
144143

145144
expect(actual, expected);
146145
});
@@ -154,39 +153,47 @@ void main() {
154153
isNotEmpty,
155154
);
156155

157-
final pubspec = File('test_resources/pubspec_assets_no_integrations.yaml');
156+
final pubspec =
157+
File('test_resources/pubspec_assets_no_integrations.yaml');
158158
final config = await Config(pubspec).load();
159-
final formatter = DartFormatter(pageWidth: config.flutterGen.lineLength);
159+
final formatter = DartFormatter(
160+
pageWidth: config.flutterGen.lineLength, lineEnding: '\n');
160161

161162
final actual = generateAssets(
162163
pubspec, formatter, config.flutterGen, config.flutter.assets);
163164
final expected =
164-
File('test_resources/actual_data/assets_no_integrations.gen.dart').readAsStringSync();
165+
File('test_resources/actual_data/assets_no_integrations.gen.dart')
166+
.readAsStringSync()
167+
.replaceAll('\r\n', '\n');
165168

166169
expect(actual, expected);
167170
});
168171

169172
test('Fonts on pubspec.yaml', () async {
170173
final config =
171174
await Config(File('test_resources/pubspec_fonts.yaml')).load();
172-
final formatter = DartFormatter(pageWidth: config.flutterGen.lineLength);
175+
final formatter = DartFormatter(
176+
pageWidth: config.flutterGen.lineLength, lineEnding: '\n');
173177

174178
final actual = generateFonts(formatter, config.flutter.fonts);
175-
final expected =
176-
File('test_resources/actual_data/fonts.gen.dart').readAsStringSync();
179+
final expected = File('test_resources/actual_data/fonts.gen.dart')
180+
.readAsStringSync()
181+
.replaceAll('\r\n', '\n');
177182

178183
expect(actual, expected);
179184
});
180185

181186
test('Colors on pubspec.yaml', () async {
182187
final pubspec = File('test_resources/pubspec_colors.yaml');
183188
final config = await Config(pubspec).load();
184-
final formatter = DartFormatter(pageWidth: config.flutterGen.lineLength);
189+
final formatter = DartFormatter(
190+
pageWidth: config.flutterGen.lineLength, lineEnding: '\n');
185191

186192
final actual =
187193
generateColors(pubspec, formatter, config.flutterGen.colors);
188-
final expected =
189-
File('test_resources/actual_data/colors.gen.dart').readAsStringSync();
194+
final expected = File('test_resources/actual_data/colors.gen.dart')
195+
.readAsStringSync()
196+
.replaceAll('\r\n', '\n');
190197

191198
expect(actual, expected);
192199
});

0 commit comments

Comments
 (0)