Skip to content

Commit

Permalink
fix: qa fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
WillieRuemmele committed Oct 18, 2023
1 parent 594cc9e commit 975a38f
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions src/commands/dev/convert/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,23 @@ export default class ConvertScript extends SfCommand<void> {
for (let index = 0; index < lines.length; index++) {
let line = lines[index];
try {
// if we have a multi line command, build it together
if (line.endsWith('\\')) {
while (line.endsWith('\\')) {
line = line.concat(lines[index + 1]);
lines.splice(index + 1, 1);
}
// we'll grab the next line after the last line that ends with '\', see ~L82
line = line.concat(`${lines[index + 1]} `);
lines.splice(index + 1, 1);
}
// if the line looks like it's a valid sfdx command
if (line.match(/sfdx \w+/g)?.length && line.includes(':') && !line.startsWith('#')) {
// if we have a multi line command, build it together
if (line.endsWith('\\')) {
while (line.endsWith('\\')) {
line = line.concat(lines[index + 1]);
lines.splice(index + 1, 1);
}
// we'll grab the next line after the last line that ends with '\', see ~L82
line = line.concat(`${lines[index + 1]} `);
if (lines[index + 2] === '') {
// if there's a space to the next command, the multi-line commands will miss that, so check and grab it here
line = line.concat(os.EOL);
}
lines.splice(index, 1);
}

const commandId = line.split('sfdx ')[1]?.split(' ')[0];

const replacement = this.findReplacement(commandId);
Expand All @@ -108,12 +113,12 @@ export default class ConvertScript extends SfCommand<void> {
}
}
} catch (e) {
line = line.concat(` # ${messages.getMessage('errorComment')}`);
line = line.concat(` # ${messages.getMessage('errorComment')}${os.EOL}`);
this.warn(messages.getMessage('errorComment'));
} finally {
// bare minimum replace sfdx with sf, and -u -> --target-org, -v -> --target-dev-hub
line = line.replace('sfdx ', 'sf ').replace(' -u ', ' --target-org ').replace(' -v ', ' --target-dev-hub');
data.push(line.replace(/\\ /g, `\\${os.EOL}`));
data.push(line.replace(/\\ /g, `\\${os.EOL} `));
}
}

Expand Down Expand Up @@ -172,7 +177,7 @@ export default class ConvertScript extends SfCommand<void> {

if (replacement) {
// we can only replace flags for commands we know about
const commandWithSpaces = replacement.id.replace(/:/g, ' ');
const commandWithSpaces = (depTo ?? replacement.id).replace(/:/g, ' ');
if (await this.smartConfirm(messages.getMessage('replaceCommand', [commandId, commandWithSpaces]), !prompt)) {
line = line.replace(commandId, commandWithSpaces);
}
Expand Down

0 comments on commit 975a38f

Please sign in to comment.