cordova-react-vite 1.0.0

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 +1 -0
  2. package/execute.js +103 -0
  3. package/package.json +14 -0
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # cordova-react-vite
package/execute.js ADDED
@@ -0,0 +1,103 @@
1
+ #!/usr/bin/env node
2
+ const { execSync } = require("child_process");
3
+ const fs = require("fs");
4
+ const path = require("path");
5
+
6
+ function run(cmd, cwd = process.cwd()) {
7
+ console.log(`▶ ${cmd}`);
8
+ execSync(cmd, { stdio: "inherit", cwd, shell: true });
9
+ }
10
+
11
+ function toKebab(str) {
12
+ return str.toLowerCase().replace(/\s+/g, "-");
13
+ }
14
+
15
+ function toCamel(str) {
16
+ return str.replace(/\s+/g, "").toLowerCase();
17
+ }
18
+
19
+ function reverseDomain(domain, appName) {
20
+ const parts = domain.split(".").reverse();
21
+ return [...parts, toCamel(appName)].join(".");
22
+ }
23
+
24
+ function main() {
25
+ const args = process.argv.slice(2);
26
+ if (args.length < 2) {
27
+ console.error("❌ دستور اشتباه!\nمثال: cordova-react-vite Boxit Tracker boxitsoft.ir");
28
+ process.exit(1);
29
+ }
30
+
31
+ const domain = args[args.length - 1];
32
+ const appNameParts = args.slice(0, -1);
33
+ const displayName = appNameParts.join(" ");
34
+ const npmName = toKebab(displayName);
35
+ const cordovaId = reverseDomain(domain, displayName);
36
+ const cordovaName = displayName;
37
+
38
+ const rootPath = path.join(process.cwd(), npmName);
39
+ if (!fs.existsSync(rootPath)) fs.mkdirSync(rootPath);
40
+
41
+ console.log(`🚀 ایجاد پروژه ${displayName}`);
42
+ console.log(`📦 npm name: ${npmName}`);
43
+ console.log(`📱 cordova id: ${cordovaId}`);
44
+ console.log(`📱 cordova name: ${cordovaName}`);
45
+
46
+ // ---- React Vite ----
47
+ console.log("📦 ایجاد پروژه React (Vite)...");
48
+ run(`npm create vite@latest react -- --template react`, rootPath);
49
+ run(`npm install`, path.join(rootPath, "react"));
50
+
51
+ // اضافه کردن <script src="cordova.js"> به index.html
52
+ const indexHtmlPath = path.join(rootPath, "react", "index.html");
53
+ if (fs.existsSync(indexHtmlPath)) {
54
+ let html = fs.readFileSync(indexHtmlPath, "utf8");
55
+ if (!html.includes('cordova.js')) {
56
+ html = html.replace("</body>", " <script src=\"cordova.js\"></script>\n</body>");
57
+ fs.writeFileSync(indexHtmlPath, html, "utf8");
58
+ console.log("✔ <script src=\"cordova.js\"> به index.html اضافه شد");
59
+ }
60
+ }
61
+
62
+ // ---- Cordova ----
63
+ console.log("📱 ایجاد پروژه Cordova...");
64
+ run(`npx cordova create cordova ${cordovaId} "${cordovaName}"`, rootPath);
65
+
66
+ // ---- Android platform ----
67
+ console.log("📱 اضافه کردن Android platform...");
68
+ run(`npx cordova platform add android`, path.join(rootPath, "cordova"));
69
+
70
+ // ---- package.json روت ----
71
+ console.log("🛠 ایجاد package.json روت...");
72
+ const rootPkg = {
73
+ name: npmName,
74
+ version: "1.0.0",
75
+ description: `${cordovaName} - React + Cordova project`,
76
+ scripts: {
77
+ "react:build": "cd react && npm run build",
78
+ "sync:build": "rimraf cordova\\www && xcopy react\\dist cordova\\www /E /H /C /I",
79
+ "cordova:build": "cd cordova && cordova build android",
80
+ "move:apk": "xcopy cordova\\platforms\\android\\app\\build\\outputs\\apk\\debug\\app-debug.apk . /Y",
81
+ "build": "npm run react:build && npm run sync:build && npm run cordova:build && npm run move:apk",
82
+ "start": "cd react && npm run dev"
83
+ },
84
+ devDependencies: {
85
+ rimraf: "^5.0.0"
86
+ }
87
+ };
88
+
89
+ fs.writeFileSync(
90
+ path.join(rootPath, "package.json"),
91
+ JSON.stringify(rootPkg, null, 2)
92
+ );
93
+
94
+ console.log("✅ پروژه آماده شد!");
95
+ console.log(`📂 ساختار پروژه:
96
+ ${npmName}/
97
+ ├─ react/ ← پروژه React Vite
98
+ ├─ cordova/ ← پروژه Cordova (${cordovaId}, Android platform اضافه شد)
99
+ └─ package.json ← مدیریت مشترک build
100
+ `);
101
+ }
102
+
103
+ main();
package/package.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "cordova-react-vite",
3
+ "version": "1.0.0",
4
+ "description": "CLI to create a full React + Vite + Cordova project with Android platform",
5
+ "main": "execute.js",
6
+ "bin": {
7
+ "cordova-react-vite": "execute.js"
8
+ },
9
+ "keywords": ["cordova", "react", "vite", "android", "cli"],
10
+ "author": "Your Name",
11
+ "license": "ISC",
12
+ "dependencies": {},
13
+ "devDependencies": {}
14
+ }