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

Use xdg compliant directories when available #5087

Open
wants to merge 1 commit into
base: develop
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/@ionic/cli/src/commands/config/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import { columnar, prettyPath } from '@ionic/utils-terminal';
import chalk from 'chalk';
import * as lodash from 'lodash';
import * as util from 'util';
import * as path from 'path';

import { COLUMNAR_OPTIONS, PROJECT_FILE } from '../../constants';
import { CommandLineInputs, CommandLineOptions, CommandMetadata } from '../../definitions';
import { input, strong, weak } from '../../lib/color';
import { DEFAULT_CONFIG_DIRECTORY } from '../../lib/config';

import { BaseConfigCommand, ConfigContext, getConfigValue } from './base';

Expand All @@ -20,7 +22,7 @@ export class ConfigGetCommand extends BaseConfigCommand {
type: 'global',
summary: 'Print config values',
description: `
This command reads and prints configuration values from the project's ${strong(projectFile)} file. It can also operate on the global CLI configuration (${strong('~/.ionic/config.json')}) using the ${input('--global')} option.
This command reads and prints configuration values from the project's ${strong(projectFile)} file. It can also operate on the global CLI configuration (${strong(path.join(DEFAULT_CONFIG_DIRECTORY, 'config.json'))}) using the ${input('--global')} option.

For nested properties, separate nest levels with dots. For example, the property name ${input('integrations.cordova')} will look in the ${strong('integrations')} object for the ${strong('cordova')} property.

Expand Down
4 changes: 3 additions & 1 deletion packages/@ionic/cli/src/commands/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { prettyPath } from '@ionic/utils-terminal';
import * as path from 'path';

import { PROJECT_FILE } from '../../constants';
import { input, strong } from '../../lib/color';
import { DEFAULT_CONFIG_DIRECTORY } from '../../lib/config';
import { CommandMap, Namespace } from '../../lib/namespace';

export class ConfigNamespace extends Namespace {
Expand All @@ -16,7 +18,7 @@ These commands are used to programmatically read, write, and delete CLI and proj

By default, these commands use your project's ${strong(prettyPath(projectFile))} file.

To use these commands for the global CLI config file (${strong('~/.ionic/config.json')}), use the ${input('--global')} flag.
To use these commands for the global CLI config file (${strong(path.join(DEFAULT_CONFIG_DIRECTORY, 'config.json'))}), use the ${input('--global')} flag.
`,
};
}
Expand Down
4 changes: 3 additions & 1 deletion packages/@ionic/cli/src/commands/config/set.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { MetadataGroup, validators } from '@ionic/cli-framework';
import { prettyPath } from '@ionic/utils-terminal';
import * as path from 'path';

import { PROJECT_FILE } from '../../constants';
import { CommandLineInputs, CommandLineOptions, CommandMetadata } from '../../definitions';
import { input, strong, weak } from '../../lib/color';
import { DEFAULT_CONFIG_DIRECTORY } from '../../lib/config';
import { FatalException } from '../../lib/errors';

import { BaseConfigCommand, getConfigValue, setConfigValue } from './base';
Expand All @@ -17,7 +19,7 @@ export class ConfigSetCommand extends BaseConfigCommand {
type: 'global',
summary: 'Set config values',
description: `
This command writes configuration values to the project's ${strong(prettyPath(projectFile))} file. It can also operate on the global CLI configuration (${strong('~/.ionic/config.json')}) using the ${input('--global')} option.
This command writes configuration values to the project's ${strong(prettyPath(projectFile))} file. It can also operate on the global CLI configuration (${strong(path.join(DEFAULT_CONFIG_DIRECTORY, 'config.json'))}) using the ${input('--global')} option.

For nested properties, separate nest levels with dots. For example, the property name ${input('integrations.cordova')} will look in the ${strong('integrations')} object for the ${strong('cordova')} property.

Expand Down
4 changes: 3 additions & 1 deletion packages/@ionic/cli/src/commands/config/unset.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { MetadataGroup, validators } from '@ionic/cli-framework';
import { prettyPath } from '@ionic/utils-terminal';
import * as path from 'path';

import { PROJECT_FILE } from '../../constants';
import { CommandLineInputs, CommandLineOptions, CommandMetadata } from '../../definitions';
import { input, strong, weak } from '../../lib/color';
import { DEFAULT_CONFIG_DIRECTORY } from '../../lib/config';
import { FatalException } from '../../lib/errors';

import { BaseConfigCommand, getConfigValue, unsetConfigValue } from './base';
Expand All @@ -17,7 +19,7 @@ export class ConfigUnsetCommand extends BaseConfigCommand {
type: 'global',
summary: 'Delete config values',
description: `
This command deletes configuration values from the project's ${strong(prettyPath(projectFile))} file. It can also operate on the global CLI configuration (${strong('~/.ionic/config.json')}) using the ${input('--global')} option.
This command deletes configuration values from the project's ${strong(prettyPath(projectFile))} file. It can also operate on the global CLI configuration (${strong(path.join(DEFAULT_CONFIG_DIRECTORY, 'config.json'))}) using the ${input('--global')} option.

For nested properties, separate nest levels with dots. For example, the property name ${input('integrations.cordova')} will look in the ${strong('integrations')} object for the ${strong('cordova')} property.

Expand Down
16 changes: 10 additions & 6 deletions packages/@ionic/cli/src/commands/ssl/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as path from 'path';

import { CommandLineInputs, CommandLineOptions, CommandMetadata, CommandPreRun } from '../../definitions';
import { input, strong } from '../../lib/color';
import { DEFAULT_CONFIG_DIRECTORY } from '../../lib/config';
import { FatalException } from '../../lib/errors';

import { SSLBaseCommand } from './base';
Expand All @@ -26,19 +27,22 @@ interface OpenSSLConfig {
commonName: string;
}

const DEFAULT_KEY_FILE = '.ionic/ssl/key.pem';
const DEFAULT_CERT_FILE = '.ionic/ssl/cert.pem';

export class SSLGenerateCommand extends SSLBaseCommand implements CommandPreRun {
getDefaultSslDirectory() {
return this.project ? path.resolve(this.project.directory, '.ionic', 'ssl') :
path.resolve(DEFAULT_CONFIG_DIRECTORY, 'ssl');
}

getDefaultKeyPath() {
return path.resolve(this.project ? this.project.directory : '', DEFAULT_KEY_FILE);
return path.resolve(this.getDefaultSslDirectory(), 'key.pem');
}

getDefaultCertPath() {
return path.resolve(this.project ? this.project.directory : '', DEFAULT_CERT_FILE);
return path.resolve(this.getDefaultSslDirectory(), 'cert.pem');
}

async getMetadata(): Promise<CommandMetadata> {
const defaultSslDirectory = prettyPath(this.getDefaultSslDirectory())
const defaultKeyPath = prettyPath(this.getDefaultKeyPath());
const defaultCertPath = prettyPath(this.getDefaultCertPath());

Expand All @@ -52,7 +56,7 @@ Uses OpenSSL to create a self-signed certificate for ${strong('localhost')} (by

After the certificate is generated, you will still need to add it to your system or browser as a trusted certificate.

The default directory for ${input('--key-path')} and ${input('--cert-path')} is ${input('.ionic/ssl/')}.
The default directory for ${input('--key-path')} and ${input('--cert-path')} is ${input(defaultSslDirectory)}.

Deprecated. Developers should generate an SSL certificate locally and then configure it using their project tooling such as Vite or Angular CLI.
`,
Expand Down
14 changes: 13 additions & 1 deletion packages/@ionic/cli/src/lib/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { BaseConfig, BaseConfigOptions, MetadataGroup, ParsedArgs, metadataOptionsToParseArgsOptions, parseArgs } from '@ionic/cli-framework';
import * as os from 'os';
import * as path from 'path';
import * as fs from 'fs';

import { CommandMetadataOption, ConfigFile, CreateRequestOptions, IConfig, OAuthServerConfig } from '../definitions';

Expand Down Expand Up @@ -53,7 +54,18 @@ export const GLOBAL_OPTIONS: readonly CommandMetadataOption[] = [
];

export const CONFIG_FILE = 'config.json';
export const DEFAULT_CONFIG_DIRECTORY = path.resolve(os.homedir(), '.ionic');
export const DEFAULT_CONFIG_DIRECTORY = findDefaultConfigDir();

function findDefaultConfigDir() {
const fallback = path.resolve(os.homedir(), '.ionic');
if (fs.existsSync(fallback)) return fallback;

if (process.env.XDG_CONFIG_HOME) {
return path.resolve(process.env.XDG_CONFIG_HOME, 'ionic');
} else {
return fallback;
}
}

export class Config extends BaseConfig<ConfigFile> implements IConfig {
constructor(p: string, options?: BaseConfigOptions) {
Expand Down