DartScript class Null safety

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.
read-only
doctor → void
used by the 'doctor' command to prints the details for this project.
read-only
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'.
read-only
hashCode int
The hash code for this object. [...]
read-only, inherited
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.
@visibleForTesting, read-only
isCompiled bool
True if the script is compiled.
read-only
isInstalled bool
Checks if the Script has been compiled and installed into the ~/.dcli/bin path
read-only
isPubGlobalActivated bool
True if the script has been installed via 'dart pub global active' and as such is running from the pub cache.
read-only
isReadyToRun bool
True if the script has been compiled or pre-compiled via a pub get.
read-only
pathToExe String
Returns the path to the executable if it was to be compiled into its local directory (the default action of compile).
read-only
pathToInstalledExe String
Returns the path that the script would be installed to if compiled with dcli with the --install switch.
read-only
pathToProjectRoot String
Determines the script project root. The project root is defined as the directory which contains the scripts 'pubspec.yaml' file. [...]
read-only
pathToPubSpec String
Returns the path to a scripts pubspec.yaml. The pubspec.yaml is located in the project's root directory.
read-only
pathToScript String
Absolute path to 'this' script including the script name [...]
read-only
pathToScriptDirectory String
the absolute path to the directory the script lives in
read-only
project DartProject
the project for this scrtipt.
read-only
pubsecNameKey String
the name of the script without its extension. this is used for the 'name' key in the pubspec.
read-only
pubSpec PubSpec
reads and returns the project's virtual pubspec and returns it.
read-only
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited
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.
read-only

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 non-existent 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.
toString() String
A string representation of this object. [...]
inherited

Operators

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

Static Properties

current DartScript
@Deprecated('Use DartScript.self or DartScript.fromPath()'), read-only
self DartScript
Returns the instance of the currently running script. [...]
read-only

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