本文整理汇总了TypeScript中@ionic/utils-fs.pathExists函数的典型用法代码示例。如果您正苦于以下问题:TypeScript pathExists函数的具体用法?TypeScript pathExists怎么用?TypeScript pathExists使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pathExists函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: run
async run(inputs: CommandLineInputs, options: CommandLineOptions): Promise<void> {
const { getGeneratedPrivateKeyPath } = await import('../../lib/ssh');
const { bits, annotation } = options;
const keyPath = inputs[0] ? expandPath(String(inputs[0])) : await getGeneratedPrivateKeyPath(this.env.config.get('user.id'));
const keyPathDir = path.dirname(keyPath);
const pubkeyPath = `${keyPath}.pub`;
if (!(await pathExists(keyPathDir))) {
await mkdirp(keyPathDir, 0o700 as any); // tslint:disable-line
this.env.log.msg(`Created ${strong(prettyPath(keyPathDir))} directory for you.`);
}
if (await pathExists(keyPath)) {
const confirm = await this.env.prompt({
type: 'confirm',
name: 'confirm',
message: `Key ${strong(prettyPath(keyPath))} exists. Overwrite?`,
});
if (confirm) {
await unlink(keyPath);
} else {
this.env.log.msg(`Not overwriting ${strong(prettyPath(keyPath))}.`);
return;
}
}
this.env.log.info(
'Enter a passphrase for your private key.\n' +
`You will be prompted to provide a ${strong('passphrase')}, which is used to protect your private key should you lose it. (If someone has your private key, they can impersonate you!) Passphrases are recommended, but not required.\n`
);
const shellOptions = { stdio: 'inherit', showCommand: false, showError: false };
await this.env.shell.run('ssh-keygen', ['-q', '-t', String(options['type']), '-b', String(bits), '-C', String(annotation), '-f', keyPath], shellOptions);
this.env.log.nl();
this.env.log.rawmsg(
`Private Key (${strong(prettyPath(keyPath))}): Keep this safe!\n` +
`Public Key (${strong(prettyPath(pubkeyPath))}): Give this to all your friends!\n\n`
);
this.env.log.ok('A new pair of SSH keys has been generated!');
this.env.log.nl();
this.env.log.msg(
`${strong('Next steps:')}\n` +
` * Add your public key to Ionic: ${input('ionic ssh add ' + prettyPath(pubkeyPath))}\n` +
` * Use your private key for secure communication with Ionic: ${input('ionic ssh use ' + prettyPath(keyPath))}`
);
}
示例2: 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();
}
示例3: async
const serveCordovaPlatformResource = async (req: Request, res: Response, next: NextFunction) => {
if (options.engine !== 'cordova' || !options.platform) {
return next();
}
const resourcePath = path.resolve('platforms', options.platform, 'platform_www');
if (await pathExists(path.join(resourcePath, req.url))) {
res.sendFile(req.url, { root: resourcePath });
} else {
next();
}
};
示例4: 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))}.`);
}
}
}
示例5: run
async run(inputs: CommandLineInputs, options: CommandLineOptions): Promise<void> {
const { loadConfigXml } = await import('../../lib/integrations/cordova/config');
if (!this.project) {
throw new FatalException(`Cannot run ${input('ionic monitoring syncmaps')} outside a project directory.`);
}
const token = this.env.session.getUserToken();
const appflowId = await this.project.requireAppflowId();
const [ snapshotId ] = inputs;
const doBuild = options.build ? true : false;
const cordova = this.project.requireIntegration('cordova');
const conf = await loadConfigXml(cordova);
const cordovaInfo = conf.getProjectInfo();
const appVersion = cordovaInfo.version;
const commitHash = (await this.env.shell.output('git', ['rev-parse', 'HEAD'], { cwd: this.project.directory })).trim();
debug(`Commit hash: ${strong(commitHash)}`);
const sourcemapsDir = path.resolve(this.project.directory, SOURCEMAP_DIRECTORY);
let sourcemapsExist = await pathExists(sourcemapsDir);
if (doBuild || !sourcemapsExist) {
// TODO: use runner directly
await build({ config: this.env.config, log: this.env.log, shell: this.env.shell, prompt: this.env.prompt, project: this.project }, [], { _: [], prod: true });
}
sourcemapsExist = await pathExists(sourcemapsDir);
if (sourcemapsExist) {
this.env.log.msg(`Using existing sourcemaps in ${strong(prettyPath(sourcemapsDir))}`);
} else { // TODO: this is hard-coded for ionic-angular, make it work for all project types
throw new FatalException(
`Cannot find directory: ${strong(prettyPath(sourcemapsDir))}.\n` +
`Make sure you have the latest ${strong('@ionic/app-scripts')}. Then, re-run this command.`
);
}
let count = 0;
const tasks = this.createTaskChain();
const syncTask = tasks.next('Syncing sourcemaps');
const sourcemapFiles = (await readdirSafe(sourcemapsDir)).filter(f => f.endsWith('.js.map'));
debug(`Found ${sourcemapFiles.length} sourcemap files: ${sourcemapFiles.map(f => strong(f)).join(', ')}`);
await Promise.all(sourcemapFiles.map(async f => {
await this.syncSourcemap(path.resolve(sourcemapsDir, f), snapshotId, appVersion, commitHash, appflowId, token);
count += 1;
syncTask.msg = `Syncing sourcemaps: ${strong(`${count} / ${sourcemapFiles.length}`)}`;
}));
syncTask.msg = `Syncing sourcemaps: ${strong(`${sourcemapFiles.length} / ${sourcemapFiles.length}`)}`;
tasks.end();
const details = columnar([
['App ID', strong(appflowId)],
['Version', strong(appVersion)],
['Package ID', strong(cordovaInfo.id)],
['Snapshot ID', snapshotId ? strong(snapshotId) : weak('not set')],
], { vsep: ':' });
this.env.log.ok(
`Sourcemaps synced!\n` +
details + '\n\n' +
`See the Error Monitoring docs for usage information and next steps: ${strong('https://ionicframework.com/docs/appflow/monitoring')}`
);
}
示例6: pathExists
const platforms = (await Promise.all(platformsToCheck.map(async (p): Promise<[string, boolean]> => [p, await pathExists(path.resolve(integrationRoot, p))])))
示例7: run
async run(inputs: CommandLineInputs, options: CommandLineOptions, runinfo: CommandInstanceInfo): Promise<void> {
const { getGeneratedPrivateKeyPath } = await import('../../lib/ssh');
const { getConfigPath } = await import('../../lib/ssh-config');
const { promptToLogin } = await import('../../lib/session');
if (!this.env.session.isLoggedIn()) {
await promptToLogin(this.env);
}
const CHOICE_AUTOMATIC = 'automatic';
const CHOICE_MANUAL = 'manual';
const CHOICE_SKIP = 'skip';
const CHOICE_IGNORE = 'ignore';
if (this.env.config.get('git.setup')) {
const rerun = await this.env.prompt({
type: 'confirm',
name: 'confirm',
message: `SSH setup wizard has run before. Would you like to run it again?`,
});
if (!rerun) {
return;
}
} else {
this.env.log.msg(`Looks like you haven't configured your SSH settings yet.`);
}
// TODO: link to docs about manual git setup
const setupChoice = await this.env.prompt({
type: 'list',
name: 'setupChoice',
message: `How would you like to connect to Ionic?`,
choices: [
{
name: 'Automatically setup new a SSH key pair for Ionic',
value: CHOICE_AUTOMATIC,
},
{
name: 'Use an existing SSH key pair',
value: CHOICE_MANUAL,
},
{
name: 'Skip for now',
value: CHOICE_SKIP,
},
{
name: 'Ignore this prompt forever',
value: CHOICE_IGNORE,
},
],
});
if (setupChoice === CHOICE_AUTOMATIC) {
const sshconfigPath = getConfigPath();
const keyPath = await getGeneratedPrivateKeyPath(this.env.config.get('user.id'));
const pubkeyPath = `${keyPath}.pub`;
const [ pubkeyExists, keyExists ] = await Promise.all([pathExists(keyPath), pathExists(pubkeyPath)]);
if (!pubkeyExists && !keyExists) {
this.env.log.info(
'The automatic SSH setup will do the following:\n' +
`1) Generate a new SSH key pair with OpenSSH (will not overwrite any existing keys).\n` +
`2) Upload the generated SSH public key to our server, registering it on your account.\n` +
`3) Modify your SSH config (${strong(prettyPath(sshconfigPath))}) to use the generated SSH private key for our server(s).`
);
const confirm = await this.env.prompt({
type: 'confirm',
name: 'confirm',
message: 'May we proceed?',
});
if (!confirm) {
throw new FatalException();
}
}
if (pubkeyExists && keyExists) {
this.env.log.msg(
`Using your previously generated key: ${strong(prettyPath(keyPath))}.\n` +
`You can generate a new one by deleting it.`
);
} else {
await runCommand(runinfo, ['ssh', 'generate', keyPath]);
}
await runCommand(runinfo, ['ssh', 'add', pubkeyPath, '--use']);
} else if (setupChoice === CHOICE_MANUAL) {
await runCommand(runinfo, ['ssh', 'add']);
}
if (setupChoice === CHOICE_SKIP) {
this.env.log.warn(`Skipping for now. You can configure your SSH settings using ${input('ionic ssh setup')}.`);
} else {
if (setupChoice === CHOICE_IGNORE) {
this.env.log.ok(`We won't pester you about SSH settings anymore!`);
} else {
//.........这里部分代码省略.........
示例8: ensureDirectory
private async ensureDirectory(p: string) {
if (!(await pathExists(p))) {
await mkdirp(p, 0o700 as any); // tslint:disable-line
this.env.log.msg(`Created ${strong(prettyPath(p))} directory for you.`);
}
}
示例9: isRepoInitialized
export async function isRepoInitialized(dir: string): Promise<boolean> {
return pathExists(path.join(dir, '.git'));
}
示例10: run
async run(inputs: CommandLineInputs, options: CommandLineOptions, runinfo: CommandInstanceInfo): Promise<void> {
const { ERROR_SSH_INVALID_PUBKEY, SSHKeyClient, parsePublicKeyFile } = await import('../../lib/ssh');
const pubkeyPath = expandPath(inputs[0]);
const pubkeyName = prettyPath(pubkeyPath);
let pubkey: string;
try {
[ pubkey ] = await parsePublicKeyFile(pubkeyPath);
} catch (e) {
if (e.code === 'ENOENT') {
throw new FatalException(
`${strong(prettyPath(pubkeyPath))} does not appear to exist. Please specify a valid SSH public key.\n` +
`If you are having issues, try using ${input('ionic ssh setup')}.`
);
} else if (e === ERROR_SSH_INVALID_PUBKEY) {
throw new FatalException(
`${strong(pubkeyName)} does not appear to be a valid SSH public key. (Not in ${strong('authorized_keys')} file format.)\n` +
`If you are having issues, try using ${input('ionic ssh setup')}.`
);
}
throw e;
}
const user = this.env.session.getUser();
const token = this.env.session.getUserToken();
const sshkeyClient = new SSHKeyClient({ client: this.env.client, token, user });
try {
const key = await sshkeyClient.create({ pubkey });
this.env.log.ok(`Your public key (${strong(key.fingerprint)}) has been added to Ionic!`);
} catch (e) {
if (isSuperAgentError(e) && e.response.status === 409) {
this.env.log.msg('Pubkey already added to Ionic.');
} else {
throw e;
}
}
if (pubkeyPath.endsWith('.pub')) {
let confirm = options['use'];
if (!confirm) {
confirm = await this.env.prompt({
type: 'confirm',
name: 'confirm',
message: 'Would you like to use this key as your default for Ionic?',
});
}
if (confirm) {
const keyPath = pubkeyPath.substring(0, pubkeyPath.length - 4); // corresponding private key, theoretically
const keyExists = await pathExists(keyPath);
if (keyExists) {
await runCommand(runinfo, ['ssh', 'use', prettyPath(keyPath)]);
} else {
this.env.log.error(
`SSH key does not exist: ${strong(prettyPath(keyPath))}.\n` +
`Please use ${input('ionic ssh use')} manually to use the corresponding private key.`
);
}
}
}
}