webnek 0.1.0 → 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.
package/README.md CHANGED
@@ -1,44 +1,23 @@
1
1
  # webnek
2
2
 
3
- Installer for the Rust web framework. Run it with `bunx` / `npx` — it is **not** a dependency of your app.
4
-
5
- Generated apps have **no** `package.json`, **no** lockfile, **no** `node_modules`. `Cargo.toml` is the only manifest (`[package.metadata.npm]` for JS packages, cached in `~/.cargo/webnek/cache/`).
6
-
7
- ## Create an app
8
-
9
3
  ```bash
10
4
  bunx webnek my-app
11
- # or
12
- npx webnek my-app
13
- ```
14
-
15
- ```
16
- my-app/
17
- Cargo.toml # only manifest (Rust crates + [package.metadata.npm])
18
- Cargo.lock
19
- public/
20
- src/
5
+ cd my-app
6
+ bunx webnek dev
21
7
  ```
22
8
 
23
- Then:
9
+ That last command installs the Rust CLI the first time, then starts the app.
24
10
 
25
- ```bash
26
- cd my-app
27
- cargo webnek dev
28
- cargo webnek add canvas-confetti --npm
29
- vercel
30
- ```
11
+ Generated apps have **no** `package.json`, **no** lockfile, **no** `node_modules`. `Cargo.toml` is the only manifest (`[package.metadata.npm]` for JS packages, cached in `~/.cargo/webnek/cache/`).
31
12
 
32
- Do not `bun add webnek` inside the app. That is the two-ecosystem split this installer exists to avoid.
13
+ Do not `bun add webnek` inside the app.
33
14
 
34
15
  ## Commands
35
16
 
36
17
  | Command | What it does |
37
18
  |---|---|
38
- | `webnek [dir]` / `webnek new [dir]` | Scaffold a project |
39
- | `webnek init` | Scaffold into the current directory |
40
- | `webnek dev` | `cargo webnek dev` |
41
- | `webnek build` | `cargo webnek build` |
42
- | `webnek add <pkg>` | `cargo webnek add` |
19
+ | `bunx webnek [dir]` | Scaffold a project |
20
+ | `bunx webnek dev` | Start the app |
21
+ | `bunx webnek add <pkg>` | Add a crate or npm package |
43
22
 
44
- Requires [Rust](https://rustup.rs/). `cargo webnek` is the `cargo-webnek` binary (`cargo install --path crates/cli` from this repo).
23
+ Requires [Rust](https://rustup.rs/).
package/bin/cli.mjs CHANGED
@@ -15,6 +15,7 @@ import { fileURLToPath } from "node:url";
15
15
  const here = dirname(fileURLToPath(import.meta.url));
16
16
  const pkgRoot = resolve(here, "..");
17
17
  const templateRoot = join(pkgRoot, "template");
18
+ const GIT = "https://github.com/Grenish/webnek";
18
19
 
19
20
  const args = process.argv.slice(2);
20
21
  const cmd = args[0];
@@ -39,16 +40,16 @@ const IGNORE_WHEN_EMPTY = new Set([
39
40
  ]);
40
41
 
41
42
  function help() {
43
+ const run = invokeCmd();
42
44
  console.log(`
43
- webnek 0.1.0
44
-
45
- webnek [dir] Scaffold a new app
46
- webnek new [dir] Same as above
47
- webnek init Scaffold into the current directory
48
- webnek dev [...args] cargo webnek dev
49
- webnek build [...args] cargo webnek build
50
- webnek add [...args] cargo webnek add
51
- webnek export [...args] cargo webnek export
45
+ webnek 0.1.1
46
+
47
+ ${run} [dir] Scaffold a new app
48
+ ${run} new [dir] Same as above
49
+ ${run} init Scaffold into the current directory
50
+ ${run} dev Start the app
51
+ ${run} build Production build
52
+ ${run} add <pkg> Add a crate or npm package
52
53
  `);
53
54
  }
54
55
 
@@ -88,7 +89,7 @@ function frameworkDep(appDir) {
88
89
  rel = rel.replaceAll("\\", "/");
89
90
  return `webnek = { path = "${rel}", features = ["ssr"] }`;
90
91
  }
91
- return `webnek = { version = "0.1.0", features = ["ssr"] }`;
92
+ return `webnek = { git = "${GIT}", features = ["ssr"] }`;
92
93
  }
93
94
 
94
95
  function isEffectivelyEmpty(dir) {
@@ -159,22 +160,19 @@ function scaffold(targetArg) {
159
160
  PACKAGE_NAME: pkgName,
160
161
  FRAMEWORK_DEP: frameworkDep(appDir),
161
162
  PROJECT_NAME: pkgName,
163
+ START_CMD: invokeCmd(),
162
164
  };
163
165
  copyTemplate(templateRoot, appDir, vars);
164
166
  stripNodeManifests(appDir);
165
167
 
166
168
  const rel = relative(process.cwd(), appDir) || ".";
167
- console.log(`
168
- webnek created ${rel}
169
-
170
- src/ source (Rust, TS islands, styles.css)
171
- public/ static files you add
172
- target/web/ generated CSS/JS (gitignored)
173
-
174
- Next:
175
- cd ${rel === "." ? "." : rel}
176
- cargo webnek dev
177
- `);
169
+ const run = invokeCmd();
170
+ const lines = [` webnek created ${rel}`, ``, ` Next:`];
171
+ if (rel !== ".") {
172
+ lines.push(` cd ${rel}`);
173
+ }
174
+ lines.push(` ${run} dev`);
175
+ console.log(`\n${lines.join("\n")}\n`);
178
176
  }
179
177
 
180
178
  function which(bin) {
@@ -182,36 +180,68 @@ function which(bin) {
182
180
  return r.status === 0 ? r.stdout.trim() : "";
183
181
  }
184
182
 
185
- function ensureCargoWeb() {
183
+ function invokeCmd() {
184
+ const ua = process.env.npm_config_user_agent || "";
185
+ const argv0 = process.argv[0] || "";
186
+ const argv1 = process.argv[1] || "";
187
+ if (ua.includes("bun") || argv0.includes("bun") || argv1.includes("bun")) {
188
+ return "bunx webnek";
189
+ }
190
+ if (ua.includes("npx") || argv1.includes("npx") || argv1.includes("/npm/")) {
191
+ return "npx webnek";
192
+ }
193
+ if (which("webnek")) return "webnek";
194
+ return "bunx webnek";
195
+ }
196
+
197
+ function cargoWebnekOk() {
186
198
  const probe = spawnSync("cargo", ["webnek", "--help"], {
187
199
  encoding: "utf8",
188
200
  stdio: "pipe",
189
201
  });
190
- if (probe.status === 0) return "cargo";
191
-
192
- if (which("cargo-webnek")) {
193
- return "cargo-webnek";
194
- }
202
+ return probe.status === 0 || Boolean(which("cargo-webnek"));
203
+ }
195
204
 
205
+ function installCargoWebnek() {
196
206
  const root = findFrameworkRoot();
197
207
  if (root && existsSync(join(root, "crates/cli/Cargo.toml"))) {
198
- console.log(" webnek installing cargo-webnek from local crates/cli …");
208
+ console.log(" webnek installing cargo-webnek …");
199
209
  const ins = spawnSync(
200
210
  "cargo",
201
211
  ["install", "--path", join(root, "crates/cli"), "--force"],
202
212
  { stdio: "inherit" }
203
213
  );
204
- if (ins.status === 0) return "cargo";
214
+ return ins.status === 0;
205
215
  }
216
+ console.log(" webnek installing cargo-webnek (once, from git) …");
217
+ const ins = spawnSync(
218
+ "cargo",
219
+ ["install", "--git", GIT, "webnek-cli"],
220
+ { stdio: "inherit" }
221
+ );
222
+ return ins.status === 0;
223
+ }
206
224
 
207
- console.error(`
208
- cargo-webnek is not installed.
225
+ function ensureCargoWeb() {
226
+ if (cargoWebnekOk()) return;
209
227
 
210
- cargo install cargo-webnek
211
- # or, from this repo:
212
- cargo install --path crates/cli
228
+ if (!which("cargo")) {
229
+ console.error(`
230
+ cargo is not installed. Install Rust first:
231
+
232
+ https://rustup.rs/
213
233
  `);
214
- process.exit(1);
234
+ process.exit(1);
235
+ }
236
+
237
+ if (!installCargoWebnek()) {
238
+ console.error(`
239
+ ✖ could not install cargo-webnek.
240
+
241
+ cargo install --git ${GIT} webnek-cli
242
+ `);
243
+ process.exit(1);
244
+ }
215
245
  }
216
246
 
217
247
  function proxyCargoWeb(forward) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "webnek",
3
- "version": "0.1.0",
4
- "description": "Next-gen fullstack Rust web framework with React ergonomics. Scaffold with bunx webnek, then cargo webnek dev.",
3
+ "version": "0.1.1",
4
+ "description": "Webnek app installer. bunx webnek my-app && bunx webnek dev",
5
5
  "type": "module",
6
6
  "license": "MIT OR Apache-2.0",
7
7
  "author": "Grenish Rai <mrcoder2033d@gmail.com>",
@@ -1,19 +1,15 @@
1
1
  # {{PROJECT_NAME}}
2
2
 
3
- Fullstack Rust with React ergonomics.
4
-
5
3
  ```bash
6
- cargo webnek dev
4
+ {{START_CMD}} dev
7
5
  ```
8
6
 
9
7
  - Edit `src/styles.css` (Tailwind v4). Compiled CSS goes to `target/web/`.
10
8
  - `public/` is for files you add (favicon, images).
11
- - JS packages: `cargo webnek add <pkg> --npm` (global cache, no local node_modules).
9
+ - JS packages: `{{START_CMD}} add <pkg> --npm`
12
10
 
13
- ## Deploy to Vercel
11
+ ## Deploy
14
12
 
15
13
  ```bash
16
14
  vercel
17
15
  ```
18
-
19
- Same app, no `package.json`. Vercel compiles `api/index.rs`. CSS and client JS are built during that compile.