Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,18 @@ jobs:
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Lint
run: npm run lint
- name: Lint and format
run: npm run fix

- name: Fail if lint/format produced changes
run: |
if ! git diff --exit-code --quiet || ! git diff --cached --exit-code --quiet; then
echo "::error::Lint/format produced uncommitted changes. Run \`npm run fix\` locally and commit."
echo "=== DIFF ==="
git diff
echo "=== END DIFF ==="
exit 1
fi

- name: Typecheck
run: npm run typecheck
Expand Down
171 changes: 170 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,175 @@ npx canton-dev-tools check-dar-version-policy --all
npx canton-dev-tools check-dar-version-policy --extra-policy-paths scripts/codegen,libs/splice
npx canton-dev-tools check-upgrade-compat
npx canton-dev-tools sync-splice-dars
npx canton-dev-tools codegen-js
npx canton-dev-tools bundle-dependencies
npx canton-dev-tools create-root-index
npx canton-dev-tools fix-splice-refs --target lib
npx canton-dev-tools prepare-release --changelog-repo Fairmint/canton-assets
```

`backup-dar` / version-policy / upgrade-compat skip `Test` packages by default. Pass `--package` with the daml.yaml name, source dir, or a fuzzy alias (e.g. `wrappedAssets`).

### `codegen-js` (Phase 1)

Generic DAML → JS bindings steps for packages that declare `codegen.js` in `daml.yaml`:

1. `dpm codegen-js` in each `generated/build/<pkg>` (expects `prepare-build` already done)
2. Stamp generated `package.json` name/version from the repo root
3. Write per-package `index.js` / `index.d.ts`
4. Fix Splice namespace refs on generated `lib/` trees (optional `@fairmint/*` → `__bundled__` rewrite when present)

### Phase 2: `bundle-dependencies` + `create-root-index`

Config-driven stdlib/Splice bundling and merged published `lib/` creation. Driven by
`daml-js-bundle.json` (or `--config` / `package.json` → `cantonDevTools.damlJsBundle`).
**No product package names are hardcoded** in canton-dev-tools — consumers select presets and
describe their root index in JSON.

```bash
npx canton-dev-tools bundle-dependencies [--root <dir>] [--config <path>]
npx canton-dev-tools create-root-index [--root <dir>] [--config <path>]
npx canton-dev-tools fix-splice-refs --target lib
```

Built-in presets (stdlib / Splice only):

| Preset id | Bundles |
| ----------------------------- | ---------------------------------------------------------------------- |
| `da-internal-template` | `ghc-stdlib-DA-Internal-Template` (always applied) |
| `featured-app-v1` | `splice-api-featured-app-v1` |
| `featured-app-v2` | `splice-api-featured-app-v2` (only when amulet needs it) |
| `amulet` | `splice-amulet-<pin>` |
| `da-time-types` | `daml-stdlib-DA-Time-Types` |
| `da-types` | `daml-prim-DA-Types` |
| `da-set-types` | `daml-stdlib-DA-Set-Types` |
| `splice-token-v1` | token burn/mint, metadata, holding, allocation\*, transfer-instruction |
| `splice-token-standard-utils` | `splice-token-standard-utils-<pin>` |

Pins (optional): `pins.amulet` (default `0.1.19`), `pins.tokenStandardUtils` (default `2.0.0`).

Example `daml-js-bundle.json` (assets-like shape; product names belong in the **consumer** config):

```json
{
"generatedJsDir": "generated/js",
"presets": [
"da-internal-template",
"featured-app-v1",
"featured-app-v2",
"amulet",
"da-time-types",
"da-types",
"da-set-types",
"splice-token-v1",
"splice-token-standard-utils"
],
"pins": {
"amulet": "0.1.19",
"tokenStandardUtils": "2.0.0"
},
"rootIndex": {
"outputDir": "lib",
"sourcePackage": { "namePrefix": "WrappedAssets" },
"copy": ["DA", "Splice", "__bundled__", "WrappedAssets"],
"namespaces": ["WrappedAssets", "DA", "Splice"],
"templateConstants": {
"WRAPPED_ASSETS_TEMPLATES": {
"burnMintFactory": {
"from": "./WrappedAssets/BurnMint/module",
"binding": "WrappedAssetsBurnMintFactory"
},
"burnOffer": {
"from": "./WrappedAssets/BurnOffer/module",
"binding": "BurnOffer"
},
"wrappedAsset": {
"from": "./WrappedAssets/Holding/module",
"binding": "WrappedAsset"
},
"frozenWrappedAsset": {
"from": "./WrappedAssets/Holding/module",
"binding": "FrozenWrappedAsset"
}
}
},
"postBundlePresets": [
"da-time-types",
"da-types",
"splice-token-v1",
"splice-token-standard-utils",
"da-set-types"
]
}
}
```

Or point at the file from `package.json`:

```json
{
"cantonDevTools": {
"damlJsBundle": "./daml-js-bundle.json"
}
}
```

Library imports:

```ts
import {
runCodegenJs,
bundleDependencies,
createRootIndex,
fixSpliceRefs,
resolveDamlJsBundleConfig,
BUNDLE_PRESET_IDS,
} from '@fairmint/canton-dev-tools/daml';
```

Example consumer scripts:

```json
{
"scripts": {
"prepare-build": "canton-dev-tools prepare-build",
"codegen": "npm run build && canton-dev-tools codegen-js && canton-dev-tools bundle-dependencies && canton-dev-tools create-root-index && canton-dev-tools fix-splice-refs --target lib",
"prepare-release": "canton-dev-tools prepare-release"
}
}
```

NFT / CapTable merge hooks stay consumer-local (out of scope for Phase 2).

Optional publish suffixes in root `package.json` (multi-package repos):

```json
{
"cantonDevTools": {
"codegenPublishSuffixes": {
"OpenCapTableReports-v01": "reports",
"WrappedAssets-v01": null
}
}
}
```

`null` publishes as the root package name. A single codegen package defaults to the root name.

Library imports (Phase 1 helpers):

```ts
import {
runCodegenJs,
createPackageIndexes,
updateGeneratedPackagesFromRoot,
fixSpliceRefs,
collapseManifestLines,
verifyPackageImports,
applyGeneratedImportRewrites,
} from '@fairmint/canton-dev-tools/daml';
```

### `check-dar-version-policy` extra watch paths

By default, auto-selection only treats package `daml.yaml` / `daml/` sources and `dars/<package>/`
Expand Down Expand Up @@ -97,7 +262,11 @@ Optional overrides, in order:
### Library import

```ts
import { prepareBuild, discoverManagedPackages } from '@fairmint/canton-dev-tools/daml';
import {
prepareBuild,
discoverManagedPackages,
runCodegenJs,
} from '@fairmint/canton-dev-tools/daml';
```

## TypeScript helpers
Expand Down
11 changes: 10 additions & 1 deletion bin/canton-dev-tools
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,19 @@ DAML package commands (from a multi-package repo root):
check-upgrade-compat
sync-splice-dars [--config <path>] [--force]
install-dpm-sdks
codegen-js [--root <dir>] [--skip-dpm]
bundle-dependencies [--root <dir>] [--config <path>]
create-root-index [--root <dir>] [--config <path>]
fix-splice-refs [--root <dir>] [--target <dir>]
prepare-release [--root <dir>] [--changelog-repo owner/repo]
collapse-manifest

One-liners:
npx @fairmint/canton-dev-tools start
npx @fairmint/canton-dev-tools prepare-build
npx @fairmint/canton-dev-tools codegen-js
npx @fairmint/canton-dev-tools bundle-dependencies
npx @fairmint/canton-dev-tools create-root-index

Environment:
CANTON_LOCALNET_QUICKSTART_DIR Use an existing cn-quickstart/quickstart directory
Expand Down Expand Up @@ -212,7 +221,7 @@ main() {
fi
exit 0
;;
prepare-build | verify-dars | backup-dar | check-dar-version-policy | check-upgrade-compat | check-upgrade-compatibility | sync-splice-dars)
prepare-build | verify-dars | backup-dar | check-dar-version-policy | check-upgrade-compat | check-upgrade-compatibility | sync-splice-dars | codegen-js | bundle-dependencies | create-root-index | fix-splice-refs | prepare-release | collapse-manifest)
shift || true
run_daml_cli "${command}" "$@"
;;
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"localnet:cip56-transfer": "CANTON_CIP56_REQUIRE_LOCALNET=1 tsx scripts/run-cip56-transfer-smoke.ts",
"pack:check": "npm run check:package-artifacts",
"prepack": "npm run clean && npm run build",
"prepare": "tsc -p tsconfig.json",
"prepare-release": "tsx scripts/prepare-release.ts",
"prepublishOnly": "npm run prepack",
"test": "npm run -s typecheck && jest",
Expand Down
Loading
Loading