本文整理汇总了TypeScript中@ionic/cli-framework/utils/format.prettyPath函数的典型用法代码示例。如果您正苦于以下问题:TypeScript prettyPath函数的具体用法?TypeScript prettyPath怎么用?TypeScript prettyPath使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了prettyPath函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: getMetadata
async getMetadata(): Promise<CommandMetadata> {
const projectFile = this.project ? prettyPath(this.project.filePath) : PROJECT_FILE;
return {
name: 'set',
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.
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.
For multi-app projects, this command is scoped to the current project by default. To operate at the root of the project configuration file instead, use the ${input('--root')} option.
This command will attempt to coerce ${input('value')} into a suitable JSON type. If it is JSON-parsable, such as ${input('123')}, ${input('true')}, ${input('[]')}, etc., then it takes the parsed result. Otherwise, the value is interpreted as a string. For stricter input, use ${input('--json')}, which will error with non-JSON values.
By default, if ${input('property')} exists and is an object or an array, the value is not overwritten. To disable this check and always overwrite the property, use ${input('--force')}.
`,
inputs: [
{
name: 'property',
summary: 'The property name you wish to set',
validators: [validators.required],
},
{
name: 'value',
summary: 'The new value of the given property',
validators: [validators.required],
},
],
options: [
{
name: 'global',
summary: 'Use global CLI config',
type: Boolean,
aliases: ['g'],
},
{
name: 'json',
summary: `Always interpret ${input('value')} as JSON`,
type: Boolean,
groups: [MetadataGroup.ADVANCED],
},
{
name: 'force',
summary: 'Always overwrite existing values',
type: Boolean,
groups: [MetadataGroup.ADVANCED],
},
{
name: 'root',
summary: `Operate on root of ${strong(prettyPath(projectFile))}`,
type: Boolean,
hint: weak('[multi-app]'),
groups: [MetadataGroup.ADVANCED],
},
],
exampleCommands: ['name newAppName', 'name "\\"newAppName\\"" --json', '-g interactive false'],
};
}
示例2: processResult
processResult(result: ProjectDetailsResult): void {
const { log } = this.e;
const errorCodes = result.errors.map(e => e.code);
const e1 = result.errors.find(e => e.code === 'ERR_INVALID_PROJECT_FILE');
const e2 = result.errors.find(e => e.code === 'ERR_INVALID_PROJECT_TYPE');
if (e1) {
log.error(
`Error while loading config (project config: ${strong(prettyPath(result.configPath))})\n` +
`${e1.error ? `${e1.message}: ${failure(e1.error.toString())}` : failure(e1.message)}. ` +
`Run ${input('ionic init')} to re-initialize your Ionic project. Without a valid project config, the CLI will not have project context.`
);
log.nl();
}
if (result.context === 'multiapp') {
if (errorCodes.includes('ERR_MULTI_MISSING_ID')) {
log.warn(
`Multi-app workspace detected, but cannot determine which project to use.\n` +
`Please set a ${input('defaultProject')} in ${strong(prettyPath(result.configPath))} or specify the project using the global ${input('--project')} option. Read the documentation${ancillary('[1]')} for more information.\n\n` +
`${ancillary('[1]')}: ${strong('https://beta.ionicframework.com/docs/cli/configuration#multi-app-projects')}`
);
log.nl();
}
if (result.id && errorCodes.includes('ERR_MULTI_MISSING_CONFIG')) {
log.warn(
`Multi-app workspace detected, but project was not found in configuration.\n` +
`Project ${input(result.id)} could not be found in the workspace. Did you add it to ${strong(prettyPath(result.configPath))}?`
);
}
}
if (errorCodes.includes('ERR_MISSING_PROJECT_TYPE')) {
const listWrapOptions = { width: TTY_WIDTH - 8 - 3, indentation: 1 };
log.warn(
`Could not determine project type (project config: ${strong(prettyPath(result.configPath))}).\n` +
`- ${wordWrap(`For ${strong(prettyProjectName('angular'))} projects, make sure ${input('@ionic/angular')} is listed as a dependency in ${strong('package.json')}.`, listWrapOptions)}\n` +
`- ${wordWrap(`For ${strong(prettyProjectName('ionic-angular'))} projects, make sure ${input('ionic-angular')} is listed as a dependency in ${strong('package.json')}.`, listWrapOptions)}\n` +
`- ${wordWrap(`For ${strong(prettyProjectName('ionic1'))} projects, make sure ${input('ionic')} is listed as a dependency in ${strong('bower.json')}.`, listWrapOptions)}\n\n` +
`Alternatively, set ${strong('type')} attribute in ${strong(prettyPath(result.configPath))} to one of: ${PROJECT_TYPES.map(v => input(v)).join(', ')}.\n\n` +
`If the Ionic CLI does not know what type of project this is, ${input('ionic build')}, ${input('ionic serve')}, and other commands may not work. You can use the ${input('custom')} project type if that's okay.`
);
log.nl();
}
if (e2) {
log.error(
`${e2.message} (project config: ${strong(prettyPath(result.configPath))}).\n` +
`Project type must be one of: ${PROJECT_TYPES.map(v => input(v)).join(', ')}`
);
log.nl();
}
}
示例3: getMetadata
async getMetadata(): Promise<CommandMetadata> {
const projectFile = this.project ? prettyPath(this.project.filePath) : PROJECT_FILE;
return {
name: 'link',
type: 'project',
summary: 'Connect local apps to Ionic',
description: `
Link apps on Ionic Appflow to local Ionic projects with this command.
If the ${input('id')} argument is excluded, this command will prompt you to select an app from Ionic Appflow.
Ionic Appflow uses a git-based workflow to manage app updates. During the linking process, select ${strong('GitHub')} (recommended) or ${strong('Ionic Appflow')} as a git host. See our documentation[^appflow-git-basics] for more information.
Ultimately, this command sets the ${strong('id')} property in ${strong(prettyPath(projectFile))}, which marks this app as linked.
If you are having issues linking, please get in touch with our Support[^support-request].
`,
footnotes: [
{
id: 'appflow-git-basics',
url: 'https://ionicframework.com/docs/appflow/basics/git',
shortUrl: 'https://ion.link/appflow-git-basics',
},
{
id: 'support-request',
url: 'https://ion.link/support-request',
},
],
exampleCommands: ['', 'a1b2c3d4'],
inputs: [
{
name: 'id',
summary: `The Ionic Appflow ID of the app to link (e.g. ${input('a1b2c3d4')})`,
},
],
options: [
{
name: 'name',
summary: 'The app name to use during the linking of a new app',
groups: [MetadataGroup.HIDDEN],
},
{
name: 'create',
summary: 'Create a new app on Ionic Appflow and link it with this local Ionic project',
type: Boolean,
groups: [MetadataGroup.HIDDEN],
},
{
name: 'pro-id',
summary: 'Specify an app ID from the Ionic Appflow to link',
groups: [MetadataGroup.DEPRECATED, MetadataGroup.HIDDEN],
spec: { value: 'id' },
},
],
};
}
示例4: run
async run(inputs: CommandLineInputs, options: CommandLineOptions): Promise<void> {
const { ERROR_SSH_INVALID_PRIVKEY, ERROR_SSH_MISSING_PRIVKEY, validatePrivateKey } = await import('../../lib/ssh');
const { ensureHostAndKeyPath, getConfigPath } = await import('../../lib/ssh-config');
const keyPath = expandPath(inputs[0]);
try {
await validatePrivateKey(keyPath);
} catch (e) {
if (e === ERROR_SSH_MISSING_PRIVKEY) {
throw new FatalException(
`${strong(prettyPath(keyPath))} does not appear to exist. Please specify a valid SSH private key.\n` +
`If you are having issues, try using ${input('ionic ssh setup')}.`
);
} else if (e === ERROR_SSH_INVALID_PRIVKEY) {
throw new FatalException(
`${strong(prettyPath(keyPath))} does not appear to be a valid SSH private key. (Missing '-----BEGIN RSA PRIVATE KEY-----' header.)\n` +
`If you are having issues, try using ${input('ionic ssh setup')}.`
);
} else {
throw e;
}
}
const { SSHConfig } = await import('../../lib/ssh-config');
const sshConfigPath = getConfigPath();
const text1 = await fileToString(sshConfigPath);
const conf = SSHConfig.parse(text1);
ensureHostAndKeyPath(conf, { host: this.env.config.getGitHost(), port: this.env.config.getGitPort() }, keyPath);
const text2 = SSHConfig.stringify(conf);
if (text1 === text2) {
this.env.log.msg(`${strong(prettyPath(keyPath))} is already your active SSH key.`);
return;
} else {
const { diffPatch } = await import('../../lib/diff');
const diff = await diffPatch(sshConfigPath, text1, text2);
this.env.log.rawmsg(diff);
const confirm = await this.env.prompt({
type: 'confirm',
name: 'confirm',
message: `May we make the above change(s) to '${prettyPath(sshConfigPath)}'?`,
});
if (!confirm) {
// TODO: link to docs about manual git setup
throw new FatalException();
}
}
await writeFile(sshConfigPath, text2, { encoding: 'utf8', mode: 0o600 });
this.env.log.ok(`Your active Ionic SSH key has been set to ${strong(keyPath)}!`);
}
示例5: getMetadata
async getMetadata() {
const projectFile = this.project ? prettyPath(this.project.filePath) : PROJECT_FILE;
return {
name: 'config',
summary: 'Manage CLI and project config values',
description: `
These commands are used to programmatically read, write, and delete CLI and project config values.
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.
`,
};
}
示例6: checkExistingFile
private async checkExistingFile(p: string): Promise<boolean | undefined> {
if (await pathExists(p)) {
const confirm = await this.env.prompt({
type: 'confirm',
name: 'confirm',
message: `Key ${strong(prettyPath(p))} exists. Overwrite?`,
});
if (confirm) {
return true;
} else {
throw new FatalException(`Not overwriting ${strong(prettyPath(p))}.`);
}
}
}
示例7: loadGulp
export async function loadGulp(): Promise<typeof import('gulp')> {
if (!_gulpInst) {
const gulpFilePath = path.resolve('gulpfile.js');
debug(`Using gulpfile: ${gulpFilePath}`);
try {
const gulpPath = require.resolve('gulp');
debug(`Using gulp: ${gulpPath}`);
_gulpInst = require(gulpPath);
} catch (e) {
if (e.code !== 'MODULE_NOT_FOUND') {
throw e;
}
throw new Error(chalk.red(`Cannot find module 'gulp'`));
}
try {
require(gulpFilePath); // requiring the gulp file sets up the gulp instance with local gulp task definitions
} catch (e) {
if (e.code !== 'MODULE_NOT_FOUND') {
throw e;
}
throw new Error(
`Error in module: ${chalk.bold(prettyPath(gulpFilePath))}:\n` +
chalk.red(e.stack ? e.stack : e)
);
}
debug('Loaded gulp tasks: %o', _gulpInst.tasks);
}
return _gulpInst;
}
示例8: preRunChecks
protected async preRunChecks(runinfo: CommandInstanceInfo) {
if (!this.project) {
throw new FatalException('Cannot use Cordova outside a project directory.');
}
const { loadConfigXml } = await import('../../lib/integrations/cordova/config');
await this.checkCordova(runinfo);
// Check for www folder
if (this.project.directory) {
const wwwPath = path.join(this.integration.root, 'www');
const wwwExists = await pathExists(wwwPath); // TODO: hard-coded
if (!wwwExists) {
const tasks = this.createTaskChain();
tasks.next(`Creating ${strong(prettyPath(wwwPath))} directory for you`);
await mkdirp(wwwPath);
tasks.end();
}
}
const conf = await loadConfigXml(this.integration);
conf.resetContentSrc();
await conf.save();
}
示例9: run
async run(inputs: CommandLineInputs, options: CommandLineOptions): Promise<void> {
if (!this.project) {
throw new FatalException(`Cannot run ${input('ionic ssl generate')} outside a project directory.`);
}
const keyPath = path.resolve(options['key-path'] ? String(options['key-path']) : this.getDefaultKeyPath());
const keyPathDir = path.dirname(keyPath);
const certPath = path.resolve(options['cert-path'] ? String(options['cert-path']) : this.getDefaultCertPath());
const certPathDir = path.dirname(certPath);
const bits = options['bits'] ? String(options['bits']) : DEFAULT_BITS;
const countryName = options['country-name'] ? String(options['country-name']) : DEFAULT_COUNTRY_NAME;
const stateOrProvinceName = options['state-or-province-name'] ? String(options['state-or-province-name']) : DEFAULT_STATE_OR_PROVINCE_NAME;
const localityName = options['locality-name'] ? String(options['locality-name']) : DEFAULT_LOCALITY_NAME;
const organizationName = options['organization-name'] ? String(options['organization-name']) : DEFAULT_ORGANIZATION_NAME;
const commonName = options['common-name'] ? String(options['common-name']) : DEFAULT_COMMON_NAME;
await this.ensureDirectory(keyPathDir);
await this.ensureDirectory(certPathDir);
const overwriteKeyPath = await this.checkExistingFile(keyPath);
const overwriteCertPath = await this.checkExistingFile(certPath);
if (overwriteKeyPath) {
await unlink(keyPath);
}
if (overwriteCertPath) {
await unlink(certPath);
}
const cnf = { bits, countryName, stateOrProvinceName, localityName, organizationName, commonName };
const cnfPath = await this.writeConfig(cnf);
await this.env.shell.run('openssl', ['req', '-x509', '-newkey', `rsa:${bits}`, '-nodes', '-subj', this.formatSubj(cnf), '-reqexts', 'SAN', '-extensions', 'SAN', '-config', cnfPath, '-days', '365', '-keyout', keyPath, '-out', certPath], {});
this.env.log.nl();
this.env.log.rawmsg(
`Key: ${strong(prettyPath(keyPath))}\n` +
`Cert: ${strong(prettyPath(certPath))}\n\n`
);
this.env.log.ok('Generated key & certificate!');
}
示例10: npmRepair
async npmRepair(project: IProject) {
const { pkgManagerArgs } = await import('../lib/utils/npm');
const [ installer, ...installerArgs ] = await pkgManagerArgs(this.env.config.get('npmClient'), { command: 'install' });
const tasks = this.createTaskChain();
const packageLockFile = path.resolve(project.directory, 'package-lock.json');
const nodeModulesDir = path.resolve(project.directory, 'node_modules');
tasks.next(`Removing ${strong(prettyPath(packageLockFile))}`);
await unlink(packageLockFile);
tasks.next(`Removing ${strong(prettyPath(nodeModulesDir))}`);
await remove(nodeModulesDir);
tasks.end();
await this.env.shell.run(installer, installerArgs, { cwd: project.directory, stdio: 'inherit' });
}