Skip to content

Commit 2c2335e

Browse files
author
Mohith Shrivastava
committed
add support for changeset based development
1 parent 3eb6591 commit 2c2335e

File tree

7 files changed

+109
-9
lines changed

7 files changed

+109
-9
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ To open command pallete and look for all CCDX Commands use below .
116116
1. Fixes connection method to use salesforce core library native methods
117117
2. Adds ability to deploy the src folder for classic metadata directly from explorer menu
118118

119+
![Deploy source from src folder](./images/deploySrc.png)
120+
119121
### 0.2.7
120122

121123
1. Fixes Manage Conflicts with server is not working for Apex Components and Apex Pages

package-lock.json

Lines changed: 38 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@
7272
{
7373
"command": "deploy.src",
7474
"title": "CCDX: Deploy Source To Salesforce"
75+
},
76+
{
77+
"command": "changeset.retrieve",
78+
"title": "CCDX: Retrieve Source From Changeset"
7579
}
7680
],
7781
"menus": {
@@ -129,6 +133,12 @@
129133
"command": "deploy.src",
130134
"group": "DXCompanion",
131135
"when": "explorerResourceIsFolder && resourceFilename == src"
136+
},
137+
{
138+
"command": "changeset.retrieve",
139+
"title": "CCDX: Retrieve Source From Changeset",
140+
"group": "DXCompanion",
141+
"when": "explorerResourceIsFolder && resourceFilename == changesets"
132142
}
133143
]
134144
},

src/extension.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@
44
import * as vscode from 'vscode';
55
import {Config} from './services/config';
66
import CodeCompanionContentProvider from './providers/ContentProvider' ;
7+
import {Changeset} from './services/changeset';
78
import {DeploySource} from './services/deploy';
89
import {NavigationService} from './services/navigation';
910
import {RetrieveSource} from './services/retrieve';
1011
import {switchOrg} from './services/switchOrg';
1112
import {VSCodeCore} from './services/vscodeCore';
12-
import { OSUtil } from './services/osUtils';
13-
1413
// this method is called when your extension is activated
1514
// your extension is activated the very first time the command is executed
1615
export function activate(context: vscode.ExtensionContext) {
@@ -31,11 +30,12 @@ export function activate(context: vscode.ExtensionContext) {
3130
});
3231

3332
const deploysrc = vscode.commands.registerCommand('deploy.src', async (fileUri: { path: string; }) => {
34-
let activeTerminal = VSCodeCore.setupTerminal();
35-
if(activeTerminal) {
36-
let deployCommand = 'sfdx force:mdapi:deploy -d ' + OSUtil.toUnixStyle(fileUri.path);
37-
activeTerminal.sendText(deployCommand);
38-
}
33+
await DeploySource.deploySrc(fileUri.path);
34+
});
35+
36+
const changesetRetrieve = vscode.commands.registerCommand('changeset.retrieve', async () => {
37+
let changeset = new Changeset();
38+
await changeset.retrieve();
3939
});
4040

4141
const openSLDS = vscode.commands.registerCommand('open.slds', () => {
@@ -103,6 +103,7 @@ export function activate(context: vscode.ExtensionContext) {
103103
DeploySource.deploy(textDocument);
104104
}));
105105
context.subscriptions.push(deploySource);
106+
context.subscriptions.push(changesetRetrieve);
106107
context.subscriptions.push(compareSource);
107108
context.subscriptions.push(refreshSource);
108109
context.subscriptions.push(retrieveSource);

src/services/changeset.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
'use strict';
2+
3+
import * as fs from 'fs';
4+
import * as vscode from 'vscode';
5+
import { VSCodeCore } from './vscodeCore';
6+
import {VSCodeUI} from './vscodeUI';
7+
8+
export class Changeset {
9+
10+
public async retrieve(): Promise<void> {
11+
12+
const name: string = await VSCodeUI.showInputBox('Enter changeset name');
13+
if(vscode.workspace.workspaceFolders){
14+
const changesetDir = vscode.workspace.workspaceFolders[0].uri.fsPath + '/changesets' ;
15+
const subDirectory = changesetDir + '/' + name.trim().toLowerCase().replace(/\s/g,'');
16+
17+
if(!fs.existsSync(changesetDir)) {
18+
//create changesets directory
19+
fs.mkdirSync(changesetDir);
20+
}
21+
if(!fs.existsSync(subDirectory)) {
22+
fs.mkdirSync(subDirectory);
23+
}
24+
let activeTerminal = VSCodeCore.setupTerminal();
25+
if(activeTerminal){
26+
//let retrievecommand = 'sfdx force:mdapi:retrieve -s -p ' + '"' + name + '"' + ' -r ' + subDirectory + ' -w 30 --json';
27+
let retrievecommand = 'sfdx retrieve:pkgsource -n ' + '"' + name + '"' + ' -r ' + 'changesets/' + name.trim().toLowerCase().replace(/\s/g,'') + '/src';
28+
activeTerminal.sendText(retrievecommand);
29+
}
30+
}
31+
}
32+
}

src/services/deploy.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import { CommandService } from './commandBuilder';
99
import { Config } from './config';
1010
import { SalesforceUtil } from './sfdcUtils';
1111
import { VSCodeCore } from './vscodeCore';
12+
import { OSUtil } from './osUtils';
13+
import { VSCodeUI } from './vscodeUI';
1214

1315

1416
export class DeploySource {
@@ -192,4 +194,20 @@ export class DeploySource {
192194
}
193195
return fileSupported;
194196
}
197+
198+
public static async deploySrc(uripath: string) :Promise<void> {
199+
if(vscode.workspace.workspaceFolders){
200+
let activeTerminal = VSCodeCore.setupTerminal();
201+
let deployCommand = 'sfdx force:mdapi:deploy -d ' + OSUtil.toUnixStyle(uripath) + ' -w -1';
202+
if(uripath.indexOf('changesets') > -1) {
203+
//changesets folder so ask for relevant org
204+
const orgs = fs.readdirSync(vscode.workspace.workspaceFolders[0].uri.fsPath +'/.sfdx/orgs');
205+
const username = await VSCodeUI.showQuickPick(orgs, 'Select Org for deployment(Orgs found in .sfdx/orgs are only displayed)');
206+
deployCommand = deployCommand + ' -u ' + username;
207+
}
208+
if(activeTerminal) {
209+
activeTerminal.sendText(deployCommand);
210+
}
211+
}
212+
}
195213
}

src/services/retrieve.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export class RetrieveSource {
2222
if(unmanagedpkg) {
2323
let activeTerminal = VSCodeCore.setupTerminal();
2424
if(activeTerminal){
25-
let retrievecommand = cmd + '"' + unmanagedpkg + '"';
25+
let retrievecommand = cmd + '"' + unmanagedpkg + '"' ;
2626
activeTerminal.sendText(retrievecommand);
2727
}
2828
}

0 commit comments

Comments
 (0)