create-dalila 1.0.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/README.md +42 -0
- package/index.js +111 -0
- package/package.json +27 -0
- package/template/index.html +35 -0
- package/template/package.json +17 -0
- package/template/src/main.ts +30 -0
- package/template/src/style.css +101 -0
- package/template/tsconfig.json +12 -0
package/README.md
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# create-dalila
|
|
2
|
+
|
|
3
|
+
Scaffold a new Dalila project with one command.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm create dalila my-app
|
|
9
|
+
cd my-app
|
|
10
|
+
npm install
|
|
11
|
+
npm run dev
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Open http://localhost:4242 to see your app.
|
|
15
|
+
|
|
16
|
+
## What's Included
|
|
17
|
+
|
|
18
|
+
- Counter example with signals and computed values
|
|
19
|
+
- Hot reload development server
|
|
20
|
+
- TypeScript support out of the box
|
|
21
|
+
- Minimal CSS styling
|
|
22
|
+
|
|
23
|
+
## Project Structure
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
my-app/
|
|
27
|
+
├── index.html # Main HTML file
|
|
28
|
+
├── src/
|
|
29
|
+
│ ├── main.ts # Application entry point
|
|
30
|
+
│ └── style.css # Styles
|
|
31
|
+
├── package.json
|
|
32
|
+
└── tsconfig.json
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Scripts
|
|
36
|
+
|
|
37
|
+
- `npm run dev` - Start development server
|
|
38
|
+
- `npm run build` - Compile TypeScript
|
|
39
|
+
|
|
40
|
+
## Learn More
|
|
41
|
+
|
|
42
|
+
- [Dalila Documentation](https://github.com/evertonccarvalho/dalila)
|
package/index.js
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import { fileURLToPath } from 'url';
|
|
6
|
+
|
|
7
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
8
|
+
const __dirname = path.dirname(__filename);
|
|
9
|
+
|
|
10
|
+
const args = process.argv.slice(2);
|
|
11
|
+
const projectName = args[0];
|
|
12
|
+
|
|
13
|
+
// Colors for terminal
|
|
14
|
+
const green = (text) => `\x1b[32m${text}\x1b[0m`;
|
|
15
|
+
const cyan = (text) => `\x1b[36m${text}\x1b[0m`;
|
|
16
|
+
const yellow = (text) => `\x1b[33m${text}\x1b[0m`;
|
|
17
|
+
const bold = (text) => `\x1b[1m${text}\x1b[0m`;
|
|
18
|
+
|
|
19
|
+
function printHelp() {
|
|
20
|
+
console.log(`
|
|
21
|
+
${bold('create-dalila')} - Create a new Dalila project
|
|
22
|
+
|
|
23
|
+
${bold('Usage:')}
|
|
24
|
+
npm create dalila ${cyan('<project-name>')}
|
|
25
|
+
npx create-dalila ${cyan('<project-name>')}
|
|
26
|
+
|
|
27
|
+
${bold('Examples:')}
|
|
28
|
+
npm create dalila my-app
|
|
29
|
+
npx create-dalila todo-app
|
|
30
|
+
|
|
31
|
+
${bold('Options:')}
|
|
32
|
+
-h, --help Show this help message
|
|
33
|
+
-v, --version Show version
|
|
34
|
+
`);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function copyDir(src, dest) {
|
|
38
|
+
fs.mkdirSync(dest, { recursive: true });
|
|
39
|
+
|
|
40
|
+
for (const entry of fs.readdirSync(src, { withFileTypes: true })) {
|
|
41
|
+
const srcPath = path.join(src, entry.name);
|
|
42
|
+
const destPath = path.join(dest, entry.name);
|
|
43
|
+
|
|
44
|
+
if (entry.isDirectory()) {
|
|
45
|
+
copyDir(srcPath, destPath);
|
|
46
|
+
} else {
|
|
47
|
+
fs.copyFileSync(srcPath, destPath);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function updatePackageJson(projectPath, projectName) {
|
|
53
|
+
const pkgPath = path.join(projectPath, 'package.json');
|
|
54
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
|
|
55
|
+
pkg.name = projectName;
|
|
56
|
+
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function main() {
|
|
60
|
+
// Handle flags
|
|
61
|
+
if (args.includes('-h') || args.includes('--help')) {
|
|
62
|
+
printHelp();
|
|
63
|
+
process.exit(0);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (args.includes('-v') || args.includes('--version')) {
|
|
67
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(__dirname, 'package.json'), 'utf8'));
|
|
68
|
+
console.log(pkg.version);
|
|
69
|
+
process.exit(0);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Validate project name
|
|
73
|
+
if (!projectName) {
|
|
74
|
+
console.error(`${yellow('Error:')} Please specify the project name:\n`);
|
|
75
|
+
console.log(` npm create dalila ${cyan('<project-name>')}\n`);
|
|
76
|
+
console.log('For example:');
|
|
77
|
+
console.log(` npm create dalila ${cyan('my-app')}\n`);
|
|
78
|
+
process.exit(1);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Check if directory exists
|
|
82
|
+
const projectPath = path.resolve(process.cwd(), projectName);
|
|
83
|
+
|
|
84
|
+
if (fs.existsSync(projectPath)) {
|
|
85
|
+
console.error(`${yellow('Error:')} Directory "${projectName}" already exists.\n`);
|
|
86
|
+
process.exit(1);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
console.log();
|
|
90
|
+
console.log(`Creating ${bold(projectName)}...`);
|
|
91
|
+
console.log();
|
|
92
|
+
|
|
93
|
+
// Copy template
|
|
94
|
+
const templatePath = path.join(__dirname, 'template');
|
|
95
|
+
copyDir(templatePath, projectPath);
|
|
96
|
+
|
|
97
|
+
// Update package.json with project name
|
|
98
|
+
updatePackageJson(projectPath, projectName);
|
|
99
|
+
|
|
100
|
+
// Success message
|
|
101
|
+
console.log(`${green('Done!')} Created ${bold(projectName)}\n`);
|
|
102
|
+
console.log('Next steps:\n');
|
|
103
|
+
console.log(` ${cyan('cd')} ${projectName}`);
|
|
104
|
+
console.log(` ${cyan('npm install')}`);
|
|
105
|
+
console.log(` ${cyan('npm run dev')}`);
|
|
106
|
+
console.log();
|
|
107
|
+
console.log(`Open ${cyan('http://localhost:4242')} to see your app.`);
|
|
108
|
+
console.log();
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
main();
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "create-dalila",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Create Dalila apps with one command",
|
|
5
|
+
"bin": {
|
|
6
|
+
"create-dalila": "index.js"
|
|
7
|
+
},
|
|
8
|
+
"type": "module",
|
|
9
|
+
"files": [
|
|
10
|
+
"index.js",
|
|
11
|
+
"template"
|
|
12
|
+
],
|
|
13
|
+
"keywords": [
|
|
14
|
+
"dalila",
|
|
15
|
+
"create",
|
|
16
|
+
"scaffold",
|
|
17
|
+
"template",
|
|
18
|
+
"signals",
|
|
19
|
+
"reactive"
|
|
20
|
+
],
|
|
21
|
+
"author": "Everton",
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "https://github.com/evertonccarvalho/dalila"
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<title>Dalila App</title>
|
|
7
|
+
<link rel="stylesheet" href="/src/style.css">
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
<div id="app" class="container">
|
|
11
|
+
<h1>Welcome to Dalila</h1>
|
|
12
|
+
|
|
13
|
+
<section class="card">
|
|
14
|
+
<h2>Counter: {count}</h2>
|
|
15
|
+
<p>Doubled: {doubled}</p>
|
|
16
|
+
|
|
17
|
+
<div class="buttons">
|
|
18
|
+
<button d-on-click="decrement">-</button>
|
|
19
|
+
<button d-on-click="increment">+</button>
|
|
20
|
+
</div>
|
|
21
|
+
</section>
|
|
22
|
+
|
|
23
|
+
<section class="card">
|
|
24
|
+
<p when={isEven}>The count is even</p>
|
|
25
|
+
<p when={isOdd}>The count is odd</p>
|
|
26
|
+
</section>
|
|
27
|
+
|
|
28
|
+
<footer>
|
|
29
|
+
<p>Edit <code>src/main.ts</code> and save to see changes.</p>
|
|
30
|
+
</footer>
|
|
31
|
+
</div>
|
|
32
|
+
|
|
33
|
+
<script type="module" src="/src/main.ts"></script>
|
|
34
|
+
</body>
|
|
35
|
+
</html>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "dalila-app",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "dalila-dev",
|
|
8
|
+
"build": "tsc",
|
|
9
|
+
"preview": "dalila-dev --dist"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"dalila": "^1.4.0"
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"typescript": "^5.7.3"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { signal, computed, createScope, withScope } from 'dalila';
|
|
2
|
+
import { bind } from 'dalila/runtime';
|
|
3
|
+
|
|
4
|
+
// Create app scope
|
|
5
|
+
const app = createScope();
|
|
6
|
+
|
|
7
|
+
withScope(app, () => {
|
|
8
|
+
// Reactive state
|
|
9
|
+
const count = signal(0);
|
|
10
|
+
const doubled = computed(() => count() * 2);
|
|
11
|
+
const isEven = computed(() => count() % 2 === 0);
|
|
12
|
+
const isOdd = computed(() => count() % 2 !== 0);
|
|
13
|
+
|
|
14
|
+
// Actions
|
|
15
|
+
const increment = () => count.update(n => n + 1);
|
|
16
|
+
const decrement = () => count.update(n => n - 1);
|
|
17
|
+
|
|
18
|
+
// Bind to DOM
|
|
19
|
+
const root = document.getElementById('app');
|
|
20
|
+
if (root) {
|
|
21
|
+
bind(root, {
|
|
22
|
+
count,
|
|
23
|
+
doubled,
|
|
24
|
+
isEven,
|
|
25
|
+
isOdd,
|
|
26
|
+
increment,
|
|
27
|
+
decrement,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
});
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
* {
|
|
2
|
+
box-sizing: border-box;
|
|
3
|
+
margin: 0;
|
|
4
|
+
padding: 0;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
:root {
|
|
8
|
+
--bg: #1a1a2e;
|
|
9
|
+
--card-bg: #16213e;
|
|
10
|
+
--text: #eee;
|
|
11
|
+
--text-muted: #888;
|
|
12
|
+
--primary: #e94560;
|
|
13
|
+
--primary-hover: #ff6b6b;
|
|
14
|
+
--border: #333;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
body {
|
|
18
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
19
|
+
background: var(--bg);
|
|
20
|
+
color: var(--text);
|
|
21
|
+
min-height: 100vh;
|
|
22
|
+
display: flex;
|
|
23
|
+
justify-content: center;
|
|
24
|
+
align-items: center;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.container {
|
|
28
|
+
max-width: 400px;
|
|
29
|
+
padding: 2rem;
|
|
30
|
+
text-align: center;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
h1 {
|
|
34
|
+
font-size: 2rem;
|
|
35
|
+
margin-bottom: 2rem;
|
|
36
|
+
background: linear-gradient(135deg, var(--primary), #a855f7);
|
|
37
|
+
-webkit-background-clip: text;
|
|
38
|
+
-webkit-text-fill-color: transparent;
|
|
39
|
+
background-clip: text;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.card {
|
|
43
|
+
background: var(--card-bg);
|
|
44
|
+
border-radius: 12px;
|
|
45
|
+
padding: 1.5rem;
|
|
46
|
+
margin-bottom: 1rem;
|
|
47
|
+
border: 1px solid var(--border);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.card h2 {
|
|
51
|
+
font-size: 1.5rem;
|
|
52
|
+
margin-bottom: 0.5rem;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.card p {
|
|
56
|
+
color: var(--text-muted);
|
|
57
|
+
margin-bottom: 1rem;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.buttons {
|
|
61
|
+
display: flex;
|
|
62
|
+
gap: 1rem;
|
|
63
|
+
justify-content: center;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
button {
|
|
67
|
+
background: var(--primary);
|
|
68
|
+
color: white;
|
|
69
|
+
border: none;
|
|
70
|
+
padding: 0.75rem 2rem;
|
|
71
|
+
font-size: 1.25rem;
|
|
72
|
+
border-radius: 8px;
|
|
73
|
+
cursor: pointer;
|
|
74
|
+
transition: background 0.2s, transform 0.1s;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
button:hover {
|
|
78
|
+
background: var(--primary-hover);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
button:active {
|
|
82
|
+
transform: scale(0.95);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
footer {
|
|
86
|
+
margin-top: 2rem;
|
|
87
|
+
color: var(--text-muted);
|
|
88
|
+
font-size: 0.875rem;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
footer code {
|
|
92
|
+
background: var(--card-bg);
|
|
93
|
+
padding: 0.25rem 0.5rem;
|
|
94
|
+
border-radius: 4px;
|
|
95
|
+
font-family: 'Fira Code', monospace;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/* Hide elements with tokens until bound */
|
|
99
|
+
[d-loading] {
|
|
100
|
+
visibility: hidden;
|
|
101
|
+
}
|