DartScript class

Used to manage a DCli script.

We expose DartScript as it permits some self discovery of the dart script you are currently running.

Constructors

DartScript.createScript({required DartProject project, required String scriptName, required String templateName})
factory
DartScript.fromFile(String scriptPathTo, {DartProject? project})
Creates a DartScript object from a dart script located at scriptPathTo.

Properties

basename String
The scriptname without its '.dart' extension.
no setter
doctor → void
used by the 'doctor' command to prints the details for this project.
no setter
exeName String
Returns the platform dependant name of the compiled script's exe name. On Linux and MacOS this is just the basename (script name without the extension) on Windows this is the 'basename.exe'.
no setter
hashCode int
The hash code for this object.
no setterinherited
inUnitTest bool
Returns true if we are running in a unit test. We do this by inspecting the stack looking for the test_api package so this method has very limited use and is intended for internal dcli testing.
no setter
isCompiled bool
True if the script is compiled.
no setter
isInstalled bool
Checks if the Script has been compiled and installed into the ~/.dcli/bin path
no setter
isPubGlobalActivated bool
True if the script has been installed via 'dart pub global active' and as such is running from the pub cache.
no setter
isReadyToRun bool
True if the script has been compiled or pre-compiled via a pub get.
no setter
pathToExe String
Returns the path to the executable if it was to be compiled into its local directory (the default action of compile).
no setter
pathToInstalledExe String
Returns the path that the script would be installed to if compiled with dcli with the --install switch.
no setter
pathToProjectRoot String
Determines the script project root. The project root is defined as the directory which contains the scripts 'pubspec.yaml' file.
no setter
pathToPubSpec String
Returns the path to a scripts pubspec.yaml. The pubspec.yaml is located in the project's root directory.
no setter
pathToScript String
Absolute path to 'this' script including the script name
no setter
pathToScriptDirectory String
the absolute path to the directory the script lives in
no setter
project DartProject
the project for this scrtipt.
no setter
pubsecNameKey String
the name of the script without its extension. this is used for the 'name' key in the pubspec.
no setter
pubSpec PubSpec
reads and returns the project's virtual pubspec and returns it.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
scriptName String
The filename of the script including the extension. If you are running in a compiled script then scriptName won't have a '.dart' extension. In a compiled script the extension generally depends on the OS but it could in theory be anything (except for .dart). Common extensions are .exe for windows and no extension for Linux and MacOS.
no setter

Methods

compile({bool install = false, bool overwrite = false, String? workingDirectory}) → void
Compiles this script and optionally installs it to ~/.dcli/bin
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
run({List<String> args = const <String>[]}) int
Runs the dart script with an optional set of args.
runPubGet() → void
Runs pub get in the script's DartProject folder.
start({List<String> args = const <String>[], Progress? progress, bool runInShell = false, bool detached = false, bool terminal = false, bool privileged = false, bool nothrow = false, String? workingDirectory, bool extensionSearch = true}) Progress
Runs the dart script with an optional set of args.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Properties

current DartScript
no setter
self DartScript
Returns the instance of the currently running script.
no setter

Static Methods

sansRoot(String path) String
Strips the root prefix of a path so we can use it as part of the virtual projects path. For linux this just removes any leading / For windows this removes c:\
stripDartVersionSuffix(String pathToCurrentScript) String
internal method do not use.
validate(String scriptPath) → void
validate that the passed arguments points to a valid script