From c5bfb88526df3b94d4033ce589e1dc2b6e9c2298 Mon Sep 17 00:00:00 2001 From: Johann Schopplich Date: Tue, 3 Oct 2023 17:21:39 +0200 Subject: [PATCH 1/3] feat: load app name from `capacitor.config.{json,js,ts}` --- src/module.ts | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/module.ts b/src/module.ts index dfdaffac..3537d115 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 { @@ -113,18 +114,30 @@ export default defineNuxtModule({ getContents: () => `export default ${JSON.stringify(options.config)}`, }) + // Create an Ionic config file if it doesn't exist yet // 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 From 3b1d83b64fa7f2f7b14abcecef025a9fd03a99a9 Mon Sep 17 00:00:00 2001 From: Johann Schopplich Date: Tue, 3 Oct 2023 17:28:15 +0200 Subject: [PATCH 2/3] chore: remove duplicated config --- src/module.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/module.ts b/src/module.ts index 3537d115..32ef278b 100644 --- a/src/module.ts +++ b/src/module.ts @@ -114,7 +114,6 @@ export default defineNuxtModule({ getContents: () => `export default ${JSON.stringify(options.config)}`, }) - // Create an Ionic config file if it doesn't exist yet // Create an Ionic config file if it doesn't exist yet const ionicConfigPath = join(nuxt.options.rootDir, 'ionic.config.json') if (!existsSync(ionicConfigPath)) { From 6fc64e7c0e0a8119a8e580d067711831870613ed Mon Sep 17 00:00:00 2001 From: Johann Schopplich Date: Wed, 4 Oct 2023 11:05:28 +0200 Subject: [PATCH 3/3] chore: add `c12` as dependency --- package.json | 2 +- pnpm-lock.yaml | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 23c215c9..cb762ef2 100644 --- a/package.json +++ b/package.json @@ -60,9 +60,9 @@ "@ionic/vue-router": "^7.0.1", "@kevinmarrec/nuxt-pwa": "^0.17.0", "@nuxt/kit": "^3.1.0", + "c12": "^1.4.2", "ionicons": "^7.0.0", "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 71071f8d..997e2c55 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.28.0) + c12: + specifier: ^1.4.2 + version: 1.4.2 ionicons: specifier: ^7.0.0 version: 7.0.0 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