Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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');
files.getManifest(rawUrlManifest, body => {
const manifestJson = JSON.parse(body);
const version = manifestJson.version;
const sourceFolder = manifestJson.sourceFolder;
// check version
if (version === '1.0.0') {
const sfdxSource = manifestJson.sfdxSource;
// currently only support SFDX source
if (!sfdxSource) {
throw new SfdxError('Currently only sfdx source is supported');
}
const manifestFolders = manifestJson.folders;
files.writeFolders(manifestFolders, targetPath, rawUrlManifestFolder, rawApiUrl, sourceFolder, outputFiles => {
this.ux.log('Writing files for folders ...');
for (let i = 0, len = outputFiles.length; i < len; i++) {
this.ux.log(` ${outputFiles[i]}`);
}
});
// grab the files
const manifestFiles = manifestJson.files;
}
// 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 workbenchPathJson = require(globalWorkbenchFilePath);
targetWorkbenchUrl = workbenchPathJson.defaultWorkbenchUrl;
}
const org = this.org;
const conn = org.getConnection();
await org.refreshAuth();
const accessToken = conn.accessToken;
const instanceUrl = conn.instanceUrl;
const serverUrl = `${instanceUrl}/services/Soap/u/41.0`;
const workbenchUrlWithSid = url.resolve(targetWorkbenchUrl, `/login.php?serverUrl=${serverUrl}&sid=${accessToken}`);
if (urlOnly) {
private collectNamespaces(directoryArgs: string[]): Array<[string, string]> {
const namespaceDirectories = [];
for (const arg of directoryArgs) {
const parts = arg.split("=");
if (parts.length === 1) {
this.checkDirectoryExists(arg);
namespaceDirectories.push(["", arg]);
} else if (parts.length === 2) {
if (parts[1] !== "") {
this.checkDirectoryExists(parts[1]);
}
namespaceDirectories.push([parts[0], parts[1]]);
} else {
throw new SfdxError(messages.getMessage("badNamespace", [arg]));
}
}
return namespaceDirectories;
}
private directoryArgs(): Array<[string, string]> {
const flagTypes = this.flagTypes();
const directoryArgs = [];
let skipArgs = 0;
for (const arg of this.argv) {
if (skipArgs > 0) {
skipArgs -= 1;
} else {
skipArgs = flagTypes.get(arg);
if (skipArgs === undefined) {
if (arg.startsWith("--")) {
throw new SfdxError(
messages.getMessage("expectingDirectory", [arg])
);
}
directoryArgs.push(arg);
skipArgs = 0;
}
}
}
if (directoryArgs.length > 0) return this.collectNamespaces(directoryArgs);
else return [["", process.cwd()]];
}
if (manifestFiles.length > 0) {
files.writeFiles(manifestFiles, targetPath, rawUrlManifestFolder, outputFiles => {
this.ux.log('Writing files ...');
for (let i = 0, len = outputFiles.length; i < len; i++) {
this.ux.log(` ${outputFiles[i]}`);
}
resolve();
});
}
} else {
reject(new SfdxError('Only version 1.0.0 is currently supported'));
}
});
});
this.ux.log(writer.output());
} else {
const writer = new MessageWriter();
writer.writeMessages(issues);
this.ux.log(writer.output());
}
}
for (const depenencyDetail of dependResults) {
this.ux.log(
`${depenencyDetail.name}, ${depenencyDetail.dependencies.join(", ")}`
);
}
if (issues.files.length > 0) {
throw new SfdxError("Problems detected in project")
}
return {};
}
}