create-jslop 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 p-arndt
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,32 @@
1
+ # create-jslop
2
+
3
+ Scaffold a new [JSlop](https://github.com/p-arndt/jslop) app.
4
+
5
+ ```bash
6
+ npm create jslop@latest my-app
7
+ # or
8
+ pnpm create jslop my-app
9
+ # or
10
+ bun create jslop my-app
11
+ ```
12
+
13
+ Then:
14
+
15
+ ```bash
16
+ cd my-app
17
+ pnpm install
18
+ pnpm dev
19
+ ```
20
+
21
+ ## Flags
22
+
23
+ - `--template=<name>` — pick a template non-interactively. Currently shipped: `minimal`.
24
+ - `--yes` / `-y` — skip prompts. With a project name on the command line and a single template available, no prompts fire anyway.
25
+
26
+ ## Templates
27
+
28
+ | Template | What you get |
29
+ |-----------|------------------------------------------------------------------------------|
30
+ | `minimal` | One route, `state`, two-way `bind:value`, `{#if}`, a Vite config and a Node `serve.mjs` for production. |
31
+
32
+ More templates (Tailwind, CRUD) will land alongside future JSlop releases.
package/dist/index.js ADDED
@@ -0,0 +1,123 @@
1
+ #!/usr/bin/env node
2
+ import { cpSync, existsSync, mkdirSync, readdirSync, readFileSync, statSync, writeFileSync, } from "node:fs";
3
+ import { dirname, join, relative, resolve } from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+ import { createInterface } from "node:readline/promises";
6
+ import { stdin, stdout } from "node:process";
7
+ const HERE = dirname(fileURLToPath(import.meta.url));
8
+ // dist/index.js → ../templates resolves to the templates dir that ships in the
9
+ // npm tarball (see `files` in package.json).
10
+ const TEMPLATES_DIR = resolve(HERE, "..", "templates");
11
+ function parseArgs(argv) {
12
+ const out = { projectName: null, template: null, yes: false };
13
+ for (const a of argv) {
14
+ if (a === "--yes" || a === "-y")
15
+ out.yes = true;
16
+ else if (a.startsWith("--template="))
17
+ out.template = a.slice("--template=".length);
18
+ else if (!a.startsWith("-") && !out.projectName)
19
+ out.projectName = a;
20
+ }
21
+ return out;
22
+ }
23
+ function listTemplates() {
24
+ return readdirSync(TEMPLATES_DIR).filter((n) => statSync(join(TEMPLATES_DIR, n)).isDirectory());
25
+ }
26
+ function loadOwnVersion() {
27
+ const pkg = JSON.parse(readFileSync(resolve(HERE, "..", "package.json"), "utf8"));
28
+ return pkg.version;
29
+ }
30
+ function copyTree(from, to, replacements) {
31
+ mkdirSync(to, { recursive: true });
32
+ for (const entry of readdirSync(from)) {
33
+ const src = join(from, entry);
34
+ // npm strips `.gitignore` from published tarballs (renames it to .npmignore).
35
+ // Workaround: ship as `_gitignore` and rename at scaffold time. Same trick
36
+ // for any other dotfile we want to ship.
37
+ const renamed = entry.startsWith("_") ? "." + entry.slice(1) : entry;
38
+ const dst = join(to, renamed);
39
+ const s = statSync(src);
40
+ if (s.isDirectory()) {
41
+ copyTree(src, dst, replacements);
42
+ continue;
43
+ }
44
+ // Substitute placeholders only in text-ish files; for everything else
45
+ // copy bytes verbatim so we don't accidentally corrupt binaries.
46
+ if (looksTextual(entry)) {
47
+ let text = readFileSync(src, "utf8");
48
+ for (const [k, v] of Object.entries(replacements)) {
49
+ text = text.split(k).join(v);
50
+ }
51
+ writeFileSync(dst, text);
52
+ }
53
+ else {
54
+ cpSync(src, dst);
55
+ }
56
+ }
57
+ }
58
+ function looksTextual(name) {
59
+ return /\.(json|jsonc|mjs|cjs|js|ts|tsx|jsx|jslop|css|html|md|txt|svg|yml|yaml|toml)$/i.test(name)
60
+ || name === "package.json"
61
+ || name.startsWith("_");
62
+ }
63
+ async function promptName() {
64
+ const rl = createInterface({ input: stdin, output: stdout });
65
+ const answer = (await rl.question("Project name: ")).trim();
66
+ rl.close();
67
+ if (!answer) {
68
+ console.error("project name is required");
69
+ process.exit(1);
70
+ }
71
+ return answer;
72
+ }
73
+ async function promptTemplate(available) {
74
+ if (available.length === 1)
75
+ return available[0];
76
+ console.log("Available templates:");
77
+ available.forEach((t, i) => console.log(` ${i + 1}. ${t}`));
78
+ const rl = createInterface({ input: stdin, output: stdout });
79
+ const answer = (await rl.question(`Pick one [1-${available.length}, default 1]: `)).trim();
80
+ rl.close();
81
+ const idx = answer === "" ? 1 : Number(answer);
82
+ if (!Number.isInteger(idx) || idx < 1 || idx > available.length) {
83
+ console.error(`invalid choice: ${answer}`);
84
+ process.exit(1);
85
+ }
86
+ return available[idx - 1];
87
+ }
88
+ async function main() {
89
+ const args = parseArgs(process.argv.slice(2));
90
+ const templates = listTemplates();
91
+ const projectName = args.projectName ?? (await promptName());
92
+ if (!/^[a-z0-9][a-z0-9._-]*$/i.test(projectName)) {
93
+ console.error(`invalid project name: ${projectName}`);
94
+ console.error("use letters, digits, '.', '_', '-' and start with a letter or digit.");
95
+ process.exit(1);
96
+ }
97
+ const template = args.template ?? (await promptTemplate(templates));
98
+ if (!templates.includes(template)) {
99
+ console.error(`unknown template: ${template}`);
100
+ console.error(`available: ${templates.join(", ")}`);
101
+ process.exit(1);
102
+ }
103
+ const target = resolve(process.cwd(), projectName);
104
+ if (existsSync(target)) {
105
+ console.error(`directory already exists: ${relative(process.cwd(), target) || "."}`);
106
+ process.exit(1);
107
+ }
108
+ const version = loadOwnVersion();
109
+ // create-jslop is in the same fixed-version group as @jslop/*, so its own
110
+ // version doubles as the framework version the scaffold should request.
111
+ const jslopRange = `^${version}`;
112
+ const replacements = {
113
+ "__JSLOP_VERSION__": jslopRange,
114
+ "__PROJECT_NAME__": projectName,
115
+ };
116
+ copyTree(join(TEMPLATES_DIR, template), target, replacements);
117
+ console.log(`\n✔ Created ${projectName} (template: ${template})\n`);
118
+ console.log("Next steps:");
119
+ console.log(` cd ${projectName}`);
120
+ console.log(" pnpm install # or: npm install / bun install");
121
+ console.log(" pnpm dev\n");
122
+ }
123
+ void main();
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "create-jslop",
3
+ "version": "0.1.0",
4
+ "description": "Scaffold a new JSlop app. Run `npm create jslop@latest my-app` or `pnpm create jslop my-app`.",
5
+ "keywords": [
6
+ "jslop",
7
+ "create",
8
+ "scaffold",
9
+ "starter",
10
+ "framework"
11
+ ],
12
+ "license": "MIT",
13
+ "author": "p-arndt",
14
+ "homepage": "https://github.com/p-arndt/jslop#readme",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/p-arndt/jslop.git",
18
+ "directory": "packages/create-jslop"
19
+ },
20
+ "bugs": "https://github.com/p-arndt/jslop/issues",
21
+ "engines": {
22
+ "node": ">=20"
23
+ },
24
+ "type": "module",
25
+ "bin": {
26
+ "create-jslop": "./dist/index.js"
27
+ },
28
+ "files": [
29
+ "dist",
30
+ "templates",
31
+ "README.md"
32
+ ],
33
+ "publishConfig": {
34
+ "access": "public"
35
+ },
36
+ "devDependencies": {
37
+ "@types/node": "^25.7.0",
38
+ "typescript": "^5.6.3"
39
+ },
40
+ "scripts": {
41
+ "build": "tsc -p tsconfig.json && node -e \"import('node:fs').then(fs => fs.chmodSync('dist/index.js', 0o755))\""
42
+ }
43
+ }
@@ -0,0 +1,27 @@
1
+ # __PROJECT_NAME__
2
+
3
+ A [JSlop](https://github.com/p-arndt/jslop) app.
4
+
5
+ ## Develop
6
+
7
+ ```bash
8
+ pnpm install
9
+ pnpm dev
10
+ ```
11
+
12
+ Open <http://localhost:5173>. Edit `src/routes/index.jslop` — the dev server reloads on save.
13
+
14
+ ## Build for production
15
+
16
+ ```bash
17
+ pnpm build # emits dist/client and dist/server
18
+ pnpm serve # runs the Node adapter against the built output
19
+ ```
20
+
21
+ ## Layout
22
+
23
+ - `src/routes/` — file-based routes. `index.jslop` → `/`, `about.jslop` → `/about`, `users/[id].jslop` → `/users/:id`.
24
+ - `src/routes/_layout.jslop` — wraps every route in this directory (optional). Use `<children/>` to mark where the inner route goes.
25
+ - `src/routes/_404.jslop` — custom not-found page (optional).
26
+ - `vite.config.mjs` — the Vite + `@jslop/vite` configuration.
27
+ - `serve.mjs` — production Node entrypoint.
@@ -0,0 +1,4 @@
1
+ node_modules
2
+ dist
3
+ .DS_Store
4
+ *.log
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "__PROJECT_NAME__",
3
+ "version": "0.0.1",
4
+ "private": true,
5
+ "type": "module",
6
+ "scripts": {
7
+ "dev": "vite",
8
+ "build": "vite build && vite build --ssr",
9
+ "preview": "vite preview",
10
+ "serve": "node serve.mjs"
11
+ },
12
+ "dependencies": {
13
+ "@jslop/client": "__JSLOP_VERSION__",
14
+ "@jslop/node-adapter": "__JSLOP_VERSION__",
15
+ "@jslop/router": "__JSLOP_VERSION__",
16
+ "@jslop/runtime": "__JSLOP_VERSION__",
17
+ "@jslop/server": "__JSLOP_VERSION__"
18
+ },
19
+ "devDependencies": {
20
+ "@jslop/vite": "__JSLOP_VERSION__",
21
+ "vite": "^7.0.0"
22
+ }
23
+ }
@@ -0,0 +1,16 @@
1
+ import { createServer } from "@jslop/node-adapter";
2
+ import { render } from "./dist/server/entry-server.js";
3
+ import { resolve, dirname } from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+
6
+ const here = dirname(fileURLToPath(import.meta.url));
7
+ const port = Number(process.env.PORT ?? 3000);
8
+
9
+ const server = createServer({
10
+ render,
11
+ clientDir: resolve(here, "dist/client"),
12
+ });
13
+
14
+ server.listen(port, () => {
15
+ console.log(`__PROJECT_NAME__ listening on http://localhost:${port}`);
16
+ });
@@ -0,0 +1,34 @@
1
+ component Index {
2
+ state count = 0
3
+ state name = "world"
4
+
5
+ function increment() {
6
+ count++
7
+ }
8
+
9
+ view {
10
+ <main>
11
+ <h1>Hello, {name}!</h1>
12
+
13
+ <label>
14
+ Your name:
15
+ <input bind:value={name} />
16
+ </label>
17
+
18
+ <p>You've clicked the button {count} times.</p>
19
+ <button onclick={increment}>+1</button>
20
+
21
+ {#if count >= 10}
22
+ <p>Nice — keep going.</p>
23
+ {/if}
24
+
25
+ <hr/>
26
+
27
+ <p>
28
+ Edit <code>src/routes/index.jslop</code> and save. The dev server
29
+ reloads automatically. Add more routes by dropping <code>.jslop</code>
30
+ files into <code>src/routes/</code>.
31
+ </p>
32
+ </main>
33
+ }
34
+ }
@@ -0,0 +1,6 @@
1
+ import { defineConfig } from "vite";
2
+ import jslop from "@jslop/vite";
3
+
4
+ export default defineConfig({
5
+ plugins: [jslop()],
6
+ });