feat: change project structure

This commit is contained in:
rvcas 2022-10-24 00:03:02 -04:00 committed by Lucas
parent 825783ca61
commit a41d05f7b6
4 changed files with 21 additions and 6 deletions

View File

@ -70,15 +70,26 @@ impl Project {
}
fn read_source_files(&mut self) -> Result<(), Error> {
let lib = self.root.join("lib");
let scripts = self.root.join("scripts");
let lib = self.root.join(format!("src/{}", self.config.name));
let scripts = self.root.join("src/scripts");
self.read_root_lib_file()?;
self.aiken_files(&scripts, ModuleKind::Script)?;
self.aiken_files(&lib, ModuleKind::Lib)?;
Ok(())
}
fn read_root_lib_file(&mut self) -> Result<(), Error> {
let root_lib_path = self.root.join(format!("src/{}.ak", self.config.name));
if root_lib_path.exists() {
self.add_module(root_lib_path, &self.root.join("src"), ModuleKind::Lib)?;
}
Ok(())
}
fn parse_sources(&mut self) -> Result<ParsedModules, Error> {
let mut errors = Vec::new();
let mut parsed_modules = HashMap::with_capacity(self.sources.len());
@ -235,7 +246,7 @@ impl Project {
full_module_path: &Path,
kind: ModuleKind,
) -> String {
// ../../lib/module.ak
// ../../{config.name}/module.ak
// module.ak
let mut module_path = full_module_path
@ -244,7 +255,7 @@ impl Project {
.to_path_buf();
// module
let _ = module_path.set_extension("");
module_path.set_extension("");
// Stringify
let name = module_path
@ -256,7 +267,7 @@ impl Project {
let name = name.replace('\\', "/");
// project_name/module
if kind.is_lib() {
if kind.is_lib() && name != self.config.name {
format!("{}/{}", self.config.name, name)
} else {
name

View File

@ -0,0 +1,3 @@
pub type ScriptContext {
thing: String
}

View File

@ -1,3 +1,4 @@
use sample
use sample/syntax.{append}
pub type Datum {
@ -9,7 +10,7 @@ pub type Redeemer {
Sell
}
pub fn validate(datum: Datum, rdmr: Redeemer, ctx: syntax.ScriptContext) -> Bool {
pub fn validate(datum: Datum, rdmr: Redeemer, ctx: sample.ScriptContext) -> Bool {
let thing = if True {
3
} else {