@secondlayer/cli 8.14.3 → 9.0.0
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 +12 -8
- package/dist/cli.js +103 -7
- package/dist/cli.js.map +3 -3
- package/dist/plugins/index.d.ts +6 -19
- package/dist/plugins/index.js +72 -237
- package/dist/plugins/index.js.map +6 -8
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -167,6 +167,7 @@ address prefix), or globs.
|
|
|
167
167
|
sl contracts generate ./contracts/token.clar -o ./src/generated.ts
|
|
168
168
|
sl contracts generate SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9.alex-vault -o ./src/generated.ts
|
|
169
169
|
sl contracts generate "./contracts/*.clar" -o ./src/generated.ts
|
|
170
|
+
sl contracts generate --watch # regenerate on .clar / config / Clarinet.toml changes
|
|
170
171
|
```
|
|
171
172
|
|
|
172
173
|
Config-driven:
|
|
@@ -179,33 +180,36 @@ sl contracts generate # regenerates from the config
|
|
|
179
180
|
```typescript
|
|
180
181
|
// secondlayer.config.ts
|
|
181
182
|
import { defineConfig } from "@secondlayer/cli"
|
|
182
|
-
import { clarinet,
|
|
183
|
+
import { clarinet, react } from "@secondlayer/cli/plugins"
|
|
183
184
|
|
|
184
185
|
export default defineConfig({
|
|
185
186
|
out: "src/generated.ts",
|
|
186
|
-
plugins: [clarinet(),
|
|
187
|
+
plugins: [clarinet(), react()],
|
|
187
188
|
})
|
|
188
189
|
```
|
|
189
190
|
|
|
190
191
|
| Plugin | What it adds |
|
|
191
192
|
|---|---|
|
|
192
|
-
| `clarinet()` | Parse local Clarinet project |
|
|
193
|
-
| `actions()` | `read.*` + `write.*` helpers per contract |
|
|
193
|
+
| `clarinet()` | Parse local Clarinet project — includes `[project.requirements]` dependency contracts too (`includeRequirements: false` to opt out) |
|
|
194
194
|
| `react()` | Typed React Query hooks |
|
|
195
195
|
| `testing()` | Clarinet SDK test helpers |
|
|
196
196
|
|
|
197
|
+
Generated output includes named per-function type aliases (`TokenTransferArgs`,
|
|
198
|
+
`TokenTransferResult`), a `TokenTypes` bundle, and a `tokenAbi` const branded
|
|
199
|
+
with `TypedAbi` — `getContract` from `@secondlayer/stacks` picks up the brand
|
|
200
|
+
so hovers and type errors show the named aliases instead of expanded inline
|
|
201
|
+
types.
|
|
202
|
+
|
|
197
203
|
```typescript
|
|
198
204
|
import { token } from "./generated/contracts"
|
|
199
205
|
|
|
200
|
-
//
|
|
206
|
+
// Generated call descriptors compose with any tx builder:
|
|
201
207
|
await makeContractCall({
|
|
202
208
|
...token.transfer({ amount: 100n, recipient: "SP..." }),
|
|
203
209
|
network: "mainnet",
|
|
204
210
|
})
|
|
205
211
|
|
|
206
|
-
//
|
|
207
|
-
const balance = await token.read.getBalance({ account: "SP..." })
|
|
208
|
-
await token.write.transfer({ amount: 100n, recipient: "SP..." })
|
|
212
|
+
// Maps/vars/constants accessors are built in:
|
|
209
213
|
const supply = await token.vars.totalSupply.get()
|
|
210
214
|
```
|
|
211
215
|
|
package/dist/cli.js
CHANGED
|
@@ -31647,6 +31647,14 @@ async function buildConfigFromInputs(parsedInputs, outPath, apiKey, defaultAddre
|
|
|
31647
31647
|
};
|
|
31648
31648
|
}
|
|
31649
31649
|
async function generate(files, options3) {
|
|
31650
|
+
if (!options3.watch) {
|
|
31651
|
+
await runGenerate(files, options3, { exitOnError: true });
|
|
31652
|
+
return;
|
|
31653
|
+
}
|
|
31654
|
+
await runGenerate(files, options3, { exitOnError: false });
|
|
31655
|
+
await watchAndRegenerate(files, options3);
|
|
31656
|
+
}
|
|
31657
|
+
async function runGenerate(files, options3, { exitOnError }) {
|
|
31650
31658
|
try {
|
|
31651
31659
|
let config;
|
|
31652
31660
|
if (files && files.length > 0) {
|
|
@@ -31723,8 +31731,96 @@ ${getErrorMessage2(error2)}`));
|
|
|
31723
31731
|
if (process.env.DEBUG && error2 instanceof Error) {
|
|
31724
31732
|
console.error(error2.stack);
|
|
31725
31733
|
}
|
|
31726
|
-
|
|
31734
|
+
if (exitOnError) {
|
|
31735
|
+
process.exit(1);
|
|
31736
|
+
}
|
|
31737
|
+
}
|
|
31738
|
+
}
|
|
31739
|
+
function isWatchRelevant(filename) {
|
|
31740
|
+
return filename.endsWith(".clar") || filename.endsWith(".toml") || filename.startsWith("secondlayer.config");
|
|
31741
|
+
}
|
|
31742
|
+
async function collectWatchTargets(files, options3) {
|
|
31743
|
+
const { promises: fs8 } = await import("node:fs");
|
|
31744
|
+
const dirs = new Map;
|
|
31745
|
+
const addParentDir = (filePath) => {
|
|
31746
|
+
const dir = path11.dirname(path11.resolve(process.cwd(), filePath));
|
|
31747
|
+
if (!dirs.get(dir))
|
|
31748
|
+
dirs.set(dir, false);
|
|
31749
|
+
};
|
|
31750
|
+
if (files && files.length > 0) {
|
|
31751
|
+
const parsedInputs = await parseInputs(files);
|
|
31752
|
+
for (const file of parsedInputs.files) {
|
|
31753
|
+
addParentDir(file);
|
|
31754
|
+
}
|
|
31755
|
+
} else {
|
|
31756
|
+
const configPath = options3.config ? path11.resolve(process.cwd(), options3.config) : await findConfigFile(process.cwd());
|
|
31757
|
+
if (configPath)
|
|
31758
|
+
addParentDir(configPath);
|
|
31759
|
+
try {
|
|
31760
|
+
const config = await loadConfig2(options3.config);
|
|
31761
|
+
for (const contract of config.contracts || []) {
|
|
31762
|
+
if (contract.source)
|
|
31763
|
+
addParentDir(contract.source);
|
|
31764
|
+
}
|
|
31765
|
+
} catch {}
|
|
31766
|
+
const manifestPath = path11.resolve(process.cwd(), "Clarinet.toml");
|
|
31767
|
+
try {
|
|
31768
|
+
await fs8.access(manifestPath);
|
|
31769
|
+
addParentDir(manifestPath);
|
|
31770
|
+
const contractsDir = path11.resolve(process.cwd(), "contracts");
|
|
31771
|
+
try {
|
|
31772
|
+
const stat2 = await fs8.stat(contractsDir);
|
|
31773
|
+
if (stat2.isDirectory())
|
|
31774
|
+
dirs.set(contractsDir, true);
|
|
31775
|
+
} catch {}
|
|
31776
|
+
} catch {}
|
|
31727
31777
|
}
|
|
31778
|
+
return [...dirs.entries()].map(([dir, recursive]) => ({
|
|
31779
|
+
path: dir,
|
|
31780
|
+
recursive
|
|
31781
|
+
}));
|
|
31782
|
+
}
|
|
31783
|
+
async function watchAndRegenerate(files, options3) {
|
|
31784
|
+
const { watch: watch2 } = await import("node:fs");
|
|
31785
|
+
const targets = await collectWatchTargets(files, options3);
|
|
31786
|
+
if (targets.length === 0) {
|
|
31787
|
+
console.log(source_default3.yellow("⚠ Nothing to watch — no local inputs were found"));
|
|
31788
|
+
return;
|
|
31789
|
+
}
|
|
31790
|
+
console.log(source_default3.cyan(`\uD83D\uDC40 Watching ${targets.length} ${targets.length === 1 ? "location" : "locations"} for changes — press Ctrl+C to stop`));
|
|
31791
|
+
let timer3;
|
|
31792
|
+
let running = false;
|
|
31793
|
+
let rerunRequested = false;
|
|
31794
|
+
const regenerate = async (changed) => {
|
|
31795
|
+
if (running) {
|
|
31796
|
+
rerunRequested = true;
|
|
31797
|
+
return;
|
|
31798
|
+
}
|
|
31799
|
+
running = true;
|
|
31800
|
+
console.log(source_default3.gray(`↻ ${changed ? `${changed} changed` : "Change detected"} — regenerating...`));
|
|
31801
|
+
await runGenerate(files, options3, { exitOnError: false });
|
|
31802
|
+
running = false;
|
|
31803
|
+
if (rerunRequested) {
|
|
31804
|
+
rerunRequested = false;
|
|
31805
|
+
await regenerate();
|
|
31806
|
+
}
|
|
31807
|
+
};
|
|
31808
|
+
const onEvent = (filename) => {
|
|
31809
|
+
const name = typeof filename === "string" ? filename : filename?.toString();
|
|
31810
|
+
if (name && !isWatchRelevant(path11.basename(name)))
|
|
31811
|
+
return;
|
|
31812
|
+
if (timer3)
|
|
31813
|
+
clearTimeout(timer3);
|
|
31814
|
+
timer3 = setTimeout(() => void regenerate(name ?? undefined), 150);
|
|
31815
|
+
};
|
|
31816
|
+
for (const target of targets) {
|
|
31817
|
+
try {
|
|
31818
|
+
watch2(target.path, { recursive: target.recursive }, (_event, filename) => onEvent(filename));
|
|
31819
|
+
} catch {
|
|
31820
|
+
console.warn(source_default3.yellow(`⚠ Could not watch ${target.path}`));
|
|
31821
|
+
}
|
|
31822
|
+
}
|
|
31823
|
+
await new Promise(() => {});
|
|
31728
31824
|
}
|
|
31729
31825
|
async function resolveContract(source, network, apiKey, apiUrl) {
|
|
31730
31826
|
if (source.source) {
|
|
@@ -31824,7 +31920,7 @@ var {
|
|
|
31824
31920
|
// package.json
|
|
31825
31921
|
var package_default = {
|
|
31826
31922
|
name: "@secondlayer/cli",
|
|
31827
|
-
version: "
|
|
31923
|
+
version: "9.0.0",
|
|
31828
31924
|
repository: {
|
|
31829
31925
|
type: "git",
|
|
31830
31926
|
url: "git+https://github.com/ryanwaits/secondlayer.git",
|
|
@@ -31873,11 +31969,11 @@ var package_default = {
|
|
|
31873
31969
|
dependencies: {
|
|
31874
31970
|
"@inquirer/prompts": "^8.2.0",
|
|
31875
31971
|
"@secondlayer/bundler": "^0.4.0",
|
|
31876
|
-
"@secondlayer/scaffold": "^1.
|
|
31972
|
+
"@secondlayer/scaffold": "^1.4.0",
|
|
31877
31973
|
"@secondlayer/sdk": "^6.23.1",
|
|
31878
|
-
"@secondlayer/shared": "^6.41.
|
|
31879
|
-
"@secondlayer/stacks": "^2.
|
|
31880
|
-
"@secondlayer/subgraphs": "^3.19.
|
|
31974
|
+
"@secondlayer/shared": "^6.41.3",
|
|
31975
|
+
"@secondlayer/stacks": "^2.11.0",
|
|
31976
|
+
"@secondlayer/subgraphs": "^3.19.6",
|
|
31881
31977
|
"@biomejs/js-api": "^0.7.0",
|
|
31882
31978
|
"@biomejs/wasm-nodejs": "^1.9.0",
|
|
31883
31979
|
esbuild: "^0.19.0",
|
|
@@ -38149,5 +38245,5 @@ registerAccountCommand(program);
|
|
|
38149
38245
|
registerKeysCommand(program);
|
|
38150
38246
|
program.parse();
|
|
38151
38247
|
|
|
38152
|
-
//# debugId=
|
|
38248
|
+
//# debugId=4C5A2BC0BF36CBB764756E2164756E21
|
|
38153
38249
|
//# sourceMappingURL=cli.js.map
|