Skip to content

Commit 2ac66d9

Browse files
Add a custom property (#552)
Co-authored-by: Manuel Thalmann <m@nuth.ch>
1 parent 9dfdbf5 commit 2ac66d9

File tree

5 files changed

+73
-43
lines changed

5 files changed

+73
-43
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ Every night at [03:03 UTC](https://github.com/open-vsx/publish-extensions/blob/e
6262
The [publishing process](https://github.com/open-vsx/publish-extensions/blob/d2df425a84093023f4ee164592f2491c32166297/publish-extensions.js#L58-L87) can be summarized like this:
6363

6464
1. [`git clone "repository"`](https://github.com/open-vsx/publish-extensions/blob/d2df425a84093023f4ee164592f2491c32166297/publish-extensions.js#L61)
65+
66+
If a `custom` property is provided, then every command from the array is executed, otherwise, the following 2 steps are executed: (the rest is always the same)
67+
6568
2. [`npm install`](https://github.com/open-vsx/publish-extensions/blob/d2df425a84093023f4ee164592f2491c32166297/publish-extensions.js#L68) (or `yarn install` if a `yarn.lock` file is detected in the repository)
6669
3. _([`"prepublish"`](https://github.com/open-vsx/publish-extensions/blob/d2df425a84093023f4ee164592f2491c32166297/publish-extensions.js#L70))_
6770
4. _([`ovsx create-namespace "publisher"`](https://github.com/open-vsx/publish-extensions/blob/d2df425a84093023f4ee164592f2491c32166297/publish-extensions.js#L75) if it doesn't already exist)_

extensions-schema.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
"type": "string",
2525
"description": "Relative path of the extension vsix file inside the git repo (i.e. when it is built by prepublish commands"
2626
},
27+
"custom": {
28+
"type": "array",
29+
"description": "Build using a custom script. Must output an `extension.vsix` file in the `location` directory."
30+
},
2731
"timeout": {
2832
"type": "number",
2933
"description": "Timeout to build the extension vsix from sources."

extensions.json

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,12 @@
361361
},
362362
"formulahendry.auto-rename-tag": {
363363
"repository": "https://github.com/formulahendry/vscode-auto-rename-tag",
364-
"location": "packages/extension"
364+
"location": "packages/extension",
365+
"custom": [
366+
"npm i",
367+
"npm run package",
368+
"mv dist/auto-rename-tag-*.vsix packages/extension/extension.vsix"
369+
]
365370
},
366371
"formulahendry.code-runner": {
367372
"repository": "https://github.com/formulahendry/vscode-code-runner"
@@ -855,7 +860,11 @@
855860
"ms-vscode.vscode-js-profile-table": {
856861
"repository": "https://github.com/microsoft/vscode-js-profile-visualizer",
857862
"location": "packages/vscode-js-profile-table",
858-
"prepublish": "npm run compile"
863+
"custom": [
864+
"npm install",
865+
"npm run compile",
866+
"cd packages/vscode-js-profile-table && vsce package --yarn --out extension.vsix"
867+
]
859868
},
860869
"ms-vscode.vscode-smoketest-check": {
861870
"repository": "https://github.com/microsoft/vscode-smoketest-check"
@@ -1274,4 +1283,4 @@
12741283
"zxh404.vscode-proto3": {
12751284
"repository": "https://github.com/zxh0/vscode-proto3"
12761285
}
1277-
}
1286+
}

publish-extension.js

Lines changed: 53 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -39,52 +39,63 @@ const { createVSIX } = require('vsce');
3939
} else if (context.repo && context.ref) {
4040
console.log(`${id}: preparing from ${context.repo}...`);
4141
await exec(`git checkout ${context.ref}`, { cwd: context.repo });
42-
let yarn = await new Promise(resolve => {
43-
fs.access(path.join(context.repo, 'yarn.lock'), error => resolve(!error));
44-
});
45-
try {
46-
await exec(`${yarn ? 'yarn' : 'npm'} install`, { cwd: packagePath });
47-
} catch (e) {
48-
const pck = JSON.parse(await fs.promises.readFile(path.join(packagePath, 'package.json'), 'utf-8'));
49-
// try to auto migrate from vscode: https://code.visualstudio.com/api/working-with-extensions/testing-extension#migrating-from-vscode
50-
if (pck.scripts?.postinstall === 'node ./node_modules/vscode/bin/install') {
51-
delete pck.scripts['postinstall'];
52-
pck.devDependencies = pck.devDependencies || {};
53-
delete pck.devDependencies['vscode'];
54-
pck.devDependencies['@types/vscode'] = pck.engines['vscode'];
55-
const content = JSON.stringify(pck, undefined, 2).replace(/node \.\/node_modules\/vscode\/bin\/compile/g, 'tsc');
56-
await fs.promises.writeFile(path.join(packagePath, 'package.json'), content, 'utf-8');
57-
await exec(`${yarn ? 'yarn' : 'npm'} install`, { cwd: packagePath });
58-
} else {
42+
if (extension.custom) {
43+
try {
44+
for (const command of extension.custom) {
45+
await exec(command, { cwd: context.repo });
46+
}
47+
options = { extensionFile: path.join(context.repo, extension.location, 'extension.vsix') };
48+
} catch (e) {
5949
throw e;
6050
}
61-
}
62-
if (extension.prepublish) {
63-
await exec(extension.prepublish, { cwd: context.repo })
64-
}
65-
if (extension.extensionFile) {
66-
options = { extensionFile: path.join(context.repo, extension.extensionFile) };
6751
} else {
68-
options = { extensionFile: path.join(context.repo, 'extension.vsix') };
69-
if (yarn) {
70-
options.yarn = true;
71-
}
72-
// answer y to all quetions https://github.com/microsoft/vscode-vsce/blob/7182692b0f257dc10e7fc643269511549ca0c1db/src/util.ts#L12
73-
const vsceTests = process.env['VSCE_TESTS'];
74-
process.env['VSCE_TESTS'] = '1';
52+
let yarn = await new Promise(resolve => {
53+
fs.access(path.join(context.repo, 'yarn.lock'), error => resolve(!error));
54+
});
7555
try {
76-
await createVSIX({
77-
cwd: packagePath,
78-
packagePath: options.extensionFile,
79-
baseContentUrl: options.baseContentUrl,
80-
baseImagesUrl: options.baseImagesUrl,
81-
useYarn: options.yarn
82-
});
83-
} finally {
84-
process.env['VSCE_TESTS'] = vsceTests;
56+
await exec(`${yarn ? 'yarn' : 'npm'} install`, { cwd: packagePath });
57+
} catch (e) {
58+
const pck = JSON.parse(await fs.promises.readFile(path.join(packagePath, 'package.json'), 'utf-8'));
59+
// try to auto migrate from vscode: https://code.visualstudio.com/api/working-with-extensions/testing-extension#migrating-from-vscode
60+
if (pck.scripts?.postinstall === 'node ./node_modules/vscode/bin/install') {
61+
delete pck.scripts['postinstall'];
62+
pck.devDependencies = pck.devDependencies || {};
63+
delete pck.devDependencies['vscode'];
64+
pck.devDependencies['@types/vscode'] = pck.engines['vscode'];
65+
const content = JSON.stringify(pck, undefined, 2).replace(/node \.\/node_modules\/vscode\/bin\/compile/g, 'tsc');
66+
await fs.promises.writeFile(path.join(packagePath, 'package.json'), content, 'utf-8');
67+
await exec(`${yarn ? 'yarn' : 'npm'} install`, { cwd: packagePath });
68+
} else {
69+
throw e;
70+
}
71+
}
72+
if (extension.prepublish) {
73+
await exec(extension.prepublish, { cwd: context.repo })
74+
}
75+
if (extension.extensionFile) {
76+
options = { extensionFile: path.join(context.repo, extension.extensionFile) };
77+
} else {
78+
options = { extensionFile: path.join(context.repo, 'extension.vsix') };
79+
if (yarn) {
80+
options.yarn = true;
81+
}
82+
// answer y to all quetions https://github.com/microsoft/vscode-vsce/blob/7182692b0f257dc10e7fc643269511549ca0c1db/src/util.ts#L12
83+
const vsceTests = process.env['VSCE_TESTS'];
84+
process.env['VSCE_TESTS'] = '1';
85+
try {
86+
await createVSIX({
87+
cwd: packagePath,
88+
packagePath: options.extensionFile,
89+
baseContentUrl: options.baseContentUrl,
90+
baseImagesUrl: options.baseImagesUrl,
91+
useYarn: options.yarn
92+
});
93+
} finally {
94+
process.env['VSCE_TESTS'] = vsceTests;
95+
}
8596
}
97+
console.log(`${id}: prepared from ${context.repo}`);
8698
}
87-
console.log(`${id}: prepared from ${context.repo}`);
8899
}
89100

90101
// Check if the requested version is greater than the one on Open VSX.
@@ -93,6 +104,7 @@ const { createVSIX } = require('vsce');
93104
if (!context.version) {
94105
throw new Error(`${extension.id}: version is not resolved`);
95106
}
107+
96108
if (context.ovsxVersion) {
97109
if (semver.gt(context.ovsxVersion, context.version)) {
98110
throw new Error(`extensions.json is out-of-date: Open VSX version ${context.ovsxVersion} is already greater than specified version ${context.version}`);
@@ -102,6 +114,7 @@ const { createVSIX } = require('vsce');
102114
return;
103115
}
104116
}
117+
105118
// TODO(ak) check license is open-source
106119
if (!xmlManifest?.PackageManifest?.Metadata[0]?.License?.[0] && !manifest.license && !(packagePath && await ovsx.isLicenseOk(packagePath, manifest))) {
107120
throw new Error(`${extension.id}: license is missing`);

types.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export interface Extension {
5858
location?: string
5959
prepublish?: string
6060
extensionFile?: string
61+
custom?: string[]
6162
timeout?: number
6263
}
6364

0 commit comments

Comments
 (0)