cordova-react-vite 3.0.0 → 3.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.
Files changed (2) hide show
  1. package/execute.js +63 -47
  2. package/package.json +7 -10
package/execute.js CHANGED
@@ -2,77 +2,99 @@
2
2
  const { execSync } = require("child_process");
3
3
  const fs = require("fs");
4
4
  const path = require("path");
5
- const inquirer = require("inquirer");
6
5
 
7
6
  function run(cmd, cwd = process.cwd()) {
8
7
  console.log(`▶ ${cmd}`);
9
8
  execSync(cmd, { stdio: "inherit", cwd, shell: true });
10
9
  }
11
10
 
12
- async function main() {
13
- // گرفتن آرگومان‌ها
14
- const args = process.argv.slice(2);
15
- let rootName = args[0];
16
- let cordovaId = args[1];
11
+ function toKebab(str) {
12
+ return str.toLowerCase().replace(/\s+/g, "-");
13
+ }
17
14
 
18
- // اگر آرگومان نبود، interactive کنیم
19
- if (!rootName || !cordovaId) {
20
- const answers = await inquirer.prompt([
21
- {
22
- type: "input",
23
- name: "cordovaId",
24
- message: "نام Package ID برای Cordova (مثال: com.example.name) چیه؟",
25
- validate: input => input ? true : "نمیشه خالی باشه!"
26
- },
27
- {
28
- type: "input",
29
- name: "rootName",
30
- message: "نام فولدر اصلی و package.json (kebab-case) چیه؟",
31
- validate: input => input ? true : "نمیشه خالی باشه!"
32
- }
33
- ]);
15
+ function toCamel(str) {
16
+ return str.replace(/\s+/g, "").toLowerCase();
17
+ }
34
18
 
35
- rootName = answers.rootName;
36
- cordovaId = answers.cordovaId;
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("❌ wrong statement example: cordova-react-vite Boxit Tracker boxitsoft.ir");
28
+ process.exit(1);
37
29
  }
38
30
 
39
- const displayName = rootName;
40
- const npmName = rootName;
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);
41
36
  const cordovaName = displayName;
42
37
 
43
38
  const rootPath = path.join(process.cwd(), npmName);
44
39
  if (!fs.existsSync(rootPath)) fs.mkdirSync(rootPath);
45
40
 
46
- console.log(`🚀 ایجاد پروژه ${displayName}`);
41
+ console.log(`🚀 create project ${displayName}`);
47
42
  console.log(`📦 npm name: ${npmName}`);
48
43
  console.log(`📱 cordova id: ${cordovaId}`);
44
+ console.log(`📱 cordova name: ${cordovaName}`);
49
45
 
50
46
  // ---- React Vite ----
51
- console.log("📦 ایجاد پروژه React (Vite)...");
47
+ console.log("📦 create project React (Vite)...");
52
48
  run(`npm create vite@latest react -- --template react`, rootPath);
53
49
  run(`npm install`, path.join(rootPath, "react"));
54
-
55
- // اضافه کردن <script src="cordova.js"> به index.html
50
+ // install aio-cordova
51
+ console.log("📦 install aio-cordova in React...");
52
+ run(`npm install aio-cordova`, path.join(rootPath, "react"));
53
+ // add <script src="cordova.js"> to index.html
56
54
  const indexHtmlPath = path.join(rootPath, "react", "index.html");
57
55
  if (fs.existsSync(indexHtmlPath)) {
58
56
  let html = fs.readFileSync(indexHtmlPath, "utf8");
59
57
  if (!html.includes('cordova.js')) {
60
58
  html = html.replace("</body>", " <script src=\"cordova.js\"></script>\n</body>");
61
59
  fs.writeFileSync(indexHtmlPath, html, "utf8");
62
- console.log("✔ <script src=\"cordova.js\"> به index.html اضافه شد");
60
+ console.log("✔ <script src=\"cordova.js\"> added to index.html");
63
61
  }
64
62
  }
63
+ // ---- overwrite App.tsx ----
64
+ const appTsxPath = path.join(rootPath, "react", "src", "App.tsx");
65
+ const appTsxContent = `import { FC } from "react";
66
+ import { AIOCordovaComponent, AIOCordova } from "aio-cordova";
65
67
 
68
+ const App: FC = () => {
69
+ return (
70
+ <AIOCordovaComponent
71
+ startWindows={() => <WindowsApp />}
72
+ startAndroid={(aioCordova) => <AndroidApp aioCordova={aioCordova} />}
73
+ />
74
+ )
75
+ }
76
+ export default App;
77
+
78
+ const WindowsApp: FC = () => {
79
+ return null;
80
+ }
81
+ const AndroidApp: FC = (inst: AIOCordova) => {
82
+ return null;
83
+ }
84
+ `;
85
+
86
+ fs.writeFileSync(appTsxPath, appTsxContent, "utf8");
87
+ console.log("✔ src/App.tsx changed");
66
88
  // ---- Cordova ----
67
- console.log("📱 ایجاد پروژه Cordova...");
89
+ console.log("creating cordova project");
68
90
  run(`npx cordova create cordova ${cordovaId} "${cordovaName}"`, rootPath);
69
91
 
70
92
  // ---- Android platform ----
71
- console.log("📱 اضافه کردن Android platform...");
93
+ console.log("add android platform");
72
94
  run(`npx cordova platform add android`, path.join(rootPath, "cordova"));
73
95
 
74
- // ---- package.json روت ----
75
- console.log("🛠 ایجاد package.json روت...");
96
+ // ---- package.json root ----
97
+ console.log("create root package.json");
76
98
  const rootPkg = {
77
99
  name: npmName,
78
100
  version: "1.0.0",
@@ -85,9 +107,8 @@ async function main() {
85
107
  "build": "npm run react:build && npm run sync:build && npm run cordova:build && npm run move:apk",
86
108
  "start": "cd react && npm run dev"
87
109
  },
88
- dependencies: {
89
- "rimraf": "^5.0.0",
90
- "inquirer": "^9.2.0"
110
+ devDependencies: {
111
+ rimraf: "^5.0.0"
91
112
  }
92
113
  };
93
114
 
@@ -95,14 +116,9 @@ async function main() {
95
116
  path.join(rootPath, "package.json"),
96
117
  JSON.stringify(rootPkg, null, 2)
97
118
  );
98
-
99
- console.log(" پروژه آماده شد!");
100
- console.log(`📂 ساختار پروژه:
101
- ${npmName}/
102
- ├─ react/ ← پروژه React Vite
103
- ├─ cordova/ ← پروژه Cordova (${cordovaId}, Android platform اضافه شد)
104
- └─ package.json ← مدیریت مشترک build
105
- `);
119
+ // ---- install root package.json dependencies ----
120
+ console.log("📦 install root package.json dependencies...");
121
+ run(`npm install`, rootPath);
122
+ console.log("✅ project is ready!");
106
123
  }
107
-
108
124
  main();
package/package.json CHANGED
@@ -1,17 +1,14 @@
1
1
  {
2
2
  "name": "cordova-react-vite",
3
- "version": "3.0.0",
4
- "description": "Create React + Vite + Cordova project with Android build",
3
+ "version": "3.0.2",
4
+ "description": "CLI to create a full React + Vite + Cordova project with Android platform",
5
+ "main": "execute.js",
5
6
  "bin": {
6
7
  "cordova-react-vite": "execute.js"
7
8
  },
8
- "scripts": {
9
- "start": "node execute.js"
10
- },
11
- "author": "Your Name",
9
+ "keywords": ["cordova", "react", "vite", "android", "cli"],
10
+ "author": "mohammad shadrif feiz",
12
11
  "license": "ISC",
13
- "dependencies": {
14
- "inquirer": "^9.2.0",
15
- "rimraf": "^5.0.0"
16
- }
12
+ "dependencies": {},
13
+ "devDependencies": {}
17
14
  }