frontend-hamroun 1.0.0 → 1.0.1

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/bin/cli.js ADDED
@@ -0,0 +1,109 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { program } from 'commander';
4
+ import inquirer from 'inquirer';
5
+ import chalk from 'chalk';
6
+ import fs from 'fs-extra';
7
+ import path from 'path';
8
+ import { createSpinner } from 'nanospinner';
9
+ import { fileURLToPath } from 'url';
10
+
11
+ const __filename = fileURLToPath(import.meta.url);
12
+ const __dirname = path.dirname(__filename);
13
+
14
+ const CHOICES = {
15
+ SPA: 'Single Page Application',
16
+ COMPONENT: 'Component Library'
17
+ };
18
+
19
+ async function createProject(projectName, options) {
20
+ const spinner = createSpinner('Creating project...').start();
21
+
22
+ try {
23
+ // Validate project name
24
+ if (!projectName) {
25
+ spinner.error({ text: 'Project name is required' });
26
+ process.exit(1);
27
+ }
28
+
29
+ const targetDir = path.join(process.cwd(), projectName);
30
+
31
+ // Check if directory exists
32
+ if (fs.existsSync(targetDir)) {
33
+ spinner.error({ text: 'Directory already exists!' });
34
+ process.exit(1);
35
+ }
36
+
37
+ // Get template path
38
+ const templatePath = path.join(__dirname, '../templates', options.template.toLowerCase());
39
+
40
+ // Ensure template exists
41
+ if (!fs.existsSync(templatePath)) {
42
+ spinner.error({ text: 'Template not found!' });
43
+ process.exit(1);
44
+ }
45
+
46
+ // Copy template
47
+ await fs.copy(templatePath, targetDir);
48
+
49
+ // Update package.json
50
+ const packageJsonPath = path.join(targetDir, 'package.json');
51
+ const packageJson = await fs.readJson(packageJsonPath);
52
+ packageJson.name = projectName;
53
+ await fs.writeJson(packageJsonPath, packageJson, { spaces: 2 });
54
+
55
+ spinner.success({ text: `Project ${chalk.green(projectName)} created successfully!` });
56
+
57
+ console.log('\nNext steps:');
58
+ console.log(` cd ${projectName}`);
59
+ console.log(' npm install');
60
+ console.log(' npm run dev\n');
61
+
62
+ } catch (error) {
63
+ spinner.error({ text: `Error: ${error.message}` });
64
+ process.exit(1);
65
+ }
66
+ }
67
+
68
+ program
69
+ .name('frontend-hamroun')
70
+ .description('CLI for Frontend Hamroun Framework')
71
+ .version('1.0.0');
72
+
73
+ program
74
+ .command('create <project-name>')
75
+ .description('Create a new project')
76
+ .action(async (projectName) => {
77
+ const answers = await inquirer.prompt([
78
+ {
79
+ type: 'list',
80
+ name: 'template',
81
+ message: 'What type of project do you want to create?',
82
+ choices: Object.values(CHOICES)
83
+ }
84
+ ]);
85
+
86
+ await createProject(projectName, {
87
+ template: answers.template === CHOICES.SPA ? 'spa' : 'component'
88
+ });
89
+ });
90
+
91
+ program
92
+ .command('dev')
93
+ .description('Start development server')
94
+ .action(() => {
95
+ const spinner = createSpinner('Starting development server...').start();
96
+ // Add dev server logic here
97
+ spinner.success({ text: 'Development server started on http://localhost:3000' });
98
+ });
99
+
100
+ program
101
+ .command('build')
102
+ .description('Build for production')
103
+ .action(() => {
104
+ const spinner = createSpinner('Building for production...').start();
105
+ // Add build logic here
106
+ spinner.success({ text: 'Build complete!' });
107
+ });
108
+
109
+ program.parse();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "frontend-hamroun",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "A lightweight frontend framework with hooks and virtual DOM",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -9,7 +9,9 @@
9
9
  "files": [
10
10
  "dist",
11
11
  "README.md",
12
- "LICENSE"
12
+ "LICENSE",
13
+ "bin",
14
+ "templates"
13
15
  ],
14
16
  "exports": {
15
17
  ".": {
@@ -18,6 +20,10 @@
18
20
  "types": "./dist/index.d.ts"
19
21
  }
20
22
  },
23
+ "bin": {
24
+ "frontend-hamroun": "./bin/cli.js",
25
+ "create-frontend-app": "./bin/cli.js"
26
+ },
21
27
  "scripts": {
22
28
  "build": "vite build && tsc --emitDeclarationOnly",
23
29
  "clean": "node -e \"if(require('fs').existsSync('dist')) require('fs').rmSync('dist',{recursive:true})\"",
@@ -41,7 +47,13 @@
41
47
  "@vitejs/plugin-react": "^4.0.4",
42
48
  "typescript": "^5.0.0",
43
49
  "vite": "^4.4.9",
44
- "vitest": "^0.34.0"
50
+ "vitest": "^0.34.0",
51
+ "nanospinner": "^1.1.0",
52
+ "chalk": "^5.3.0",
53
+ "commander": "^11.0.0",
54
+ "inquirer": "^9.2.10",
55
+ "fs-extra": "^11.1.1",
56
+ "ora": "^7.0.1"
45
57
  },
46
58
  "publishConfig": {
47
59
  "access": "public"
@@ -0,0 +1,12 @@
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>Frontend Hamroun App</title>
7
+ </head>
8
+ <body>
9
+ <div id="app"></div>
10
+ <script type="module" src="/src/main.ts"></script>
11
+ </body>
12
+ </html>
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "frontend-app",
3
+ "private": true,
4
+ "version": "0.0.0",
5
+ "type": "module",
6
+ "scripts": {
7
+ "dev": "vite",
8
+ "build": "vite build",
9
+ "preview": "vite preview"
10
+ },
11
+ "dependencies": {
12
+ "frontend-hamroun": "^1.0.0"
13
+ },
14
+ "devDependencies": {
15
+ "vite": "^4.4.9",
16
+ "typescript": "^5.0.0"
17
+ }
18
+ }
@@ -0,0 +1,26 @@
1
+ import { useState } from 'frontend-hamroun';
2
+
3
+ export default function App() {
4
+ const [count, setCount] = useState(0);
5
+
6
+ return {
7
+ type: 'div',
8
+ props: {
9
+ children: [
10
+ {
11
+ type: 'h1',
12
+ props: {
13
+ children: 'Frontend Hamroun App'
14
+ }
15
+ },
16
+ {
17
+ type: 'button',
18
+ props: {
19
+ onClick: () => setCount(count + 1),
20
+ children: `Count: ${count}`
21
+ }
22
+ }
23
+ ]
24
+ }
25
+ };
26
+ }
@@ -0,0 +1,4 @@
1
+ import { render } from 'frontend-hamroun';
2
+ import App from './App';
3
+
4
+ render(App(), document.getElementById('app')!);