export async function publish()

in src/publish.ts [36:92]


export async function publish(options: IPublishOptions = {}): Promise<any> {
	if (options.packagePath) {
		if (options.version) {
			throw new Error(`Both options not supported simultaneously: 'packagePath' and 'version'.`);
		} else if (options.targets) {
			throw new Error(`Both options not supported simultaneously: 'packagePath' and 'target'.`);
		}

		for (const packagePath of options.packagePath) {
			const vsix = await readVSIXPackage(packagePath);
			let target: string | undefined;

			try {
				target = vsix.xmlManifest.PackageManifest.Metadata[0].Identity[0].$.TargetPlatform ?? undefined;
			} catch (err) {
				throw new Error(`Invalid extension VSIX manifest. ${err}`);
			}

			if (options.preRelease) {
				let isPreReleasePackage = false;
				try {
					isPreReleasePackage = !!vsix.xmlManifest.PackageManifest.Metadata[0].Properties[0].Property.some(
						p => p.$.Id === 'Microsoft.VisualStudio.Code.PreRelease'
					);
				} catch (err) {
					throw new Error(`Invalid extension VSIX manifest. ${err}`);
				}
				if (!isPreReleasePackage) {
					throw new Error(
						`Cannot use '--pre-release' flag with a package that was not packaged as pre-release. Please package it using the '--pre-release' flag and publish again.`
					);
				}
			}

			await _publish(packagePath, vsix.manifest, { ...options, target });
		}
	} else {
		const cwd = options.cwd || process.cwd();
		const manifest = await readManifest(cwd);
		patchOptionsWithManifest(options, manifest);

		await prepublish(cwd, manifest, options.useYarn);
		await versionBump(options);

		if (options.targets) {
			for (const target of options.targets) {
				const packagePath = await tmpName();
				const packageResult = await pack({ ...options, target, packagePath });
				await _publish(packagePath, packageResult.manifest, { ...options, target });
			}
		} else {
			const packagePath = await tmpName();
			const packageResult = await pack({ ...options, packagePath });
			await _publish(packagePath, packageResult.manifest, options);
		}
	}
}