UNPKG

ionic

Version:

A tool for creating and developing Ionic Framework mobile apps.

99 lines (98 loc) 4.11 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const cli_framework_1 = require("@ionic/cli-framework"); const utils_fs_1 = require("@ionic/utils-fs"); const path = require("path"); const __1 = require("../"); const npm_1 = require("../../utils/npm"); const config_1 = require("./config"); class Integration extends __1.BaseIntegration { constructor() { super(...arguments); this.name = 'capacitor'; this.summary = `Target native iOS and Android with Capacitor, Ionic's new native layer`; this.archiveUrl = undefined; } get config() { return new __1.IntegrationConfig(this.e.project.filePath, { pathPrefix: [...this.e.project.pathPrefix, 'integrations', this.name] }); } async add(details) { let name = this.e.project.config.get('name'); let packageId = 'io.ionic.starter'; const options = []; if (this.e.project.type === 'react') { options.push('--web-dir', 'build'); } else if (this.e.project.type === 'vue') { options.push('--web-dir', 'dist'); } if (details.enableArgs) { const parsedArgs = cli_framework_1.parseArgs(details.enableArgs); name = parsedArgs._[0] || name; packageId = parsedArgs._[1] || packageId; if (parsedArgs['web-dir']) { options.push('--web-dir', parsedArgs['web-dir']); } options.push('--npm-client', this.e.config.get('npmClient')); } await this.installCapacitorCore(); await this.installCapacitorCLI(); await utils_fs_1.mkdirp(details.root); await this.e.shell.run('capacitor', ['init', name, packageId, ...options], { cwd: details.root }); await super.add(details); } async getConfig() { const conf = new config_1.CapacitorConfig(path.resolve(this.e.project.directory, config_1.CAPACITOR_CONFIG_FILE)); return conf; } async installCapacitorCore() { const [manager, ...managerArgs] = await npm_1.pkgManagerArgs(this.e.config.get('npmClient'), { command: 'install', pkg: '@capacitor/core' }); await this.e.shell.run(manager, managerArgs, { cwd: this.e.project.directory }); } async installCapacitorCLI() { const [manager, ...managerArgs] = await npm_1.pkgManagerArgs(this.e.config.get('npmClient'), { command: 'install', pkg: '@capacitor/cli', saveDev: true }); await this.e.shell.run(manager, managerArgs, { cwd: this.e.project.directory }); } async personalize({ name, packageId }) { const conf = await this.getConfig(); conf.set('appName', name); if (packageId) { conf.set('appId', packageId); } } async getInfo() { const conf = await this.getConfig(); const bundleId = conf.get('appId'); const [[capacitorCorePkg, capacitorCorePkgPath], capacitorCLIVersion,] = await Promise.all([ this.e.project.getPackageJson('@capacitor/core'), this.getCapacitorCLIVersion(), ]); // TODO: https://github.com/microsoft/TypeScript/issues/33752 const info = [ { group: 'capacitor', name: 'Capacitor CLI', key: 'capacitor_cli_version', value: capacitorCLIVersion || 'not installed', }, { group: 'capacitor', name: '@capacitor/core', key: 'capacitor_core_version', value: capacitorCorePkg ? capacitorCorePkg.version : 'not installed', path: capacitorCorePkgPath, }, { group: 'capacitor', name: 'Bundle ID', key: 'bundle_id', value: bundleId || 'unknown', hidden: true, }, ]; return info; } async getCapacitorCLIVersion() { return this.e.shell.cmdinfo('capacitor', ['--version'], { cwd: this.e.project.directory }); } } exports.Integration = Integration;