shibosoftwaredev/f1c100s-linux-nema17-stepper-controller

A four-layer NEMA 17 motor-controller PCB combining an Allwinner F1C100S Linux computer, USB‑PD/buck power system, W5500 Ethernet, STM32 real-time motion control, DRV8825 stepper driver, protection/temperature/current telemetry, USB interfaces, and local LED/buzzer diagnostics.

Version
0.4.56
License
unset
Stars
0

scripts/recover-round3-publication.mjs

import fs from "node:fs"
import path from "node:path"
import os from "node:os"
import assert from "node:assert/strict"
import crypto from "node:crypto"
import {gzipSync} from "node:zlib"

const manifest=JSON.parse(fs.readFileSync("reports/round3-publish-manifest.json","utf8"))
const nameWithVersion=`${manifest.packageName}@${manifest.version}`
const config=JSON.parse(fs.readFileSync(path.join(os.homedir(),"Library/Preferences/tscircuit-nodejs/config.json"),"utf8"))
const token=process.env.TSCIRCUIT_TOKEN??config.sessionToken;assert.ok(token)
async function post(endpoint,body){
  const response=await fetch("https://registry-api.tscircuit.com/"+endpoint,{method:"POST",
    headers:{authorization:`Bearer ${token}`,"content-type":"application/json"},body:JSON.stringify(body),signal:AbortSignal.timeout(240000)})
  if(!response.ok)throw Error(`${endpoint}: HTTP ${response.status}: ${(await response.text()).slice(0,350)}`)
  return response.json()
}
const release=(await post("package_releases/get",{package_name_with_version:nameWithVersion})).package_release
const pkg=(await post("packages/get",{name:manifest.packageName})).package
assert.ok([manifest.previous.latestReleaseId,release.package_release_id].includes(pkg.latest_package_release_id))
const mode=process.argv[2]
if(mode==="--restore-latest"){
  if(pkg.latest_package_release_id!==manifest.previous.latestReleaseId)
    await post("package_releases/update",{package_release_id:manifest.previous.latestReleaseId,is_latest:true})
  const after=(await post("packages/get",{name:manifest.packageName})).package
  assert.equal(after.latest_package_release_id,manifest.previous.latestReleaseId)
  console.log(JSON.stringify({latestRestored:true,latestVersion:after.latest_version,pendingReleaseId:release.package_release_id}))
}else if(mode==="--upload"){
  assert.equal(pkg.latest_package_release_id,manifest.previous.latestReleaseId,"hold published latest during recovery")
  const files=manifest.files.map(file=>{
    const bytes=fs.readFileSync(path.join(manifest.destination,file.file))
    assert.equal(crypto.createHash("sha256").update(bytes).digest("hex"),file.sha256)
    const binary=bytes.subarray(0,8192).includes(0)||/\.(png|jpe?g|gif|webp|glb|gltf|obj|stl|zip|gz|tar)$/i.test(file.file)
    return binary?{file_path:file.file,content_base64:bytes.toString("base64")}:{file_path:file.file,content_text:bytes.toString("utf8")}
  })
  const archive=gzipSync(JSON.stringify({files}),{level:9})
  console.log(JSON.stringify({uploading:true,files:files.length,compressedBytes:archive.length,releaseId:release.package_release_id}))
  await post("package_files/upload_archive",{package_name_with_version:nameWithVersion,archive_base64:archive.toString("base64")})
  console.log(JSON.stringify({archiveUploaded:true,files:files.length,releaseId:release.package_release_id}))
}else if(mode==="--ready"){
  await post("package_releases/update",{package_release_id:release.package_release_id,ready_to_build:true})
  console.log(JSON.stringify({buildRequested:true,releaseId:release.package_release_id}))
}else throw Error("expected --restore-latest, --upload or --ready")