-
Notifications
You must be signed in to change notification settings - Fork 41
/
uniquify.ts
41 lines (32 loc) · 1.63 KB
/
uniquify.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { flags, SfdxCommand } from '@salesforce/command';
import chalk from 'chalk';
import { writeJSONasXML } from '@mshanemc/plugin-helpers/dist/JSONXMLtools';
import { getExisting } from '@mshanemc/plugin-helpers/dist/getExisting';
import fs = require('fs-extra');
export default class ConnectedAppUniquify extends SfdxCommand {
public static description = 'modify a clientId/consumerKey on a local connected app to guaranatee uniqueness';
public static examples = [
`sfdx shane:connectedapp:uniquify -a force-app/main/default/connectedApps/myConnectedApp.connectedApp-meta.xml -p 5h4n3
// update the consumerKey of myConnectedApp to be unique, but start with 5h4n3
`
];
protected static flagsConfig = {
prefix: flags.string({ char: 'p', required: true, description: "add a prefix to the connected app's consumerKey" }),
app: flags.filepath({ char: 'a', required: true, description: 'full path to your connected app locally' })
};
protected static requiresProject = true;
public async run(): Promise<any> {
if (!(await fs.pathExists(this.flags.app))) {
throw new Error(`file not found: ${this.flags.app}`);
}
const consumerKey = `${this.flags.prefix}x${new Date().getTime()}`;
const existing = await getExisting(this.flags.app, 'ConnectedApp');
existing.oauthConfig.consumerKey = consumerKey;
await writeJSONasXML({
type: 'ConnectedApp',
path: this.flags.app,
json: existing
});
this.ux.log(`${chalk.green('Connected app updated locally')}. Consumer Key is now ${consumerKey}`);
}
}