Skip to content

Commit 66989eb

Browse files
committed
working on npx creation of ojs app
1 parent d61a7e8 commit 66989eb

89 files changed

Lines changed: 2464 additions & 376 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
</p>
99

1010
<p align="center">
11-
<strong>The Progressive, PHP-Inspired JavaScript Framework for Artisans.</strong>
11+
<strong>The Progressive, Lightweight JavaScript Framework for Artisans.</strong>
1212
</p>
1313

1414
<p align="center">
@@ -443,7 +443,6 @@ OpenScript is built around an **Inversion of Control (IoC) Container**. Instead
443443
| **Markup Engine** | `app('h')` | Helper proxy for creating DOM elements. |
444444
| **Router** | `app('router')` | Manages navigation and URL handling. |
445445
| **Broker** | `app('broker')` | Central event bus for decoupled communication. |
446-
| **Context** | `app('contextProvider')` | Manages global application state contexts. |
447446

448447
---
449448

@@ -485,8 +484,9 @@ export default class Counter extends Component {
485484
}
486485
}
487486

488-
// CRITICAL: Register before usage!
489-
ojs(Counter);
487+
// ./components/App.js
488+
// CRITICAL: Register counter before usage!
489+
// ojs(Counter);
490490
```
491491

492492
> [!IMPORTANT]
@@ -569,7 +569,7 @@ Listen to global application events dispatched via the Broker. Methods prefixed
569569
import { parsePayload } from "modular-openscriptjs";
570570
571571
export default class UserProfile extends Component {
572-
// Listen for 'auth:login' event
572+
// Listen for 'auth' and 'login' event
573573
async $$auth_login(eventData, eventName) {
574574
// 1. Parse the payload
575575
const data = parsePayload(eventData);

package.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,8 @@
1919
"require": "./build/vite-plugin-openscript.js"
2020
}
2121
},
22-
"bin": {
23-
"create-ojs-app": "bin/create-ojs-app"
24-
},
2522
"files": [
2623
"dist",
27-
"bin",
28-
"templates",
2924
"build/vite-plugin-openscript.js",
3025
"build/vite-plugin-openscript.d.ts",
3126
"styles",

packages/create-ojs-app/README.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# create-ojs-app
2+
3+
CLI tool to scaffold new OpenScript projects.
4+
5+
## Usage
6+
7+
```bash
8+
npx create-ojs-app <project-name> [template]
9+
```
10+
11+
## Available Templates
12+
13+
| Template | Description |
14+
| ----------- | -------------------------------------------- |
15+
| `basic` | Basic OpenScript project with Vite (default) |
16+
| `tailwind` | Project with TailwindCSS integration |
17+
| `bootstrap` | Project with Bootstrap 5 integration |
18+
19+
## Examples
20+
21+
```bash
22+
# Create a basic project
23+
npx create-ojs-app my-app
24+
25+
# Create a project with TailwindCSS
26+
npx create-ojs-app my-app tailwind
27+
28+
# Create a project with Bootstrap
29+
npx create-ojs-app my-app bootstrap
30+
```
31+
32+
## What's Included
33+
34+
Each scaffolded project includes:
35+
36+
- 📦 Vite for fast development and building
37+
- 🎯 Pre-configured OpenScript setup with Vite plugin
38+
- 🛣️ Router with example routes
39+
- 🧩 Example components (App, HomePage, AboutUs, Counter)
40+
- 📝 Context management setup
41+
- 📡 Event broker with mediators
42+
43+
## ⚠️ Important: Vite Plugin Required!
44+
45+
**The OpenScript Vite plugin is REQUIRED for your application to work.** All templates come pre-configured with the plugin in `vite.config.js`:
46+
47+
```javascript
48+
import { defineConfig } from "vite";
49+
import { openScriptComponentPlugin } from "modular-openscriptjs/plugin";
50+
51+
export default defineConfig({
52+
// ...
53+
plugins: [
54+
openScriptComponentPlugin({
55+
componentsDir: "src/components",
56+
autoRegister: true,
57+
generateTypes: true,
58+
}),
59+
],
60+
});
61+
```
62+
63+
**Do NOT remove this plugin** - it handles component registration, type generation, and other essential build-time transformations.
64+
65+
## Learn More
66+
67+
- [OpenScriptJs Documentation](https://github.com/OpenScriptJs/modular-openscript)
68+
- [Vite Documentation](https://vitejs.dev/)
69+
70+
## License
71+
72+
MIT
Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,15 @@ async function createProject(projectName, template = "basic") {
5959
logSuccess(`Created directory: ${projectName}`);
6060

6161
// Get template path
62-
const templatesDir = path.join(__dirname, "..", "templates");
62+
const templatesDir = path.join(__dirname, "templates");
6363
const templatePath = path.join(templatesDir, template);
6464

6565
if (!fs.existsSync(templatePath)) {
6666
logError(`Template "${template}" not found!`);
67+
log("\nAvailable templates:", "cyan");
68+
log(" basic - Basic OpenScript project (default)", "cyan");
69+
log(" tailwind - Project with TailwindCSS integration", "cyan");
70+
log(" bootstrap - Project with Bootstrap 5 integration\n", "cyan");
6771
fs.rmdirSync(projectPath);
6872
process.exit(1);
6973
}
@@ -101,7 +105,7 @@ async function createProject(projectName, template = "basic") {
101105

102106
fs.writeFileSync(
103107
path.join(projectPath, "package.json"),
104-
JSON.stringify(packageJson, null, 2)
108+
JSON.stringify(packageJson, null, 2),
105109
);
106110
logSuccess("Created package.json");
107111

@@ -163,7 +167,7 @@ function updateProjectName(projectPath, projectName) {
163167
let content = fs.readFileSync(indexHtmlPath, "utf8");
164168
content = content.replace(
165169
/<title>.*<\/title>/,
166-
`<title>${projectName}</title>`
170+
`<title>${projectName}</title>`,
167171
);
168172
fs.writeFileSync(indexHtmlPath, content);
169173
}
@@ -177,17 +181,35 @@ function updateProjectName(projectPath, projectName) {
177181
}
178182
}
179183

184+
function showHelp() {
185+
log("\n📦 create-ojs-app - OpenScript Project Scaffolding Tool\n", "bright");
186+
log("Usage:", "cyan");
187+
log(" npx create-ojs-app <project-name> [template]\n", "cyan");
188+
log("Arguments:", "cyan");
189+
log(" project-name Name of your new project (required)", "cyan");
190+
log(" template Template to use (optional, default: basic)\n", "cyan");
191+
log("Available templates:", "cyan");
192+
log(" basic - Basic OpenScript project with Vite", "cyan");
193+
log(" tailwind - Project with TailwindCSS integration", "cyan");
194+
log(" bootstrap - Project with Bootstrap 5 integration\n", "cyan");
195+
log("Examples:", "cyan");
196+
log(" npx create-ojs-app my-app", "cyan");
197+
log(" npx create-ojs-app my-app tailwind", "cyan");
198+
log(" npx create-ojs-app my-app bootstrap\n", "cyan");
199+
}
200+
180201
// Parse command line arguments
181202
const args = process.argv.slice(2);
182203

204+
// Handle help flag
205+
if (args.includes("--help") || args.includes("-h")) {
206+
showHelp();
207+
process.exit(0);
208+
}
209+
183210
if (args.length === 0) {
184211
log("\n❌ Please specify a project name\n", "red");
185-
log("Usage: npm create ojs-app <project-name> [template]\n", "cyan");
186-
log(" or: npx create-ojs-app <project-name> [template]\n", "cyan");
187-
log("Available templates:", "cyan");
188-
log(" basic - Basic OpenScript project (default)", "cyan");
189-
log(" tailwind - Project with TailwindCSS integration", "cyan");
190-
log(" bootstrap - Project with Bootstrap 5 integration\n", "cyan");
212+
showHelp();
191213
process.exit(1);
192214
}
193215

@@ -197,7 +219,7 @@ const template = args[1] || "basic";
197219
// Validate project name
198220
if (!/^[a-z0-9-_]+$/.test(projectName)) {
199221
logError(
200-
"Project name can only contain lowercase letters, numbers, hyphens, and underscores"
222+
"Project name can only contain lowercase letters, numbers, hyphens, and underscores",
201223
);
202224
process.exit(1);
203225
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"name": "create-ojs-app",
3+
"version": "1.0.0",
4+
"description": "CLI to scaffold OpenScript projects - Create modern web apps with OpenScriptJs",
5+
"type": "module",
6+
"bin": {
7+
"create-ojs-app": "index.js"
8+
},
9+
"files": [
10+
"index.js",
11+
"templates"
12+
],
13+
"keywords": [
14+
"openscript",
15+
"openscriptjs",
16+
"scaffold",
17+
"cli",
18+
"create-app",
19+
"vite",
20+
"frontend",
21+
"framework"
22+
],
23+
"author": "Levi Kamara Zwannah",
24+
"license": "MIT",
25+
"repository": {
26+
"type": "git",
27+
"url": "git+https://github.com/OpenScriptJs/modular-openscript.git",
28+
"directory": "packages/create-ojs-app"
29+
},
30+
"bugs": {
31+
"url": "https://github.com/OpenScriptJs/modular-openscript/issues"
32+
},
33+
"homepage": "https://github.com/OpenScriptJs/modular-openscript#readme",
34+
"engines": {
35+
"node": ">=16.0.0"
36+
}
37+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Dependencies
2+
node_modules
3+
package-lock.json
4+
yarn.lock
5+
pnpm-lock.yaml
6+
7+
# Build outputs
8+
dist
9+
dist-ssr
10+
*.local
11+
12+
# Editor
13+
.vscode/*
14+
!.vscode/extensions.json
15+
.idea
16+
.DS_Store
17+
*.suo
18+
*.ntvs*
19+
*.njsproj
20+
*.sln
21+
*.sw?
22+
23+
# Logs
24+
logs
25+
*.log
26+
npm-debug.log*
27+
yarn-debug.log*
28+
yarn-error.log*
29+
30+
# Environment
31+
.env
32+
.env.local
33+
.env.*.local
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# {{PROJECT_NAME}}
2+
3+
A new OpenScript project created with `create-ojs-app`.
4+
5+
## Getting Started
6+
7+
```bash
8+
# Install dependencies
9+
npm install
10+
11+
# Start development server
12+
npm run dev
13+
14+
# Build for production
15+
npm run build
16+
```
17+
18+
## Project Structure
19+
20+
```
21+
src/
22+
├── components/ # OpenScript components
23+
│ ├── App.js # Root component
24+
│ └── Counter.js # Example counter component
25+
├── style.css # Global styles
26+
└── main.js # Application entry point
27+
```
28+
29+
## Learn More
30+
31+
- [OpenScript Documentation](https://github.com/yourusername/openscriptjs)
32+
- [OpenScript Examples](https://github.com/yourusername/openscriptjs/tree/main/examples)
33+
34+
## Features
35+
36+
- ⚡️ Fast development with Vite
37+
- 🎨 Component-based architecture
38+
- 📦 Reactive state management
39+
- 🔄 Built-in routing
40+
- 🎯 Event-driven communication
41+
42+
Enjoy building with OpenScript! 🚀
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>OpenScript App</title>
8+
</head>
9+
10+
<body>
11+
<div id="app-root"></div>
12+
<script type="module" src="src/main.js"></script>
13+
</body>
14+
15+
</html>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import {Component, app} from "modular-openscriptjs";
2+
3+
const h = app("h");
4+
5+
export default class AboutUs extends Component {
6+
render(...args) {
7+
return h.div(
8+
{ class: "about-us" },
9+
h.h1("About Us"),
10+
h.p("This is the about page"),
11+
...args
12+
);
13+
}
14+
}

0 commit comments

Comments
 (0)