Code Monkey home page Code Monkey logo

flutter_dd_cli's Introduction

flutter_dd_cli Pub

A helper CLI Utility to simplify usages of Dart Defines.

Features

  • Generates a string of formatted --dart-defines ready to be pasted into any flutter build and flutter run commands.
  • Simplify flutter build command by specifying an existing file containing ready-to-inject values (in json or line separated), converting them to --dart-define format.
  • Provides an alternative way instead of editing .vscode/launch.json or .idea/workspace.xml directly.

Getting started

Installation

flutter pub global activate flutter_dd_cli

If you have direct access to pub in your PATH then you can omit the flutter prefix.

The CLI will be available as the terminal command fdd. But in order to use it everywhere, e.g on your current Flutter project directory, you have to add the system cache bin directory to your PATH environment variable.

Assuming the Flutter installation is located at the default location, here are some known possible PATHs:

  • MacOS/Linux Path:

$HOME/.pub-cache/bin
  • Windows Path:

%LOCALAPPDATA%\Pub\Cache\bin

Usage

Generate Dart Defines

From JSON File

Given the sample JSON File below with name env.json

{
  "log": true,
  "apiKeyA": "NeverGonnaGiveYouUp",
  "apiKeyB": "NeverGonnaLetYouDown",
  "apiKeyC": "NeverGonnaRunAround",
  "protocol": "and",
  "baseUrl": "Deserts.You",
  "port": 420
}

Assuming env.json is currently located at current working directory

fdd generate json env.json

# or if the file is located somewhere else
fdd generate json /path/to/env.json

From Formatted Env File

For this method, the env file is expected to be in this format, read line by line:

log=true
apiKeyA=NeverGonnaGiveYouUp
apiKeyB=NeverGonnaLetYouDown
apiKeyC=NeverGonnaRunAround
protocol=and
baseUrl=Deserts.You
port=420

Where key consists of alphanumeric and underscores and value consists of String-likes.

# assuming the file name is config
fdd generate env config

# or named debug.old
fdd generate env debug.old

# from somewhere else
fdd generate env /path/to/env

Generated Result

The result is expected to look like this

--dart-define=log=true --dart-define=apiKeyA=NeverGonnaGiveYouUp ...

You may copy/pipe the result from your terminal and use it directly on your flutter build/flutter run script or add it into Run/Build Configuration section on Android Studio.

Build with Dart Defines

The build command will delegate the arguments into flutter build command.

# This will delegate the dart defines into flutter build appbundle --release command
fdd build json env.json appbundle --release

# Delegates to flutter build apk --debug
fdd build env debug.old apk --debug

# Add --clean to run flutter clean before flutter build
fdd build json env.json appbundle --release --clean

# Clean and defaults to --release
fdd build json env.json appbundle --clean

Flutter Obfuscation

There is a Flutter command to obfuscate the Dart code using --obfuscate --split-debug-info=... which is optionally available by adding the parameter below.

--obfuscateSplitPath=</path_to/project_name/directory>

Outputs

The generated build files are located at the same location defined by flutter build command.

Extra: it also pipes the stdout and stderr from the flutter commands.

Additional information

Constraints

  • Values with spaces are not allowed
  • Invalid entries are skipped
  • For referencing an env file, avoid naming the file as env

TODOs

  • Integrate flutter run
  • Add contents for --help / -h arguments
  • Add more textual Error Messages
  • Add more Error classes
  • Code breakdown into smaller classes
  • Localizations

flutter_dd_cli's People

Contributors

nsneruno avatar

Watchers

 avatar

flutter_dd_cli's Issues

can't generate from env.json

I installed the package with

flutter pub global activate flutter_dd_cli

log:

ayub@192 ~ % flutter pub global activate flutter_dd_cli
Resolving dependencies...

  • flutter_dd_cli 0.2.0
  • meta 1.8.0
    Downloading flutter_dd_cli 0.2.0...
    Downloading meta 1.8.0...
    Installed executable fdd.
    Warning: Executable "fdd" runs "bin/fdd.dart", which was not found in flutter_dd_cli.
    Activated flutter_dd_cli 0.2.0.

if I don't run the command below I get an error

dart pub global activate flutter_dd_cli

error:

No active package flutter_dd_cli.

and I have installed pub-cache to env (macOs)

export PATH="$PATH":"$HOME/flutter/.pub-cache/bin"

is there something wrong with the installation steps? here is the error code

ayub@192 project % fdd generate assets/config/dev.json
Unhandled exception:
'null': Switch case fall-through at line 0.
#0 FlutterDDCLI._getFileType (package:flutter_dd_cli/flutter_dd_cli.dart:44:5)
#1 FlutterDDCLI.run (package:flutter_dd_cli/flutter_dd_cli.dart:165:39)
#2 main (file:///Users/ayub/.pub-cache/hosted/pub.dartlang.org/flutter_dd_cli-0.2.0/bin/fdd.dart:5:13)
#3 _delayEntrypointInvocation. (dart:isolate-patch/isolate_patch.dart:295:32)
#4 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:192:12)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.