Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
if (args.sObjects || args.s) {
config.sObjects = (args.sObjects || args.s).split(',');
}
if (config.auth.accessToken === undefined) {
// if just username is set, load from sfdx
if (config.auth.username !== undefined && config.auth.password === undefined) {
let username = await Aliases.fetch(config.auth.username);
if (username) {
config.auth.username = username;
}
console.log(config.auth.username);
let connection: Connection = await Connection.create({
authInfo: await AuthInfo.create({ username: config.auth.username }
)
});
let org = await Org.create({ connection });
await org.refreshAuth();
connection = org.getConnection();
config.auth.accessToken = connection.accessToken;
config.auth.instanceUrl = connection.instanceUrl;
} else if (config.auth.username !== undefined && config.auth.password !== undefined) {
// otherwise lets try username/password flow
let pwConfig = new UsernamePasswordConfig(
config.auth.clientId,
config.auth.clientSecret,
config.auth.oAuthHost,
config.auth.username,
config.sObjects = (args.sObjects || args.s).split(',');
}
if (config.auth.accessToken === undefined) {
// if just username is set, load from sfdx
if (config.auth.username !== undefined && config.auth.password === undefined) {
let username = await Aliases.fetch(config.auth.username);
if (username) {
config.auth.username = username;
}
console.log(config.auth.username);
let connection: Connection = await Connection.create({
authInfo: await AuthInfo.create({ username: config.auth.username }
)
});
let org = await Org.create({ connection });
await org.refreshAuth();
connection = org.getConnection();
config.auth.accessToken = connection.accessToken;
config.auth.instanceUrl = connection.instanceUrl;
} else if (config.auth.username !== undefined && config.auth.password !== undefined) {
// otherwise lets try username/password flow
let pwConfig = new UsernamePasswordConfig(
config.auth.clientId,
config.auth.clientSecret,
config.auth.oAuthHost,
config.auth.username,
config.auth.password
);
}
if (args.instanceUrl || args.i) {
config.auth.instanceUrl = args.instanceUrl || args.i;
}
if (args.outputFile || args.o) {
config.outPath = args.outputFile || args.o;
}
if (args.sObjects || args.s) {
config.sObjects = (args.sObjects || args.s).split(',');
}
if (config.auth.accessToken === undefined) {
// if just username is set, load from sfdx
if (config.auth.username !== undefined && config.auth.password === undefined) {
let username = await Aliases.fetch(config.auth.username);
if (username) {
config.auth.username = username;
}
console.log(config.auth.username);
let connection: Connection = await Connection.create({
authInfo: await AuthInfo.create({ username: config.auth.username }
)
});
let org = await Org.create({ connection });
await org.refreshAuth();
connection = org.getConnection();
config.auth.accessToken = connection.accessToken;
config.auth.instanceUrl = connection.instanceUrl;
} else if (config.auth.username !== undefined && config.auth.password !== undefined) {
msg += message;
// tslint:disable-next-line:no-console
console.log(msg);
}
// And entry to list
this.entries.push({
description: message,
entryNumber: this.counter + (segmentNumber > 1 ? `.${segmentNumber}` : ""),
level: LogLevel[level],
lineNumber: lineNumber.padEnd(20, " "),
timestamp,
});
// Add entry to SFDX logger
Logger.root().then((logger: Logger) => {
switch (level) {
case LogLevel.TRACE:
logger.trace("[" + lineNumber + "][" + timestamp + "]: " + message);
break;
case LogLevel.DEBUG:
logger.trace("[" + lineNumber + "][" + timestamp + "]: " + message);
break;
case LogLevel.INFO:
logger.info("[" + lineNumber + "][" + timestamp + "]: " + message);
break;
case LogLevel.WARN:
logger.warn("[" + lineNumber + "][" + timestamp + "]: " + message);
break;
case LogLevel.ERROR:
logger.error("[" + lineNumber + "][" + timestamp + "]: " + message);
break;
// create a temp project so we can leverage force:source:convert for destructiveChanges
let tmpDeleteProj: string;
let tempDeleteProjConverted: string;
if (hasDeletions) {
tmpDeleteProj = await this.setupTmpProject(diffResults.removed, toBranch);
tempDeleteProjConverted = await this.mkTempDir();
await spawnPromise('sfdx', ['force:source:convert', '-d', tempDeleteProjConverted], { shell: true, cwd: tmpDeleteProj });
}
// create a temp project so we can leverage force:source:convert for primary deploy
const tmpProject = await this.setupTmpProject(diffResults.changed, fromBranch);
const outDir = isAbsolute(this.flags.outputdir) ? this.flags.outputdir : join(this.projectPath, this.flags.outputdir);
try {
const stat = await fs.stat(outDir);
if (stat.isDirectory()) {
let purge = false;
if (this.flags.purge) {
purge = true;
} else {
const resp = await this.ux.prompt(`The output path ${outDir} already exists. How would you like to continue? (purge | merge | exit)`);
if (resp.toLocaleLowerCase() === 'purge') {
purge = true;
} else if (resp.toLocaleLowerCase() !== 'merge') {
this.exit(1);
return;
}
}
if (purge) {
this.ux.log(`Removing all files inside of ${outDir}`);
try {
return new Promise((resolve, reject) => {
// Make folder
const overrideFolder = overrideSettings.configfolder;
if (!readFolder) {
readFolder = "ETCopyData";
}
this.rootFolderRaw = readFolder;
this.rootFolderFull = this.rootFolderRaw;
if (overrideFolder) {
if (readFolder.indexOf(overrideFolder) !== 0) {
this.rootFolderFull = overrideFolder + "/" + readFolder;
}
}
fs.mkdirp(this.rootFolderFull)
.then(() => {
let path: string = "";
path = this.rootFolderFull;
// VERBOSE: Create sub-folders based on time so files do not override
// path += `/${Util.getWallTime(true)}`;
fs.mkdirp(path)
.then(() => {
this.rootFolderFull = path;
resolve(this.rootFolderFull);
});
});
});
}
.then(() => {
let path: string = "";
path = this.rootFolderFull;
// VERBOSE: Create sub-folders based on time so files do not override
// path += `/${Util.getWallTime(true)}`;
fs.mkdirp(path)
.then(() => {
this.rootFolderFull = path;
resolve(this.rootFolderFull);
});
});
});
public async run(): Promise {
const urlOnly = this.flags.urlonly;
const setDefaultworkbenchUrl = this.flags.setdefaultworkbenchurl;
let targetWorkbenchUrl = this.flags.targetworkbenchurl;
const globalWorkbenchFilePath = this.getDefaultWorkbenchFilePath();
if (targetWorkbenchUrl) {
const urlParseResult = url.parse(targetWorkbenchUrl);
if (!urlParseResult.hostname) {
throw new SfdxError('Invalid target workbench url. Please use a valid url.');
}
// store default workbench url if if possible
if (setDefaultworkbenchUrl) {
const workbench = {
defaultWorkbenchUrl: targetWorkbenchUrl
};
await fsx.outputFile(globalWorkbenchFilePath, JSON.stringify(workbench, null, 2));
this.ux.log(`Stored ${targetWorkbenchUrl} in ${globalWorkbenchFilePath}.\n`);
}
} else {
// Check the default
try {
await fsx.stat(globalWorkbenchFilePath);
} catch (err) {
throw new SfdxError('A default Workbench URL was not found. Please specify with -t|--targetWorkbenchUrl.');
}
const branch = this.flags.branch || this.flags.tag;
// check to ensure Github repo exists
if (!(await this.checkUrl(url))) {
throw new SfdxError('Github repository not found');
}
const rawUrlManifestFolder = `https://raw.githubusercontent.com/${this.flags.repository}/${branch}`;
const rawUrlManifest = `${rawUrlManifestFolder}/sfdx-oss-manifest.json`;
const rawApiUrl = `https://api.github.com/repos/${this.flags.repository}/git/trees/${branch}?recursive=1`;
// check to ensure sfdx-oss-manifest.json exists
if (!(await this.checkUrl(rawUrlManifest))) {
throw new SfdxError('sfdx-oss-manifest.json not found in repository');
}
await this.writeFiles(rawUrlManifest, targetPath, rawUrlManifestFolder, rawApiUrl);
return { rawUrlManifest, targetPath, rawUrlManifestFolder, rawApiUrl };
}
public async run(): Promise {
const targetPath = this.flags.path;
const server = this.flags.server;
const url = `https://${server}/${this.flags.repository}`;
// ensure source folder exists
if (!fs.existsSync(targetPath)) {
throw new SfdxError(`Specifiec file path ${targetPath} doesn't exists`);
}
const branch = this.flags.branch || this.flags.tag;
// check to ensure Github repo exists
if (!(await this.checkUrl(url))) {
throw new SfdxError('Github repository not found');
}
const rawUrlManifestFolder = `https://raw.githubusercontent.com/${this.flags.repository}/${branch}`;
const rawUrlManifest = `${rawUrlManifestFolder}/sfdx-oss-manifest.json`;
const rawApiUrl = `https://api.github.com/repos/${this.flags.repository}/git/trees/${branch}?recursive=1`;
// check to ensure sfdx-oss-manifest.json exists
if (!(await this.checkUrl(rawUrlManifest))) {
throw new SfdxError('sfdx-oss-manifest.json not found in repository');