create-dig-app 0.1.1

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.
Files changed (119) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +217 -0
  3. package/bin/create-dig-app.js +17 -0
  4. package/lib/cli.js +438 -0
  5. package/lib/index.js +235 -0
  6. package/lib/nft-cli.js +265 -0
  7. package/lib/nft-metadata.js +515 -0
  8. package/lib/substitute.js +47 -0
  9. package/lib/templates.js +185 -0
  10. package/package.json +51 -0
  11. package/templates/dapp-window-chia/README.md +63 -0
  12. package/templates/dapp-window-chia/_env.example +7 -0
  13. package/templates/dapp-window-chia/_gitignore +10 -0
  14. package/templates/dapp-window-chia/dig.toml +17 -0
  15. package/templates/dapp-window-chia/index.html +12 -0
  16. package/templates/dapp-window-chia/package.json +24 -0
  17. package/templates/dapp-window-chia/src/App.jsx +91 -0
  18. package/templates/dapp-window-chia/src/main.jsx +10 -0
  19. package/templates/dapp-window-chia/src/styles.css +71 -0
  20. package/templates/dapp-window-chia/src/wallet.js +47 -0
  21. package/templates/dapp-window-chia/vite.config.js +14 -0
  22. package/templates/next-static/README.md +41 -0
  23. package/templates/next-static/_gitignore +6 -0
  24. package/templates/next-static/app/globals.css +49 -0
  25. package/templates/next-static/app/layout.jsx +14 -0
  26. package/templates/next-static/app/page.jsx +18 -0
  27. package/templates/next-static/dig.toml +17 -0
  28. package/templates/next-static/next.config.mjs +11 -0
  29. package/templates/next-static/package.json +16 -0
  30. package/templates/nft-collection/README.md +119 -0
  31. package/templates/nft-collection/_env.example +5 -0
  32. package/templates/nft-collection/_gitignore +9 -0
  33. package/templates/nft-collection/assets/banner.svg +11 -0
  34. package/templates/nft-collection/assets/icon.svg +10 -0
  35. package/templates/nft-collection/collection.json +14 -0
  36. package/templates/nft-collection/dig.toml +23 -0
  37. package/templates/nft-collection/images/sample-1.svg +5 -0
  38. package/templates/nft-collection/images/sample-2.svg +5 -0
  39. package/templates/nft-collection/licenses/.gitkeep +1 -0
  40. package/templates/nft-collection/metadata/.gitkeep +2 -0
  41. package/templates/nft-collection/package.json +18 -0
  42. package/templates/nft-collection/scripts/dig-nft.mjs +479 -0
  43. package/templates/nft-collection/src/mint.js +72 -0
  44. package/templates/nft-collection/src/styles.css +64 -0
  45. package/templates/nft-collection/traits.csv +3 -0
  46. package/templates/nft-drop/README.md +71 -0
  47. package/templates/nft-drop/_env.example +7 -0
  48. package/templates/nft-drop/_gitignore +10 -0
  49. package/templates/nft-drop/dig.toml +18 -0
  50. package/templates/nft-drop/index.html +12 -0
  51. package/templates/nft-drop/package.json +24 -0
  52. package/templates/nft-drop/src/App.jsx +91 -0
  53. package/templates/nft-drop/src/main.jsx +10 -0
  54. package/templates/nft-drop/src/mint.js +72 -0
  55. package/templates/nft-drop/src/styles.css +70 -0
  56. package/templates/nft-drop/vite.config.js +13 -0
  57. package/templates/static-site/README.md +41 -0
  58. package/templates/static-site/_gitignore +5 -0
  59. package/templates/static-site/dig.toml +19 -0
  60. package/templates/static-site/package.json +10 -0
  61. package/templates/static-site/scripts/build.mjs +14 -0
  62. package/templates/static-site/src/index.html +20 -0
  63. package/templates/static-site/src/styles.css +49 -0
  64. package/templates/vite-react/README.md +42 -0
  65. package/templates/vite-react/_gitignore +5 -0
  66. package/templates/vite-react/dig.toml +17 -0
  67. package/templates/vite-react/index.html +12 -0
  68. package/templates/vite-react/package.json +20 -0
  69. package/templates/vite-react/src/App.jsx +18 -0
  70. package/templates/vite-react/src/main.jsx +10 -0
  71. package/templates/vite-react/src/styles.css +49 -0
  72. package/templates/vite-react/vite.config.js +9 -0
  73. package/templates-ts/dapp-window-chia/README.md +67 -0
  74. package/templates-ts/dapp-window-chia/_env.example +7 -0
  75. package/templates-ts/dapp-window-chia/_gitignore +10 -0
  76. package/templates-ts/dapp-window-chia/dig.toml +17 -0
  77. package/templates-ts/dapp-window-chia/index.html +12 -0
  78. package/templates-ts/dapp-window-chia/package.json +28 -0
  79. package/templates-ts/dapp-window-chia/src/App.tsx +93 -0
  80. package/templates-ts/dapp-window-chia/src/main.tsx +13 -0
  81. package/templates-ts/dapp-window-chia/src/styles.css +71 -0
  82. package/templates-ts/dapp-window-chia/src/vite-env.d.ts +11 -0
  83. package/templates-ts/dapp-window-chia/src/wallet.ts +62 -0
  84. package/templates-ts/dapp-window-chia/tsconfig.json +20 -0
  85. package/templates-ts/dapp-window-chia/vite.config.ts +14 -0
  86. package/templates-ts/next-static/README.md +43 -0
  87. package/templates-ts/next-static/_gitignore +7 -0
  88. package/templates-ts/next-static/app/globals.css +49 -0
  89. package/templates-ts/next-static/app/layout.tsx +16 -0
  90. package/templates-ts/next-static/app/page.tsx +18 -0
  91. package/templates-ts/next-static/dig.toml +17 -0
  92. package/templates-ts/next-static/next-env.d.ts +5 -0
  93. package/templates-ts/next-static/next.config.mjs +11 -0
  94. package/templates-ts/next-static/package.json +23 -0
  95. package/templates-ts/next-static/tsconfig.json +21 -0
  96. package/templates-ts/nft-drop/README.md +74 -0
  97. package/templates-ts/nft-drop/_env.example +7 -0
  98. package/templates-ts/nft-drop/_gitignore +10 -0
  99. package/templates-ts/nft-drop/dig.toml +18 -0
  100. package/templates-ts/nft-drop/index.html +12 -0
  101. package/templates-ts/nft-drop/package.json +28 -0
  102. package/templates-ts/nft-drop/src/App.tsx +93 -0
  103. package/templates-ts/nft-drop/src/main.tsx +13 -0
  104. package/templates-ts/nft-drop/src/mint.ts +86 -0
  105. package/templates-ts/nft-drop/src/styles.css +70 -0
  106. package/templates-ts/nft-drop/src/vite-env.d.ts +11 -0
  107. package/templates-ts/nft-drop/tsconfig.json +20 -0
  108. package/templates-ts/nft-drop/vite.config.ts +13 -0
  109. package/templates-ts/vite-react/README.md +44 -0
  110. package/templates-ts/vite-react/_gitignore +5 -0
  111. package/templates-ts/vite-react/dig.toml +17 -0
  112. package/templates-ts/vite-react/index.html +12 -0
  113. package/templates-ts/vite-react/package.json +24 -0
  114. package/templates-ts/vite-react/src/App.tsx +18 -0
  115. package/templates-ts/vite-react/src/main.tsx +13 -0
  116. package/templates-ts/vite-react/src/styles.css +49 -0
  117. package/templates-ts/vite-react/src/vite-env.d.ts +1 -0
  118. package/templates-ts/vite-react/tsconfig.json +20 -0
  119. package/templates-ts/vite-react/vite.config.ts +9 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 DIG Network
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,217 @@
1
+ # create-dig-app
2
+
3
+ Scaffold a wallet-wired, deployable **DIG Network** app — **free, no mint**. The JS front door for
4
+ building dapps, frontends, and NFT collections on Chia.
5
+
6
+ > **Prefer Rust?** [`digstore new`](https://docs.dig.net/docs/build-a-dapp/scaffold) scaffolds the same
7
+ > starters from the CLI — `create-dig-app` and `digstore new` are the two front doors to the same
8
+ > templates (the `static-site` / `vite-react` / … ids match).
9
+
10
+ ```sh
11
+ npm create dig-app@latest my-app -- --template vite-react
12
+
13
+ # …or scaffold the TypeScript variant:
14
+ npm create dig-app@latest my-app -- --template vite-react --typescript
15
+ ```
16
+
17
+ …or run it with no arguments for an interactive picker (it asks for the name, template, **and
18
+ JavaScript-or-TypeScript**):
19
+
20
+ ```sh
21
+ npm create dig-app@latest
22
+ ```
23
+
24
+ `create-dig-app` writes a runnable starter project: a `dig.toml` manifest, a real app you can build,
25
+ and (for the wallet templates) `@dignetwork/dig-sdk` already wired in. Then it prints your next
26
+ steps. It has **no runtime dependencies** and works on Node 18+.
27
+
28
+ ## JavaScript or TypeScript
29
+
30
+ Every buildable template ships in **both JavaScript (default) and TypeScript**. Pick TypeScript with
31
+ `--typescript` (`--ts`, or `--lang ts`), or choose it in the interactive prompt. The TypeScript
32
+ variant adds a `tsconfig.json`, `.ts`/`.tsx` sources, the `typescript` (and React `@types/*`)
33
+ devDeps, an env shim (`vite-env.d.ts` / `next-env.d.ts`), and a build that type-checks
34
+ (`tsc --noEmit && vite build`, or Next's built-in checking). Run `npm run typecheck` any time.
35
+
36
+ The wallet templates use [`@dignetwork/dig-sdk`](https://github.com/DIG-Network/dig-sdk)'s **shipped
37
+ types** — `ChiaProvider`, `ConnectOptions`, and friends are fully typed straight from the package's
38
+ `.d.ts`, so no `@types/*` shim is needed for the SDK.
39
+
40
+ > The `static-site` template has no build step (it just copies `src/` → `public/`), so it has no
41
+ > TypeScript variant — requesting `--typescript` for it scaffolds JavaScript and tells you so.
42
+ > (The legacy id `static` still works as a hidden alias.)
43
+
44
+ ## Free until publish
45
+
46
+ **Scaffolding, building, and previewing cost nothing.** Creating a project does **not** mint,
47
+ touch the chain, or spend any funds. You spend **$DIG** only when you publish a **capsule** with
48
+ `digstore deploy`. *Iterate for free, publish when it's ready.*
49
+
50
+ ```sh
51
+ digstore dev # preview on the real chia:// read path — FREE, no chain, no spend
52
+ digstore deploy # publish a capsule when you're ready (the only step that spends $DIG)
53
+ ```
54
+
55
+ A published app lives on **DIGHUb** at `hub.dig.net/stores/<id>`, and you can optionally register a
56
+ human name so it is also reachable at `<your-name>.on.dig.net` (a pay-to-register domain).
57
+
58
+ ## Templates
59
+
60
+ | Template | What you get | Wallet wired | Languages |
61
+ |---|---|---|---|
62
+ | `static-site` | Plain HTML/CSS/JS — zero build step, the lightest way to ship a site. | — | JS |
63
+ | `vite-react` | A React SPA built with Vite — the fast default for an app frontend. | — | JS · TS |
64
+ | `next-static` | Next.js exported to static files (`output: 'export'`), deployable as a capsule. | — | JS · TS |
65
+ | `nft-drop` | A wallet-connected NFT mint page (`ChiaProvider` + the canonical CHIP-0035 spend builder). | yes | JS · TS |
66
+ | `nft-collection` | An NFT collection workspace — art + CHIP-0007 metadata/license tooling for `digstore collection mint`. | yes | JS |
67
+ | `dapp-window-chia` | A dapp wired to a Chia wallet via `ChiaProvider` — injected `window.chia`, or Sage over WalletConnect. | yes | JS · TS |
68
+
69
+ The **`nft-collection`** template is a *collection workspace*, not a single page: drop your art in
70
+ `images/`, describe the set once in `collection.json`, and its dependency-free tooling
71
+ (`npm run generate` / `npm run validate`) emits the canonical **CHIP-0007** metadata + the
72
+ `items.json` manifest that `digstore collection mint` consumes — byte-for-byte the same shape the
73
+ DIGHUb NFT studio mints, so a collection built here mints cleanly either way. New to minting on DIG?
74
+ See <https://docs.dig.net/docs/audiences/nft-developers>.
75
+
76
+ The wallet templates wire [`@dignetwork/dig-sdk`](https://github.com/DIG-Network/dig-sdk): a Chia
77
+ wallet your dapp gets for free. `ChiaProvider.connect({ mode: "auto" })` **prefers the injected DIG
78
+ Browser wallet** (`window.chia`) and **falls back to WalletConnect → Sage** (the main Chia wallet)
79
+ so a scaffolded dapp connects in a normal browser too — not just the DIG Browser. NFT minting uses
80
+ the SDK's `/spend` builder — spends are never hand-rolled. **Nothing is minted, signed, or spent at
81
+ scaffold time** — minting is an explicit, wallet-signed action a user triggers later.
82
+
83
+ ### Wallet connection — injected DIG Browser **or** Sage (WalletConnect)
84
+
85
+ The same **Connect** button works in both worlds, in both JS and TS:
86
+
87
+ | | Injected (DIG Browser / extension) | WalletConnect → Sage (any browser) |
88
+ |---|---|---|
89
+ | When | `window.chia` is present | no injected wallet found |
90
+ | Setup | none | set a free **projectId** (env) |
91
+ | UX | instant connect | pairing link / QR to approve in Sage |
92
+
93
+ To enable the Sage fallback, the wallet templates ship `@walletconnect/sign-client` (the SDK's
94
+ optional WC peer dep) as a dependency and read a **project id** from the build-time env:
95
+
96
+ ```sh
97
+ cp .env.example .env
98
+ # .env — get a free id at https://cloud.reown.com (Reown / WalletConnect Cloud)
99
+ VITE_WALLETCONNECT_PROJECT_ID=your_project_id_here
100
+ ```
101
+
102
+ Leave it blank to support only the injected DIG Browser wallet (the app still builds and runs). The
103
+ project id is never committed — only the placeholder `.env.example` is tracked. (The SDK throws an
104
+ actionable error if WalletConnect is used without the peer dep / project id; the scaffolded setup
105
+ satisfies it.)
106
+
107
+ ## Usage
108
+
109
+ ```sh
110
+ # explicit template + name (JavaScript)
111
+ npm create dig-app@latest my-app -- --template <template>
112
+
113
+ # TypeScript variant
114
+ npm create dig-app@latest my-app -- --template <template> --typescript
115
+
116
+ # interactive (prompts for name + template + JS/TS)
117
+ npm create dig-app@latest
118
+
119
+ # help / templates list
120
+ npm create dig-app@latest -- --help
121
+ ```
122
+
123
+ | Option | Description |
124
+ |---|---|
125
+ | `<name>` | Project directory + npm package name (slugified to be npm-safe). |
126
+ | `-t, --template <t>` | One of: `static-site`, `vite-react`, `next-static`, `nft-drop`, `nft-collection`, `dapp-window-chia`. |
127
+ | `--typescript`, `--ts` | Scaffold the TypeScript variant (where available). |
128
+ | `--javascript`, `--js` | Scaffold the JavaScript variant (the default). |
129
+ | `--lang <js\|ts>` | Same as the language flags above. |
130
+ | `--json` | Emit one structured result object on stdout; route human prose to stderr (for scripts/agents). |
131
+ | `--list-templates` | List the available templates (pair with `--json` for machine-readable output). |
132
+ | `--help-json` | Print the full flag/template tree + exit-code table as JSON. |
133
+ | `-h, --help` | Show usage and the template list. |
134
+ | `-v, --version` | Print the version. |
135
+
136
+ > The `--` before the flags is npm's `npm create` argument separator — it forwards the rest to
137
+ > `create-dig-app`. With `npx create-dig-app` / `pnpm create dig-app` you can drop it.
138
+
139
+ ## What it writes
140
+
141
+ Every project includes:
142
+
143
+ - **`dig.toml`** — the project manifest `digstore` (and the DIG SDK adapters) read: `output-dir`,
144
+ `build-command`, and the default `remote`. This is the single source of truth `digstore deploy`
145
+ and the GitHub Action use.
146
+ - **`README.md`** — the develop -> preview (free) -> publish flow for that template.
147
+ - a real **app** that `npm install`s and builds to the template's output dir.
148
+ - for the **TypeScript** variant: a `tsconfig.json`, `.ts`/`.tsx` sources, the `typescript`
149
+ (and React `@types/*`) devDeps, and an env shim — the project type-checks and builds out of the box.
150
+
151
+ ## Deploy
152
+
153
+ Preview locally for free with `digstore dev`, publish with `digstore deploy`, and wire
154
+ push-to-deploy in CI with the GitHub deploy Action so every push to `main` publishes a new capsule:
155
+ [Deploy from GitHub Actions](https://docs.dig.net/docs/digstore/cli/deploy-from-github-actions).
156
+ Your app is then live on **DIGHUb** (`hub.dig.net/stores/<id>`) and, if you register one, at
157
+ `<your-name>.on.dig.net`.
158
+
159
+ ## Scripting / agents (machine-readable output)
160
+
161
+ `create-dig-app` is scriptable end-to-end. Pass `--json` to get a single structured object on
162
+ **stdout** (all human prose is routed to **stderr**, and no interactive prompts are shown — so an
163
+ agent can scaffold unattended):
164
+
165
+ ```sh
166
+ # Scaffold and capture the result as JSON.
167
+ npx create-dig-app my-app --template vite-react --json
168
+ # → {"schemaVersion":1,"ok":true,"result":{"appName":"my-app","template":"vite-react",
169
+ # "lang":"js","requestedLang":"js","targetDir":"…/my-app","nextSteps":[…]}}
170
+
171
+ # Discover the templates as data, or the full invocation contract:
172
+ npx create-dig-app --list-templates --json
173
+ npx create-dig-app --help-json # flags + template tree + the exit-code table
174
+ ```
175
+
176
+ On failure, `--json` emits a structured error envelope with a **stable, UPPER_SNAKE code** (never
177
+ derived from the prose), the matching exit code, and an actionable hint:
178
+
179
+ ```json
180
+ {"schemaVersion":1,"ok":false,"error":{"code":"UNKNOWN_TEMPLATE","exit_code":3,
181
+ "message":"Unknown template \"svelte\". Available: …","hint":"Run with --list-templates …",
182
+ "template":"svelte"}}
183
+ ```
184
+
185
+ ### Exit codes
186
+
187
+ A differentiated, stable exit-code table (also emitted by `--help-json`) so a script can branch on
188
+ the *kind* of failure:
189
+
190
+ | Code | Meaning |
191
+ |---|---|
192
+ | `0` | success |
193
+ | `1` | unexpected internal error |
194
+ | `2` | usage error (bad/unknown option or malformed arguments) |
195
+ | `3` | unknown template id |
196
+ | `4` | target directory exists and is not empty |
197
+ | `5` | required arguments missing in non-interactive mode |
198
+ | `6` | bundled template files are missing (packaging bug) |
199
+ | `7` | app name is not usable |
200
+
201
+ ## Develop on create-dig-app
202
+
203
+ ```sh
204
+ node --test test/ # run the test suite (no install needed)
205
+ npm ci && npm run coverage # run the suite under coverage with the ≥80% gate (installs c8)
206
+ node bin/create-dig-app.js my-app --template static-site # run the CLI locally
207
+ ```
208
+
209
+ The runtime package has **zero dependencies** — `node --test test/` runs the whole suite on the
210
+ standard library alone. The only dev dependency is [`c8`](https://github.com/bcoe/c8), the coverage
211
+ runner: `npm run coverage` runs the same tests and **fails if line/branch/function/statement coverage
212
+ drops below 80%** (thresholds live in `.c8rc.json`, scoped to `lib/` + `bin/`). CI enforces this gate
213
+ on every push and PR across the Node 18 and 20 matrix.
214
+
215
+ ## License
216
+
217
+ MIT
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env node
2
+ // create-dig-app — the `npm create dig-app` entry point.
3
+ //
4
+ // A thin wrapper around lib/cli.js (which wraps the pure scaffolder in lib/index.js). It reads its
5
+ // own version from package.json and forwards argv (minus `node script`) to run().
6
+
7
+ import { readFileSync } from "node:fs";
8
+ import { dirname, join } from "node:path";
9
+ import { fileURLToPath } from "node:url";
10
+
11
+ import { run } from "../lib/cli.js";
12
+
13
+ const here = dirname(fileURLToPath(import.meta.url));
14
+ const pkg = JSON.parse(readFileSync(join(here, "..", "package.json"), "utf8"));
15
+
16
+ const code = await run(process.argv.slice(2), { version: pkg.version });
17
+ process.exit(code);