diff --git a/package.json b/package.json index 516fc121..89b263c2 100644 --- a/package.json +++ b/package.json @@ -60,9 +60,9 @@ "@ionic/vue-router": "^7.5.2", "@kevinmarrec/nuxt-pwa": "^0.17.0", "@nuxt/kit": "^3.1.0", + "c12": "^1.4.2", "ionicons": "^7.2.1", "pathe": "^1.1.1", - "pkg-types": "^1.0.3", "ufo": "^1.1.2", "unimport": "^3.0.8" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 472a4505..7a58bffb 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -35,15 +35,15 @@ importers: '@nuxt/kit': specifier: 3.6.5 version: 3.6.5(rollup@3.29.4) + c12: + specifier: ^1.4.2 + version: 1.4.2 ionicons: specifier: ^7.2.1 version: 7.2.1 pathe: specifier: ^1.1.1 version: 1.1.1 - pkg-types: - specifier: ^1.0.3 - version: 1.0.3 ufo: specifier: ^1.1.2 version: 1.1.2 diff --git a/src/module.ts b/src/module.ts index dfdaffac..32ef278b 100644 --- a/src/module.ts +++ b/src/module.ts @@ -8,7 +8,7 @@ import { addImportsSources, } from '@nuxt/kit' import { join, resolve } from 'pathe' -import { readPackageJSON } from 'pkg-types' +import { loadConfig } from 'c12' import { defineUnimportPreset } from 'unimport' import { runtimeDir } from './utils' @@ -21,6 +21,7 @@ import { setupMeta } from './parts/meta' import { setupPWA } from './parts/pwa' import { setupRouter } from './parts/router' +import type { CapacitorConfig } from '@capacitor/cli' import type { AnimationBuilder, SpinnerTypes, PlatformConfig } from '@ionic/vue' export interface ModuleOptions { @@ -116,15 +117,26 @@ export default defineNuxtModule({ // Create an Ionic config file if it doesn't exist yet const ionicConfigPath = join(nuxt.options.rootDir, 'ionic.config.json') if (!existsSync(ionicConfigPath)) { + // Look for any `capacitor.config.{json,js,ts}` and load it + const { config } = await loadConfig({ + cwd: nuxt.options.rootDir, + name: 'capacitor', + rcFile: false, + jitiOptions: { + interopDefault: true, + esmResolve: true, + }, + }) + await fsp.writeFile( ionicConfigPath, JSON.stringify( { - name: await readPackageJSON(nuxt.options.rootDir).then( - ({ name }) => name || 'nuxt-ionic-project' - ), - integrations: {}, - type: 'vue', + name: config?.appName || 'nuxt-ionic-project', + integrations: { + capacitor: {}, + }, + type: 'vue-vite', }, null, 2