Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: load app name from capacitor.config.{json,js,ts} #469

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
6 changes: 3 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 18 additions & 6 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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 {
Expand Down Expand Up @@ -116,15 +117,26 @@ export default defineNuxtModule<ModuleOptions>({
// 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<CapacitorConfig>({
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',
Comment on lines +137 to +139
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are these changes to the written file definitely correct, bearing in mind the user might not use capacitor? And I'm not sure vue-vite is right:

To support this, we’ve introduced a new project type in the ionic.config.json, vue-vite and react-vite. These new project types will tell the CLI that it should call Vite when you run ionic serve or ionic build.
https://ionic.io/blog/ionic-cli-v7

},
null,
2
Expand Down
Loading