Skip to content

Commit

Permalink
Merge pull request #59 from hutte-io/feat/migrate-sfdx-to-sf
Browse files Browse the repository at this point in the history
migrate sfdx to sf
  • Loading branch information
amtrack authored Oct 1, 2024
2 parents 564cc68 + c4606a5 commit 38f0b84
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 28 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
],
"homepage": "https://hutte.io",
"keywords": [
"sfdx-plugin"
"sfdx-plugin",
"sf-plugin"
],
"license": "MIT",
"oclif": {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/hutte/org/authorize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export class Authorize extends SfCommand<void> {
}

private sfdxPull(org: IScratchOrg): IScratchOrg {
const ret = cross_spawn.sync('sfdx', ['force:source:pull', '-f']);
const ret = cross_spawn.sync('sf', ['project', 'retrieve', 'start', '--ignore-conflicts']);
if (ret.status !== 0) {
throw new Error(ret.output.join('\n'));
}
Expand Down
35 changes: 15 additions & 20 deletions src/common.ts
Original file line number Diff line number Diff line change
@@ -1,45 +1,40 @@
import { execSync } from 'child_process';
import cross_spawn from 'cross-spawn';
import { readFileSync, unlinkSync, writeFileSync } from 'fs';
import { readFileSync, writeFileSync } from 'fs';
import { homedir } from 'os';
import { join } from 'path';
import { parse as parseUrl } from 'url';
import { IScratchOrg } from './api';

const AUTH_URL_FILE = 'tmp_hutte_login';

export function sfdxLogin(org: IScratchOrg): IScratchOrg {
writeFileSync(AUTH_URL_FILE, org.sfdxAuthUrl!);
const response = cross_spawn.sync('sfdx', [
'force:auth:sfdxurl:store',
'-f',
AUTH_URL_FILE,
'-a',
`hutte-${org.slug}`,
'--setdefaultusername',
]);
unlinkSync(AUTH_URL_FILE);
const response = cross_spawn.sync(
'sf',
['org', 'login', 'sfdx-url', '--alias', `hutte-${org.slug}`, '--set-default', '--sfdx-url-stdin'],
{
input: org.sfdxAuthUrl!,
},
);
if (response.status !== 0) {
throw new Error('The sfdx login failed.');
throw new Error('The login failed.');
}
if (org.revisionNumber) {
cross_spawn.sync('sfdx', ['force:source:tracking:reset', '-r', org.revisionNumber, '-p']);
cross_spawn.sync('sf', ['project', 'reset', 'tracking', '--revision', org.revisionNumber, '--no-prompt']);
}
return org;
}

export function devHubSfdxLogin(org: IScratchOrg): void {
writeFileSync(AUTH_URL_FILE, org.devhubSfdxAuthUrl!);
const result = cross_spawn.sync('sfdx', ['force:auth:sfdxurl:store', '-f', AUTH_URL_FILE, '-a', devHubAlias(org)]);
unlinkSync(AUTH_URL_FILE);
const result = cross_spawn.sync('sf', ['org', 'login', 'sfdx-url', '--alias', devHubAlias(org), '--sfdx-url-stdin'], {
input: org.devhubSfdxAuthUrl!,
});
if (result.status === 0) {
return;
}
throw new Error('The devhub login failed.');
}

export function logoutFromDefault(): void {
const result = cross_spawn.sync('sfdx', ['force:auth:logout', '-p']);
const result = cross_spawn.sync('sf', ['org', 'logout', '--no-prompt']);
if (result.status === 0) {
return;
}
Expand All @@ -61,7 +56,7 @@ interface IDefaultOrgInfo {

export function getDefaultOrgInfo(): IDefaultOrgInfo {
try {
const data = JSON.parse(execSync('sfdx force:org:display --json').toString());
const data = JSON.parse(execSync('sf org display --json').toString());
return data.result;
} catch {
throw new Error('Error reading the default scratch org');
Expand Down
12 changes: 6 additions & 6 deletions test/commands/org/authorize.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('hutte:org:authorize', async () => {

it('authorize happy path', async () => {
testContext.SANDBOX.stub(cross_spawn, 'sync')
.withArgs('sfdx')
.withArgs('sf')
// @ts-expect-error not the full SpawnSyncReturns
.returns({ status: 0 })
.withArgs('git')
Expand All @@ -54,7 +54,7 @@ describe('hutte:org:authorize', async () => {

it('authorize fails on unstaged changes', async () => {
testContext.SANDBOX.stub(cross_spawn, 'sync')
.withArgs('sfdx')
.withArgs('sf')
// @ts-expect-error not the full SpawnSyncReturns
.returns({ status: 0 })
.withArgs('git')
Expand All @@ -71,7 +71,7 @@ describe('hutte:org:authorize', async () => {

it('authorize fails on sfdx error', async () => {
testContext.SANDBOX.stub(cross_spawn, 'sync')
.withArgs('sfdx')
.withArgs('sf')
// @ts-expect-error not the full SpawnSyncReturns
.returns({ status: 1 })
.withArgs('git')
Expand All @@ -83,12 +83,12 @@ describe('hutte:org:authorize', async () => {
} catch (e) {
err = e;
}
expect(err).to.match(/The sfdx login failed/);
expect(err).to.match(/The login failed/);
});

it('authorize org by name', async () => {
testContext.SANDBOX.stub(cross_spawn, 'sync')
.withArgs('sfdx')
.withArgs('sf')
// @ts-expect-error not the full SpawnSyncReturns
.returns({ status: 0 })
.withArgs('git')
Expand All @@ -102,7 +102,7 @@ describe('hutte:org:authorize', async () => {

it('authorize fails when name does not exist', async () => {
testContext.SANDBOX.stub(cross_spawn, 'sync')
.withArgs('sfdx')
.withArgs('sf')
// @ts-expect-error not the full SpawnSyncReturns
.returns({ status: 0 })
.withArgs('git')
Expand Down

0 comments on commit 38f0b84

Please sign in to comment.