pub fn sync_assets(args: SyncConfig) -> Result<(), Error> {
    // validate parameters
    match std::fs::metadata(&args.asset_dir) {
        Ok(md) if md.is_dir() => {}
        _ => {
            return Err(Error::InvalidAssetPath(
                args.asset_dir.to_string_lossy().to_string(),
            ))
        }
    }
    match std::fs::metadata(&args.wrangler_path) {
        Ok(md) if md.is_file() => {}
        _ => {
            return Err(Error::MissingWranglerFile(
                args.wrangler_path.to_string_lossy().to_string(),
            ))
        }
    }
    wrangler::commands::publish::validate_bucket_location(&PathBuf::from(args.asset_dir))?;

    // create parent of output dir
    mkdir_bin_parent(args.output_path)?;

    let manifest = Manifest::new(args.wrangler_path)?;
    let mut target = manifest.get_target(None, args.preview_env)?;
    let user = GlobalUser::new()?;

    let site_namespace = add_namespace(&user, &mut target, false)?;
    let (to_upload, to_delete, asset_manifest) =
        wrangler::sites::sync(&target, &user, &site_namespace.id, &args.asset_dir)?;

    let index = make_index(&args.asset_dir, asset_manifest)?;
    write_index(&args, index)?;

    // First, upload all existing files in asset_dir directory
    StdErr::working("Uploading site files");
    let upload_progress_bar = make_progress_bar(to_upload.len(), UPLOAD_PROGRESS_TEMPLATE);
    bulk::put(
        &target,
        &user,
        &site_namespace.id,
        to_upload,
        &upload_progress_bar,
    )?;

    if let Some(pb) = upload_progress_bar {
        pb.finish_with_message("Done Uploading");
    }

    // Finally, remove any stale files
    if !to_delete.is_empty() {
        if args.prune {
            StdErr::info("Pruning stale files...");
            let delete_progress_bar = make_progress_bar(to_delete.len(), DELETE_PROGRESS_TEMPLATE);
            bulk::delete(
                &target,
                &user,
                &site_namespace.id,
                to_delete,
                &delete_progress_bar,
            )?;

            if let Some(pb) = delete_progress_bar {
                pb.finish_with_message("Done deleting");
            }
        } else {
            StdErr::message(&format!(
                "Deferred pruning [{}] stale files. Run with '--prune' later to remove them.",
                to_delete.len()
            ));
        }
    }
    Ok(())
}
/// Sync files
/// - scan the asset folder to determine which files need to be uploaded to KV storage;
/// - upload new files
/// - generate the manifest
/// - if the prune option is set, remove unreferenced files in the KV namespace
/// All the file system scanning and kv uploading is performed by wrangler library
Sync files
scan the asset folder to determine which files need to be uploaded to KV storage;
upload new files
generate the manifest
if the prune option is set, remove unreferenced files in the KV namespace
All the file system scanning and kv uploading is performed by wrangler library
Sync files scan the asset folder to determine which files need to be uploaded to KV storage ; upload new files generate the manifest if the prune option is set remove unreferenced files in the KV namespace All the file system scanning and kv uploading is performed by wrangler library
pub fn sync_assets(args: SyncConfig) -> Result<(), Error> {
    // validate parameters
    match std::fs::metadata(&args.asset_dir) {
        Ok(md) if md.is_dir() => {}
        _ => {
            return Err(Error::InvalidAssetPath(
                args.asset_dir.to_string_lossy().to_string(),
            ))
        }
    }
    match std::fs::metadata(&args.wrangler_path) {
        Ok(md) if md.is_file() => {}
        _ => {
            return Err(Error::MissingWranglerFile(
                args.wrangler_path.to_string_lossy().to_string(),
            ))
        }
    }
    wrangler::commands::publish::validate_bucket_location(&PathBuf::from(args.asset_dir))?;
    // create parent of output dir
    mkdir_bin_parent(args.output_path)?;
    let manifest = Manifest::new(args.wrangler_path)?;
    let mut target = manifest.get_target(None, args.preview_env)?;
    let user = GlobalUser::new()?;
    let site_namespace = add_namespace(&user, &mut target, false)?;
    let (to_upload, to_delete, asset_manifest) =
        wrangler::sites::sync(&target, &user, &site_namespace.id, &args.asset_dir)?;
    let index = make_index(&args.asset_dir, asset_manifest)?;
    write_index(&args, index)?;
    // First, upload all existing files in asset_dir directory
    StdErr::working("Uploading site files");
    let upload_progress_bar = make_progress_bar(to_upload.len(), UPLOAD_PROGRESS_TEMPLATE);
    bulk::put(
        &target,
        &user,
        &site_namespace.id,
        to_upload,
        &upload_progress_bar,
    )?;
    if let Some(pb) = upload_progress_bar {
        pb.finish_with_message("Done Uploading");
    }
    // Finally, remove any stale files
    if !to_delete.is_empty() {
        if args.prune {
            StdErr::info("Pruning stale files...");
            let delete_progress_bar = make_progress_bar(to_delete.len(), DELETE_PROGRESS_TEMPLATE);
            bulk::delete(
                &target,
                &user,
                &site_namespace.id,
                to_delete,
                &delete_progress_bar,
            )?;
            if let Some(pb) = delete_progress_bar {
                pb.finish_with_message("Done deleting");
            }
        } else {
            StdErr::message(&format!(
                "Deferred pruning [{}] stale files. Run with '--prune' later to remove them.",
                to_delete.len()
            ));
        }
    }
    Ok(())
}
pub fn sync_assets ( args : SyncConfig ) -> Result < ( ) , Error > { // validate parameters match std :: fs :: metadata ( & args . asset_dir ) { Ok ( md ) if md . is_dir ( ) => { } _ => { return Err ( Error :: InvalidAssetPath ( args . asset_dir . to_string_lossy ( ) . to_string ( ) , ) ) } } match std :: fs :: metadata ( & args . wrangler_path ) { Ok ( md ) if md . is_file ( ) => { } _ => { return Err ( Error :: MissingWranglerFile ( args . wrangler_path . to_string_lossy ( ) . to_string ( ) , ) ) } } wrangler :: commands :: publish :: validate_bucket_location ( & PathBuf :: from ( args . asset_dir ) ) ? ; // create parent of output dir mkdir_bin_parent ( args . output_path ) ? ; let manifest = Manifest :: new ( args . wrangler_path ) ? ; let mut target = manifest . get_target ( None , args . preview_env ) ? ; let user = GlobalUser :: new ( ) ? ; let site_namespace = add_namespace ( & user , & mut target , false ) ? ; let ( to_upload , to_delete , asset_manifest ) = wrangler :: sites :: sync ( & target , & user , & site_namespace . id , & args . asset_dir ) ? ; let index = make_index ( & args . asset_dir , asset_manifest ) ? ; write_index ( & args , index ) ? ; // First, upload all existing files in asset_dir directory StdErr :: working ( " " ) ; let upload_progress_bar = make_progress_bar ( to_upload . len ( ) , UPLOAD_PROGRESS_TEMPLATE ) ; bulk :: put ( & target , & user , & site_namespace . id , to_upload , & upload_progress_bar , ) ? ; if let Some ( pb ) = upload_progress_bar { pb . finish_with_message ( " " ) ; } // Finally, remove any stale files if ! to_delete . is_empty ( ) { if args . prune { StdErr :: info ( " " ) ; let delete_progress_bar = make_progress_bar ( to_delete . len ( ) , DELETE_PROGRESS_TEMPLATE ) ; bulk :: delete ( & target , & user , & site_namespace . id , to_delete , & delete_progress_bar , ) ? ; if let Some ( pb ) = delete_progress_bar { pb . finish_with_message ( " " ) ; } } else { StdErr :: message ( & format ! ( " " to_delete len ( ) ) ) ; } } Ok ( ( ) ) }
Sync files
 scan the asset folder to determine which files need to be uploaded to KV storage;
 upload new files
 generate the manifest
 if the prune option is set, remove unreferenced files in the KV namespace
All the file system scanning and kv uploading is performed by wrangler library
Sync files scan the asset folder to determine which files need to be uploaded to KV storage ; upload new files generate the manifest if the prune option is set remove unreferenced files in the KV namespace All the file system scanning and kv uploading is performed by wrangler library
args
SyncConfig
args
SyncConfig