frontend-hamroun 1.1.12 → 1.1.14

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 (2) hide show
  1. package/bin/cli.js +45 -90
  2. package/package.json +3 -3
package/bin/cli.js CHANGED
@@ -2,117 +2,72 @@
2
2
 
3
3
  import { Command } from 'commander';
4
4
  import inquirer from 'inquirer';
5
- import chalk from 'chalk';
6
5
  import fs from 'fs-extra';
7
6
  import path from 'path';
8
- import { createSpinner } from 'nanospinner';
9
7
  import { fileURLToPath } from 'url';
10
- import { dirname } from 'path';
8
+ import chalk from 'chalk';
9
+ import { createSpinner } from 'nanospinner';
11
10
 
12
11
  const __filename = fileURLToPath(import.meta.url);
13
- const __dirname = dirname(__filename);
12
+ const __dirname = path.dirname(__filename);
13
+
14
+ async function init() {
15
+ const program = new Command();
14
16
 
15
- const program = new Command();
17
+ program
18
+ .name('create-frontend-app')
19
+ .description('Create a new Frontend Hamroun application')
20
+ .argument('[name]', 'Project name')
21
+ .action(async (name) => {
22
+ const projectName = name || await askProjectName();
23
+ await createProject(projectName);
24
+ });
16
25
 
17
- const CHOICES = {
18
- SPA: 'Single Page Application',
19
- COMPONENT: 'Component Library'
20
- };
26
+ program.parse();
27
+ }
28
+
29
+ async function askProjectName() {
30
+ const { projectName } = await inquirer.prompt([{
31
+ type: 'input',
32
+ name: 'projectName',
33
+ message: 'What is your project named?',
34
+ default: 'my-frontend-app'
35
+ }]);
36
+ return projectName;
37
+ }
21
38
 
22
- async function createProject(projectName, options) {
39
+ async function createProject(projectName) {
23
40
  const spinner = createSpinner('Creating project...').start();
24
-
25
- try {
26
- // Validate project name
27
- if (!projectName) {
28
- spinner.error({ text: 'Project name is required' });
29
- process.exit(1);
30
- }
31
41
 
42
+ try {
43
+ const templateDir = path.join(__dirname, '..', 'templates', 'basic-app');
32
44
  const targetDir = path.join(process.cwd(), projectName);
33
45
 
34
- // Check if directory exists
35
- if (fs.existsSync(targetDir)) {
36
- spinner.error({ text: 'Directory already exists!' });
37
- process.exit(1);
38
- }
46
+ // Create project directory
47
+ await fs.ensureDir(targetDir);
39
48
 
40
- // Get template path
41
- const templatePath = path.join(__dirname, '../templates', options.template.toLowerCase());
42
-
43
- // Ensure template exists
44
- if (!fs.existsSync(templatePath)) {
45
- spinner.error({ text: 'Template not found!' });
46
- process.exit(1);
47
- }
48
-
49
- // Copy template
50
- await fs.copy(templatePath, targetDir);
49
+ // Copy template files
50
+ await fs.copy(templateDir, targetDir);
51
51
 
52
52
  // Update package.json
53
- const packageJsonPath = path.join(targetDir, 'package.json');
54
- const packageJson = await fs.readJson(packageJsonPath);
55
- packageJson.name = projectName;
56
- await fs.writeJson(packageJsonPath, packageJson, { spaces: 2 });
53
+ const pkgPath = path.join(targetDir, 'package.json');
54
+ const pkg = await fs.readJson(pkgPath);
55
+ pkg.name = projectName;
56
+ await fs.writeJson(pkgPath, pkg, { spaces: 2 });
57
57
 
58
58
  spinner.success({ text: `Project ${chalk.green(projectName)} created successfully!` });
59
-
59
+
60
+ // Show next steps
60
61
  console.log('\nNext steps:');
61
- console.log(` cd ${projectName}`);
62
- console.log(' npm install');
63
- console.log(' npm run dev\n');
62
+ console.log(chalk.cyan(` cd ${projectName}`));
63
+ console.log(chalk.cyan(' npm install'));
64
+ console.log(chalk.cyan(' npm run dev'));
64
65
 
65
66
  } catch (error) {
66
- spinner.error({ text: `Error: ${error.message}` });
67
+ spinner.error({ text: 'Failed to create project' });
68
+ console.error(chalk.red(error));
67
69
  process.exit(1);
68
70
  }
69
71
  }
70
72
 
71
- program
72
- .name('create-frontend-app')
73
- .description('Create a new Frontend Hamroun application')
74
- .argument('[name]', 'Project name')
75
- .action(async (name) => {
76
- let projectName = name;
77
-
78
- if (!projectName) {
79
- const response = await inquirer.prompt([{
80
- type: 'input',
81
- name: 'projectName',
82
- message: 'What is your project named?',
83
- default: 'my-frontend-app'
84
- }]);
85
- projectName = response.projectName;
86
- }
87
-
88
- const spinner = createSpinner('Creating project...').start();
89
-
90
- try {
91
- // Copy template
92
- const templateDir = path.join(__dirname, '..', 'templates', 'basic-app');
93
- const targetDir = path.join(process.cwd(), projectName);
94
-
95
- await fs.ensureDir(targetDir);
96
- await fs.copy(templateDir, targetDir);
97
-
98
- // Update package.json
99
- const pkgJsonPath = path.join(targetDir, 'package.json');
100
- const pkgJson = await fs.readJson(pkgJsonPath);
101
- pkgJson.name = projectName;
102
- await fs.writeJson(pkgJsonPath, pkgJson, { spaces: 2 });
103
-
104
- spinner.success({ text: chalk.green(`Project ${projectName} created successfully!`) });
105
-
106
- console.log('\nNext steps:');
107
- console.log(chalk.cyan(` cd ${projectName}`));
108
- console.log(chalk.cyan(' npm install'));
109
- console.log(chalk.cyan(' npm run dev'));
110
-
111
- } catch (error) {
112
- spinner.error({ text: chalk.red('Failed to create project') });
113
- console.error(error);
114
- process.exit(1);
115
- }
116
- });
117
-
118
- program.parse();
73
+ init().catch(console.error);
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "frontend-hamroun",
3
- "version": "1.1.12",
3
+ "version": "1.1.14",
4
4
  "description": "A lightweight frontend framework with hooks and virtual DOM",
5
5
  "type": "module",
6
- "main": "./dist/index.js",
7
- "module": "./dist/index.es.js",
6
+ "main": "./dist/index.d.ts",
7
+ "module": "./dist/index.d.ts",
8
8
  "types": "./dist/index.d.ts",
9
9
  "files": [
10
10
  "dist",