create-bose 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 +21 -0
- package/index.js +168 -0
- package/package.json +31 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Bosejs Contributors
|
|
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/index.js
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
|
|
5
|
+
const projectName = process.argv[2] || 'my-bose-app';
|
|
6
|
+
const targetDir = path.resolve(process.cwd(), projectName);
|
|
7
|
+
|
|
8
|
+
console.log(`\nCreating a new Bose app in ${targetDir}...\n`);
|
|
9
|
+
|
|
10
|
+
if (fs.existsSync(targetDir)) {
|
|
11
|
+
console.error(`Error: Directory "${projectName}" already exists. Choose a different name.`);
|
|
12
|
+
process.exit(1);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// ── Helpers ──────────────────────────────────────────────────────────────────
|
|
16
|
+
|
|
17
|
+
function write(filePath, content) {
|
|
18
|
+
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
19
|
+
fs.writeFileSync(filePath, content);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function file(...segments) {
|
|
23
|
+
return path.join(targetDir, ...segments);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// ── package.json ─────────────────────────────────────────────────────────────
|
|
27
|
+
|
|
28
|
+
write(file('package.json'), JSON.stringify({
|
|
29
|
+
name: projectName,
|
|
30
|
+
version: '0.1.0',
|
|
31
|
+
private: true,
|
|
32
|
+
type: 'module',
|
|
33
|
+
scripts: {
|
|
34
|
+
dev: 'vite',
|
|
35
|
+
build: 'vite build',
|
|
36
|
+
preview: 'vite preview',
|
|
37
|
+
},
|
|
38
|
+
dependencies: {
|
|
39
|
+
'@bosejs/core': 'latest',
|
|
40
|
+
'@bosejs/state': 'latest',
|
|
41
|
+
},
|
|
42
|
+
devDependencies: {
|
|
43
|
+
vite: 'latest',
|
|
44
|
+
},
|
|
45
|
+
}, null, 2));
|
|
46
|
+
|
|
47
|
+
// ── vite.config.js ───────────────────────────────────────────────────────────
|
|
48
|
+
|
|
49
|
+
write(file('vite.config.js'), `\
|
|
50
|
+
import { defineConfig } from 'vite';
|
|
51
|
+
import bosePlugin from '@bosejs/core';
|
|
52
|
+
|
|
53
|
+
export default defineConfig({
|
|
54
|
+
plugins: [bosePlugin()],
|
|
55
|
+
});
|
|
56
|
+
`);
|
|
57
|
+
|
|
58
|
+
// ── src/pages/index.js ───────────────────────────────────────────────────────
|
|
59
|
+
// This is the home page component — maps to the "/" route.
|
|
60
|
+
//
|
|
61
|
+
// Key concepts shown here:
|
|
62
|
+
// useSignal — import from @bosejs/state. Creates reactive state that
|
|
63
|
+
// the compiler serialises into HTML for zero-hydration.
|
|
64
|
+
//
|
|
65
|
+
// $( ) — a GLOBAL compiler marker (no import needed). The Bose
|
|
66
|
+
// compiler extracts the closure into its own lazy chunk.
|
|
67
|
+
// The page loads with 0 JS; the chunk is fetched only on
|
|
68
|
+
// the first interaction.
|
|
69
|
+
//
|
|
70
|
+
// bose:bind — reactive text binding. Updated instantly by the runtime
|
|
71
|
+
// when the signal changes — no re-render.
|
|
72
|
+
//
|
|
73
|
+
// bose:state — serialised state embedded in HTML. The chunk reads this
|
|
74
|
+
// on resumption so it never loses context.
|
|
75
|
+
|
|
76
|
+
write(file('src', 'pages', 'index.js'), `\
|
|
77
|
+
import { useSignal } from '@bosejs/state';
|
|
78
|
+
|
|
79
|
+
export default function Home() {
|
|
80
|
+
// useSignal creates reactive state. The compiler injects a stable ID
|
|
81
|
+
// so the runtime can sync DOM nodes to this signal after resumption.
|
|
82
|
+
const count = useSignal(0);
|
|
83
|
+
|
|
84
|
+
// $() is a global compiler marker — no import needed.
|
|
85
|
+
// The closure is extracted into a separate JS chunk that is fetched
|
|
86
|
+
// lazily on the first click. Until then, 0 bytes of JS are loaded.
|
|
87
|
+
const increment = $(() => {
|
|
88
|
+
count.value++;
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
const decrement = $(() => {
|
|
92
|
+
count.value--;
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
const reset = $(() => {
|
|
96
|
+
count.value = 0;
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
return \`
|
|
100
|
+
<div style="
|
|
101
|
+
font-family: system-ui, sans-serif;
|
|
102
|
+
display: flex;
|
|
103
|
+
flex-direction: column;
|
|
104
|
+
align-items: center;
|
|
105
|
+
justify-content: center;
|
|
106
|
+
min-height: 100vh;
|
|
107
|
+
margin: 0;
|
|
108
|
+
background: #020617;
|
|
109
|
+
color: #f8fafc;
|
|
110
|
+
">
|
|
111
|
+
<h1 style="font-size: 2rem; margin-bottom: 0.25rem;">Bose Counter</h1>
|
|
112
|
+
<p style="color: #94a3b8; margin-bottom: 3rem;">
|
|
113
|
+
Resumable island — <strong>0 JS</strong> on page load.
|
|
114
|
+
</p>
|
|
115
|
+
|
|
116
|
+
<!-- bose:bind keeps this span in sync with the 'count' signal -->
|
|
117
|
+
<div style="font-size: 6rem; font-weight: 900; line-height: 1; margin-bottom: 2rem;">
|
|
118
|
+
<span bose:bind="count">\${count.value}</span>
|
|
119
|
+
</div>
|
|
120
|
+
|
|
121
|
+
<div style="display: flex; gap: 1rem;">
|
|
122
|
+
<button
|
|
123
|
+
style="padding: 0.75rem 1.5rem; border-radius: 0.5rem; border: 1px solid #334155; background: #1e293b; color: #f8fafc; font-size: 1.25rem; cursor: pointer;"
|
|
124
|
+
bose:on:click="\${decrement.chunk}"
|
|
125
|
+
bose:state='\${JSON.stringify({ count: count.value })}'>
|
|
126
|
+
−
|
|
127
|
+
</button>
|
|
128
|
+
|
|
129
|
+
<button
|
|
130
|
+
style="padding: 0.75rem 1.5rem; border-radius: 0.5rem; border: 1px solid #334155; background: #1e293b; color: #f8fafc; font-size: 1.25rem; cursor: pointer;"
|
|
131
|
+
bose:on:click="\${reset.chunk}"
|
|
132
|
+
bose:state='\${JSON.stringify({ count: count.value })}'>
|
|
133
|
+
Reset
|
|
134
|
+
</button>
|
|
135
|
+
|
|
136
|
+
<button
|
|
137
|
+
style="padding: 0.75rem 1.5rem; border-radius: 0.5rem; border: none; background: #6366f1; color: #fff; font-size: 1.25rem; cursor: pointer;"
|
|
138
|
+
bose:on:click="\${increment.chunk}"
|
|
139
|
+
bose:state='\${JSON.stringify({ count: count.value })}'>
|
|
140
|
+
+
|
|
141
|
+
</button>
|
|
142
|
+
</div>
|
|
143
|
+
</div>
|
|
144
|
+
\`;
|
|
145
|
+
}
|
|
146
|
+
`);
|
|
147
|
+
|
|
148
|
+
// ── .gitignore ────────────────────────────────────────────────────────────────
|
|
149
|
+
|
|
150
|
+
write(file('.gitignore'), `\
|
|
151
|
+
node_modules/
|
|
152
|
+
dist/
|
|
153
|
+
public/chunks/
|
|
154
|
+
bose-error.log
|
|
155
|
+
.env*.local
|
|
156
|
+
`);
|
|
157
|
+
|
|
158
|
+
// ── Done ─────────────────────────────────────────────────────────────────────
|
|
159
|
+
|
|
160
|
+
const steps = [
|
|
161
|
+
` cd ${projectName}`,
|
|
162
|
+
` npm install`,
|
|
163
|
+
` npm run dev`,
|
|
164
|
+
];
|
|
165
|
+
|
|
166
|
+
console.log('Done! Next steps:\n');
|
|
167
|
+
console.log(steps.join('\n'));
|
|
168
|
+
console.log('\nThen open http://localhost:5173\n');
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "create-bose",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Scaffold a new Bose framework application.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"create-bose": "index.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"index.js",
|
|
11
|
+
"LICENSE"
|
|
12
|
+
],
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": ">=18.0.0"
|
|
15
|
+
},
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"access": "public"
|
|
18
|
+
},
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/bosejs/bosejs.git",
|
|
22
|
+
"directory": "packages/create-bose"
|
|
23
|
+
},
|
|
24
|
+
"keywords": [
|
|
25
|
+
"bose",
|
|
26
|
+
"scaffold",
|
|
27
|
+
"cli",
|
|
28
|
+
"create"
|
|
29
|
+
],
|
|
30
|
+
"license": "MIT"
|
|
31
|
+
}
|