@open-mova/cli 0.1.17 → 0.1.18

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.
@@ -1,5 +1,5 @@
1
1
  import { spawnSync } from 'node:child_process';
2
- import { existsSync, writeFileSync } from 'node:fs';
2
+ import { existsSync, readFileSync, writeFileSync } from 'node:fs';
3
3
  import { join } from 'node:path';
4
4
  import { readApplicationConfiguration, requireApplicationRoot, } from '../application/configuration.js';
5
5
  import { localBinaryName, npmCommand, useCommandShell } from '../utils/platform.js';
@@ -12,13 +12,21 @@ export function registerCapacitorCommands(program) {
12
12
  const root = requireApplicationRoot(process.cwd());
13
13
  buildMobileShell(root);
14
14
  runCapacitor(root, ['add', selectedPlatform]);
15
+ configureNativePlatform(root, selectedPlatform);
15
16
  });
16
17
  capacitor.command('sync [platform]')
17
18
  .description('Compila la shell y sincroniza sus assets y plugins nativos')
18
19
  .action((platform) => {
19
20
  const root = requireApplicationRoot(process.cwd());
20
21
  buildMobileShell(root);
21
- runCapacitor(root, ['sync', ...(platform ? [parsePlatform(platform)] : [])]);
22
+ const selectedPlatform = platform ? parsePlatform(platform) : undefined;
23
+ runCapacitor(root, ['sync', ...(selectedPlatform ? [selectedPlatform] : [])]);
24
+ if (selectedPlatform) {
25
+ configureNativePlatform(root, selectedPlatform);
26
+ }
27
+ else {
28
+ configureExistingPlatforms(root);
29
+ }
22
30
  });
23
31
  capacitor.command('open <platform>')
24
32
  .description('Abre el proyecto nativo en Android Studio o Xcode')
@@ -64,6 +72,35 @@ function isHttpsUrl(value) {
64
72
  return false;
65
73
  }
66
74
  }
75
+ function configureExistingPlatforms(root) {
76
+ if (existsSync(join(root, 'android'))) {
77
+ configureNativePlatform(root, 'android');
78
+ }
79
+ }
80
+ function configureNativePlatform(root, platform) {
81
+ if (platform === 'android') {
82
+ configureBackgroundRunnerForAndroid(root);
83
+ }
84
+ }
85
+ function configureBackgroundRunnerForAndroid(root) {
86
+ const packageJson = JSON.parse(readFileSync(join(root, 'package.json'), 'utf8'));
87
+ if (!packageJson.dependencies?.['@capacitor/background-runner'])
88
+ return;
89
+ const gradlePath = join(root, 'android', 'app', 'build.gradle');
90
+ if (!existsSync(gradlePath)) {
91
+ throw new Error('No se encuentra android/app/build.gradle para configurar Background Runner.');
92
+ }
93
+ const repositoryEntry = "dirs '../../node_modules/@capacitor/background-runner/android/src/main/libs', 'libs'";
94
+ const gradle = readFileSync(gradlePath, 'utf8');
95
+ if (gradle.includes(repositoryEntry))
96
+ return;
97
+ const flatDirectory = /flatDir\s*\{/;
98
+ if (!flatDirectory.test(gradle)) {
99
+ throw new Error('No se ha encontrado el bloque flatDir en android/app/build.gradle.');
100
+ }
101
+ const configuredGradle = gradle.replace(flatDirectory, (match) => `${match}\n ${repositoryEntry}`);
102
+ writeFileSync(gradlePath, configuredGradle, 'utf8');
103
+ }
67
104
  function runCapacitor(root, args) {
68
105
  if (!existsSync(join(root, 'capacitor.config.ts'))) {
69
106
  throw new Error('Esta versión de shell no incluye Capacitor. Usa una shell v0.1.2 o posterior.');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-mova/cli",
3
- "version": "0.1.17",
3
+ "version": "0.1.18",
4
4
  "description": "CLI para crear y mantener aplicaciones Open Mova",
5
5
  "license": "MIT",
6
6
  "author": "Open Mova contributors",