MustafaMulla29/rp2040-bldc-motor-controller-new

A USB‑C PD–powered RP2040 BLDC motor controller PCB with 3.3 V logic, MCT8329A sensorless commutation, three MOSFET half-bridges, protected power switching, USB data, controls, and motor connectors.

Version
0.3.82
License
unset
Stars
0

scripts/export-factory-review.mjs

/** Pack native fabrication outputs with the independently reviewed assembly CSVs.
 * Does not change any Gerber copper, drill, mask, paste or silkscreen geometry.
 */
import {spawnSync} from 'node:child_process'
import {readFileSync,writeFileSync} from 'node:fs'
import {resolve,dirname} from 'node:path'
import {fileURLToPath} from 'node:url'
import {createHash} from 'node:crypto'
import {zipSync,unzipSync,strToU8} from 'fflate'
const root=resolve(dirname(fileURLToPath(import.meta.url)),'..')
function run(command,args){
 const r=spawnSync(command,args,{cwd:root,encoding:'utf8',maxBuffer:12e6})
 if(r.status!==0)throw Error((r.stdout??'')+(r.stderr??'')+String(r.error??''))
 return(r.stdout??'')+(r.stderr??'')
}
console.log(run('bun',['scripts/prepare-assembly.mjs']))
const input=resolve(root,'dist/index/circuit.json'),native=resolve(root,'dist/assembly-review/native-export.zip')
const log=run(resolve(root,'node_modules/.bin/tsci'),['export',input,'-f','gerbers','-o',native])
writeFileSync(resolve(root,'dist/assembly-review/native-export.log'),log)
console.log(run('bun',['scripts/check-native-stencil.mjs']))
const entries=unzipSync(readFileSync(native)),fab={}
// The native CSVs contain fallback positions/angles; supply the reviewed files
// separately. This is file selection, not alteration of manufacturing geometry.
for(const[name,bytes]of Object.entries(entries))if(/\.(gbr|drl)$/i.test(name))fab[name]=bytes
for(const required of ['F_Cu.gbr','In1_Cu.gbr','In2_Cu.gbr','B_Cu.gbr','F_Paste.gbr','B_Paste.gbr','drill-L1-L4.drl','drill_npth.drl','Edge_Cuts.gbr'])if(!fab[required])throw Error('Missing native fabrication file '+required)
const pack={'board-gerbers.zip':zipSync(fab)}
for(const name of ['bom.csv','cpl-reviewed.csv','assembly-scope.csv','orientation-review.json','native-stencil-review.json'])pack[name]=readFileSync(resolve(root,'dist/assembly-review',name))
for(const name of ['CURRENT-REVISION.md','assembly-instructions.md','motor-harness.md','stencil-u7.svg','stencil-u7.json','stackup.json'])pack[name]=readFileSync(resolve(root,'manufacturing',name))
pack['offboard-parts.csv']=readFileSync(resolve(root,'docs/offboard-parts.csv'))
pack['connectors-and-firmware.md']=readFileSync(resolve(root,'docs/connectors-and-firmware.md'))
pack['order-readiness.md']=readFileSync(resolve(root,'docs/order-readiness.md'))
pack['pd-only-design.md']=readFileSync(resolve(root,'docs/pd-only-design.md'))
pack['pd-config-check.json']=readFileSync(resolve(root,'dist/pd-config.json'))
pack['pd-electrical-review.json']=readFileSync(resolve(root,'dist/pd-electrical-review.json'))
pack['integration-check.json']=readFileSync(resolve(root,'dist/system/integration-check.json'))
pack['README-FIRST.txt']=strToU8('FACTORY ENGINEERING REVIEW PACKAGE — NOT PRODUCTION APPROVED\nRead assembly-instructions.md and order-readiness.md before quoting or fabrication.\nAll Gerber/drill geometry is the unmodified native tscircuit export. U7 exports six rectangular paste windows natively; review the requested R0.05 corner rounding and stencil process in the accompanying instruction.\nUse cpl-reviewed.csv for assembly; all BOM components are included. Confirm factory-library alignment in the placement preview.\nFactory approval is still required for the stencil, actual USB impedance geometry, stock and top-side placement and through-hole soldering.\nCircuit SHA-256: '+createHash('sha256').update(readFileSync(input)).digest('hex')+'\n')
const hashes=Object.fromEntries(Object.entries(pack).map(([k,v])=>[k,createHash('sha256').update(v).digest('hex')]))
pack['manifest.json']=strToU8(JSON.stringify({status:'FACTORY_REVIEW_REQUIRED',files:hashes},null,2)+'\n')
const target=resolve(root,'dist/factory-review.zip');writeFileSync(target,zipSync(pack))
console.log('Factory review package:',target)