Skip to content

Commit

Permalink
breaking refactor with argh; tag 0.9.0-a1
Browse files Browse the repository at this point in the history
  • Loading branch information
tiye committed Jul 6, 2024
1 parent 7dae7b4 commit 620a9ee
Show file tree
Hide file tree
Showing 11 changed files with 206 additions and 364 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
run: >
yarn
&& yarn tsc
&& cargo run --bin cr calcit/test.cirru --emit-js --once
&& cargo run --bin cr calcit/test.cirru --once js
&& ln -s ../../ node_modules/@calcit/procs
&& cp -v scripts/main.mjs js-out/
&& node js-out/main.mjs
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
run: >
yarn
&& yarn tsc
&& cargo run --bin cr calcit/test.cirru --emit-js --once
&& cargo run --bin cr calcit/test.cirru --once js
&& ln -s ../../ node_modules/@calcit/procs
&& cp -v scripts/main.mjs js-out/
&& node js-out/main.mjs
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ builds/
.DS_Store

/profile.json

.DS_Store
115 changes: 23 additions & 92 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "calcit"
version = "0.8.59"
version = "0.9.0-a1"
authors = ["jiyinyiyong <[email protected]>"]
edition = "2021"
license = "MIT"
Expand All @@ -24,7 +24,7 @@ cirru_edn = "0.6.11"
# cirru_edn = { path = "/Users/chenyong/repo/cirru/edn.rs" }
cirru_parser = "0.1.31"
# cirru_parser = { path = "/Users/chenyong/repo/cirru/parser.rs" }
clap = "4.5.7"
argh = "0.1.12"
dirs = "5.0.1"
lazy_static = "1.4.0"
notify = "6.1.1"
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ To use Calcit in GitHub Actions, try [setup-cr](https://github.com/calcit-lang/s
Snippets evaling:

```bash
cr -e 'range 100'
cr eval 'range 100'
```

multi-lines snippet:

```bash
cr -e '
cr eval '
println "|a demo"
Expand Down Expand Up @@ -85,8 +85,8 @@ cr compact.cirru --entry server
It compiles to JavaScript and runs in consistet semantics. However it might require a lot of JavaScript interop.

```bash
cr compact.cirru --emit-js # compile to js
cr compact.cirru --emit-js --emit-path=out/ # compile to js and save in `out/`
cr compact.cirru js # compile to js
cr compact.cirru js --emit-path=out/ # compile to js and save in `out/`
```

By default, js code is generated to `js-out/`. You will need Vite or Node to run it, from an entry file:
Expand Down Expand Up @@ -139,12 +139,12 @@ I use these commands to run local examples:
cargo run --bin cr -- calcit/test.cirru -1

# run tests in Node.js
cargo run --bin cr -- calcit/test.cirru --emit-js -1 && yarn try-js
cargo run --bin cr -- calcit/test.cirru -1 js && yarn try-js

# run snippet
cargo run --bin cr -- -e 'range 100'
cargo run --bin cr -- eval 'range 100'

cr compact.cirru --emit-ir # compiles intermediate representation into program-ir.cirru
cr compact.cirru -1 ir # compiles intermediate representation into program-ir.cirru
```

- [Cirru Parser](https://github.com/Cirru/parser.rs) for indentation-based syntax parsing.
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@calcit/procs",
"version": "0.8.59",
"version": "0.9.0-a1",
"main": "./lib/calcit.procs.mjs",
"devDependencies": {
"@types/node": "^20.11.28",
Expand All @@ -10,12 +10,12 @@
"compile": "rm -rfv lib/* && tsc",
"procs-link": "ln -s ../../ node_modules/@calcit/procs",
"cp-mac": "cargo build --release && rm -rfv builds/* && node scripts/cp-version.js && scp builds/* [email protected]:/web-assets/repo/calcit-lang/binaries/macos/",
"eval": "cargo run --bin cr -- -e",
"eval": "cargo run --bin cr -- eval",
"check-all": "yarn compile && yarn try-rs && yarn try-js && yarn try-ir",
"try-rs": "cargo run --bin cr -- calcit/test.cirru -1",
"try-js-brk": "cargo run --bin cr -- calcit/test.cirru --emit-js -1 && node --inspect-brk js-out/main.mjs",
"try-js": "cargo run --bin cr -- calcit/test.cirru --emit-js -1 && node js-out/main.mjs",
"try-ir": "cargo run --bin cr -- calcit/test.cirru --emit-ir -1"
"try-js-brk": "cargo run --bin cr -- calcit/test.cirru -1 js && node --inspect-brk js-out/main.mjs",
"try-js": "cargo run --bin cr -- calcit/test.cirru -1 js && node js-out/main.mjs",
"try-ir": "cargo run --bin cr -- calcit/test.cirru -1 js"
},
"repository": {
"type": "git",
Expand Down
71 changes: 26 additions & 45 deletions src/bin/bundle_calcit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use std::{
sync::Arc,
};

use argh::FromArgs;

use calcit::snapshot::{ChangesDict, CodeEntry};
use calcit::snapshot::{FileChangeInfo, FileInSnapShot};

Expand All @@ -22,10 +24,13 @@ use cirru_edn::{Edn, EdnMapView, EdnRecordView, EdnTag};
use cirru_parser::Cirru;

pub fn main() -> io::Result<()> {
let cli_matches = parse_cli();
let verbose = cli_matches.get_flag("verbose");
let base_dir = Path::new(cli_matches.get_one::<String>("src").expect("src"));
let out_path = Path::new(cli_matches.get_one::<String>("out").expect("out"));
let cli_args: TopLevelBundleCalcit = argh::from_env();

let verbose = cli_args.verbose;
let src = cli_args.src.as_deref().unwrap_or("src");
let base_dir = Path::new(&src);
let out = cli_args.out.as_deref().unwrap_or("./");
let out_path = Path::new(&out);
let out_file = match out_path.extension() {
Some(ext) => {
let ext_str = ext.to_str().expect("ext");
Expand All @@ -38,12 +43,9 @@ pub fn main() -> io::Result<()> {
None => out_path.join("compact.cirru"),
};
let inc_file_path = out_path.join(".compact-inc.cirru");
let no_watcher = cli_matches.get_flag("once");
let no_watcher = cli_args.once;

let package_file = Path::new(cli_matches.get_one::<String>("src").expect("src"))
.parent()
.expect("parent path")
.join("package.cirru");
let package_file = base_dir.parent().expect("parent path").join("package.cirru");

perform_compaction(base_dir, &package_file, &out_file, &inc_file_path, verbose)?;

Expand Down Expand Up @@ -272,42 +274,21 @@ fn load_files_to_edn(package_file: &Path, base_dir: &Path, verbose: bool) -> Res

pub const CALCIT_VERSION: &str = env!("CARGO_PKG_VERSION");

fn parse_cli() -> clap::ArgMatches {
clap::Command::new("Calcit Bundle")
.version(CALCIT_VERSION)
.author("Jon. <[email protected]>")
.about("Calcit Bundler")
.arg(
clap::Arg::new("src")
.help("source folder")
.default_value("src/")
.short('s')
.long("src")
.num_args(1),
)
.arg(
clap::Arg::new("out")
.help("output folder")
.default_value("./") // TODO a better default value
.short('o')
.long("out")
.num_args(1),
)
.arg(
clap::Arg::new("verbose")
.help("verbose mode")
.short('v')
.long("verbose")
.num_args(0),
)
.arg(
clap::Arg::new("once")
.help("run without watcher")
.short('1')
.long("once")
.num_args(0),
)
.get_matches()
#[derive(FromArgs, PartialEq, Debug)]
/// Top-level command.
pub struct TopLevelBundleCalcit {
/// source folder
#[argh(option, short = 's')]
pub src: Option<String>,
/// output folder
#[argh(option, short = 'o')]
pub out: Option<String>,
/// verbose mode
#[argh(switch, short = 'v')]
pub verbose: bool,
/// run without watcher
#[argh(switch, short = '1')]
pub once: bool,
}

// simulate an IO error with String
Expand Down
Loading

0 comments on commit 620a9ee

Please sign in to comment.