@secondlayer/cli 3.5.4 → 3.5.6

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/README.md CHANGED
@@ -27,6 +27,11 @@ sl subgraphs deploy subgraphs/my-contract.ts --start-block <recent-block>
27
27
  sl subgraphs query my-contract <table> --sort _block_height --order desc
28
28
  ```
29
29
 
30
+ `sl subgraphs scaffold` writes the definition file, creates or updates
31
+ `package.json`, and runs `bun install` by default so the generated import is
32
+ deployable immediately. Pass `--no-install` to skip the install and run
33
+ `bun install` manually in the output directory.
34
+
30
35
  Then wire a receiver:
31
36
 
32
37
  ```bash
@@ -128,7 +133,7 @@ invocation. No long-lived key on disk.
128
133
  | `sl subgraphs stop <name>` | Pause processing |
129
134
  | `sl subgraphs gaps <name>` | List missing block ranges |
130
135
  | `sl subgraphs delete <name>` | Drop the subgraph + its schema |
131
- | `sl subgraphs scaffold <SP...::contract>` | Generate a starter subgraph from a deployed contract |
136
+ | `sl subgraphs scaffold <SP...::contract> [-o <path>] [--no-install]` | Generate a starter subgraph from a deployed contract, write/amend `package.json`, and install dependencies unless skipped |
132
137
  | `sl subgraphs generate <name>` | Regenerate TS types for an existing subgraph |
133
138
 
134
139
  ### Local dev + OSS
package/dist/cli.js CHANGED
@@ -26406,7 +26406,7 @@ var require_cross_spawn = __commonJS((exports, module) => {
26406
26406
  var cp = __require("child_process");
26407
26407
  var parse2 = require_parse3();
26408
26408
  var enoent = require_enoent();
26409
- function spawn(command, args, options3) {
26409
+ function spawn2(command, args, options3) {
26410
26410
  const parsed = parse2(command, args, options3);
26411
26411
  const spawned = cp.spawn(parsed.command, parsed.args, parsed.options);
26412
26412
  enoent.hookChildProcess(spawned, parsed);
@@ -26418,8 +26418,8 @@ var require_cross_spawn = __commonJS((exports, module) => {
26418
26418
  result.error = result.error || enoent.verifyENOENTSync(result.status, parsed);
26419
26419
  return result;
26420
26420
  }
26421
- module.exports = spawn;
26422
- module.exports.spawn = spawn;
26421
+ module.exports = spawn2;
26422
+ module.exports.spawn = spawn2;
26423
26423
  module.exports.sync = spawnSync;
26424
26424
  module.exports._parse = parse2;
26425
26425
  module.exports._enoent = enoent;
@@ -31750,7 +31750,7 @@ var init_promise = __esm(() => {
31750
31750
 
31751
31751
  // ../../node_modules/execa/lib/methods/main-async.js
31752
31752
  import { setMaxListeners } from "node:events";
31753
- import { spawn } from "node:child_process";
31753
+ import { spawn as spawn2 } from "node:child_process";
31754
31754
  var execaCoreAsync = (rawFile, rawArguments, rawOptions, createNested) => {
31755
31755
  const { file, commandArguments, command, escapedCommand, startTime, verboseInfo, options: options3, fileDescriptors } = handleAsyncArguments(rawFile, rawArguments, rawOptions);
31756
31756
  const { subprocess, promise } = spawnSubprocessAsync({
@@ -31795,7 +31795,7 @@ var execaCoreAsync = (rawFile, rawArguments, rawOptions, createNested) => {
31795
31795
  }, spawnSubprocessAsync = ({ file, commandArguments, options: options3, startTime, verboseInfo, command, escapedCommand, fileDescriptors }) => {
31796
31796
  let subprocess;
31797
31797
  try {
31798
- subprocess = spawn(...concatenateShell(file, commandArguments, options3));
31798
+ subprocess = spawn2(...concatenateShell(file, commandArguments, options3));
31799
31799
  } catch (error2) {
31800
31800
  return handleEarlyError({
31801
31801
  error: error2,
@@ -32439,7 +32439,7 @@ var {
32439
32439
  // package.json
32440
32440
  var package_default = {
32441
32441
  name: "@secondlayer/cli",
32442
- version: "3.5.4",
32442
+ version: "3.5.6",
32443
32443
  description: "CLI for subgraphs and blockchain indexing on Stacks",
32444
32444
  type: "module",
32445
32445
  bin: {
@@ -34315,6 +34315,7 @@ async function resyncDatabase(skipConfirm, backfill) {
34315
34315
  }
34316
34316
  }
34317
34317
  // src/commands/subgraphs.ts
34318
+ import { spawn } from "node:child_process";
34318
34319
  import {
34319
34320
  existsSync as existsSync3,
34320
34321
  mkdirSync as mkdirSync2,
@@ -34637,6 +34638,32 @@ function ensureScaffoldPackageJson(dir) {
34637
34638
  writeFileSync2(packagePath, `${JSON.stringify(pkg, null, 2)}
34638
34639
  `, "utf8");
34639
34640
  }
34641
+ async function runBunInstall(dir) {
34642
+ await new Promise((resolvePromise, reject) => {
34643
+ const proc = spawn("bun", ["install"], {
34644
+ cwd: dir,
34645
+ stdio: "inherit"
34646
+ });
34647
+ proc.on("error", reject);
34648
+ proc.on("close", (exitCode, signal) => {
34649
+ if (exitCode === 0) {
34650
+ resolvePromise();
34651
+ return;
34652
+ }
34653
+ if (exitCode !== null) {
34654
+ reject(new Error(`bun install exited with code ${exitCode}`));
34655
+ return;
34656
+ }
34657
+ reject(new Error(`bun install exited with signal ${signal}`));
34658
+ });
34659
+ });
34660
+ }
34661
+ async function installScaffoldDependencies(dir, options2 = {}) {
34662
+ if (options2.install === false)
34663
+ return "skipped";
34664
+ await (options2.installer ?? runBunInstall)(dir);
34665
+ return "installed";
34666
+ }
34640
34667
  function createSubgraphDeployPreview(def, options2 = {}) {
34641
34668
  const tableColumns = Object.entries(def.schema).map(([table, schema]) => `${table}: ${Object.keys(schema.columns).join(", ") || "(no columns)"}`);
34642
34669
  return {
@@ -35117,7 +35144,7 @@ ${rows.length} row(s)`));
35117
35144
  handleApiError(err, "delete subgraph");
35118
35145
  }
35119
35146
  });
35120
- subgraphs.command("scaffold <contractAddress>").description("Scaffold a defineSubgraph() file from a contract ABI").option("-o, --output <path>", "Output file path (required)").option("--api-key <key>", "Stacks node API key for direct RPC URLs").action(async (contractAddress, options2) => {
35147
+ subgraphs.command("scaffold <contractAddress>").description("Scaffold a defineSubgraph() file from a contract ABI").option("-o, --output <path>", "Output file path (required)").option("--api-key <key>", "Stacks node API key for direct RPC URLs").option("--no-install", "Skip bun install after writing package.json").action(async (contractAddress, options2) => {
35121
35148
  try {
35122
35149
  if (!options2.output) {
35123
35150
  error("--output <path> is required");
@@ -35141,6 +35168,18 @@ ${rows.length} row(s)`));
35141
35168
  await writeTextFile(outPath, content);
35142
35169
  ensureScaffoldPackageJson(dir);
35143
35170
  success(`Created ${outPath}`);
35171
+ if (options2.install === false) {
35172
+ info(`Run: cd ${dir} && bun install`);
35173
+ } else {
35174
+ info("Installing dependencies with bun install...");
35175
+ try {
35176
+ await installScaffoldDependencies(dir);
35177
+ } catch (err) {
35178
+ error(`Dependency install failed: ${err instanceof Error ? err.message : String(err)}`);
35179
+ info(`Run: cd ${dir} && bun install`);
35180
+ process.exit(1);
35181
+ }
35182
+ }
35144
35183
  info(`Next: sl subgraphs deploy ${options2.output}`);
35145
35184
  } catch (err) {
35146
35185
  error(`Failed to scaffold subgraph: ${err}`);
@@ -36197,12 +36236,12 @@ function registerInstanceCommand(program2) {
36197
36236
  });
36198
36237
  instance.command("delete").description("Permanently delete your instance + all data").option("--yes", "Skip typed-slug confirm").action(async (opts) => {
36199
36238
  guardOssMode();
36200
- const info_ = await httpPlatform("/api/tenants/me").catch(() => null);
36201
- if (!info_?.tenant) {
36239
+ const tenant = await fetchCurrentTenant();
36240
+ if (!tenant) {
36202
36241
  warn("No instance to delete.");
36203
36242
  return;
36204
36243
  }
36205
- const slug = info_.tenant.slug;
36244
+ const slug = tenant.slug;
36206
36245
  if (!opts.yes) {
36207
36246
  if (!process.stdin.isTTY) {
36208
36247
  error(`Refusing to prompt in a non-interactive terminal. Re-run with --yes to delete instance "${slug}".`);
@@ -36219,6 +36258,13 @@ function registerInstanceCommand(program2) {
36219
36258
  await httpPlatform("/api/tenants/me", { method: "DELETE" });
36220
36259
  success("Instance deleted.");
36221
36260
  } catch (err) {
36261
+ const afterDelete = await fetchCurrentTenant().catch(() => {
36262
+ return;
36263
+ });
36264
+ if (afterDelete === null) {
36265
+ success("Instance deleted.");
36266
+ return;
36267
+ }
36222
36268
  handleInstanceError(err, "delete");
36223
36269
  }
36224
36270
  });
@@ -36341,19 +36387,29 @@ async function requireActiveProject() {
36341
36387
  }
36342
36388
  return active.slug;
36343
36389
  }
36344
- async function renderInstanceInfo() {
36390
+ async function fetchCurrentTenant() {
36345
36391
  try {
36346
36392
  const res = await httpPlatform("/api/tenants/me");
36347
- if (!res.tenant) {
36393
+ return res.tenant;
36394
+ } catch (err) {
36395
+ if (err instanceof CliHttpError && err.status === 404) {
36396
+ return null;
36397
+ }
36398
+ throw err;
36399
+ }
36400
+ }
36401
+ async function renderInstanceInfo() {
36402
+ try {
36403
+ const tenant = await fetchCurrentTenant();
36404
+ if (!tenant) {
36348
36405
  info("No instance for the active project. Run `sl instance create --plan launch`.");
36349
36406
  return;
36350
36407
  }
36351
- const t = res.tenant;
36352
36408
  console.log(formatKeyValue([
36353
- ["URL", t.apiUrl],
36354
- ["Plan", t.plan],
36355
- ["Status", t.status],
36356
- ["Created", new Date(t.createdAt).toLocaleString()]
36409
+ ["URL", tenant.apiUrl],
36410
+ ["Plan", tenant.plan],
36411
+ ["Status", tenant.status],
36412
+ ["Created", new Date(tenant.createdAt).toLocaleString()]
36357
36413
  ]));
36358
36414
  } catch (err) {
36359
36415
  handleInstanceError(err, "fetch instance");
@@ -36582,5 +36638,5 @@ registerLocalCommand(program);
36582
36638
  registerAccountCommand(program);
36583
36639
  program.parse();
36584
36640
 
36585
- //# debugId=96B7A917235EEA4164756E2164756E21
36641
+ //# debugId=CA129D1D7E8ADE9A64756E2164756E21
36586
36642
  //# sourceMappingURL=cli.js.map