Skip to content

Commit

Permalink
Merge pull request #214 from amtrack/feat/sf
Browse files Browse the repository at this point in the history
feat: sf style
  • Loading branch information
amtrack authored Oct 21, 2023
2 parents a0e29ca + d01a943 commit dadb2c0
Show file tree
Hide file tree
Showing 9 changed files with 1,390 additions and 2,422 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@ jobs:
default:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: 18
- name: Install dependencies
run: |
yarn install
yarn global add sfdx-cli
yarn global add @salesforce/cli
- name: Release package
run: npx semantic-release
env:
Expand Down
32 changes: 0 additions & 32 deletions .vscode/launch.json

This file was deleted.

29 changes: 11 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,17 @@
"sfdx-plugin-auth-url": "bin/run"
},
"dependencies": {
"@salesforce/command": "5.3.8",
"tmp": "0.2.1",
"tslib": "2.5.0"
"@salesforce/sf-plugins-core": "4.0.0",
"tmp": "0.2.1"
},
"devDependencies": {
"@oclif/test": "2.3.20",
"@salesforce/ts-sinon": "1.4.6",
"@types/mocha": "10.0.1",
"@types/tmp": "0.2.3",
"chai": "4.3.7",
"mocha": "10.2.0",
"nyc": "15.1.0",
"oclif": "3.9.0",
"@salesforce/dev-config": "4.0.1",
"@salesforce/prettier-config": "0.0.3",
"@types/tmp": "0.2.5",
"oclif": "4.0.3",
"prettier": "3.0.3",
"ts-node": "10.9.1",
"typescript": "5.0.4"
},
"engines": {
"node": ">=14.16"
"typescript": "5.2.2"
},
"files": [
"/bin",
Expand All @@ -39,7 +32,8 @@
"license": "MIT",
"oclif": {
"commands": "./lib/commands",
"bin": "sfdx",
"bin": "sf",
"topicSeparator": " ",
"topics": {
"auth-url": {
"description": "Commands for importing/exporting orgs using a Sfdx Auth Url."
Expand All @@ -53,7 +47,6 @@
"scripts": {
"build": "rm -rf lib && tsc -p . && oclif manifest",
"prepack": "yarn build",
"prepare": "yarn build",
"test": "nyc --reporter=lcov --reporter=text mocha --require ts-node/register \"test/**/*.test.ts\""
"prepare": "yarn build"
}
}
6 changes: 6 additions & 0 deletions prettier.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const salesforcePrettierConfig = require("@salesforce/prettier-config");

module.exports = {
...salesforcePrettierConfig,
singleQuote: false,
};
33 changes: 17 additions & 16 deletions src/commands/auth-url/export.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
import { SfdxCommand } from '@salesforce/command';
import type { AnyJson } from '@salesforce/ts-types';
import { SfCommand, requiredOrgFlagWithDeprecations } from '@salesforce/sf-plugins-core';
import { promisify } from 'util';
import child_process = require('child_process');
const exec = promisify(child_process.exec);

export default class ExportOrgUsingAuthUrlCommand extends SfdxCommand {
export type ExportOrgUsingAuthUrlResult = {
sfdxAuthUrl: string;
};

export class ExportOrgUsingAuthUrlCommand extends SfCommand<ExportOrgUsingAuthUrlResult> {
public static description =
'Print a Sfdx Auth Url.\nThis is a wrapper for sfdx force:org:display --verbose.';

public static examples = [
`$ sfdx <%= command.id %> --targetusername [email protected]
`$ <%= config.bin %> <%= command.id %> --targetusername [email protected]
force://PlatformCLI::[email protected]
`
];

public static args = [];

protected static flagsConfig = {};

// Comment this out if your command does not require an org username
protected static requiresUsername = true;
public static readonly flags = {
"target-org": requiredOrgFlagWithDeprecations,
}

public async run(): Promise<AnyJson> {
public async run(): Promise<ExportOrgUsingAuthUrlResult> {
const { flags } = await this.parse(ExportOrgUsingAuthUrlCommand);
const args = ['--verbose', '--json'];
if (this.flags.targetusername) {
args.push(...['--targetusername', this.flags.targetusername]);
if (flags['target-org']) {
args.push(...['--targetusername', flags["target-org"].getUsername()!]);
}
const execResult = await exec(`sfdx force:org:display ${args.join(' ')}`);
const stdoutJson = JSON.parse(execResult.stdout);
this.ux.log(stdoutJson.result.sfdxAuthUrl);
return { sfdxAuthUrl: stdoutJson.result.sfdxAuthUrl };
const { result } = JSON.parse(execResult.stdout);
this.log(result.sfdxAuthUrl);
return { sfdxAuthUrl: result.sfdxAuthUrl };
}
}
49 changes: 25 additions & 24 deletions src/commands/auth-url/import.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,35 @@
import { flags, SfdxCommand } from '@salesforce/command';
import type { AnyJson } from '@salesforce/ts-types';
import { Args } from '@oclif/core';
import { Flags, SfCommand } from '@salesforce/sf-plugins-core';
import { promises as fsPromises } from 'fs';
import type { FileResult } from 'tmp';
import { promisify } from 'util';
import child_process = require('child_process');
import tmp = require('tmp');
const exec = promisify(child_process.exec);

export default class ImportOrgUsingAuthUrlCommand extends SfdxCommand {
export class ImportOrgUsingAuthUrlCommand extends SfCommand<void> {
public static description =
'Authorize an org.\nThis is a wrapper for sfdx auth:sfdxurl:store without requiring a sfdxAuthUrl file.';

public static examples = [
'$ sfdx <%= command.id %> --setalias myOrg force://PlatformCLI::[email protected]'
'$ <%= config.bin %> <%= command.id %> --setalias myOrg force://PlatformCLI::[email protected]'
];

public static args = [
{
name: 'sfdxAuthUrl'
}
];
public static readonly args = {
sfdxAuthUrl: Args.string()
};

protected static flagsConfig = {
setalias: flags.string({
public static readonly flags = {
setalias: Flags.string({
description: 'set an alias for the authenticated org',
char: 'a'
}),
setdefaultdevhubusername: flags.boolean({
setdefaultdevhubusername: Flags.boolean({
description:
'set the authenticated org as the default dev hub org for scratch org creation',
char: 'd'
}),
setdefaultusername: flags.boolean({
setdefaultusername: Flags.boolean({
description:
'set the authenticated org as the default username that all commands run against',
char: 's'
Expand All @@ -40,24 +38,27 @@ export default class ImportOrgUsingAuthUrlCommand extends SfdxCommand {

protected tempObj!: FileResult;

public async run(): Promise<AnyJson> {
public async run(): Promise<void> {
const { flags, args } = await this.parse(ImportOrgUsingAuthUrlCommand);
this.tempObj = tmp.fileSync();
const sfdxAuthUrlFile = this.tempObj.name;
const sfdxAuthUrl = this.args.sfdxAuthUrl;
if (!args.sfdxAuthUrl) {
throw new Error("missing argument sfdxAuthUrl");
}
const sfdxAuthUrl = args.sfdxAuthUrl;
await fsPromises.writeFile(sfdxAuthUrlFile, sfdxAuthUrl);

const args = ['--sfdxurlfile', sfdxAuthUrlFile];
if (this.flags.setalias) {
args.push(...['--setalias', this.flags.setalias]);
const orgLoginArgs = ['--sfdxurlfile', sfdxAuthUrlFile];
if (flags.setalias) {
orgLoginArgs.push(...['--setalias', flags.setalias]);
}
if (this.flags.setdefaultusername) {
args.push('--setdefaultusername');
if (flags.setdefaultusername) {
orgLoginArgs.push('--setdefaultusername');
}
if (this.flags.setdefaultdevhubusername) {
args.push('--setdefaultdevhubusername');
if (flags.setdefaultdevhubusername) {
orgLoginArgs.push('--setdefaultdevhubusername');
}
await exec(`sfdx auth:sfdxurl:store ${args.join(' ')}`);
return {};
await exec(`sfdx auth:sfdxurl:store ${orgLoginArgs.join(' ')}`);
}

public async finally(): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export default {};
export {};
17 changes: 7 additions & 10 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
{
"extends": "@salesforce/dev-config/tsconfig",
"include": ["./src/**/*.ts"],
"compilerOptions": {
"outDir": "lib",
"module": "commonjs",
"target": "es2020",
"lib": ["es2020"],
"sourceMap": true,
"declaration": true,
"moduleResolution": "node",
"rootDir": "src",
"skipLibCheck": true,
"strictNullChecks": true,
"esModuleInterop": true,
"strict": true,
"noUnusedLocals": true
},
"include": ["./src/**/*.ts"]
"declaration": false,
}
}
Loading

0 comments on commit dadb2c0

Please sign in to comment.