Download packages/loop-contract-schema/bin/cli.js from cy0307/awesome-loop-engineering: direct link, hf CLI and curl.
- Browser
- Download file 1.29 kB
-
https://huggingface.co/datasets/cy0307/awesome-loop-engineering/resolve/refs%2Fpr%2F3/packages/loop-contract-schema/bin/cli.js
- Command line
-
hf download hf://datasets/cy0307/awesome-loop-engineering@refs/pr/3/packages/loop-contract-schema/bin/cli.js
-
curl -L -o cli.js https://huggingface.co/datasets/cy0307/awesome-loop-engineering/resolve/refs%2Fpr%2F3/packages/loop-contract-schema/bin/cli.js
1.29 kB
| ; | |
| const fs = require('fs'); | |
| const path = require('path'); | |
| const validate = require('../validate'); | |
| function loadSchema() { | |
| // Prefer the packaged schema; fall back to the repository copy when run in-tree. | |
| const candidates = [ | |
| path.join(__dirname, '..', 'loop-contract.schema.json'), | |
| path.join(__dirname, '..', '..', '..', 'schemas', 'loop-contract.schema.json'), | |
| ]; | |
| for (const candidate of candidates) { | |
| if (fs.existsSync(candidate)) return JSON.parse(fs.readFileSync(candidate, 'utf8')); | |
| } | |
| throw new Error('loop-contract.schema.json not found'); | |
| } | |
| function main() { | |
| const file = process.argv[2]; | |
| if (!file) { | |
| process.stderr.write('Usage: loop-contract-validate <contract.json>\n'); | |
| process.exit(2); | |
| } | |
| let data; | |
| try { | |
| data = JSON.parse(fs.readFileSync(file, 'utf8')); | |
| } catch (error) { | |
| process.stderr.write(`Could not read ${file}: ${error.message}\n`); | |
| process.exit(2); | |
| } | |
| const errors = validate(data, loadSchema(), '$'); | |
| if (errors.length === 0) { | |
| process.stdout.write(`${file}: valid loop contract\n`); | |
| process.exit(0); | |
| } | |
| process.stderr.write(`${file}: invalid loop contract\n`); | |
| for (const error of errors) process.stderr.write(`- ${error}\n`); | |
| process.exit(1); | |
| } | |
| main(); | |