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