#ScriptScript

#Script is a simple, fast, highly versatile and embeddable scripting language for .NET Core and .NET Apps that utilizes a familiar JavaScript inspired expressive Syntax to enable dynamic scripting of .NET Apps via controlled access to pluggable methods and arguments within a sandbox environment - ensuring scripts are encapsulated and encourages the use of reusable and testable components where live environments can be easily re-created and simulated.

#Script supports template mode (default), code mode and lisp, see how they compare in C#'s 101 LINQ Examples:

Popular Use Cases

These qualities opens #Script up to a number of new use-cases that's better suited than Razor for maintaining content-heavy websites, live documents, Email Templates and can easily introspect the state of running .NET Apps where they provide valuable insight at a glance.

Embed in .NET

After adding the ServiceStack.Common NuGet package, you can start executing #Script by initializing a ScriptContext

var context = new ScriptContext().Init();

The ScriptContext is the sandbox where all scripts are executed within, everything your script has access to and generates is maintained within the ScriptContext. Once initialized you can start using it to evaluate scripts which you can do with:

var output = context.RenderScript("Time is now: {{ now |> dateFormat('HH:mm:ss') }}");

Or if your script performs any async I/O, it can be evaluated asynchronously with:

var output = await context.RenderScriptAsync("Time is now: {{ now |> dateFormat('HH:mm:ss') }}");

See Embedding in .NET docs for how to customize and add additional functionality to your ScriptContext.

To find out how to enable unrestricted access to existing .NET Types see Scripting .NET Types.

Sharp Scripts

The easiest way to get started is to use the dotnet web tool to run a Sharp Script in watch mode by creating a text file with the .ss extension and running it with web watch <name>.ss.

Exploratory programming

Unlike most languages, #Script has 2 outputs, the side-effect of the script itself and its textual output which makes it ideal for literate programming where executable snippets can be embedded inside an executable document.

code blocks are a convenient markup for embedding executable scripts within a document without the distracting boilerplate of wrapping each statement in expression blocks. Together with web watch, #Script allows for an iterative, exploratory style of programming in a live programming environment that benefits many domains whose instant progressive feedback unleashes an unprecedented amount of productivity, one of those areas it benefits is shell scripting where the iterative feedback is invaluable in working towards a solution for automating the desired task.

Live Shell Scripting

To provide a glimpse of the productivity of this real-time exploratory programming-style, here's an example of a task we needed to automate to import and rename 48px SVG images from Material Design Icons Project folders into the form needed in the mix Gists:

YouTube: youtu.be/joXSHtfb_7g

Here we can see how we're able to progressively arrive at our solution without leaving the source code, with the watched script automatically updated at each Ctrl+S save point where we're able to easily infer its behavior from its descriptive textual output.

Explore HTTP APIs in real-time

The real-time scriptability of #Script makes it ideal for a whole host of Exploratory programming tasks that would otherwise be painful in the slow code/build/debug cycles of a compiled language like C#, like being able to cut, sort & slice HTTP APIs with ease:

YouTube: youtu.be/Yjx_9Tp91bQ

Live Querying of Databases

It also serves a great tool for data exploration, akin to a programmable SQL Studio environment with instant feedback:

YouTube: youtu.be/HCjxVJ8RyPc

That benefits from being able to maintain reusable queries in simple, executable text files that can be organized along with other shell scripts and treated like source code where it can be checked into a versionable repo, that anyone will be able to checkout and run from the command-line in Windows, macOS or Linux OS's.

Querying AWS and Azure RDBMS and File Storage Resources

Scripts have access to all built-in Scripts and ServiceStack's which makes it easy to create scripts that run against all supported RDBMS's and cloud agnostic ServiceStack.Aws and ServiceStack.Azure as seen below with the same script below performs adhoc queries against an AWS RDS PostgreSQL managed database and S3 File Storage and an Azure SQL Server Database and Azure Blob File Storage:

YouTube: youtu.be/GQvxyPHQjhM

Live Transformations

The watch mode enables an live REPL which serves as an interactive Exploratory playground that's especially useful in scripts where you want instant feedback like viewing the results of live transformations:

Sharp Apps

One use-case made possible by #Script we're extremely excited about is Sharp Apps - a new approach to dramatically simplify .NET Web App development and provide the most productive development experience possible.

Sharp Apps leverages #Script to develop entire content-rich, data-driven websites in a pure live development model without needing to write any C#, compile projects or manually refresh pages. Checkout the Spirals Sharp App below for a glimpse of the Live Development experience available:

See the Making of Spirals for a walk through on how to create the Spirals Web App from scratch.

The integrated development experience extends to end-to-end to provide a seamless installation and deployment experience where the same web dotnet tool used to develop Sharp Apps is all users need to find and install Apps locally or hosted as a server App where they're easily deployed and hosted on Linux or run within Docker - the overall Sharp Apps experience results in the easiest and fastest way to develop and deploy Web Apps in .NET!

GitHub Desktop Apps

Sharp Apps can also be published to Gists where they can be run on-the-fly without installation, they're always up-to-date, have tiny footprints are fast to download and launch that can also run locally, off-line and cross-platform across Windows, macOS and Linux OS's.

Pure Cloud Apps

Sharp Apps also enable the development of Pure Cloud Apps where the same SharpApp can be developed and run entirely on AWS S3 and RDS or Azure Blob Storage and SQL Server by just changing its app.settings.

Learn #Script

Get started learning #Script by going through the Interactive Guide and creating a Starter Project.

View the source code of this #Script Pages website to see how clean a website built with it is.

Checkout the Live LINQ examples for a fun Live programming experience to explore its querying features, as a quick preview here's a copy of the first LINQ example you can play with below:

Or can be written using different languages within the same #Script using Language Blocks and Expressions:

Language

The language itself a familiar combination of JavaScript expressions contained within Template Expressions popularized in Vue.js filters and Angular's Template Expressions whilst statements adopt Handlebars block helpers syntax. The language is also highly extensible which is pre-configured comprehensive suite of safe methods and blocks by default, but are all registered via its rich plugin functionality which can be completely removed or "shadowed" (aka overridden) where it could be used to form the basis of your own completely different DSL.

Ecosystem

In addition to the language, #Script includes a surrounding ecosystem of rich functionality adapting #Script to power a number of fun and exciting scenarios. E.g. Scripts are lazily loaded from its Virtual File System which can be configured to use any of the available Virtual File Systems and is what enables Pure Cloud Apps where entire Sharp Apps could be hosted within your AWS S3 Bucket or Azure Blob Storage.

Dynamic

It's small, lightweight footprint and built-in Hot Reloading provides a fun, clean and productive alternative to MVC Razor that's easily integrated into any web framework and runs identically in every platform ServiceStack runs on, as well as within ASP.NET MVC and ASP.NET Core MVC Controllers - in all cases, using the same high-performance implementation to asynchronously write to a forward-only OutputStream for max performance and maximum potential reuse of your Source Code.

#Script scripts are lazily loaded and late-bound for Instant Startup, doesn't require any pre-compilation, coupling to any external configuration files, build tools, designer tooling or have any special deployment requirements. It can be used as a general purpose scripting or templating language to generate any text format and includes built-in support for .html.

Encapsulated

Similar to Vue.js Components, Sharp Script's are evaluated in an Encapsulated Sandbox that enables fine-grained control over exactly what functionality and instances are available to different Scripts. They're pre-configured with a comprehensive suite of safe Default Scripts which when running in trusted contexts can easily be granted access to enhanced functionality.

Simple

#Script is designed to be incrementally adoptable where its initial form is ideal for non-programmers, that can gradually adopt more power and functionality when needed where they can leverage existing Services or MVC Controllers to enable an MVC programming model or have .html pages upgraded to use Code Pages where they can utilize the full unlimited power of the C# programming language to enable precise control over the rendering of pages and partials. Code pages take precedence and are interchangeable wherever normal .html pages are requested making them a non-invasive alternative whenever advanced functionality is required.

Free!

We believe we've only scratched the surface of what's possible with #Script and we'd love to see what new use-cases it can help achieve and help encourage an ecosystem of pluggable and reusable scripts, #Script is being developed in ServiceStack.Common which is a free library for commercial or non-commercial use.

ServiceStack's existing free-quotas only applies if you're using OrmLite, ServiceStack.Redis or exceed the allowed free-quota of ServiceStack Services.

made with by ServiceStack