Scoop API

scoop:scoop.core:0.1.0

src/compiler/directory.scoop

Selected production source · src/compiler/directory.scoop

1package scoop.compiler
3import Array
4import Byte
5import Option.*
6import String
8/**
9 * Embeds selected files from a directory inside the defining Cone.
10 * The constant path is relative to this call's source directory. Every entry
11 * and resolved symlink target must stay inside the Cone, even when excluded.
12 * Include and exclude are array literals of constant String patterns. Include
13 * patterns form a union; exclude patterns remove matches. Matching uses full,
14 * case-sensitive relative paths with '/' separators. '*' stays in a component;
15 * '**' spans zero or more directory levels, including the root directory.
16 * Defaults include all files, including hidden files; no gitignore is applied.
17 * Files are ordered by relative path in UTF-8 byte order. Empty directories
18 * are omitted. This compile-time intrinsic cannot be used as a function reference.
19 */
20@Intrinsic("include_dir")
21public fun includeDir(
22 path: String,
23 include: Array<String> = ["**"],
24 exclude: Array<String> = []
25): EmbeddedDir
27/** One immutable file with its logical path relative to the included directory. */
28public struct EmbeddedFile(val path: String, val bytes: Array<Byte>)
30/**
31 * An immutable file table. Lookup returns the first exact path match, or None.
32 * Lookup does not expand globs, normalize paths, or access the file system.
33 */
34public struct EmbeddedDir(val files: Array<EmbeddedFile>) {
35 public operator fun get(path: String): Array<Byte>? {
36 for (file in files) {
37 if (file.path == path)
38 return Some(file.bytes)
39 }
40 return None
41 }