webnek 0.1.0 → 0.1.2

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
- 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/
4
+ bunx webnek@latest my-app
5
+ cd my-app
6
+ bunx webnek@latest 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@latest [dir]` | Scaffold a project |
20
+ | `bunx webnek@latest dev` | Start the app |
21
+ | `bunx webnek@latest 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,8 @@ 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";
19
+ const VERSION = JSON.parse(readFileSync(join(pkgRoot, "package.json"), "utf8")).version;
18
20
 
19
21
  const args = process.argv.slice(2);
20
22
  const cmd = args[0];
@@ -39,16 +41,16 @@ const IGNORE_WHEN_EMPTY = new Set([
39
41
  ]);
40
42
 
41
43
  function help() {
44
+ const run = invokeCmd();
42
45
  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
46
+ webnek ${VERSION}
47
+
48
+ ${run} [dir] Scaffold a new app
49
+ ${run} new [dir] Same as above
50
+ ${run} init Scaffold into the current directory
51
+ ${run} dev Start the app
52
+ ${run} build Production build
53
+ ${run} add <pkg> Add a crate or npm package
52
54
  `);
53
55
  }
54
56
 
@@ -159,22 +161,19 @@ function scaffold(targetArg) {
159
161
  PACKAGE_NAME: pkgName,
160
162
  FRAMEWORK_DEP: frameworkDep(appDir),
161
163
  PROJECT_NAME: pkgName,
164
+ START_CMD: invokeCmd(),
162
165
  };
163
166
  copyTemplate(templateRoot, appDir, vars);
164
167
  stripNodeManifests(appDir);
165
168
 
166
169
  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
- `);
170
+ const run = invokeCmd();
171
+ const lines = [` webnek ${VERSION} created ${rel}`, ``, ` Next:`];
172
+ if (rel !== ".") {
173
+ lines.push(` cd ${rel}`);
174
+ }
175
+ lines.push(` ${run} dev`);
176
+ console.log(`\n${lines.join("\n")}\n`);
178
177
  }
179
178
 
180
179
  function which(bin) {
@@ -182,36 +181,68 @@ function which(bin) {
182
181
  return r.status === 0 ? r.stdout.trim() : "";
183
182
  }
184
183
 
185
- function ensureCargoWeb() {
184
+ function invokeCmd() {
185
+ const ua = process.env.npm_config_user_agent || "";
186
+ const argv0 = process.argv[0] || "";
187
+ const argv1 = process.argv[1] || "";
188
+ if (ua.includes("bun") || argv0.includes("bun") || argv1.includes("bun")) {
189
+ return "bunx webnek@latest";
190
+ }
191
+ if (ua.includes("npx") || argv1.includes("npx") || argv1.includes("/npm/")) {
192
+ return "npx webnek@latest";
193
+ }
194
+ if (which("webnek")) return "webnek";
195
+ return "bunx webnek@latest";
196
+ }
197
+
198
+ function cargoWebnekOk() {
186
199
  const probe = spawnSync("cargo", ["webnek", "--help"], {
187
200
  encoding: "utf8",
188
201
  stdio: "pipe",
189
202
  });
190
- if (probe.status === 0) return "cargo";
191
-
192
- if (which("cargo-webnek")) {
193
- return "cargo-webnek";
194
- }
203
+ return probe.status === 0 || Boolean(which("cargo-webnek"));
204
+ }
195
205
 
206
+ function installCargoWebnek() {
196
207
  const root = findFrameworkRoot();
197
208
  if (root && existsSync(join(root, "crates/cli/Cargo.toml"))) {
198
- console.log(" webnek installing cargo-webnek from local crates/cli …");
209
+ console.log(" webnek installing cargo-webnek …");
199
210
  const ins = spawnSync(
200
211
  "cargo",
201
212
  ["install", "--path", join(root, "crates/cli"), "--force"],
202
213
  { stdio: "inherit" }
203
214
  );
204
- if (ins.status === 0) return "cargo";
215
+ return ins.status === 0;
205
216
  }
217
+ console.log(" webnek installing cargo-webnek (once) …");
218
+ const ins = spawnSync(
219
+ "cargo",
220
+ ["install", "webnek-cli"],
221
+ { stdio: "inherit" }
222
+ );
223
+ return ins.status === 0;
224
+ }
206
225
 
207
- console.error(`
208
- cargo-webnek is not installed.
226
+ function ensureCargoWeb() {
227
+ if (cargoWebnekOk()) return;
209
228
 
210
- cargo install cargo-webnek
211
- # or, from this repo:
212
- cargo install --path crates/cli
229
+ if (!which("cargo")) {
230
+ console.error(`
231
+ cargo is not installed. Install Rust first:
232
+
233
+ https://rustup.rs/
213
234
  `);
214
- process.exit(1);
235
+ process.exit(1);
236
+ }
237
+
238
+ if (!installCargoWebnek()) {
239
+ console.error(`
240
+ ✖ could not install cargo-webnek.
241
+
242
+ cargo install webnek-cli
243
+ `);
244
+ process.exit(1);
245
+ }
215
246
  }
216
247
 
217
248
  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.2",
4
+ "description": "Webnek app installer. bunx webnek@latest my-app && bunx webnek@latest 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.