Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rhai: rfs in all phases #604

Merged
merged 2 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions bin/src/modules/hook/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,11 @@ pub fn scope(ctx: &Context, vfs: bool) -> Result<Scope, Error> {
scope.push_constant("HEMTT_ADDONS", ctx.addons().to_vec());
if vfs {
scope.push_constant("HEMTT_VFS", ctx.workspace().vfs().clone());
} else {
scope.push_constant("HEMTT_DIRECTORY", ctx.project_folder().clone());
scope.push_constant("HEMTT_OUTPUT", ctx.build_folder().clone());
scope.push_constant("HEMTT_RFS", ctx.project_folder().clone());
scope.push_constant("HEMTT_OUT", ctx.build_folder().clone());
}
scope.push_constant("HEMTT_DIRECTORY", ctx.project_folder().clone());
scope.push_constant("HEMTT_OUTPUT", ctx.build_folder().clone());
scope.push_constant("HEMTT_RFS", ctx.project_folder().clone());
scope.push_constant("HEMTT_OUT", ctx.build_folder().clone());

scope.push_constant("HEMTT", RhaiHemtt::new(ctx));

Expand All @@ -54,10 +53,8 @@ fn engine(vfs: bool) -> Engine {
if vfs {
let virt = libraries::VfsPackage::new();
engine.register_static_module("hemtt_vfs", virt.as_shared_module());
} else {
let real = libraries::RfsPackage::new();
engine.register_static_module("hemtt_rfs", real.as_shared_module());
}
engine.register_static_module("hemtt_rfs", libraries::RfsPackage::new().as_shared_module());
engine.register_static_module("hemtt", libraries::HEMTTPackage::new().as_shared_module());
engine.register_fn("date", time::date);
engine
Expand Down Expand Up @@ -195,7 +192,7 @@ impl Module for Hooks {
self.0 = ctx.hemtt_folder().join("hooks").exists();
if self.0 {
for phase in &["pre_build", "post_build", "pre_release", "post_release"] {
let engine = engine(phase.ends_with("build"));
let engine = engine(phase != &"post_release");
let dir = ctx.hemtt_folder().join("hooks").join(phase);
if !dir.exists() {
continue;
Expand All @@ -220,7 +217,7 @@ impl Module for Hooks {
}

fn pre_release(&self, ctx: &Context) -> Result<(), Error> {
self.run_folder(ctx, "pre_release", false)
self.run_folder(ctx, "pre_release", true)
}

fn post_release(&self, ctx: &Context) -> Result<(), Error> {
Expand Down
10 changes: 5 additions & 5 deletions book/commands/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

## Development

- [hemtt new](./new.md) - Create a new project
- [hemtt dev](./dev.md) - Build the project for local development
- [hemtt launch](./launch.md) - Launch Arma 3 with your mod and dependencies
- [hemtt build](./build.md) - Build the project for local testing
- [hemtt new](./new.md) - Create a new project
- [hemtt dev](./dev.md) - Build the project for local development
- [hemtt launch](./launch.md) - Launch Arma 3 with your mod and dependencies
- [hemtt build](./build.md) - Build the project for local testing

## Release

- [hemtt release](./release.md) - Build the project for release
- [hemtt release](./release.md) - Build the project for release

## Global Options

Expand Down
4 changes: 2 additions & 2 deletions book/getting-started/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ It's important to use a version control system when developing mods. Git is the

While any text editor will work, Visual Studio Code is the recommended editor for HEMTT. It is a powerful editor that has a lot of features that will make your life easier. It has several extensions that are great for Arma 3 modding.

- [Arma 3 - Open Last RPT](https://marketplace.visualstudio.com/items?itemName=bux578.vscode-openlastrpt)
- [SQF Language](https://marketplace.visualstudio.com/items?itemName=Armitxes.sqf)
- [Arma 3 - Open Last RPT](https://marketplace.visualstudio.com/items?itemName=bux578.vscode-openlastrpt)
- [SQF Language](https://marketplace.visualstudio.com/items?itemName=Armitxes.sqf)

### [HEMTT](https://github.com/brettmayson/HEMTT)

Expand Down
40 changes: 22 additions & 18 deletions book/rhai/library/filesystem.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@ HEMTT has two types of file systems, which one is used depends on the context.

[Scripts](../scripts/index.md) always use the real file system, as they run outside of the build process.

[Hooks](../hooks/index.md) use the virtual file system during the `pre_build` and `post_build` phases, and the real file system during the `pre_release` and `post_release` phases.
[Hooks](../hooks/index.md) use the virtual file system during the `pre_build`, `post_build`, and `pre_release` phases.

## `HEMTT_VFS` - Virtual File System

`*_build` phases have a virtual file system. This means that the files are not actually written to disk. Files can be created, deleted, read from, written to, and these changes will appear only in the build output.
`pre_build`, `post_build`, and `pre_release` phases have access to the virtual file system. This means that the files are not actually written to disk. Files can be created, deleted, read from, written to, and these changes will appear only in the build output.

This is useful for modifying files with find-and-replace, or adding files to the build output, without the need for cleaning up after the build.

When using the virtual file system, the `HEMTT_VFS` constant is available. It is used as the root path.

```admonish warning
During the `pre_release` phase, only files outside of addons should be changed. PBOs are already built, and changing files inside of addons will have no effect.
```

**.hemtt/project.toml**

```toml
Expand Down Expand Up @@ -44,7 +48,7 @@ print("Set version to " + HEMTT.project().version().to_string());

## `HEMTT_RFS` - Real File System

`*_release` phases have a real file system. This means that the files are actually written to disk.
All phases and scripts have access to the real file system. This means that the files are actually written to disk.

```admonish danger
Be careful when modifying files while using the real file system, as you can destructively modify the project files. It is recommended to use the virtual file system whenever possible, and commit the changes to the project files prior to testing hooks.
Expand All @@ -65,11 +69,11 @@ version.replace("0.0.0", HEMTT.project().version().to_string());
HEMTT_OUT.join("docs").join("version.txt").create_file().write(version);
```

# Functions
## Functions

All the functions below are available on both the virtual and real file systems.

## `join(string)`
### `join(string)`

Joins the path with the given string.

Expand All @@ -78,7 +82,7 @@ HEMTT_VFS.join("addons"); // Points to ./addons in the project folder
HEMTT_VFS.join("addons").join("main"); // Points to ./addons/main in the project folder
```

## `exists()`
### `exists()`

Returns `true` if the path exists.

Expand All @@ -87,7 +91,7 @@ HEMTT_VFS.join("addons").exists(); // true
HEMTT_VFS.join(".hemtt").join("project.toml").exists(); // true
```

## `is_dir()`
### `is_dir()`

Returns `true` if the path is a directory.

Expand All @@ -96,7 +100,7 @@ HEMTT_VFS.join("addons").is_dir(); // true
HEMTT_VFS.join(".hemtt").join("project.toml").is_dir(); // false
```

## `is_file()`
### `is_file()`

Returns `true` if the path is a file.

Expand All @@ -105,7 +109,7 @@ HEMTT_VFS.join("addons").is_file(); // false
HEMTT_VFS.join(".hemtt").join("project.toml").is_file(); // true
```

## `parent()`
### `parent()`

Returns the parent directory of the path.
Will panic if the path is root while using the real file system.
Expand All @@ -116,7 +120,7 @@ HEMTT_VFS.join("addons").parent(); // Points to ./
HEMTT_VFS.join(".hemtt").join("project.toml").parent(); // Points to ./.hemtt
```

## `file_name()`
### `file_name()`

Returns the file name of the path.

Expand All @@ -125,63 +129,63 @@ HEMTT_VFS.join("addons").file_name(); // addons
HEMTT_VFS.join(".hemtt").join("project.toml").file_name(); // project.toml
```

## `copy(path)`
### `copy(path)`

Copies the file or directory to the given path.

```ts
HEMTT_VFS.join("docs").copy(HEMTT_OUT.join("docs")); // Copies the docs folder to the build output
```

## `move(path)`
### `move(path)`

Moves the file or directory to the given path.

```ts
HEMTT_VFS.join("docs").move(HEMTT_OUT.join("docs")); // Moves the docs folder to the build output
```

## `list(path)`
### `list(path)`

Lists the contents of the directory. If the path is a file, returns an empty array.

```ts
HEMTT_VFS.join("docs").list(); // Returns an array of paths of files and directories in the docs folder
```

## `open_file()`
### `open_file()`

Opens the file for reading.

```ts
HEMTT_VFS.join("docs").join("readme.md").open_file(); // Returns a File object
```

## `create_file()`
### `create_file()`

Creates the file for writing. Overwrites the file if it exists.

```ts
HEMTT_VFS.join("docs").join("readme.md").create_file(); // Returns a File object
```

## `remove_file()`
### `remove_file()`

Removes the file.

```ts
HEMTT_VFS.join("docs").join("readme.md").remove_file(); // Removes the file
```

## `read()`
### `read()`

Reads the contents of the file.

```ts
HEMTT_VFS.join("docs").join("readme.md").open_file().read(); // Returns a string containing the contents of the file
```

## `write(string)`
### `write(string)`

Writes the string to the file. Can be called multiple times to append to the file.

Expand Down
8 changes: 4 additions & 4 deletions book/rhai/library/hemtt.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ HEMTT.project().version().to_string(); // "1.3.0.1052"

Returns the current mode of HEMTT, one of:

- dev
- launch
- build
- release
- dev
- launch
- build
- release

```js
HEMTT.mode(); // "release"
Expand Down
Loading