-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e2e35f2
Showing
10 changed files
with
284 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# -- CLEAN | ||
|
||
# use yarn by default, so ignore npm | ||
package-lock.json | ||
|
||
# never checkin npm config | ||
.npmrc | ||
|
||
# debug logs | ||
npm-error.log | ||
yarn-error.log | ||
lerna-debug.log | ||
|
||
# compile source | ||
lib | ||
|
||
# test artifacts | ||
*xunit.xml | ||
*checkstyle.xml | ||
*unitcoverage | ||
.nyc_output | ||
coverage | ||
test_session** | ||
|
||
# generated docs | ||
docs | ||
|
||
# -- CLEAN ALL | ||
node_modules | ||
|
||
# -- | ||
# put files here you don't want cleaned with sf-clean | ||
|
||
# os specific files | ||
.DS_Store | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
environment: | ||
nodejs_version: "10" | ||
cache: | ||
- '%LOCALAPPDATA%\Yarn -> appveyor.yml' | ||
- node_modules -> yarn.lock | ||
|
||
install: | ||
- ps: Install-Product node $env:nodejs_version x64 | ||
- yarn | ||
|
||
build: off | ||
|
||
build_script: | ||
- ps: Write-Host “Prepack plugin” | ||
- yarn prepack | ||
|
||
test_script: | ||
- yarn test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/usr/bin/env node | ||
|
||
const oclif = require('@oclif/core'); | ||
|
||
const path = require('path'); | ||
const project = path.join(__dirname, '..', 'tsconfig.json'); | ||
|
||
// In dev mode -> use ts-node and dev plugins | ||
process.env.NODE_ENV = 'development'; | ||
|
||
require('ts-node').register({ project }); | ||
|
||
// In dev mode, always show stack traces | ||
oclif.settings.debug = true; | ||
|
||
// Start the CLI | ||
oclif.run().then(oclif.flush).catch(oclif.Errors.handle); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
@echo off | ||
|
||
node "%~dp0\dev" %* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"commandDescription": "print a greeting and your org IDs", | ||
"nameFlagDescription": "name to print", | ||
"forceFlagDescription": "example boolean flag", | ||
"errorNoOrgResults": "No results found for the org '%s'.", | ||
"examples": [ | ||
"sfdx hello:org --targetusername [email protected] --targetdevhubusername [email protected]", | ||
"sfdx hello:org --name myname --targetusername [email protected]" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
{ | ||
"name": "@rocko1204/rocko-sfdx", | ||
"description": "Salesforce DX (SFDX) commands to support salesforce developments & deployments", | ||
"version": "0.0.1", | ||
"author": "Ronny Rokitta", | ||
"bugs": "https://github.com/github/rocko-sfdx/issues", | ||
"dependencies": { | ||
"@oclif/core": "^1", | ||
"@salesforce/command": "^5", | ||
"@salesforce/core": "^3", | ||
"chalk": "^5.1.2", | ||
"simple-git": "^3.14.1", | ||
"tslib": "^2" | ||
}, | ||
"devDependencies": { | ||
"@oclif/test": "^2", | ||
"@salesforce/ts-sinon": "^1", | ||
"@types/chai": "^4", | ||
"@types/mocha": "^8", | ||
"@typescript-eslint/eslint-plugin": "^4", | ||
"@typescript-eslint/parser": "^4", | ||
"chai": "^4", | ||
"eslint": "^7", | ||
"eslint-config-prettier": "^8", | ||
"eslint-plugin-header": "^3", | ||
"eslint-plugin-import": "^2", | ||
"eslint-plugin-jsdoc": "^35", | ||
"eslint-plugin-prettier": "^3", | ||
"eslint-plugin-typescript": "^0", | ||
"mocha": "^9", | ||
"nyc": "^15", | ||
"oclif": "^3", | ||
"prettier": "^2", | ||
"sinon": "10.0.0", | ||
"ts-node": "^10", | ||
"typescript": "4" | ||
}, | ||
"engines": { | ||
"node": ">=14.0.0" | ||
}, | ||
"files": [ | ||
"/lib", | ||
"/messages", | ||
"/npm-shrinkwrap.json", | ||
"/oclif.manifest.json" | ||
], | ||
"homepage": "https://github.com/github/rocko-sfdx", | ||
"keywords": [ | ||
"sfdx-plugin" | ||
], | ||
"license": "MIT", | ||
"oclif": { | ||
"commands": "./lib/commands", | ||
"bin": "sfdx", | ||
"topics": { | ||
"hello": { | ||
"description": "Commands to say hello." | ||
} | ||
} | ||
}, | ||
"repository": "github/rocko-sfdx", | ||
"scripts": { | ||
"build": "tsc -p .", | ||
"lint": "eslint src/**/*.ts test/**/*.ts", | ||
"postpack": "rm -f oclif.manifest.json", | ||
"posttest": "eslint src/**/*.ts test/**/*.ts", | ||
"prepack": "rm -rf lib && tsc -b && oclif manifest && oclif readme", | ||
"test": "nyc --extension .ts --require ts-node/register mocha --forbid-only \"test/**/*.test.ts\"", | ||
"version": "oclif readme && git add README.md" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* Copyright (c) 2020, salesforce.com, inc. | ||
* All rights reserved. | ||
* Licensed under the BSD 3-Clause license. | ||
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
import * as os from 'os'; | ||
import { flags, SfdxCommand } from '@salesforce/command'; | ||
import { Messages, SfError } from '@salesforce/core'; | ||
import { AnyJson } from '@salesforce/ts-types'; | ||
|
||
// Initialize Messages with the current plugin directory | ||
Messages.importMessagesDirectory(__dirname); | ||
|
||
// Load the specific messages for this file. Messages from @salesforce/command, @salesforce/core, | ||
// or any library that is using the messages framework can also be loaded this way. | ||
const messages = Messages.loadMessages('@rocko1204/rocko-sfdx', 'org'); | ||
|
||
export default class Org extends SfdxCommand { | ||
public static description = messages.getMessage('commandDescription'); | ||
|
||
public static examples = messages.getMessage('examples').split(os.EOL); | ||
|
||
public static args = [{ name: 'file' }]; | ||
|
||
protected static flagsConfig = { | ||
// flag with a value (-n, --name=VALUE) | ||
name: flags.string({ | ||
char: 'n', | ||
description: messages.getMessage('nameFlagDescription'), | ||
}), | ||
force: flags.boolean({ | ||
char: 'f', | ||
description: messages.getMessage('forceFlagDescription'), | ||
}), | ||
}; | ||
|
||
// Comment this out if your command does not require an org username | ||
protected static requiresUsername = true; | ||
|
||
// Comment this out if your command does not support a hub org username | ||
protected static supportsDevhubUsername = true; | ||
|
||
// Set this to true if your command requires a project workspace; 'requiresProject' is false by default | ||
protected static requiresProject = false; | ||
|
||
public async run(): Promise<AnyJson> { | ||
const name = (this.flags.name || 'world') as string; | ||
|
||
// this.org is guaranteed because requiresUsername=true, as opposed to supportsUsername | ||
const conn = this.org.getConnection(); | ||
const query = 'Select Name, TrialExpirationDate from Organization'; | ||
|
||
// The type we are querying for | ||
interface Organization { | ||
Name: string; | ||
TrialExpirationDate: string; | ||
} | ||
|
||
// Query the org | ||
const result = await conn.query<Organization>(query); | ||
|
||
// Organization will always return one result, but this is an example of throwing an error | ||
// The output and --json will automatically be handled for you. | ||
if (!result.records || result.records.length <= 0) { | ||
throw new SfError(messages.getMessage('errorNoOrgResults', [this.org.getOrgId()])); | ||
} | ||
|
||
// Organization always only returns one result | ||
const orgName = result.records[0].Name; | ||
const trialExpirationDate = result.records[0].TrialExpirationDate; | ||
|
||
let outputString = `Hello ${name}! This is org: ${orgName}`; | ||
if (trialExpirationDate) { | ||
const date = new Date(trialExpirationDate).toDateString(); | ||
outputString = `${outputString} and I will be around until ${date}!`; | ||
} | ||
this.ux.log(outputString); | ||
|
||
// this.hubOrg is NOT guaranteed because supportsHubOrgUsername=true, as opposed to requiresHubOrgUsername. | ||
if (this.hubOrg) { | ||
const hubOrgId = this.hubOrg.getOrgId(); | ||
this.ux.log(`My hub org id is: ${hubOrgId}`); | ||
} | ||
|
||
if (this.flags.force && this.args.file) { | ||
this.ux.log(`You input --force and a file: ${this.args.file as string}`); | ||
} | ||
|
||
// Return an object to be displayed with --json | ||
return { orgId: this.org.getOrgId(), outputString }; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { expect, test } from '@salesforce/command/lib/test'; | ||
import { ensureJsonMap, ensureString } from '@salesforce/ts-types'; | ||
|
||
describe('hello:org', () => { | ||
test | ||
.withOrg({ username: '[email protected]' }, true) | ||
.withConnectionRequest((request) => { | ||
const requestMap = ensureJsonMap(request); | ||
if (/Organization/.exec(ensureString(requestMap.url))) { | ||
return Promise.resolve({ | ||
records: [ | ||
{ | ||
Name: 'Super Awesome Org', | ||
TrialExpirationDate: '2018-03-20T23:24:11.000+0000', | ||
}, | ||
], | ||
}); | ||
} | ||
return Promise.resolve({ records: [] }); | ||
}) | ||
.stdout() | ||
.command(['hello:org', '--targetusername', '[email protected]']) | ||
.it('runs hello:org --targetusername [email protected]', (ctx) => { | ||
expect(ctx.stdout).to.contain( | ||
'Hello world! This is org: Super Awesome Org and I will be around until Tue Mar 20 2018!' | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"require": "ts-node/register,source-map-support/register", | ||
"watch-extensions": "ts", | ||
"recursive": true, | ||
"reporter": "spec", | ||
"timeout": 5000 | ||
} |