create-laju-app 1.0.1 → 1.0.4

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.
Files changed (3) hide show
  1. package/README.md +322 -0
  2. package/bin/cli.js +14 -14
  3. package/package.json +18 -1
package/README.md ADDED
@@ -0,0 +1,322 @@
1
+ # Laju
2
+
3
+ A high-performance TypeScript web framework combining HyperExpress, Svelte 5, and Inertia.js for building modern full-stack applications. Features server-side rendering, real-time capabilities, and seamless client-server state management.
4
+
5
+ Visit [laju.dev](https://laju.dev)
6
+
7
+ ## Features
8
+
9
+ - Fast server-side rendering with HyperExpress
10
+ - Modern frontend with Svelte 5
11
+ - TypeScript support for better type safety
12
+ - Inertia.js integration for seamless client-server communication
13
+ - Built-in authentication system
14
+ - SQLite database with Knex query builder
15
+ - Email support with Nodemailer
16
+ - Google APIs integration
17
+ - Redis caching support
18
+ - Asset bundling with Vite
19
+ - TailwindCSS for styling
20
+
21
+ ## Prerequisites
22
+
23
+ - Node.js (Latest LTS version recommended)
24
+ - npm or yarn
25
+ - Redis server (optional, for caching)
26
+
27
+ ## Installation
28
+
29
+ 1. Run the following command
30
+ ```bash
31
+ npx create-laju-app project-name
32
+ ```
33
+ 2. Open the project directory
34
+ ```bash
35
+ cd project-name
36
+ ```
37
+ 2. Install dependencies:
38
+ ```bash
39
+ npm install
40
+ ```
41
+ 4. Copy `.env.example` to `.env` and configure your environment variables:
42
+ ```bash
43
+ cp .env.example .env
44
+ ```
45
+
46
+ ## Development
47
+
48
+ To start the development server:
49
+
50
+ ```bash
51
+ npm run dev
52
+ ```
53
+
54
+ This will:
55
+ - Start the Vite development server for frontend assets
56
+ - Run the backend server with nodemon for auto-reloading
57
+
58
+ ## Building for Production
59
+
60
+ To build the application for production:
61
+
62
+ ```bash
63
+ npm run build
64
+ ```
65
+
66
+ This command will:
67
+ - Clean the build directory
68
+ - Build frontend assets with Vite
69
+ - Compile TypeScript files
70
+ - Copy necessary files to the build directory
71
+
72
+ ## Project Structure
73
+
74
+ - `/app` - Core application files
75
+ - `/middlewares` - Custom middleware functions
76
+ - `/services` - Service layer implementations
77
+ - `/controllers` - Application controllers
78
+ - `/resources` - Frontend resources
79
+ - `/views` - Svelte components and views
80
+ - `/js` - JavaScript assets and modules
81
+ - `/routes` - Route definitions
82
+ - `/migrations` - Database migrations
83
+ - `/public` - Static files
84
+ - `/dist` - Compiled assets (generated)
85
+ - `/build` - Production build output
86
+
87
+ ## Key Dependencies
88
+
89
+ ### Backend
90
+ - HyperExpress - High-performance web server
91
+ - Knex - SQL query builder
92
+ - SQLite3 - Database
93
+ - Nodemailer - Email sending
94
+ - Redis - Caching (optional)
95
+
96
+ ### Frontend
97
+ - Svelte 5 - UI framework
98
+ - Inertia.js - Client-server communication
99
+ - TailwindCSS - Utility-first CSS framework
100
+ - Vite - Build tool and dev server
101
+
102
+ ## Scripts
103
+
104
+ - `npm run dev` - Start development server
105
+ - `npm run build` - Build for production
106
+
107
+ ## Contributing
108
+
109
+ 1. Fork the repository
110
+ 2. Create your feature branch
111
+ 3. Commit your changes
112
+ 4. Push to the branch
113
+ 5. Create a new Pull Request
114
+
115
+ ## License
116
+
117
+ ISC License
118
+
119
+ ## Tutorial: Building Your First App
120
+
121
+ This tutorial will guide you through building a simple application using this framework.
122
+
123
+ ### 1. Setting Up a New Route and Controller
124
+
125
+ First, let's create a new route and controller for a blog post feature.
126
+
127
+ 1. Create a new controller file `app/controllers/PostController.ts`:
128
+
129
+ ```typescript
130
+ import { Request, Response } from "../../type";
131
+ import DB from "../services/DB";
132
+
133
+ class Controller {
134
+ public async index(request: Request, response: Response) {
135
+ const posts = await DB.from("posts");
136
+ return response.inertia("posts/index", { posts });
137
+ }
138
+
139
+ public async create(request: Request, response: Response) {
140
+ return response.inertia("posts/create");
141
+ }
142
+
143
+ public async store(request: Request, response: Response) {
144
+ const { title, content } = request.body;
145
+
146
+ await DB.table("posts").insert({
147
+ title,
148
+ content,
149
+ created_at: Date.now(),
150
+ updated_at: Date.now()
151
+ });
152
+
153
+ return response.redirect("/posts");
154
+ }
155
+ }
156
+
157
+ export default new Controller();
158
+ ```
159
+
160
+ 2. Add routes in `routes/web.ts`:
161
+
162
+ ```typescript
163
+ import PostController from "../app/controllers/PostController";
164
+
165
+ // Add these routes with your existing routes
166
+ Route.get("/posts", PostController.index);
167
+ Route.get("/posts/create", PostController.create);
168
+ Route.post("/posts", PostController.store);
169
+ ```
170
+
171
+ ### 2. Creating the Database Migration
172
+
173
+ Create a migration for the posts table:
174
+
175
+ ```bash
176
+ npx knex migrate:make create_posts_table
177
+ ```
178
+
179
+ In the generated migration file:
180
+
181
+ ```typescript
182
+ import { Knex } from "knex";
183
+
184
+ export async function up(knex: Knex): Promise<void> {
185
+ await knex.schema.createTable('posts', function (table) {
186
+ table.increments('id').primary();
187
+ table.string('title').notNullable();
188
+ table.text('content').notNullable();
189
+ table.bigInteger('created_at');
190
+ table.bigInteger('updated_at');
191
+ });
192
+ }
193
+
194
+ export async function down(knex: Knex): Promise<void> {
195
+ await knex.schema.dropTable('posts');
196
+ }
197
+ ```
198
+
199
+ Run the migration:
200
+
201
+ ```bash
202
+ npx knex migrate:latest
203
+ ```
204
+
205
+ ### 3. Creating Svelte Components
206
+
207
+ 1. Create `resources/views/posts/index.svelte`:
208
+
209
+ ```svelte
210
+ <script>
211
+ export let posts = [];
212
+ </script>
213
+
214
+ <div class="max-w-4xl mx-auto p-4">
215
+ <div class="flex justify-between items-center mb-6">
216
+ <h1 class="text-2xl font-bold">Blog Posts</h1>
217
+ <a
218
+ href="/posts/create"
219
+ class="bg-blue-500 text-white px-4 py-2 rounded hover:bg-blue-600"
220
+ >
221
+ Create Post
222
+ </a>
223
+ </div>
224
+
225
+ <div class="space-y-4">
226
+ {#each posts as post}
227
+ <div class="border p-4 rounded">
228
+ <h2 class="text-xl font-semibold">{post.title}</h2>
229
+ <p class="mt-2 text-gray-600">{post.content}</p>
230
+ </div>
231
+ {/each}
232
+ </div>
233
+ </div>
234
+ ```
235
+
236
+ 2. Create `resources/views/posts/create.svelte`:
237
+
238
+ ```svelte
239
+ <script>
240
+ import { router } from '@inertiajs/svelte';
241
+
242
+ let form = {
243
+ title: '',
244
+ content: ''
245
+ };
246
+
247
+ function handleSubmit() {
248
+ router.post('/posts', form);
249
+ }
250
+ </script>
251
+
252
+ <div class="max-w-4xl mx-auto p-4">
253
+ <h1 class="text-2xl font-bold mb-6">Create New Post</h1>
254
+
255
+ <form on:submit|preventDefault={handleSubmit} class="space-y-4">
256
+ <div>
257
+ <label class="block text-sm font-medium mb-1">Title</label>
258
+ <input
259
+ type="text"
260
+ bind:value={form.title}
261
+ class="w-full px-3 py-2 border rounded"
262
+ />
263
+ </div>
264
+
265
+ <div>
266
+ <label class="block text-sm font-medium mb-1">Content</label>
267
+ <textarea
268
+ bind:value={form.content}
269
+ class="w-full px-3 py-2 border rounded h-32"
270
+ ></textarea>
271
+ </div>
272
+
273
+ <div>
274
+ <button
275
+ type="submit"
276
+ class="bg-blue-500 text-white px-4 py-2 rounded hover:bg-blue-600"
277
+ >
278
+ Create Post
279
+ </button>
280
+ </div>
281
+ </form>
282
+ </div>
283
+ ```
284
+
285
+ ### 4. Testing Your Application
286
+
287
+ 1. Start the development server:
288
+ ```bash
289
+ npm run dev
290
+ ```
291
+
292
+ 2. Visit `http://localhost:5555/posts` in your browser
293
+ 3. Try creating a new post using the form
294
+ 4. View the list of posts on the index page
295
+
296
+ ### Key Concepts
297
+
298
+ 1. **Routing**: Routes are defined in `routes/web.ts` using the HyperExpress router
299
+ 2. **Controllers**: Handle business logic and return Inertia responses
300
+ 3. **Database**: Use Knex.js for database operations and migrations
301
+ 4. **Frontend**: Svelte components with Inertia.js for seamless page transitions
302
+ 5. **Styling**: TailwindCSS for utility-first styling
303
+
304
+ ### Best Practices
305
+
306
+ 1. **File Organization**
307
+ - Keep controllers in `app/controllers`
308
+ - Place Svelte components in `resources/views`
309
+ - Database migrations in `migrations`
310
+
311
+ 2. **Code Structure**
312
+ - Use TypeScript types for better type safety
313
+ - Keep controllers focused on single responsibilities
314
+ - Use Inertia.js for state management between server and client
315
+
316
+ 3. **Database**
317
+ - Always use migrations for database changes
318
+ - Use the Query Builder for complex queries
319
+ - Include timestamps for tracking record changes
320
+
321
+ Need help with anything specific? Feel free to ask!
322
+
package/bin/cli.js CHANGED
@@ -7,60 +7,60 @@ const path = require('path');
7
7
  const fs = require('fs');
8
8
 
9
9
  program
10
- .name('create-my-app')
11
- .description('CLI untuk membuat proyek baru dari template')
10
+ .name('create-laju-app')
11
+ .description('CLI to create a new project from template')
12
12
  .version('1.0.0');
13
13
 
14
14
  program
15
- .argument('[project-directory]', 'Nama direktori proyek')
15
+ .argument('[project-directory]', 'Project directory name')
16
16
  .action(async (projectDirectory) => {
17
17
  try {
18
- // Jika tidak ada nama proyek, tanya user
18
+ // If no project name, ask user
19
19
  if (!projectDirectory) {
20
20
  const response = await prompts({
21
21
  type: 'text',
22
22
  name: 'projectDirectory',
23
- message: 'Masukkan nama proyek:'
23
+ message: 'Enter project name:'
24
24
  });
25
25
  projectDirectory = response.projectDirectory;
26
26
  }
27
27
 
28
28
  if (!projectDirectory) {
29
- console.log('Nama proyek diperlukan untuk melanjutkan.');
29
+ console.log('Project name is required to continue.');
30
30
  process.exit(1);
31
31
  }
32
32
 
33
33
  const targetPath = path.resolve(projectDirectory);
34
34
 
35
- // Cek apakah direktori sudah ada
35
+ // Check if directory exists
36
36
  if (fs.existsSync(targetPath)) {
37
- console.log(`Direktori ${projectDirectory} sudah ada. Pilih nama lain.`);
37
+ console.log(`Directory ${projectDirectory} already exists. Choose another name.`);
38
38
  process.exit(1);
39
39
  }
40
40
 
41
41
  console.log(`Creating a new project in ${targetPath}...`);
42
42
 
43
- // Clone template dari GitHub
43
+ // Clone template from GitHub
44
44
  const emitter = degit('maulanashalihin/laju');
45
45
 
46
46
  await emitter.clone(targetPath);
47
47
 
48
- // Baca package.json dari template
48
+ // Read package.json from template
49
49
  const packageJsonPath = path.join(targetPath, 'package.json');
50
50
  const packageJson = require(packageJsonPath);
51
51
 
52
- // Update nama proyek di package.json
52
+ // Update project name in package.json
53
53
  packageJson.name = projectDirectory;
54
54
 
55
- // Tulis kembali package.json
55
+ // Write back package.json
56
56
  fs.writeFileSync(
57
57
  packageJsonPath,
58
58
  JSON.stringify(packageJson, null, 2)
59
59
  );
60
60
 
61
- console.log('✅ Project berhasil dibuat!');
61
+ console.log('✅ Project created successfully!');
62
62
  console.log('');
63
- console.log('Untuk memulai:');
63
+ console.log('To get started:');
64
64
  console.log(` cd ${projectDirectory}`);
65
65
  console.log(' npm install');
66
66
  console.log(' npm run dev');
package/package.json CHANGED
@@ -1,6 +1,16 @@
1
1
  {
2
2
  "name": "create-laju-app",
3
- "version": "1.0.1",
3
+ "version": "1.0.4",
4
+ "keywords": [
5
+ "laju",
6
+ "svelte",
7
+ "tailwindcss",
8
+ "hyper-express",
9
+ "sqlite",
10
+ "boilerplate",
11
+ "template",
12
+ "generator"
13
+ ],
4
14
  "bin": {
5
15
  "create-laju-app": "./bin/cli.js"
6
16
  },
@@ -8,5 +18,12 @@
8
18
  "commander": "^11.0.0",
9
19
  "degit": "^2.8.4",
10
20
  "prompts": "^2.4.2"
21
+ },
22
+ "homepage": "https://laju.dev",
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "git+https://github.com/maulanashalihin/laju.git"
11
26
  }
27
+
28
+
12
29
  }