Skip to content

Commit

Permalink
Added build.sh and README.md with build tool
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin De Keyser committed Oct 27, 2022
1 parent 0e2a615 commit 3018d72
Show file tree
Hide file tree
Showing 5 changed files with 245 additions and 15 deletions.
29 changes: 18 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
# flutterdashdocumentation
# Flutter app docset generation

A new Flutter project.
This is a slightly modified standard Flutter repo with a build.sh tool that generates a Dash compatible .docset documentation for the flutter app.

## Getting Started
Check out [build.sh] for more details.

This project is a starting point for a Flutter application.
# Install requirements
```
brew install dashing jq yq
pip3 install Pillow
```

A few resources to get you started if this is your first Flutter project:
# Install instructions for optional flutter-stylizer:

- [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab)
- [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook)

For help getting started with Flutter development, view the
[online documentation](https://docs.flutter.dev/), which offers tutorials,
samples, guidance on mobile development, and a full API reference.
```brew install go```
Add the following 3 lines to your .zshrc (or .bashrc if you're using bash)
```
export GOPATH=${HOME}/go
PATH=${PATH}:${HOME}/go/bin
mkdir -p ${HOME}/go/bin
```
Finally, install using:
`go get -u github.com/gmlewis/go-flutter-stylizer/cmd/flutter-stylizer`
8 changes: 8 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,13 @@ linter:
# avoid_print: false # Uncomment to disable the `avoid_print` rule
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule

analyzer:
exclude:
# Ignore linting issues on generated files.
- '**/*.g.dart'
- '**/*.freezed.dart'
errors:
todo: ignore

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
188 changes: 188 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
#!/bin/sh

# This script additionally needs:
# brew install dashing jq yq
# [Optional]
# For image resizing:
# pip3 install Pillow
# Install instructions for flutter-stylizer:
# brew install go
# Add the following 3 lines to your .zshrc (or .bashrc if you're using bash)
#
# export GOPATH=${HOME}/go
# PATH=${PATH}:${HOME}/go/bin
# mkdir -p ${HOME}/go/bin
#
# Finally, install using: go get -u github.com/gmlewis/go-flutter-stylizer/cmd/flutter-stylizer

# Install/Update plugins
flutter pub get

# [Essential] Run code generation
flutter pub run build_runner build --delete-conflicting-outputs

# Format the code, should be done on saving by IDE.
flutter format .

# [Optional] Stylize flutter if installed: https://github.com/gmlewis/go-flutter-stylizer
flutter-stylizer lib/...

# Run tests
flutter test

# Analyze the code for issues.
flutter analyze

# Generate a dart web documentation.
dart doc .


########################################################################################
# Generate a dash documentation from the web documentation in doc/<packagename>.docset #
########################################################################################

DASHINGFILE=doc/api/dashing.json
FLUTTERNAME="$(yq -r .name pubspec.yaml)"
FLUTTERNAME_QUOTED="\"$(yq -r .name pubspec.yaml)\""
echo '{
"name": "ExampleFlutter",
"package": "ExampleFlutter",
"index": "index.html",
"ignore": [
"ABOUT"
],
"icon32x32": "",
"allowJS": false,
"ExternalURL": "",
"selectors": {
"#exceptions span.name a": {
"type": "Exception"
},
"h1 > span.kind-library": {
"type": "Library"
},
"h1 > span.kind-class": {
"type": "Class"
},
"h1 > span.kind-function": {
"type": "Function"
},
"h1 > span.kind-typedef": {
"type": "Type"
},
"h1 > span.kind-enum": {
"type": "Enum"
},
"h1 > span.kind-top-level-constant": {
"type": "Constant"
},
"h1 > span.kind-constant": {
"type": "Constant"
},
"h1 > span.kind-method": {
"type": "Method"
},
"h1 > span.kind-property": {
"type": "Property"
},
"h1 > span.kind-top-level-property": {
"type": "Property"
},
"h1 > span.kind-constructor": {
"type": "Constructor"
},
".callables .callable": {
"requiretext": "operator ",
"type": "Operator",
"regexp": "operator ",
"replacement": ""
}
},
"ignore": [
"ABOUT"
]
}' > "$DASHINGFILE"

contents=$(jq ".name = ${FLUTTERNAME_QUOTED}" $DASHINGFILE)
echo "${contents}" > "$DASHINGFILE"
contents=$(jq ".package = ${FLUTTERNAME_QUOTED}" $DASHINGFILE)
echo "${contents}" > "$DASHINGFILE"

# [OPTIONAL] Grab the largest app icon from the ios app and resize it to 30x30 to be used as an image of the documentation.
LARGESTICON=$(du ios/Runner/Assets.xcassets/AppIcon.appiconset/* | sort -rn | awk '{print $2}' | head -n 1)
cat > resize.py <<- EOM
from PIL import Image
import sys
filename = sys.argv[1]
basewidth = 32
img = Image.open(filename)
wpercent = (basewidth/float(img.size[0]))
hsize = int((float(img.size[1])*float(wpercent)))
img = img.resize((basewidth,hsize), Image.Resampling.LANCZOS)
img.save(sys.argv[2])
EOM
DOCICONNAME_QUOTED="\"doclogo.png\""
python3 resize.py $LARGESTICON doc/api/doclogo.png
contents=$(jq ".icon32x32 = ${DOCICONNAME_QUOTED}" $DASHINGFILE)

# Build the documentation.
rm -r doc/*.docset
rm -r doc/api/*.docset
cd doc/api
dashing build dashing.json
mv *.docset ./../
cd ..

# [OPTIONAL] Set the docset language to dartlang.
cat > preprocessing.dart <<- EOM
import 'dart:io';
import 'package:args/args.dart';
/// This changes the DocSetPlatformFamily key to be "dartlang" instead of the
/// name of the package (usually "flutter").
///
/// This is so that the IntelliJ plugin for Dash will be able to go directly to
/// the docs for a symbol from a keystroke. Without this, flutter isn't part
/// of the list of package names it searches. After this, it finds the flutter
/// docs because they're declared here to be part of the "dartlang" family of
/// docs.
///
/// Dashing doesn't have a way to configure this, so we modify the Info.plist
/// directly to make the change.
void main(List<String> args) {
if(args.length <= 0) return;
final File infoPlist = File(args[0]+'/Contents/Info.plist');
String contents = infoPlist.readAsStringSync();
// Since I didn't want to add the XML package as a dependency just for this,
// I just used a regular expression to make this simple change.
final RegExp findRe = RegExp(r'(\s*<key>DocSetPlatformFamily</key>\s*<string>)[^<]+(</string>)', multiLine: true);
contents = contents.replaceAllMapped(findRe, (Match match) {
return '\${match.group(1)}dartlang\${match.group(2)}';
});
infoPlist.writeAsStringSync(contents);
}
EOM

dart preprocessing.dart "$FLUTTERNAME.docset"

cd ..

# [OPTIONAL] Clean
rm resize.py
rm doc/preprocessing.dart
rm doc/api/dashing.json

27 changes: 27 additions & 0 deletions lib/commented_floating_action_button.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import 'package:flutter/material.dart';

/// A [FloatingActionButton] that displays a tooltip with an [Icon].
///
/// It requires as arguments a function [onPressed] that is called when
/// the [FloatingActionButton] is called.
/// In addition, an [icon] is required and a descriptive String [tooltip] are required.
class CommentedFloatingActionButton extends StatelessWidget {
const CommentedFloatingActionButton({
super.key,
required this.onPressed,
required this.tooltip,
required this.icon,
});

final Function()? onPressed;
final String tooltip;
final Icon icon;
@override
Widget build(BuildContext context) {
return FloatingActionButton(
onPressed: onPressed,
tooltip: tooltip,
child: icon,
);
}
}
8 changes: 4 additions & 4 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'package:flutter/material.dart';

import 'commented_floating_action_button.dart';

void main() {
runApp(const MyApp());
}
Expand Down Expand Up @@ -71,8 +73,6 @@ class _MyHomePageState extends State<MyHomePage> {
// than having to individually change instances of widgets.
return Scaffold(
appBar: AppBar(
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text(widget.title),
),
body: Center(
Expand Down Expand Up @@ -105,10 +105,10 @@ class _MyHomePageState extends State<MyHomePage> {
],
),
),
floatingActionButton: FloatingActionButton(
floatingActionButton: CommentedFloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
icon: const Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
Expand Down

0 comments on commit 3018d72

Please sign in to comment.