Check all nested KCL samples (#6880)
This commit is contained in:
		
							
								
								
									
										7
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										7
									
								
								Makefile
									
									
									
									
									
								
							@ -44,15 +44,15 @@ endif
 | 
			
		||||
# BUILD
 | 
			
		||||
 | 
			
		||||
CARGO_SOURCES := rust/.cargo/config.toml $(wildcard rust/Cargo.*) $(wildcard rust/**/Cargo.*)
 | 
			
		||||
KCL_SOURCES := $(wildcard public/kcl-samples/**/*.kcl)
 | 
			
		||||
RUST_SOURCES := $(wildcard rust/**/*.rs)
 | 
			
		||||
 | 
			
		||||
REACT_SOURCES := $(wildcard src/*.tsx) $(wildcard src/**/*.tsx)
 | 
			
		||||
TYPESCRIPT_SOURCES := tsconfig.* $(wildcard src/*.ts) $(wildcard src/**/*.ts)
 | 
			
		||||
VITE_SOURCES := $(wildcard vite.*) $(wildcard vite/**/*.tsx)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
.PHONY: build
 | 
			
		||||
build: install public/kcl_wasm_lib_bg.wasm .vite/build/main.js
 | 
			
		||||
build: install public/kcl_wasm_lib_bg.wasm public/kcl-samples/manifest.json .vite/build/main.js
 | 
			
		||||
 | 
			
		||||
public/kcl_wasm_lib_bg.wasm: $(CARGO_SOURCES) $(RUST_SOURCES)
 | 
			
		||||
ifdef WINDOWS
 | 
			
		||||
@ -61,6 +61,9 @@ else
 | 
			
		||||
	npm run build:wasm:dev
 | 
			
		||||
endif
 | 
			
		||||
 | 
			
		||||
public/kcl-samples/manifest.json: $(KCL_SOURCES)
 | 
			
		||||
	cd rust/kcl-lib && EXPECTORATE=overwrite cargo test generate_manifest
 | 
			
		||||
 | 
			
		||||
.vite/build/main.js: $(REACT_SOURCES) $(TYPESCRIPT_SOURCES) $(VITE_SOURCES)
 | 
			
		||||
	npm run tronb:vite:dev
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -122,7 +122,6 @@
 | 
			
		||||
    "files:invalidate-bucket:nightly": "./scripts/invalidate-files-bucket.sh --nightly",
 | 
			
		||||
    "postinstall": "electron-rebuild",
 | 
			
		||||
    "generate:machine-api": "npx openapi-typescript ./openapi/machine-api.json -o src/lib/machine-api.d.ts",
 | 
			
		||||
    "generate:samples-manifest": "cd public/kcl-samples && node generate-manifest.js",
 | 
			
		||||
    "tron:start": "electron-forge start",
 | 
			
		||||
    "chrome:test": "PLATFORM=web NODE_ENV=development playwright test --config=playwright.config.ts --project='Google Chrome' --grep-invert=@snapshot",
 | 
			
		||||
    "tronb:vite:dev": "vite build -c vite.main.config.ts -m development && vite build -c vite.preload.config.ts -m development && vite build -c vite.renderer.config.ts -m development",
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										1
									
								
								rust/Cargo.lock
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										1
									
								
								rust/Cargo.lock
									
									
									
										generated
									
									
									
								
							@ -1959,6 +1959,7 @@ dependencies = [
 | 
			
		||||
 "url",
 | 
			
		||||
 "uuid",
 | 
			
		||||
 "validator",
 | 
			
		||||
 "walkdir",
 | 
			
		||||
 "wasm-bindgen",
 | 
			
		||||
 "wasm-bindgen-futures",
 | 
			
		||||
 "web-sys",
 | 
			
		||||
 | 
			
		||||
@ -85,6 +85,7 @@ tynm = "0.1.10"
 | 
			
		||||
url = { version = "2.5.4", features = ["serde"] }
 | 
			
		||||
uuid = { workspace = true, features = ["v4", "v5", "js", "serde"] }
 | 
			
		||||
validator = { version = "0.20.0", features = ["derive"] }
 | 
			
		||||
walkdir = "2.5.0"
 | 
			
		||||
web-time = "1.1"
 | 
			
		||||
winnow = "=0.6.24"
 | 
			
		||||
zip = { workspace = true }
 | 
			
		||||
 | 
			
		||||
@ -8,6 +8,7 @@ use std::{
 | 
			
		||||
use anyhow::Result;
 | 
			
		||||
use fnv::FnvHashSet;
 | 
			
		||||
use serde::{Deserialize, Serialize};
 | 
			
		||||
use walkdir::WalkDir;
 | 
			
		||||
 | 
			
		||||
use super::Test;
 | 
			
		||||
 | 
			
		||||
@ -250,19 +251,12 @@ fn get_kcl_metadata(project_path: &Path, files: &[String]) -> Option<KclMetadata
 | 
			
		||||
    let title = lines[0].trim_start_matches(COMMENT_PREFIX).trim().to_string();
 | 
			
		||||
    let description = lines[1].trim_start_matches(COMMENT_PREFIX).trim().to_string();
 | 
			
		||||
 | 
			
		||||
    // Get the path components
 | 
			
		||||
    let path_components: Vec<String> = full_path_to_primary_kcl
 | 
			
		||||
        .components()
 | 
			
		||||
        .map(|comp| comp.as_os_str().to_string_lossy().to_string())
 | 
			
		||||
        .collect();
 | 
			
		||||
 | 
			
		||||
    // Get the last two path components
 | 
			
		||||
    let len = path_components.len();
 | 
			
		||||
    let path_from_project_dir = if len >= 2 {
 | 
			
		||||
        format!("{}/{}", path_components[len - 2], path_components[len - 1])
 | 
			
		||||
    } else {
 | 
			
		||||
        primary_kcl_file.clone()
 | 
			
		||||
    };
 | 
			
		||||
    // Get the relative path from the project directory to the primary KCL file
 | 
			
		||||
    let path_from_project_dir = full_path_to_primary_kcl
 | 
			
		||||
        .strip_prefix(INPUTS_DIR.as_path())
 | 
			
		||||
        .unwrap_or(&full_path_to_primary_kcl)
 | 
			
		||||
        .to_string_lossy()
 | 
			
		||||
        .to_string();
 | 
			
		||||
 | 
			
		||||
    let mut files = files.to_vec();
 | 
			
		||||
    files.sort();
 | 
			
		||||
@ -281,21 +275,23 @@ fn get_kcl_metadata(project_path: &Path, files: &[String]) -> Option<KclMetadata
 | 
			
		||||
fn generate_kcl_manifest(dir: &Path) -> Result<()> {
 | 
			
		||||
    let mut manifest = Vec::new();
 | 
			
		||||
 | 
			
		||||
    // Collect all directory entries first and sort them by name for consistent ordering
 | 
			
		||||
    let mut entries: Vec<_> = fs::read_dir(dir)?
 | 
			
		||||
        .filter_map(Result::ok)
 | 
			
		||||
        .filter(|e| e.path().is_dir())
 | 
			
		||||
    // Collect all directory entries first
 | 
			
		||||
    let mut entries: Vec<_> = WalkDir::new(dir)
 | 
			
		||||
        .follow_links(true)
 | 
			
		||||
        .into_iter()
 | 
			
		||||
        .filter_map(|e| e.ok())
 | 
			
		||||
        .collect();
 | 
			
		||||
 | 
			
		||||
    // Sort directories by name for consistent ordering
 | 
			
		||||
    entries.sort_by_key(|a| a.file_name());
 | 
			
		||||
    entries.sort_by_key(|a| a.file_name().to_string_lossy().to_string());
 | 
			
		||||
 | 
			
		||||
    // Loop through all directories and add to manifest if KCL sample
 | 
			
		||||
    for entry in entries {
 | 
			
		||||
        let project_path = entry.path();
 | 
			
		||||
        let path = entry.path();
 | 
			
		||||
 | 
			
		||||
        if project_path.is_dir() {
 | 
			
		||||
        if path.is_dir() {
 | 
			
		||||
            // Get all .kcl files in the directory
 | 
			
		||||
            let files: Vec<String> = fs::read_dir(&project_path)?
 | 
			
		||||
            let files: Vec<String> = fs::read_dir(path)?
 | 
			
		||||
                .filter_map(Result::ok)
 | 
			
		||||
                .filter(|e| {
 | 
			
		||||
                    if let Some(ext) = e.path().extension() {
 | 
			
		||||
@ -311,7 +307,7 @@ fn generate_kcl_manifest(dir: &Path) -> Result<()> {
 | 
			
		||||
                continue;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if let Some(metadata) = get_kcl_metadata(&project_path, &files) {
 | 
			
		||||
            if let Some(metadata) = get_kcl_metadata(path, &files) {
 | 
			
		||||
                manifest.push(metadata);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user