Skip to content

Commit

Permalink
Implement target platform
Browse files Browse the repository at this point in the history
  • Loading branch information
amvanbaren committed Jan 21, 2022
1 parent f963446 commit 7b6714b
Show file tree
Hide file tree
Showing 75 changed files with 2,695 additions and 984 deletions.
16 changes: 8 additions & 8 deletions cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ovsx",
"version": "0.3.0",
"version": "0.4.0",
"description": "Command line interface for Eclipse Open VSX",
"keywords": [
"cli",
Expand Down Expand Up @@ -37,21 +37,21 @@
},
"dependencies": {
"commander": "^6.1.0",
"follow-redirects": "^1.13.2",
"follow-redirects": "^1.14.6",
"is-ci": "^2.0.0",
"leven": "^3.1.0",
"tmp": "^0.2.1",
"vsce": "^2.6.3"
},
"devDependencies": {
"@types/follow-redirects": "^1.13.0",
"@types/follow-redirects": "^1.13.1",
"@types/is-ci": "^2.0.0",
"@types/node": "^10.14.18",
"@types/semver": "^7.1.0",
"@types/node": "^10.17.60",
"@types/semver": "^7.3.9",
"@types/tmp": "^0.1.0",
"@typescript-eslint/eslint-plugin": "^3.6.1",
"@typescript-eslint/parser": "^3.6.1",
"eslint": "^7.4.0",
"@typescript-eslint/eslint-plugin": "^3.10.1",
"@typescript-eslint/parser": "^3.10.1",
"eslint": "^7.32.0",
"rimraf": "^3.0.2",
"typescript": "3.8.3"
},
Expand Down
6 changes: 5 additions & 1 deletion cli/src/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export async function getExtension(options: GetOptions): Promise<void> {
throw new Error('The extension identifier must have the form `namespace.extension`.');
}

const extension = await registry.getMetadata(match[1], match[2]);
const extension = await registry.getMetadata(match[1], match[2], options.target);
if (extension.error) {
throw new Error(extension.error);
}
Expand Down Expand Up @@ -105,6 +105,10 @@ export interface GetOptions extends RegistryOptions {
* Identifier in the form `namespace.extension` or `namespace/extension`.
*/
extensionId: string;
/**
* Target architecture.
*/
target?: string;
/**
* An exact version or version range.
*/
Expand Down
14 changes: 10 additions & 4 deletions cli/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,28 @@ module.exports = function (argv: string[]): void {

const publishCmd = program.command('publish [extension.vsix]');
publishCmd.description('Publish an extension, packaging it first if necessary.')
.option('-t, --target <targets...>', 'Target architectures')
.option('-i, --packagePath <paths...>', 'Publish the provided VSIX packages.')
.option('--baseContentUrl <url>', 'Prepend all relative links in README.md with this URL.')
.option('--baseImagesUrl <url>', 'Prepend all relative image links in README.md with this URL.')
.option('--yarn', 'Use yarn instead of npm while packing extension files.')
.action((extensionFile: string, { packagePath, baseContentUrl, baseImagesUrl, yarn }) => {
.action((extensionFile: string, { target, packagePath, baseContentUrl, baseImagesUrl, yarn }) => {
if (extensionFile !== undefined && packagePath !== undefined) {
console.error('\u274c Please specify either a package file or a package path, but not both.\n');
publishCmd.help();
}
if (extensionFile !== undefined && target !== undefined) {
console.warn("Ignoring option '--target' for prepackaged extension.");
target = undefined;
}
if (extensionFile !== undefined && baseContentUrl !== undefined)
console.warn("Ignoring option '--baseContentUrl' for prepackaged extension.");
if (extensionFile !== undefined && baseImagesUrl !== undefined)
console.warn("Ignoring option '--baseImagesUrl' for prepackaged extension.");
if (extensionFile !== undefined && yarn !== undefined)
console.warn("Ignoring option '--yarn' for prepackaged extension.");
const { registryUrl, pat } = program.opts();
publish({ extensionFile, registryUrl, pat, packagePath: typeof packagePath === 'string' ? [packagePath] : packagePath, baseContentUrl, baseImagesUrl, yarn })
publish({ extensionFile, registryUrl, pat, targets: typeof target === 'string' ? [target] : target, packagePath: typeof packagePath === 'string' ? [packagePath] : packagePath, baseContentUrl, baseImagesUrl, yarn })
.catch(handleError(program.debug,
'See the documentation for more information:\n'
+ 'https://github.com/eclipse/openvsx/wiki/Publishing-Extensions'
Expand All @@ -60,12 +65,13 @@ module.exports = function (argv: string[]): void {

const getCmd = program.command('get <namespace.extension>');
getCmd.description('Download an extension or its metadata.')
.option('-t, --target <target>', 'Target architecture')
.option('-v, --versionRange <version>', 'Specify an exact version or a version range.')
.option('-o, --output <path>', 'Save the output in the specified file or directory.')
.option('--metadata', 'Print the extension\'s metadata instead of downloading it.')
.action((extensionId: string, { versionRange, output, metadata }) => {
.action((extensionId: string, { target, versionRange, output, metadata }) => {
const { registryUrl } = program.opts();
getExtension({ extensionId, version: versionRange, registryUrl, output, metadata })
getExtension({ extensionId, target: target, version: versionRange, registryUrl, output, metadata })
.catch(handleError(program.debug));
});

Expand Down
34 changes: 28 additions & 6 deletions cli/src/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ import { checkLicense } from './check-license';
*/
export async function publish(options: PublishOptions = {}): Promise<void> {
addEnvOptions(options);
if (options.packagePath) {
// call the publish command for every package path
await Promise.all(options.packagePath.map(path => doPublish({ ...options, packagePath: path })));
} else {
return doPublish({ ... options, packagePath: undefined });
const internalPublishOptions = [];
const packagePaths = options.packagePath || [undefined];
const targets = options.targets || [undefined];
for (const packagePath of packagePaths) {
for (const target of targets) {
internalPublishOptions.push({ ... options, packagePath: packagePath, target: target });
}
}
await Promise.all(internalPublishOptions.map(publishOptions => doPublish(publishOptions)));
}

async function doPublish(options: InternalPublishOptions = {}): Promise<void> {
Expand All @@ -35,6 +38,7 @@ async function doPublish(options: InternalPublishOptions = {}): Promise<void> {
if (options.packagePath && options.packagePath.endsWith('.vsix')) {
options.extensionFile = options.packagePath;
delete options.packagePath;
delete options.target;
}
const registry = new Registry(options);
if (!options.extensionFile) {
Expand All @@ -46,7 +50,13 @@ async function doPublish(options: InternalPublishOptions = {}): Promise<void> {
if (extension.error) {
throw new Error(extension.error);
}
console.log(`\ud83d\ude80 Published ${extension.namespace}.${extension.name} v${extension.version}`);

const name = `${extension.namespace}.${extension.name}`;
const description = options.target
? `${name} (${options.target}) v${extension.version}`
: `${name} v${extension.version}`;

console.log(`\ud83d\ude80 Published ${description}`);
}

interface PublishCommonOptions extends RegistryOptions {
Expand All @@ -72,6 +82,11 @@ interface PublishCommonOptions extends RegistryOptions {
// Interface used by top level CLI
export interface PublishOptions extends PublishCommonOptions {

/**
* Target architectures.
*/
targets?: string[];

/**
* Paths to the extension to be packaged and published. Cannot be used together
* with `extensionFile`.
Expand All @@ -82,6 +97,12 @@ export interface PublishOptions extends PublishCommonOptions {
// Interface used internally by the doPublish method
interface InternalPublishOptions extends PublishCommonOptions {

/**
* Only one target for our internal command.
* Target architecture.
*/
target?: string;

/**
* Only one path for our internal command.
* Path to the extension to be packaged and published. Cannot be used together
Expand All @@ -97,6 +118,7 @@ async function packageExtension(options: InternalPublishOptions, registry: Regis

options.extensionFile = await createTempFile({ postfix: '.vsix' });
const createVSIXOptions: ICreateVSIXOptions = {
target: options.target,
cwd: options.packagePath,
packagePath: options.extensionFile,
baseContentUrl: options.baseContentUrl,
Expand Down
7 changes: 5 additions & 2 deletions cli/src/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,12 @@ export class Registry {
}
}

getMetadata(namespace: string, extension: string): Promise<Extension> {
getMetadata(namespace: string, extension: string, target?: string): Promise<Extension> {
try {
const path = `api/${encodeURIComponent(namespace)}/${encodeURIComponent(extension)}`;
let path = `api/${encodeURIComponent(namespace)}/${encodeURIComponent(extension)}`;
if (target) {
path += `/${encodeURIComponent(target)}`;
}
return this.getJson(this.getUrl(path));
} catch (err) {
return Promise.reject(err);
Expand Down
Loading

0 comments on commit 7b6714b

Please sign in to comment.