Skip to content

Commit c8d3e6b

Browse files
committed
Initial commit
0 parents  commit c8d3e6b

21 files changed

+4083
-0
lines changed

.circleci/config.yml

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
---
2+
version: 2
3+
jobs:
4+
node-latest: &test
5+
docker:
6+
- image: node:latest
7+
working_directory: ~/cli
8+
steps:
9+
- checkout
10+
- restore_cache: &restore_cache
11+
keys:
12+
- v1-npm-{{checksum ".circleci/config.yml"}}-{{checksum "yarn.lock"}}
13+
- v1-npm-{{checksum ".circleci/config.yml"}}
14+
- run:
15+
name: Install dependencies
16+
command: yarn
17+
- run:
18+
name: Testing
19+
command: yarn test
20+
- run:
21+
name: Submitting code coverage to codecov
22+
command: |
23+
./node_modules/.bin/nyc report --reporter text-lcov > coverage.lcov
24+
curl -s https://codecov.io/bash | bash
25+
node-8:
26+
<<: *test
27+
docker:
28+
- image: node:8
29+
node-10:
30+
<<: *test
31+
docker:
32+
- image: node:10
33+
cache:
34+
<<: *test
35+
steps:
36+
- checkout
37+
- run:
38+
name: Install dependencies
39+
command: yarn
40+
- save_cache:
41+
key: v1-npm-{{checksum ".circleci/config.yml"}}-{{checksum "yarn.lock"}}
42+
paths:
43+
- ~/cli/node_modules
44+
- /usr/local/share/.cache/yarn
45+
- /usr/local/share/.config/yarn
46+
47+
workflows:
48+
version: 2
49+
"changeset":
50+
jobs:
51+
- node-latest
52+
- node-8
53+
- node-10
54+
- cache:
55+
filters:
56+
tags:
57+
only: /^v.*/
58+
branches:
59+
ignore: /.*/

.editorconfig

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 2
6+
charset = utf-8
7+
trim_trailing_whitespace = true
8+
insert_final_newline = true
9+
10+
[*.md]
11+
trim_trailing_whitespace = false

.gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
*-debug.log
2+
*-error.log
3+
/.nyc_output
4+
/dist
5+
/lib
6+
/package-lock.json
7+
/tmp
8+
node_modules

.images/vscodeScreenshot.png

364 KB
Loading

.vscode/launch.json

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"type": "node",
9+
"request": "attach",
10+
"name": "Attach to Remote",
11+
"address": "127.0.0.1",
12+
"port": 9229,
13+
"localRoot": "${workspaceFolder}",
14+
"remoteRoot": "${workspaceFolder}"
15+
},
16+
{
17+
"name": "Unit Tests",
18+
"type": "node",
19+
"request": "launch",
20+
"protocol": "inspector",
21+
"program": "${workspaceRoot}/node_modules/.bin/_mocha",
22+
"args": [
23+
"--require", "test/helpers/init.js",
24+
"--require", "ts-node/register",
25+
"--require", "source-map-support/register",
26+
"--recursive",
27+
"--reporter", "spec",
28+
"test/**/*.test.ts"
29+
],
30+
"cwd": "${workspaceRoot}"
31+
}
32+
]
33+
}

README.md

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
changeset
2+
=========
3+
4+
An SFDX plugin that can retrieve components from a changeset into an org-based project
5+
6+
[![Version](https://img.shields.io/npm/v/changeset.svg)](https://npmjs.org/package/changeset)
7+
[![CircleCI](https://circleci.com/gh/loganm/sfdx-changeset/tree/master.svg?style=shield)](https://circleci.com/gh/loganm/sfdx-changeset/tree/master)
8+
[![Appveyor CI](https://ci.appveyor.com/api/projects/status/github/loganm/sfdx-changeset?branch=master&svg=true)](https://ci.appveyor.com/project/heroku/sfdx-changeset/branch/master)
9+
[![Codecov](https://codecov.io/gh/loganm/sfdx-changeset/branch/master/graph/badge.svg)](https://codecov.io/gh/loganm/sfdx-changeset)
10+
[![Greenkeeper](https://badges.greenkeeper.io/loganm/sfdx-changeset.svg)](https://greenkeeper.io/)
11+
[![Known Vulnerabilities](https://snyk.io/test/github/loganm/sfdx-changeset/badge.svg)](https://snyk.io/test/github/loganm/sfdx-changeset)
12+
[![Downloads/week](https://img.shields.io/npm/dw/changeset.svg)](https://npmjs.org/package/changeset)
13+
[![License](https://img.shields.io/npm/l/changeset.svg)](https://github.com/loganm/sfdx-changeset/blob/master/package.json)
14+
15+
<!-- toc -->
16+
* [Debugging your plugin](#debugging-your-plugin)
17+
<!-- tocstop -->
18+
<!-- install -->
19+
<!-- usage -->
20+
```sh-session
21+
$ npm install -g changeset
22+
$ sfdx COMMAND
23+
running command...
24+
$ sfdx (-v|--version|version)
25+
changeset/0.0.0 darwin-x64 node-v11.9.0
26+
$ sfdx --help [COMMAND]
27+
USAGE
28+
$ sfdx COMMAND
29+
...
30+
```
31+
<!-- usagestop -->
32+
<!-- commands -->
33+
* [`sfdx hello:org [-n <string>] [-f] [-v <string>] [-u <string>] [--apiversion <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal]`](#sfdx-helloorg--n-string--f--v-string--u-string---apiversion-string---json---loglevel-tracedebuginfowarnerrorfatal)
34+
35+
## `sfdx hello:org [-n <string>] [-f] [-v <string>] [-u <string>] [--apiversion <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal]`
36+
37+
print a greeting and your org IDs
38+
39+
```
40+
USAGE
41+
$ sfdx hello:org [-n <string>] [-f] [-v <string>] [-u <string>] [--apiversion <string>] [--json] [--loglevel
42+
trace|debug|info|warn|error|fatal]
43+
44+
OPTIONS
45+
-f, --force example boolean flag
46+
-n, --name=name name to print
47+
-u, --targetusername=targetusername username or alias for the target org; overrides default target org
48+
-v, --targetdevhubusername=targetdevhubusername username or alias for the dev hub org; overrides default dev hub org
49+
--apiversion=apiversion override the api version used for api requests made by this command
50+
--json format output as json
51+
--loglevel=(trace|debug|info|warn|error|fatal) [default: warn] logging level for this command invocation
52+
53+
EXAMPLES
54+
$ sfdx hello:org --targetusername myOrg@example.com --targetdevhubusername devhub@org.com
55+
Hello world! This is org: MyOrg and I will be around until Tue Mar 20 2018!
56+
My hub org id is: 00Dxx000000001234
57+
58+
$ sfdx hello:org --name myname --targetusername myOrg@example.com
59+
Hello myname! This is org: MyOrg and I will be around until Tue Mar 20 2018!
60+
```
61+
62+
_See code: [src/commands/hello/org.ts](https://github.com/loganm/sfdx-changeset/blob/v0.0.0/src/commands/hello/org.ts)_
63+
<!-- commandsstop -->
64+
<!-- debugging-your-plugin -->
65+
# Debugging your plugin
66+
We recommend using the Visual Studio Code (VS Code) IDE for your plugin development. Included in the `.vscode` directory of this plugin is a `launch.json` config file, which allows you to attach a debugger to the node process when running your commands.
67+
68+
To debug the `hello:org` command:
69+
1. Start the inspector
70+
71+
If you linked your plugin to the sfdx cli, call your command with the `dev-suspend` switch:
72+
```sh-session
73+
$ sfdx hello:org -u myOrg@example.com --dev-suspend
74+
```
75+
76+
Alternatively, to call your command using the `bin/run` script, set the `NODE_OPTIONS` environment variable to `--inspect-brk` when starting the debugger:
77+
```sh-session
78+
$ NODE_OPTIONS=--inspect-brk bin/run hello:org -u myOrg@example.com
79+
```
80+
81+
2. Set some breakpoints in your command code
82+
3. Click on the Debug icon in the Activity Bar on the side of VS Code to open up the Debug view.
83+
4. In the upper left hand corner of VS Code, verify that the "Attach to Remote" launch configuration has been chosen.
84+
5. Hit the green play button to the left of the "Attach to Remote" launch configuration window. The debugger should now be suspended on the first line of the program.
85+
6. Hit the green play button at the top middle of VS Code (this play button will be to the right of the play button that you clicked in step #5).
86+
<br><img src=".images/vscodeScreenshot.png" width="480" height="278"><br>
87+
Congrats, you are debugging!

appveyor.yml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
environment:
2+
nodejs_version: "10"
3+
cache:
4+
- '%LOCALAPPDATA%\Yarn -> appveyor.yml'
5+
- node_modules -> yarn.lock
6+
7+
install:
8+
- ps: Install-Product node $env:nodejs_version x64
9+
- yarn
10+
test_script:
11+
- yarn test
12+
13+
after_test:
14+
- .\node_modules\.bin\nyc report --reporter text-lcov > coverage.lcov
15+
- ps: |
16+
$env:PATH = 'C:\msys64\usr\bin;' + $env:PATH
17+
Invoke-WebRequest -Uri 'https://codecov.io/bash' -OutFile codecov.sh
18+
bash codecov.sh
19+
20+
21+
build: off
22+

bin/run

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env node
2+
3+
require('@oclif/command').run()
4+
.catch(require('@oclif/errors/handle'))

bin/run.cmd

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@echo off
2+
3+
node "%~dp0\run" %*

messages/org.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"commandDescription": "print a greeting and your org IDs",
3+
"nameFlagDescription": "name to print",
4+
"forceFlagDescription": "example boolean flag",
5+
"errorNoOrgResults": "No results found for the org '%s'."
6+
}

messages/retrieve.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"commandDescription": "print a greeting and your org IDs",
3+
"changesetnameFlagDescription": "name of changeset to retrieve",
4+
"errorNoOrgResults": "No results found for the org '%s'."
5+
}

package.json

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
{
2+
"name": "changeset",
3+
"description": "An SFDX plugin that can retrieve components from a changeset into an org-based project",
4+
"version": "0.0.0",
5+
"author": "Logan Moore @loganm",
6+
"bugs": "https://github.com/loganm/sfdx-changeset/issues",
7+
"dependencies": {
8+
"@oclif/command": "^1",
9+
"@oclif/config": "^1",
10+
"@oclif/errors": "^1",
11+
"@salesforce/command": "^1.4.1",
12+
"@salesforce/core": "^1.3.2",
13+
"adm-zip": "^0.4.13",
14+
"jsforce": "^1.9.1",
15+
"tslib": "^1"
16+
},
17+
"devDependencies": {
18+
"@oclif/dev-cli": "^1",
19+
"@oclif/plugin-help": "^2",
20+
"@oclif/test": "^1",
21+
"@salesforce/dev-config": "1.4.1",
22+
"@types/chai": "^4",
23+
"@types/mocha": "^5",
24+
"@types/node": "^10",
25+
"chai": "^4",
26+
"globby": "^8",
27+
"mocha": "^5",
28+
"nyc": "^13",
29+
"ts-node": "^8",
30+
"tslint": "^5",
31+
"typescript": "~3.3"
32+
},
33+
"engines": {
34+
"node": ">=8.0.0"
35+
},
36+
"files": [
37+
"/lib",
38+
"/messages",
39+
"/npm-shrinkwrap.json",
40+
"/oclif.manifest.json"
41+
],
42+
"homepage": "https://github.com/loganm/sfdx-changeset",
43+
"keywords": [
44+
"sfdx-plugin"
45+
],
46+
"license": "MIT",
47+
"oclif": {
48+
"commands": "./lib/commands",
49+
"bin": "sfdx",
50+
"topics": {
51+
"hello": {
52+
"description": "Commands to say hello."
53+
}
54+
},
55+
"devPlugins": [
56+
"@oclif/plugin-help"
57+
]
58+
},
59+
"repository": "loganm/sfdx-changeset",
60+
"scripts": {
61+
"postpack": "rm -f oclif.manifest.json",
62+
"posttest": "tslint -p test -t stylish",
63+
"prepack": "rm -rf lib && tsc -b && oclif-dev manifest && oclif-dev readme",
64+
"test": "nyc --extension .ts mocha --forbid-only \"test/**/*.test.ts\"",
65+
"version": "oclif-dev readme && git add README.md"
66+
}
67+
}

src/commands/changeset/retrieve.ts

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import { flags, SfdxCommand } from '@salesforce/command';
2+
import { Messages, SfdxError } from '@salesforce/core';
3+
import { AnyJson } from '@salesforce/ts-types';
4+
import * as AdmZip from 'adm-zip';
5+
import { runCommand } from '../../lib/sfdx';
6+
7+
// Initialize Messages with the current plugin directory
8+
Messages.importMessagesDirectory(__dirname);
9+
10+
// Load the specific messages for this file. Messages from @salesforce/command, @salesforce/core,
11+
// or any library that is using the messages framework can also be loaded this way.
12+
const messages = Messages.loadMessages('changeset', 'retrieve');
13+
14+
export default class Retrieve extends SfdxCommand {
15+
16+
public static description = messages.getMessage('commandDescription');
17+
18+
public static examples = [
19+
`$ sfdx changeset:retrieve --targetusername myOrg@example.com --changeset "Name of Changeset"`
20+
];
21+
22+
public static args = [{name: 'file'}];
23+
24+
protected static flagsConfig = {
25+
// flag with a value (-n, --name=VALUE)
26+
changesetname: flags.string({char: 'c', required: true, description: messages.getMessage('changesetnameFlagDescription')})
27+
};
28+
29+
// Comment this out if your command does not require an org username
30+
protected static requiresUsername = true;
31+
32+
// Set this to true if your command requires a project workspace; 'requiresProject' is false by default
33+
protected static requiresProject = true;
34+
35+
public async run(): Promise<AnyJson> {
36+
const username = this.org.getUsername();
37+
const changesetname = this.flags.changesetname;
38+
39+
const conn = this.org.getConnection();
40+
conn.metadata.pollTimeout = (10*60*1000); // 10 minutes
41+
42+
this.ux.startSpinner('Retrieving Changeset');
43+
const pkgBuf = await this.retrieveChangeset(conn, changesetname);
44+
this.ux.stopSpinner('Done!');
45+
46+
this.ux.startSpinner('Extracting package.xml');
47+
let zip = new AdmZip(pkgBuf);
48+
await zip.extractEntryTo(`${changesetname}/package.xml`, `changesets`, true, true);
49+
this.ux.stopSpinner('Done!');
50+
51+
this.ux.startSpinner('Retrieving source');
52+
await runCommand(`sfdx force:source:retrieve -u ${username} -x changesets/${changesetname}/package.xml`);
53+
this.ux.stopSpinner('Done!');
54+
55+
// Return an object to be displayed with --json
56+
return;
57+
}
58+
59+
private retrieveChangeset(conn, changesetname) {
60+
61+
return new Promise(function(resolve, reject) {
62+
var dataBuffer = [];
63+
conn.metadata.retrieve({ packageNames: [ changesetname ] })
64+
.stream()
65+
.on('data', function(chunk) {
66+
dataBuffer.push(chunk);
67+
})
68+
.on('end', function() {
69+
const data = Buffer.concat(dataBuffer);
70+
resolve(data);
71+
})
72+
.on('error', function(error) {
73+
reject(error);
74+
});
75+
});
76+
}
77+
}

src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default {};

0 commit comments

Comments
 (0)