Code Monkey home page Code Monkey logo

mtg's Introduction

Automate Boring Tasks with Deno and the Command Line


we have lots of repetitive tasks that we do manually

<iframe src="https://giphy.com/embed/lZfU9MnEJ4di0" width="480" height="478" frameBorder="0" class="giphy-embed" allowFullScreen></iframe>

via GIPHY


lets help you go from feeling like this

<iframe src="https://giphy.com/embed/wvQIqJyNBOCjK" width="480" height="387" frameBorder="0" class="giphy-embed" allowFullScreen></iframe>

via GIPHY

<iframe src="https://giphy.com/embed/5eFp76zhsq3uw" width="480" height="277" frameBorder="0" class="giphy-embed" allowFullScreen></iframe>

via GIPHY


to this, with the power of the command line

<iframe src="https://giphy.com/embed/YQitE4YNQNahy" width="480" height="270" frameBorder="0" class="giphy-embed" allowFullScreen></iframe>

via GIPHY


What is Deno?


Okay Mr. Deno Shill, but what is Deno actually?

  • An runtime environment for Javascript/Typescript
  • Set of tools to help build Javascript/Typescript projects (bundler, compiler, language server, task runner, test runner, REPL, documentation generator, AND more)
  • Designed to be edge-native (Netlify wrote their new "Edge Functions" platform on top of Deno)
  • An attempt by the original creator of Node (Ryan Dahl) to correct his biggest mistakes when building Node

Why should I care?

<iframe src="https://giphy.com/embed/tmQrpA8zpG4a16SSxm" width="480" height="480" frameBorder="0" class="giphy-embed" allowFullScreen></iframe>

via GIPHY


Why should I care?

  • Playing with new tools in the web ecosystem can be fun!
  • While Deno was not designed specifically for scripts, it's damn good at handling them

Why should I care?

  • Out-of-the-box Typescript support
  • Bundler & compiler included (can compile your scripts down to a single binary if you want!)
  • You add the specific version of a package to your dependencies list so that it doesn't break down the line
  • Deno's permissions system is well thought out (opt-in to permissions, unlike Node)
  • You have access to most of the native Web APIs that you already know and use a lot (Promises, fetch, top-level async/await, etc)

Adding a package

In Node

  • find a package on https://npmjs.com or via your favorite search engine
  • Install the package from your favorite package manager (npm, yarn, pnpm)
    • npm i better-sqlite3

Adding a package

In Deno

  • search for a package on your favorite search engine
  • does that package host the version online for you?
    • If yes, grab the URL and add it to your dependencies
    • If no, check one of https://esm.sh or https://skypack.dev to see if the package is supported with ESM and add their link to your dependencies

Adding a package (contd...)

In Deno

  • most common Deno packages are available on Deno's Third Party Modules hosting platform (https://deno.land/x)

Getting Set Up with Deno (Installing)


Getting Set Up with Deno (Editor)

Editor setup documentation

VSCode

  • Search for Deno or vscode_deno in the Extensions

Basics of Deno: Running a script

  • Running: deno run <path-to-file>
  • Compiling to a binary: deno compile <path-to-file>

Basics of Deno: Permissions System

Permissions system documentation

All of the different permissions flags you can use:

  • --allow-env, --allow-hrtime, --allow-net, --allow-ffi, --allow-read, --allow-write, --allow-run, --allow-all/-A

Basics of Deno: Config file

Configuration file documentation

  • deno.json or deno.jsonc is supported as a JSON configuration file
  • compilerOptions: provides same options as in a tsconfig.json file
  • tasks: similar to the scripts in a package.json file, instructs Deno's task runner
  • and more! (import_map, lint, test, fmt)

Basics of Deno: Import Maps

  • Browser standard that Deno has now implemented
  • Convention in Deno before was to use a deps.ts file where you import all of your dependencies, and export them aliased
// deps.ts
export {
  Database,
  Row,
} from 'https://deno.land/x/[email protected]/mod.ts';
// myProgram.ts
import { Database, Row } from './deps.ts';

Basics of Deno: Import Maps

Import map documentation

  • Define our dependencies in a JSON format, give them aliases that we will use in our project
  • Keeps firmly-versioned dependencies from the URL like Deno prefers, gives developers easier way to import dependencies in the project with lower mental overhead

When is the fun gonna start happening?

<iframe src="https://giphy.com/embed/10fxZavhBFXsUE" width="480" height="349" frameBorder="0" class="giphy-embed" allowFullScreen></iframe>

via GIPHY


Adding our first dependency: Cliffy

Cliffy's documentation

  • Package that gives us CLI superpowers in Deno
  • Common UI components that we would want to use while building command line interfaces

Live coding time!

<iframe src="https://giphy.com/embed/LRVnPYqM8DLag" width="480" height="269" frameBorder="0" class="giphy-embed" allowFullScreen></iframe>

via GIPHY


Extra resources


Thank you for listening, any questions?

<iframe src="https://giphy.com/embed/W1ecIq4sEofza" width="480" height="270" frameBorder="0" class="giphy-embed" allowFullScreen></iframe>

via GIPHY


Get this repo up and running

  1. git clone the repository to $HOME/mtg (your home folder)
  2. configure the .env and .env.defaults files to hold the proper key/value pairs for your zoom and google meet links
  3. run deno task dev to run the script!

mtg's People

Contributors

smithbm21 avatar smithbm2316 avatar

Stargazers

 avatar

Watchers

 avatar  avatar

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.