Skip to content

Commit

Permalink
build platform vsix packages on single host platform
Browse files Browse the repository at this point in the history
  • Loading branch information
tao-cumplido committed Nov 9, 2024
1 parent 5732122 commit 66a0037
Show file tree
Hide file tree
Showing 8 changed files with 332 additions and 282 deletions.
34 changes: 3 additions & 31 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,45 +8,17 @@ on:

jobs:
build:
strategy:
matrix:
include:
- os: windows-latest
platform: win32
arch: x64
- os: windows-latest
platform: win32
arch: arm64
- os: ubuntu-latest
platform: linux
arch: x64
- os: ubuntu-latest
platform: linux
arch: arm64
- os: macos-latest
platform: darwin
arch: x64
- os: macos-latest
platform: darwin
arch: arm64
runs-on: ${{ matrix.os }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
- run: npm ci
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
npm_config_arch: ${{ matrix.arch }}
- shell: pwsh
run: echo "target=${{ matrix.platform }}-${{ matrix.arch }}" >> $env:GITHUB_ENV
- run: node ./install-esbuild.mjs ${{ env.target }}
- run: npx vsce package --target ${{ env.target }}
- run: node ./build-vsix.mjs
- uses: actions/upload-artifact@v4
with:
name: ${{ env.target }}
path: "*.vsix"
path: "vsix/**/*.vsix"

publish:
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
node_modules
dist
eslint-typegen.d.ts
vsix
*.vsix
*.tgz
.token
Expand Down
10 changes: 0 additions & 10 deletions .vscodeignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
.vscode/**
.vscode-test/**
.github/**
tsconfig*.json
eslint*
logo.svg
*.vsix
modules/**
dist/**/*.html
dist/**/*.map
node_modules/**
!node_modules/@vscode/webview-ui-toolkit/dist/toolkit.min.js
!node_modules/@esbuild/
Expand Down
46 changes: 46 additions & 0 deletions build-vsix.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import fs from "node:fs/promises";
import path from "node:path";

import { $ } from "execa";

import pkg from "./package.json" with { type: "json" };

delete pkg.devDependencies;
delete pkg.scripts;

pkg.main = "extension.js";
pkg.browser = "extension.web.js";

async function buildTarget({ os, cpu, }) {
const destination = `vsix/${os}-${cpu}`;

await fs.mkdir(path.join(destination, "editor"), { recursive: true, });
await fs.writeFile(path.join(destination, "package.json"), JSON.stringify(pkg));
await fs.copyFile(".vscodeignore", path.join(destination, ".vscodeignore"));
await fs.copyFile("license", path.join(destination, "license"));
await fs.copyFile("logo.png", path.join(destination, "logo.png"));
await fs.copyFile("dist/editor/index.js", path.join(destination, "editor/index.js"));
await fs.copyFile("dist/editor/index.css", path.join(destination, "editor/index.css"));

const extension = await fs.readFile("dist/extension.js", "utf-8");
const extensionWeb = await fs.readFile("dist/extension.web.js", "utf-8");

await fs.writeFile(path.join(destination, "extension.js"), extension.replaceAll("dist/editor", "editor"));
await fs.writeFile(path.join(destination, "extension.web.js"), extensionWeb.replaceAll("dist/editor", "editor"));

const $$ = $({ cwd: destination, });

await $$`npm install --os ${os} --cpu ${cpu} --ignore-scripts`;
await $$`npx vsce package --target ${os}-${cpu}`;
}

const targets = [
{ os: "linux", cpu: "x64", },
{ os: "linux", cpu: "arm64", },
{ os: "darwin", cpu: "x64", },
{ os: "darwin", cpu: "arm64", },
{ os: "win32", cpu: "x64", },
{ os: "win32", cpu: "arm64", },
];

Promise.all(targets.map((target) => buildTarget(target)));
17 changes: 0 additions & 17 deletions install-esbuild.mjs

This file was deleted.

4 changes: 3 additions & 1 deletion modules/extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
"dependencies": {
"clear-module": "4.1.2",
"@nishin/reader": "0.6.0",
"tsx": "4.19.2",
"minimatch": "10.0.1"
},
"devDependencies": {
"esbuild": "0.24.0"
}
}
Loading

0 comments on commit 66a0037

Please sign in to comment.