|
@@ -0,0 +1,36 @@
|
|
|
+// build-android.js 位于 .build/ 目录下
|
|
|
+const fs = require('fs');
|
|
|
+const path = require('path');
|
|
|
+const { execSync } = require('child_process');
|
|
|
+
|
|
|
+// 计算各路径
|
|
|
+const rootDir = path.join(__dirname, '..'); // 项目根目录
|
|
|
+const cordovaPrjDir = path.join(__dirname, 'dros'); // .build/dros
|
|
|
+const srcDir = path.join(rootDir, 'dist', 'h5'); // ../dist/h5
|
|
|
+const dstDir = path.join(cordovaPrjDir, 'www');
|
|
|
+
|
|
|
+// 1. 在项目根目录执行 cordova create
|
|
|
+execSync('npx cordova create .build/dros', { cwd: rootDir, stdio: 'inherit' });
|
|
|
+
|
|
|
+// 2. 在 .build/dros 中执行 cordova platform add android
|
|
|
+execSync('npx cordova platform add android', { cwd: cordovaPrjDir, stdio: 'inherit' });
|
|
|
+
|
|
|
+// 3. 复制 dist/h5 → .build/dros/www
|
|
|
+fs.rmSync(dstDir, { recursive: true, force: true });
|
|
|
+fs.mkdirSync(dstDir, { recursive: true });
|
|
|
+
|
|
|
+function copy(src, dst) {
|
|
|
+ const stat = fs.statSync(src);
|
|
|
+ if (stat.isDirectory()) {
|
|
|
+ fs.mkdirSync(dst, { recursive: true });
|
|
|
+ for (const entry of fs.readdirSync(src)) {
|
|
|
+ copy(path.join(src, entry), path.join(dst, entry));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ fs.copyFileSync(src, dst);
|
|
|
+ }
|
|
|
+}
|
|
|
+copy(srcDir, dstDir);
|
|
|
+
|
|
|
+// 4. 在 .build/dros 中执行 cordova build android
|
|
|
+execSync('npx cordova build android', { cwd: cordovaPrjDir, stdio: 'inherit' });
|