Giter Club home page Giter Club logo

leaf's Introduction

Leaf

Leaf CI

A fake file system for Deno binaries by Mandarine.


Description

Leaf is a fake file system for Deno binaries. This means, you can save your files along with the binary generated by deno compile, this way, you can put all your files together in a single executable which leads to easier deployments and a more compacted deliverable output.

Usage

Using Leaf in your application is very simple, you just use the regular Deno APIs after you ran a 'leaf compile'. More on this below.

leaf compile step.

The Leaf.compile() method is responsible for creating a typescript file with your resources in it. This file is then compiled into your binary.

Leaf.compile() takes one argument containing the options to include.

// File: compile.ts
import { Leaf } from "https://deno.land/x/leaf/mod.ts";

Leaf.compile({
    modulePath: "./myEntryPoint.ts",
    contentFolders: ["./resources"],
    // flags: [],
    // output: ''
})

modulePath and contentFolders are necessary.

  • modulePath: File to be compiled into a binary.
  • contentFolders: Folders to be attached to the binary.
  • flags optional: the Deno flags normally used for deno compile.
  • output optional: Replaces the --output flags option.

readFileSync

Synchronously reads and returns the entire contents of a file as an array of bytes. TextDecoder can be used to transform the bytes to string if required. Reading a directory returns an empty data array.

const decoder = new TextDecoder("utf-8");
const data = Deno.readFileSync("hello.txt");
console.log(decoder.decode(data));

readFile

Reads and returns the entire contents of a file as an array of bytes. TextDecoder can be used to transform the bytes to string if required. Reading a directory returns an empty data array.

const decoder = new TextDecoder("utf-8");
const data = await Deno.readFile("hello.txt");
console.log(decoder.decode(data));

readTextFileSync

Synchronously reads and returns the entire contents of a file as utf8 encoded string.

const data = Deno.readTextFileSync("hello.txt");
console.log(data);

readTextFile

Reads and returns the entire contents of a file as utf8 encoded string.

const data = await Deno.readTextFile("hello.txt");
console.log(data);

Example

Compile the binary

We run the compile.ts script which creates the file system .ts which then runs deno compile to build the final binary.

// compile.ts
import { Leaf } from "https://deno.land/x/leaf/mod.ts";

Leaf.compile({
    modulePath: "./myEntryPoint.ts",
    contentFolders: ["./resources"]
})

./resources/hello.txt

Hello World

myEntryPoint.ts:

console.log(Deno.readTextFileSync("./resources/hello.txt"));
deno run --allow-all --unstable compile.ts
./myEntryPoint (.exe if windows)
# output: Hello World

Questions

For questions & community support, please visit our Discord Channel or join us on our twitter.

Want to help?

Interested in coding

In order to submit improvements to the code, open a PR and wait for it to review. We appreciate you doing this.

Not interested in coding

We would love to have you in our community, please submit an issue to provide information about a bug, feature, or improvement you would like.

Follow us wherever we are going

leaf's People

Contributors

andreespirela avatar clemens-tolboom avatar konuch avatar rotu avatar shadowtime2000 avatar ulthuan avatar

Watchers

 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.