nemar-cli 0.3.7-PR87.de877a0 → 0.3.7-PR90.95fefac
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +33 -5
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -274,8 +274,10 @@ Description:
|
|
|
274
274
|
|
|
275
275
|
Examples:
|
|
276
276
|
$ nemar auth setup-ssh # Set up SSH access
|
|
277
|
-
$ nemar auth setup-ssh --force # Regenerate key even if exists`).action(YGD);import{existsSync as LF}from"fs";import{basename as VGD,resolve as MF}from"path";var{spawn:AGD}=globalThis.Bun;var{spawn:P2}=globalThis.Bun;async function S$(){try{let D=P2({cmd:["deno","--version"],stdout:"pipe",stderr:"pipe"}),F=await new Response(D.stdout).text();await D.exited;let $=F.match(/deno\s+(\d+\.\d+\.\d+)/);return{installed:!0,version:$?$[1]:void 0}}catch{return{installed:!1}}}async function Gy(){try{let D=P2({cmd:["deno","run","-ERWN","jsr:@bids/validator","--version"],stdout:"pipe",stderr:"pipe"}),F=await new Response(D.stdout).text();await D.exited;let $=F.match(/(\d+\.\d+\.\d+)/);return $?$[1]:null}catch{return null}}async function S2(D,F={}){let $=["run","-ERWN","jsr:@bids/validator",D,"--json"];if(F.
|
|
278
|
-
|
|
277
|
+
$ nemar auth setup-ssh --force # Regenerate key even if exists`).action(YGD);import{existsSync as LF}from"fs";import{basename as VGD,resolve as MF}from"path";var{spawn:AGD}=globalThis.Bun;var{spawn:P2}=globalThis.Bun;async function S$(){try{let D=P2({cmd:["deno","--version"],stdout:"pipe",stderr:"pipe"}),F=await new Response(D.stdout).text();await D.exited;let $=F.match(/deno\s+(\d+\.\d+\.\d+)/);return{installed:!0,version:$?$[1]:void 0}}catch{return{installed:!1}}}async function Gy(){try{let D=P2({cmd:["deno","run","-ERWN","jsr:@bids/validator","--version"],stdout:"pipe",stderr:"pipe"}),F=await new Response(D.stdout).text();await D.exited;let $=F.match(/(\d+\.\d+\.\d+)/);return $?$[1]:null}catch{return null}}async function S2(D,F={}){let $=["run","-ERWN","jsr:@bids/validator",D,"--json"];if(F.format&&F.format!=="json")throw Error(`Conflicting flags: CLI always uses --json for internal parsing.
|
|
278
|
+
The --format flag with value "${F.format}" is not compatible.
|
|
279
|
+
To get pretty JSON output, use: nemar dataset validate --json | jq`);let B=new Set(["config","ignoreWarnings","recursive","prune","verbose","format"]);if(F.config)$.push("--config",F.config);if(F.ignoreWarnings)$.push("--ignoreWarnings");if(F.recursive)$.push("--recursive");if(F.prune)$.push("--prune");if(F.verbose)$.push("--verbose");for(let[V,A]of Object.entries(F)){if(B.has(V)||A===void 0||A===null)continue;let Z=V.replace(/([A-Z])/g,"-$1").toLowerCase();if(typeof A==="boolean"){if(A)$.push(`--${Z}`);continue}if(Array.isArray(A)){for(let U of A)$.push(`--${Z}`,String(U));continue}$.push(`--${Z}`,String(A))}let J=P2({cmd:["deno",...$],stdout:"pipe",stderr:"pipe"}),Q=await new Response(J.stdout).text(),X=await new Response(J.stderr).text(),Y=await J.exited;if(X.trim())console.error(`[BIDS Validator]: ${X.trim()}`);if(Y!==0&&!Q.trim())throw Error(X.includes("error:")?X.split(`
|
|
280
|
+
`).find((V)=>V.includes("error:"))||"Validation failed":`Validation failed with exit code ${Y}`);let G;try{G=JSON.parse(Q)}catch{throw Error(`Failed to parse validator output: ${Q.slice(0,200)}`)}let H=G.issues.issues||[],W=H.filter((V)=>V.severity==="error").length,K=H.filter((V)=>V.severity==="warning").length;return{valid:W===0,issues:H,codeMessages:G.issues.codeMessages||{},summary:G.summary,errorCount:W,warningCount:K}}function k2(D,F=!0){let $=[],B=D.issues.filter((Y)=>Y.severity==="error"),J=D.issues.filter((Y)=>Y.severity==="warning");if(D.valid)$.push(F?"\x1B[32m\u2713 Dataset is valid BIDS\x1B[0m":"\u2713 Dataset is valid BIDS");else $.push(F?"\x1B[31m\u2717 Dataset has validation errors\x1B[0m":"\u2717 Dataset has validation errors");if($.push(""),B.length>0){$.push(F?"\x1B[31mErrors:\x1B[0m":"Errors:");for(let Y of B){let G=F?`\x1B[31m${Y.code}\x1B[0m`:Y.code,H=D.codeMessages[Y.code]?.split(`
|
|
279
281
|
`)[0]||"";if($.push(` ${G}: ${H}`),$.push(` ${Y.location}`),Y.issueMessage)$.push(` ${Y.issueMessage.split(`
|
|
280
282
|
`)[0]}`)}$.push("")}if(J.length>0){$.push(F?"\x1B[33mWarnings:\x1B[0m":"Warnings:");for(let Y of J){let G=F?`\x1B[33m${Y.code}\x1B[0m`:Y.code,H=D.codeMessages[Y.code]?.split(`
|
|
281
283
|
`)[0]||"";$.push(` ${G}: ${H}`),$.push(` ${Y.location}`)}$.push("")}if($.push("Summary:"),$.push(` Files: ${D.summary.totalFiles}`),$.push(` Size: ${GGD(D.summary.size)}`),D.summary.subjects.length>0)$.push(` Subjects: ${D.summary.subjects.length}`);if(D.summary.sessions.length>0)$.push(` Sessions: ${D.summary.sessions.length}`);if(D.summary.tasks.length>0)$.push(` Tasks: ${D.summary.tasks.join(", ")}`);if(D.summary.modalities.length>0)$.push(` Modalities: ${D.summary.modalities.join(", ")}`);$.push(` Schema: BIDS ${D.summary.schemaVersion}`),$.push("");let Q=D.errorCount===1?"error":"errors",X=D.warningCount===1?"warning":"warnings";return $.push(`${D.errorCount} ${Q}, ${D.warningCount} ${X}`),$.join(`
|
|
@@ -299,7 +301,7 @@ Examples:
|
|
|
299
301
|
$ nemar dataset invite johndoe nm000104 # Invite user as collaborator
|
|
300
302
|
|
|
301
303
|
Learn More:
|
|
302
|
-
https://nemar-cli.pages.dev/commands/dataset/`);gD.command("validate").description("Validate a BIDS dataset locally using the official BIDS validator").argument("[path]","Path to BIDS dataset directory",".").option("--ignore-warnings","Only report errors, not warnings").option("-c, --config <file>","Validation config file (.bidsvalidatorrc)").option("-r, --recursive","Validate derivatives subdirectories").option("--prune","Skip sourcedata and derivatives for faster validation").option("-v, --verbose","Show verbose output").option("--json","Output results as JSON (for scripting)").option("--version-info","Show BIDS validator version info").addHelpText("after",`
|
|
304
|
+
https://nemar-cli.pages.dev/commands/dataset/`);gD.command("validate").description("Validate a BIDS dataset locally using the official BIDS validator").argument("[path]","Path to BIDS dataset directory",".").option("--ignore-warnings","Only report errors, not warnings").option("-c, --config <file>","Validation config file (.bidsvalidatorrc)").option("-r, --recursive","Validate derivatives subdirectories").option("--prune","Skip sourcedata and derivatives for faster validation").option("-v, --verbose","Show verbose output").option("--json","Output results as JSON (for scripting)").option("--version-info","Show BIDS validator version info").allowUnknownOption().addHelpText("after",`
|
|
303
305
|
Description:
|
|
304
306
|
Validates a BIDS dataset using the official BIDS validator (via Deno).
|
|
305
307
|
The validator checks dataset structure, file naming, and metadata.
|
|
@@ -307,6 +309,29 @@ Description:
|
|
|
307
309
|
Requirements:
|
|
308
310
|
Deno runtime must be installed: https://deno.com
|
|
309
311
|
|
|
312
|
+
Common Options:
|
|
313
|
+
-c, --config <file> Validation config file (.bidsvalidatorrc)
|
|
314
|
+
-r, --recursive Validate derivatives subdirectories
|
|
315
|
+
--prune Skip sourcedata and derivatives
|
|
316
|
+
-v, --verbose Show verbose output
|
|
317
|
+
--ignore-warnings Only report errors, not warnings
|
|
318
|
+
--json Output results as JSON
|
|
319
|
+
|
|
320
|
+
Additional BIDS Validator Flags (pass-through):
|
|
321
|
+
--format <format> Output format: text, json, json_pp
|
|
322
|
+
-s, --schema <URL-or-tag> Specify schema version to use
|
|
323
|
+
--maxRows <nrows> Max rows to validate in TSVs (default: 1000)
|
|
324
|
+
Use 0 for headers only, -1 for all rows
|
|
325
|
+
--ignoreNiftiHeaders Disregard NIfTI header content
|
|
326
|
+
--debug <level> Enable debug output (NOTSET, DEBUG, INFO,
|
|
327
|
+
WARN, ERROR, CRITICAL; default: ERROR)
|
|
328
|
+
--datasetTypes <types> Permitted types: raw, derivative, study
|
|
329
|
+
--blacklistModalities <m> Error on specified modalities (mri, eeg, meg, etc)
|
|
330
|
+
-o, --outfile <file> File to write validation results to
|
|
331
|
+
--color, --no-color Enable/disable color output
|
|
332
|
+
|
|
333
|
+
Note: Pass-through flags use camelCase (e.g., --maxRows not --max-rows)
|
|
334
|
+
|
|
310
335
|
Exit Codes:
|
|
311
336
|
0 - Dataset is valid
|
|
312
337
|
1 - Dataset has errors or validation failed
|
|
@@ -315,7 +340,10 @@ Examples:
|
|
|
315
340
|
$ nemar dataset validate # Validate current directory
|
|
316
341
|
$ nemar dataset validate ./my-dataset # Validate specific path
|
|
317
342
|
$ nemar dataset validate ./ds --prune # Fast validation (skip derivatives)
|
|
318
|
-
$ nemar dataset validate ./ds --json > out.json
|
|
343
|
+
$ nemar dataset validate ./ds --json > out.json
|
|
344
|
+
$ nemar dataset validate ./ds --debug INFO # Enable debug logging
|
|
345
|
+
$ nemar dataset validate ./ds --maxRows 0 # Validate headers only
|
|
346
|
+
$ nemar dataset validate ./ds --ignoreNiftiHeaders # Skip NIfTI header validation`).action(async(D,F,$)=>{if(F.versionInfo){let G=await S$();if(!G.installed)console.log(E.red("Deno is not installed")),console.log("Install Deno: https://deno.com"),process.exit(1);let H=await Gy();console.log(`BIDS Validator: ${H||"unknown"}`),console.log(`Deno: ${G.version||"unknown"}`);return}if(!D)console.log(E.red("Error: Missing required argument: path")),console.log("Usage: nemar dataset validate <path>"),process.exit(1);if(!(await S$()).installed)console.log(E.red("Error: Deno is required for BIDS validation")),console.log(),console.log("The BIDS validator runs on Deno runtime."),console.log("Install Deno with one of these commands:"),console.log(),console.log(E.cyan(" # macOS/Linux (curl)")),console.log(" curl -fsSL https://deno.land/install.sh | sh"),console.log(),console.log(E.cyan(" # macOS (Homebrew)")),console.log(" brew install deno"),console.log(),console.log(E.cyan(" # Windows (PowerShell)")),console.log(" irm https://deno.land/install.ps1 | iex"),console.log(),console.log("Learn more: https://docs.deno.com/runtime/getting_started/installation/"),process.exit(1);let J=MF(D);if(!LF(J))console.log(E.red(`Error: Path does not exist: ${J}`)),process.exit(1);let Q=MF(J,"dataset_description.json");if(!LF(Q))console.log(E.red("Error: Not a valid BIDS dataset")),console.log("Missing required file: dataset_description.json"),console.log(`Path: ${J}`),process.exit(1);let X=C("Validating BIDS dataset...").start(),Y;try{let G=new Set(["json","versionInfo"]),H={};for(let[W,K]of Object.entries(F))if(!G.has(W))H[W]=K;Y=await S2(J,H),X.succeed("Validation complete"),console.log()}catch(G){X.fail("Validation failed"),console.log(E.red(G.message)),process.exit(1)}if(F.json)console.log(JSON.stringify(Y,null,2));else console.log(k2(Y));if(!Y.valid)process.exit(1)});gD.command("upload").description("Upload a BIDS dataset to NEMAR").argument("<path>","Path to BIDS dataset directory").option("-n, --name <name>","Dataset name (defaults to directory name)").option("-d, --description <desc>","Dataset description").option("--skip-validation","Skip BIDS validation (not recommended)").option("--dry-run","Show what would be uploaded without doing it").option("-j, --jobs <number>","Parallel upload streams (default: 4)","4").option(xD,_D).option("--no","Skip confirmation and decline").addHelpText("after",`
|
|
319
347
|
Description:
|
|
320
348
|
Upload a BIDS dataset to NEMAR. The dataset will be validated, assigned
|
|
321
349
|
a unique ID (nm000XXX), and stored on GitHub (metadata) and S3 (data files).
|
|
@@ -566,7 +594,7 @@ Examples:
|
|
|
566
594
|
$ nemar sandbox # Run sandbox training
|
|
567
595
|
$ nemar sandbox status # Check if training is completed
|
|
568
596
|
$ nemar sandbox reset # Reset for re-training
|
|
569
|
-
`).action(CGD);async function CGD(){if(console.log(),console.log(E.bold("NEMAR Sandbox Training")),console.log(E.gray("Verify your setup and learn the upload workflow")),console.log(),!PD()){console.log(E.red("Not authenticated")),console.log(E.gray("Run 'nemar auth login' first"));return}let D=eD();if(D.sandboxCompleted){console.log(E.green("Sandbox training already completed!")),console.log(E.gray(`Dataset ID: ${D.sandboxDatasetId}`)),console.log(),console.log("You can upload real datasets with:"),console.log(E.cyan(" nemar dataset upload ./your-dataset")),console.log(),console.log(E.gray("To re-run training, use: nemar sandbox reset"));return}console.log(E.bold("Step 1/6: Checking prerequisites..."));let F=C("Checking git-annex and SSH...").start(),$=await A$();if(!$.allPassed){F.fail("Prerequisites check failed"),console.log(),console.log(E.red("Missing requirements:"));for(let P of $.errors)console.log(E.yellow(` - ${P}`));if(!$.githubSSH.accessible)console.log(E.gray(" Run 'nemar auth setup-ssh' to configure SSH"));return}F.succeed("All prerequisites met");let B=C("Verifying GitHub CLI authentication...").start(),J=await L$(D.githubUsername);if(!J.authenticated){B.fail("GitHub CLI not authenticated"),console.log(E.red(` ${J.error}`)),console.log(),console.log("GitHub CLI is required for sandbox training. Install and authenticate:"),console.log(E.cyan(" brew install gh # or visit https://cli.github.com/")),console.log(E.cyan(" gh auth login"));return}if(D.githubUsername&&!J.matches)B.warn("GitHub CLI user mismatch"),console.log(E.yellow(` ${J.error}`)),console.log(),console.log("Your gh CLI is authenticated as a different GitHub account than your NEMAR account."),console.log("This may cause issues with repository access. To fix:"),console.log(E.cyan(` gh auth login # Login as ${D.githubUsername}`)),console.log(),console.log(E.yellow("WARNING: If upload fails with permission errors, this mismatch is the likely cause.")),console.log();else B.succeed(`GitHub CLI authenticated as ${J.username}`);console.log(),console.log(E.bold("Step 2/6: Generating test dataset..."));let Q=C("Creating minimal BIDS structure...").start(),X;try{let P=Vy();X=P.root;let VD=Ay(P);Q.succeed(`Test dataset created (${C$(VD)})`),console.log(E.gray(` Location: ${X}`))}catch(P){Q.fail("Failed to generate test dataset"),console.log(E.red(` ${P instanceof Error?P.message:"Unknown error"}`));return}console.log(),console.log(E.bold("Step 3/6: Registering sandbox dataset..."));let Y=C("Creating dataset on NEMAR...").start(),G,H,W,K,V,A;try{let P=await z$({name:"Sandbox Training Dataset",description:"Placeholder dataset for sandbox training",files:[{path:"sub-01/eeg/sub-01_task-rest_eeg.edf",size:512000,type:"data"},{path:"dataset_description.json",size:200,type:"metadata"},{path:"participants.tsv",size:50,type:"metadata"},{path:"README",size:500,type:"metadata"},{path:"sub-01/eeg/sub-01_task-rest_eeg.json",size:300,type:"metadata"}],sandbox:!0});G=P.dataset.dataset_id,H=P.dataset.ssh_url,W=P.dataset.github_url,K=P.s3_config,V=P.dataset.s3_prefix,A=P.upload_urls||{},Y.succeed(`Sandbox dataset created: ${E.cyan(G)}`),console.log(E.gray(` GitHub: ${W}`)),await new Promise((VD)=>setTimeout(VD,1e4))}catch(P){if(Y.fail("Failed to create sandbox dataset"),P instanceof u)console.log(E.red(` ${P.message}`));else console.log(E.red(` ${P instanceof Error?P.message:"Unknown error"}`));A1(X);return}let Z=C("Accepting GitHub repository invitation...").start(),U=W?.match(/github\.com\/([a-zA-Z0-9_.-]+\/[a-zA-Z0-9_.-]+)/),L=U?U[1].replace(/\.git$/,""):null;if(!L){Z.fail("Invalid GitHub repository URL from backend"),console.log(E.red(` Received: ${W||"(empty)"}`)),console.log(E.red(" Expected format: https://github.com/owner/repo")),console.log(),console.log("This may indicate a backend issue. Please contact support."),A1(X);return}let M=await M$(L);if(M.accepted)if(M.alreadyCollaborator)Z.succeed("Already a collaborator on this repository");else Z.succeed("GitHub invitation accepted");else Z.warn("Could not auto-accept invitation"),console.log(E.yellow(` ${M.error}`)),console.log(),console.log("You may need to accept the invitation manually:"),console.log(E.cyan(` https://github.com/${L}/invitations`)),console.log();console.log(),console.log(E.bold("Step 4/6: Initializing repository..."));let w=C("Setting up git-annex...").start(),I=D.username&&D.email?{name:D.username,email:D.email}:void 0;try{await Z$(X,{author:I}),await U$(X),await N$(X,H),w.succeed("Repository initialized")}catch(P){w.fail("Failed to initialize repository"),console.log(E.red(` ${P instanceof Error?P.message:"Unknown error"}`)),A1(X);return}if(console.log(),console.log(E.bold("Step 5/6: Uploading to S3...")),Object.keys(A).length===0)console.log(E.yellow(" No data files to upload (metadata only)"));else{let P=C("Uploading test data...").start();try{let yD=0,g=Object.keys(A).length,ED=await R$(X,A,{jobs:4,onProgress:(WD)=>{if(WD.status==="completed"||WD.status==="failed")yD++,P.text=`Uploading... ${yD}/${g} files`}});if(ED.failed.length>0){P.fail(`Upload failed for ${ED.failed.length} file(s)`);for(let WD of ED.failed)console.log(E.red(` Failed: ${WD}`));if(ED.error)console.log(E.red(` Error: ${ED.error}`));console.log(),console.log(E.yellow("Sandbox training aborted due to upload failures.")),console.log(E.gray("Please check your network connection and try again.")),A1(X);return}P.succeed(`Uploaded ${ED.uploaded} file(s)`)}catch(yD){P.fail("Upload failed"),console.log(E.red(` ${yD instanceof Error?yD.message:"Unknown error"}`)),A1(X);return}let VD=C("Registering file URLs...").start();try{let yD={};for(let ED of Object.keys(A))yD[ED]=`${K.public_url}/${V}/${ED}`;let g=await w$(X,yD);if(!g.success){VD.fail(`URL registration failed for ${g.failed.length} file(s)`);for(let ED of g.failed)console.log(E.red(` Failed: ${ED}`));console.log(),console.log(E.yellow("Sandbox training aborted due to URL registration failures.")),console.log(E.gray("This may indicate a git-annex configuration issue.")),A1(X);return}VD.succeed(`Registered ${g.registered} file URLs`)}catch(yD){VD.fail("Failed to register URLs"),console.log(E.red(` ${yD instanceof Error?yD.message:"Unknown error"}`)),A1(X);return}}console.log(),console.log(E.bold("Step 6/6: Pushing to GitHub..."));let b=C("Saving and pushing...").start();try{await W5(X,"Initial sandbox training upload",I),await E5(X),b.succeed("Pushed to GitHub")}catch(P){b.fail("Failed to push to GitHub"),console.log(E.red(` ${P instanceof Error?P.message:"Unknown error"}`)),A1(X);return}let T=C("Finalizing...").start();try{await V$(G),await Iv(G),q0("sandboxCompleted",!0),q0("sandboxDatasetId",G),T.succeed("Sandbox training complete!")}catch(P){T.fail("Failed to finalize"),console.log(E.red(` ${P instanceof Error?P.message:"Unknown error"}`)),A1(X);return}A1(X),console.log(),console.log(E.green.bold("Congratulations! Sandbox training completed successfully.")),console.log(),console.log("Your setup is verified and you're ready to upload real datasets:"),console.log(E.cyan(" nemar dataset upload ./your-dataset")),console.log(),console.log(E.gray(`Sandbox dataset: ${G}`))}v$.command("status").description("Check sandbox training completion status").option("--refresh","Fetch latest status from server").action(async(D)=>{if(!PD()){console.log(E.red("Not authenticated")),console.log(E.gray("Run 'nemar auth login' first"));return}if(D.refresh){let F=C("Checking status...").start();try{let $=await Sv();if(q0("sandboxCompleted",$.sandbox_completed),$.sandbox_dataset_id)q0("sandboxDatasetId",$.sandbox_dataset_id);if(F.stop(),$.sandbox_completed){if(console.log(E.green("Sandbox training: Completed")),console.log(E.gray(` Dataset ID: ${$.sandbox_dataset_id}`)),$.sandbox_completed_at)console.log(E.gray(` Completed: ${$.sandbox_completed_at}`))}else console.log(E.yellow("Sandbox training: Not completed")),console.log(),console.log("Run sandbox training with:"),console.log(E.cyan(" nemar sandbox"))}catch($){if(F.fail("Failed to check status"),$ instanceof u)console.log(E.red(` ${$.message}`))}}else{let F=eD();if(F.sandboxCompleted)console.log(E.green("Sandbox training: Completed")),console.log(E.gray(` Dataset ID: ${F.sandboxDatasetId}`));else console.log(E.yellow("Sandbox training: Not completed")),console.log(),console.log("Run sandbox training with:"),console.log(E.cyan(" nemar sandbox"))}});v$.command("reset").description("Reset sandbox training status for re-training").option(xD,_D).option(lD,dD).action(async(D)=>{if(!PD()){console.log(E.red("Not authenticated")),console.log(E.gray("Run 'nemar auth login' first"));return}if(!eD().sandboxCompleted){console.log(E.yellow("Sandbox training not yet completed")),console.log(E.gray("Nothing to reset"));return}let $=await mD("Reset sandbox training status? You will need to complete training again.",D);if($!=="confirmed"){console.log(E.gray($==="declined"?"Skipped":"Cancelled"));return}let B=C("Resetting sandbox status...").start();try{await Pv(),z2("sandboxCompleted"),z2("sandboxDatasetId"),B.succeed("Sandbox status reset"),console.log(),console.log("Run sandbox training again with:"),console.log(E.cyan(" nemar sandbox"))}catch(J){if(B.fail("Failed to reset"),J instanceof u)console.log(E.red(` ${J.message}`));else console.log(E.red(` ${J instanceof Error?J.message:"Unknown error"}`))}});var Zy={name:"nemar-cli",version:"0.3.7-PR87.de877a0",description:"CLI for NEMAR (Neuroelectromagnetic Data Archive and Tools Resource) dataset management",type:"module",main:"dist/index.js",bin:{nemar:"dist/index.js"},scripts:{dev:"bun run src/index.ts",build:"bun build src/index.ts --outdir dist --target bun --minify && sed '1s|#!/usr/bin/env node|#!/usr/bin/env bun|' dist/index.js > dist/index.js.tmp && mv dist/index.js.tmp dist/index.js",test:"bun test",lint:"biome check src/","lint:fix":"biome check --fix src/",format:"biome format --write src/",typecheck:"tsc --noEmit",prepublishOnly:"bun run build","docs:generate":"bun run scripts/generate-docs.ts","docs:serve":"mkdocs serve","docs:build":"mkdocs build"},keywords:["nemar","bids","neuroimaging","eeg","emg","datalad","cli"],author:"NEMAR Team",license:"MIT",repository:{type:"git",url:"git+https://github.com/nemarDatasets/nemar-cli.git"},bugs:{url:"https://github.com/nemarDatasets/nemar-cli/issues"},homepage:"https://nemar-cli.pages.dev",engines:{bun:">=1.0.0"},files:["dist","README.md","LICENSE"],dependencies:{chalk:"^5.3.0",commander:"^12.1.0",conf:"^13.0.1",inquirer:"^9.2.15",ora:"^8.0.1",zod:"^3.23.8"},devDependencies:{"@biomejs/biome":"^1.9.4","@types/bcryptjs":"^3.0.0","@types/bun":"latest","@types/inquirer":"^9.0.7",bcryptjs:"^3.0.3",typescript:"^5.5.4"}};var Uy=Zy.version;var Z1=new D0;Z1.name("nemar").description(`CLI for NEMAR (Neuroelectromagnetic Data Archive and Tools Resource)
|
|
597
|
+
`).action(CGD);async function CGD(){if(console.log(),console.log(E.bold("NEMAR Sandbox Training")),console.log(E.gray("Verify your setup and learn the upload workflow")),console.log(),!PD()){console.log(E.red("Not authenticated")),console.log(E.gray("Run 'nemar auth login' first"));return}let D=eD();if(D.sandboxCompleted){console.log(E.green("Sandbox training already completed!")),console.log(E.gray(`Dataset ID: ${D.sandboxDatasetId}`)),console.log(),console.log("You can upload real datasets with:"),console.log(E.cyan(" nemar dataset upload ./your-dataset")),console.log(),console.log(E.gray("To re-run training, use: nemar sandbox reset"));return}console.log(E.bold("Step 1/6: Checking prerequisites..."));let F=C("Checking git-annex and SSH...").start(),$=await A$();if(!$.allPassed){F.fail("Prerequisites check failed"),console.log(),console.log(E.red("Missing requirements:"));for(let P of $.errors)console.log(E.yellow(` - ${P}`));if(!$.githubSSH.accessible)console.log(E.gray(" Run 'nemar auth setup-ssh' to configure SSH"));return}F.succeed("All prerequisites met");let B=C("Verifying GitHub CLI authentication...").start(),J=await L$(D.githubUsername);if(!J.authenticated){B.fail("GitHub CLI not authenticated"),console.log(E.red(` ${J.error}`)),console.log(),console.log("GitHub CLI is required for sandbox training. Install and authenticate:"),console.log(E.cyan(" brew install gh # or visit https://cli.github.com/")),console.log(E.cyan(" gh auth login"));return}if(D.githubUsername&&!J.matches)B.warn("GitHub CLI user mismatch"),console.log(E.yellow(` ${J.error}`)),console.log(),console.log("Your gh CLI is authenticated as a different GitHub account than your NEMAR account."),console.log("This may cause issues with repository access. To fix:"),console.log(E.cyan(` gh auth login # Login as ${D.githubUsername}`)),console.log(),console.log(E.yellow("WARNING: If upload fails with permission errors, this mismatch is the likely cause.")),console.log();else B.succeed(`GitHub CLI authenticated as ${J.username}`);console.log(),console.log(E.bold("Step 2/6: Generating test dataset..."));let Q=C("Creating minimal BIDS structure...").start(),X;try{let P=Vy();X=P.root;let VD=Ay(P);Q.succeed(`Test dataset created (${C$(VD)})`),console.log(E.gray(` Location: ${X}`))}catch(P){Q.fail("Failed to generate test dataset"),console.log(E.red(` ${P instanceof Error?P.message:"Unknown error"}`));return}console.log(),console.log(E.bold("Step 3/6: Registering sandbox dataset..."));let Y=C("Creating dataset on NEMAR...").start(),G,H,W,K,V,A;try{let P=await z$({name:"Sandbox Training Dataset",description:"Placeholder dataset for sandbox training",files:[{path:"sub-01/eeg/sub-01_task-rest_eeg.edf",size:512000,type:"data"},{path:"dataset_description.json",size:200,type:"metadata"},{path:"participants.tsv",size:50,type:"metadata"},{path:"README",size:500,type:"metadata"},{path:"sub-01/eeg/sub-01_task-rest_eeg.json",size:300,type:"metadata"}],sandbox:!0});G=P.dataset.dataset_id,H=P.dataset.ssh_url,W=P.dataset.github_url,K=P.s3_config,V=P.dataset.s3_prefix,A=P.upload_urls||{},Y.succeed(`Sandbox dataset created: ${E.cyan(G)}`),console.log(E.gray(` GitHub: ${W}`)),await new Promise((VD)=>setTimeout(VD,1e4))}catch(P){if(Y.fail("Failed to create sandbox dataset"),P instanceof u)console.log(E.red(` ${P.message}`));else console.log(E.red(` ${P instanceof Error?P.message:"Unknown error"}`));A1(X);return}let Z=C("Accepting GitHub repository invitation...").start(),U=W?.match(/github\.com\/([a-zA-Z0-9_.-]+\/[a-zA-Z0-9_.-]+)/),L=U?U[1].replace(/\.git$/,""):null;if(!L){Z.fail("Invalid GitHub repository URL from backend"),console.log(E.red(` Received: ${W||"(empty)"}`)),console.log(E.red(" Expected format: https://github.com/owner/repo")),console.log(),console.log("This may indicate a backend issue. Please contact support."),A1(X);return}let M=await M$(L);if(M.accepted)if(M.alreadyCollaborator)Z.succeed("Already a collaborator on this repository");else Z.succeed("GitHub invitation accepted");else Z.warn("Could not auto-accept invitation"),console.log(E.yellow(` ${M.error}`)),console.log(),console.log("You may need to accept the invitation manually:"),console.log(E.cyan(` https://github.com/${L}/invitations`)),console.log();console.log(),console.log(E.bold("Step 4/6: Initializing repository..."));let w=C("Setting up git-annex...").start(),I=D.username&&D.email?{name:D.username,email:D.email}:void 0;try{await Z$(X,{author:I}),await U$(X),await N$(X,H),w.succeed("Repository initialized")}catch(P){w.fail("Failed to initialize repository"),console.log(E.red(` ${P instanceof Error?P.message:"Unknown error"}`)),A1(X);return}if(console.log(),console.log(E.bold("Step 5/6: Uploading to S3...")),Object.keys(A).length===0)console.log(E.yellow(" No data files to upload (metadata only)"));else{let P=C("Uploading test data...").start();try{let yD=0,g=Object.keys(A).length,ED=await R$(X,A,{jobs:4,onProgress:(WD)=>{if(WD.status==="completed"||WD.status==="failed")yD++,P.text=`Uploading... ${yD}/${g} files`}});if(ED.failed.length>0){P.fail(`Upload failed for ${ED.failed.length} file(s)`);for(let WD of ED.failed)console.log(E.red(` Failed: ${WD}`));if(ED.error)console.log(E.red(` Error: ${ED.error}`));console.log(),console.log(E.yellow("Sandbox training aborted due to upload failures.")),console.log(E.gray("Please check your network connection and try again.")),A1(X);return}P.succeed(`Uploaded ${ED.uploaded} file(s)`)}catch(yD){P.fail("Upload failed"),console.log(E.red(` ${yD instanceof Error?yD.message:"Unknown error"}`)),A1(X);return}let VD=C("Registering file URLs...").start();try{let yD={};for(let ED of Object.keys(A))yD[ED]=`${K.public_url}/${V}/${ED}`;let g=await w$(X,yD);if(!g.success){VD.fail(`URL registration failed for ${g.failed.length} file(s)`);for(let ED of g.failed)console.log(E.red(` Failed: ${ED}`));console.log(),console.log(E.yellow("Sandbox training aborted due to URL registration failures.")),console.log(E.gray("This may indicate a git-annex configuration issue.")),A1(X);return}VD.succeed(`Registered ${g.registered} file URLs`)}catch(yD){VD.fail("Failed to register URLs"),console.log(E.red(` ${yD instanceof Error?yD.message:"Unknown error"}`)),A1(X);return}}console.log(),console.log(E.bold("Step 6/6: Pushing to GitHub..."));let b=C("Saving and pushing...").start();try{await W5(X,"Initial sandbox training upload",I),await E5(X),b.succeed("Pushed to GitHub")}catch(P){b.fail("Failed to push to GitHub"),console.log(E.red(` ${P instanceof Error?P.message:"Unknown error"}`)),A1(X);return}let T=C("Finalizing...").start();try{await V$(G),await Iv(G),q0("sandboxCompleted",!0),q0("sandboxDatasetId",G),T.succeed("Sandbox training complete!")}catch(P){T.fail("Failed to finalize"),console.log(E.red(` ${P instanceof Error?P.message:"Unknown error"}`)),A1(X);return}A1(X),console.log(),console.log(E.green.bold("Congratulations! Sandbox training completed successfully.")),console.log(),console.log("Your setup is verified and you're ready to upload real datasets:"),console.log(E.cyan(" nemar dataset upload ./your-dataset")),console.log(),console.log(E.gray(`Sandbox dataset: ${G}`))}v$.command("status").description("Check sandbox training completion status").option("--refresh","Fetch latest status from server").action(async(D)=>{if(!PD()){console.log(E.red("Not authenticated")),console.log(E.gray("Run 'nemar auth login' first"));return}if(D.refresh){let F=C("Checking status...").start();try{let $=await Sv();if(q0("sandboxCompleted",$.sandbox_completed),$.sandbox_dataset_id)q0("sandboxDatasetId",$.sandbox_dataset_id);if(F.stop(),$.sandbox_completed){if(console.log(E.green("Sandbox training: Completed")),console.log(E.gray(` Dataset ID: ${$.sandbox_dataset_id}`)),$.sandbox_completed_at)console.log(E.gray(` Completed: ${$.sandbox_completed_at}`))}else console.log(E.yellow("Sandbox training: Not completed")),console.log(),console.log("Run sandbox training with:"),console.log(E.cyan(" nemar sandbox"))}catch($){if(F.fail("Failed to check status"),$ instanceof u)console.log(E.red(` ${$.message}`))}}else{let F=eD();if(F.sandboxCompleted)console.log(E.green("Sandbox training: Completed")),console.log(E.gray(` Dataset ID: ${F.sandboxDatasetId}`));else console.log(E.yellow("Sandbox training: Not completed")),console.log(),console.log("Run sandbox training with:"),console.log(E.cyan(" nemar sandbox"))}});v$.command("reset").description("Reset sandbox training status for re-training").option(xD,_D).option(lD,dD).action(async(D)=>{if(!PD()){console.log(E.red("Not authenticated")),console.log(E.gray("Run 'nemar auth login' first"));return}if(!eD().sandboxCompleted){console.log(E.yellow("Sandbox training not yet completed")),console.log(E.gray("Nothing to reset"));return}let $=await mD("Reset sandbox training status? You will need to complete training again.",D);if($!=="confirmed"){console.log(E.gray($==="declined"?"Skipped":"Cancelled"));return}let B=C("Resetting sandbox status...").start();try{await Pv(),z2("sandboxCompleted"),z2("sandboxDatasetId"),B.succeed("Sandbox status reset"),console.log(),console.log("Run sandbox training again with:"),console.log(E.cyan(" nemar sandbox"))}catch(J){if(B.fail("Failed to reset"),J instanceof u)console.log(E.red(` ${J.message}`));else console.log(E.red(` ${J instanceof Error?J.message:"Unknown error"}`))}});var Zy={name:"nemar-cli",version:"0.3.7-PR90.95fefac",description:"CLI for NEMAR (Neuroelectromagnetic Data Archive and Tools Resource) dataset management",type:"module",main:"dist/index.js",bin:{nemar:"dist/index.js"},scripts:{dev:"bun run src/index.ts",build:"bun build src/index.ts --outdir dist --target bun --minify && sed '1s|#!/usr/bin/env node|#!/usr/bin/env bun|' dist/index.js > dist/index.js.tmp && mv dist/index.js.tmp dist/index.js",test:"bun test",lint:"biome check src/","lint:fix":"biome check --fix src/",format:"biome format --write src/",typecheck:"tsc --noEmit",prepublishOnly:"bun run build","docs:generate":"bun run scripts/generate-docs.ts","docs:serve":"mkdocs serve","docs:build":"mkdocs build"},keywords:["nemar","bids","neuroimaging","eeg","emg","datalad","cli"],author:"NEMAR Team",license:"MIT",repository:{type:"git",url:"git+https://github.com/nemarDatasets/nemar-cli.git"},bugs:{url:"https://github.com/nemarDatasets/nemar-cli/issues"},homepage:"https://nemar-cli.pages.dev",engines:{bun:">=1.0.0"},files:["dist","README.md","LICENSE"],dependencies:{chalk:"^5.3.0",commander:"^12.1.0",conf:"^13.0.1",inquirer:"^9.2.15",ora:"^8.0.1",zod:"^3.23.8"},devDependencies:{"@biomejs/biome":"^1.9.4","@types/bcryptjs":"^3.0.0","@types/bun":"latest","@types/inquirer":"^9.0.7",bcryptjs:"^3.0.3",typescript:"^5.5.4"}};var Uy=Zy.version;var Z1=new D0;Z1.name("nemar").description(`CLI for NEMAR (Neuroelectromagnetic Data Archive and Tools Resource)
|
|
570
598
|
|
|
571
599
|
NEMAR is a curated repository for neurophysiology data in BIDS format.
|
|
572
600
|
This CLI provides tools for uploading, downloading, and managing datasets.`).version(Uy,"-v, --version","Output the current version").option("--no-color","Disable colored output").option("--verbose","Enable verbose output").addHelpText("after",`
|
package/package.json
CHANGED