Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async run(inputs: CommandLineInputs, options: CommandLineOptions): Promise {
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' +
protected async getIosCapPlist(): Promise {
if (!this.project) {
return '';
}
const capIntegration = this.project.getIntegration('capacitor');
if (!capIntegration) {
return '';
}
// check first if iOS exists
if (!await pathExists(path.join(capIntegration.root, 'ios'))) {
return '';
}
const assumedPlistPath = path.join(capIntegration.root, 'ios', 'App', 'App', 'Info.plist');
if (!await pathWritable(assumedPlistPath)) {
throw new Error('The iOS Info.plist could not be found.');
}
return assumedPlistPath;
}
async run(inputs: CommandLineInputs, options: CommandLineOptions): Promise {
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;
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.`);
}
}
async checkForExisting(projectDir: string) {
const projectExists = await pathExists(projectDir);
if (projectExists) {
const confirm = await this.env.prompt({
type: 'confirm',
name: 'confirm',
message: `${input(prettyPath(projectDir))} exists. ${failure('Overwrite?')}`,
default: false,
});
if (!confirm) {
this.env.log.msg(`Not erasing existing project in ${input(prettyPath(projectDir))}.`);
throw new FatalException();
}
this.canRemoveExisting = confirm;
}
private async checkExistingFile(p: string): Promise {
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))}.`);
}
}
}
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) {
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();
}
};
export async function isRepoInitialized(dir: string): Promise {
return pathExists(path.join(dir, '.git'));
}