From 44496d1eb488a670c30ea6207d06fa58e0c511c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A1cz=20Zal=C3=A1n?= Date: Thu, 23 Nov 2023 22:57:31 +0100 Subject: [PATCH] Cleaning the platform-specific package targets --- .github/workflows/build-and-package.yml | 18 +++------- .github/workflows/publish.yml | 18 +++------- .vscodeignore | 35 +++++++++++++++++++ package.json | 16 +++------ src/core/constants.ts | 2 ++ src/extension-desktop.ts | 15 ++++++-- src/extension-web.ts | 6 ++-- src/extension.ts | 4 +++ src/providers/glsl-command-provider.ts | 11 +----- .../linux.vscodeignore | 0 .../mac.vscodeignore | 0 .../web.vscodeignore | 0 .../windows.vscodeignore | 0 13 files changed, 72 insertions(+), 53 deletions(-) create mode 100644 .vscodeignore rename linux.vscodeignore => vscodeignore/linux.vscodeignore (100%) rename mac.vscodeignore => vscodeignore/mac.vscodeignore (100%) rename web.vscodeignore => vscodeignore/web.vscodeignore (100%) rename windows.vscodeignore => vscodeignore/windows.vscodeignore (100%) diff --git a/.github/workflows/build-and-package.yml b/.github/workflows/build-and-package.yml index c4faebf..8edb811 100644 --- a/.github/workflows/build-and-package.yml +++ b/.github/workflows/build-and-package.yml @@ -13,26 +13,14 @@ jobs: include: - os: windows-latest command: package-win32-x64 - - os: windows-latest - command: package-win32-ia32 - - os: windows-latest - command: package-win32-arm64 - os: ubuntu-latest command: package-linux-x64 - - os: ubuntu-latest - command: package-linux-arm64 - - os: ubuntu-latest - command: package-linux-armhf - - os: ubuntu-latest - command: package-alpine-x64 - - os: ubuntu-latest - command: package-alpine-arm64 - os: macos-latest command: package-darwin-x64 - - os: macos-latest - command: package-darwin-arm64 - os: ubuntu-latest command: package-web + - os: ubuntu-latest + command: package-universal runs-on: ${{ matrix.os }} steps: - name: Checkout @@ -53,5 +41,7 @@ jobs: run: npm run markdownlint - name: Prettier lint run: npm run prettier-lint + - name: Build in production mode + run: npm run build-production - name: Package run: npm run ${{ matrix.command }} diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 2cf2481..6a992f5 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -19,28 +19,18 @@ jobs: - name: Generate Antlr parser run: npx antlr4ts -o "../src/_generated" -no-listener -visitor "AntlrGlslParser.g4" working-directory: ./syntaxes + - name: Build in production mode + run: npm run build-production + - name: Package universal + run: npm run package-universal - name: Package to web run: npm run package-web - name: Package to win32-x64 run: npm run package-win32-x64 - - name: Package to win32-ia32 - run: npm run package-win32-ia32 - - name: Package to win32-arm64 - run: npm run package-win32-arm64 - name: Package to darwin-x64 run: npm run package-darwin-x64 - - name: Package to darwin-arm64 - run: npm run package-darwin-arm64 - name: Package to linux-x64 run: npm run package-linux-x64 - - name: Package to linux-arm64 - run: npm run package-linux-arm64 - - name: Package to linux-armhf - run: npm run package-linux-armhf - - name: Package to alpine-x64 - run: npm run package-alpine-x64 - - name: Package to alpine-arm64 - run: npm run package-alpine-arm64 - name: Publish run: npx vsce publish --packagePath $(find . -type f -name "*.vsix" | paste -sd " ") env: diff --git a/.vscodeignore b/.vscodeignore new file mode 100644 index 0000000..ac03bcc --- /dev/null +++ b/.vscodeignore @@ -0,0 +1,35 @@ +# folder +.github +.husky +.vscode +.vscode-test +.vscode-test-web +node_modules +private +res/gif +res/png/screenshots +src +syntaxes/.antlr + +# file +.editorconfig +.eslintrc.js +.gitattributes +.gitignore +.markdownlint.json +.prettierignore +.prettierrc.json +BUILD.md +package-lock.json +tsconfig.json +webpack.config.js + +# file type +**/*.ps1 +**/*.sh +**/*.vscodeignore +**/*.g4 +**/*.map + +# universal ignore +res/bin diff --git a/package.json b/package.json index 536a6cd..9af5637 100644 --- a/package.json +++ b/package.json @@ -120,7 +120,7 @@ { "command": "webgl-glsl-editor.generatepreprocessed", "title": "Generate preprocessed GLSL source code", - "enablement": "!isWeb && editorLangId == glsl && resourceExtname != .glsl && !editorReadonly", + "enablement": "!isWeb && editorLangId == glsl && resourceExtname != .glsl && !editorReadonly && webgl-glsl-editor.canRunCompiler", "icon": "$(open-preview)" } ], @@ -129,7 +129,7 @@ { "command": "webgl-glsl-editor.generatepreprocessed", "group": "navigation", - "when": "!isWeb && editorLangId == glsl && resourceExtname != .glsl && !editorReadonly" + "when": "!isWeb && editorLangId == glsl && resourceExtname != .glsl && !editorReadonly && webgl-glsl-editor.canRunCompiler" } ] }, @@ -305,7 +305,7 @@ ] }, "scripts": { - "vscode:prepublish": "webpack --mode production", + "build-production": "webpack --mode production", "build": "webpack", "watch": "webpack --watch", "compile-antlr-windows": "@powershell -NoProfile -ExecutionPolicy Unrestricted -Command ./compile-antlr.ps1", @@ -315,18 +315,12 @@ "prettier-format": "prettier --write .", "eslint": "eslint ./src --ext .ts --ignore-pattern src/_generated", "run-in-browser": "vscode-test-web --extensionDevelopmentPath=. .", + "package-universal": "vsce package", "package-web": "vsce package --target web --ignoreFile web.vscodeignore", "package-win32-x64": "vsce package --target win32-x64 --ignoreFile windows.vscodeignore", - "package-win32-ia32": "vsce package --target win32-ia32 --ignoreFile windows.vscodeignore", - "package-win32-arm64": "vsce package --target win32-arm64 --ignoreFile windows.vscodeignore", "package-darwin-x64": "vsce package --target darwin-x64 --ignoreFile mac.vscodeignore", - "package-darwin-arm64": "vsce package --target darwin-arm64 --ignoreFile mac.vscodeignore", "package-linux-x64": "vsce package --target linux-x64 --ignoreFile linux.vscodeignore", - "package-linux-arm64": "vsce package --target linux-arm64 --ignoreFile linux.vscodeignore", - "package-linux-armhf": "vsce package --target linux-armhf --ignoreFile linux.vscodeignore", - "package-alpine-x64": "vsce package --target alpine-x64 --ignoreFile linux.vscodeignore", - "package-alpine-arm64": "vsce package --target alpine-arm64 --ignoreFile linux.vscodeignore", - "package": "start npm run package-web && start npm run package-win32-x64 && start npm run package-win32-ia32 && start npm run package-win32-arm64 && start npm run package-darwin-x64 && start npm run package-darwin-arm64 && start npm run package-linux-x64 && start npm run package-linux-arm64 && start npm run package-linux-armhf && start npm run package-alpine-x64 && start npm run package-alpine-arm64", + "package-all": "start npm run package-universal && start npm run package-web && start npm run package-win32-x64 && start npm run package-darwin-x64 && start npm run package-linux-x64", "prepare": "husky install" }, "devDependencies": { diff --git a/src/core/constants.ts b/src/core/constants.ts index 85fa7c1..7dc0ec0 100644 --- a/src/core/constants.ts +++ b/src/core/constants.ts @@ -16,6 +16,8 @@ export class Constants { public static readonly PREPROCESSED_GLSL = 'webgl-glsl-editor-preprocessed'; + public static readonly CAN_RUN_COMPILER_CONTEXT = `${Constants.EXTENSION_NAME}.canRunCompiler`; + public static readonly VEC3 = 'vec3'; public static readonly VEC4 = 'vec4'; public static readonly BOOL = 'bool'; diff --git a/src/extension-desktop.ts b/src/extension-desktop.ts index 733235b..a3006e3 100644 --- a/src/extension-desktop.ts +++ b/src/extension-desktop.ts @@ -2,15 +2,18 @@ import { ExtensionContext, languages, window, workspace } from 'vscode'; import { Documentation } from './builtin/documentation'; import { Constants } from './core/constants'; import { GlslEditor } from './core/glsl-editor'; -import { addSharedCommands, addSharedFeatures, selector } from './extension'; +import { addSharedCommands, addSharedFeatures, selector, setContext } from './extension'; import { HostDependent } from './host-dependent'; import { GlslDiagnosticProvider } from './providers/glsl-diagnostic-provider'; import { GlslFileDecorationProvider } from './providers/glsl-file-decoration-provider'; import { GlslInjectionErrorProvider } from './providers/glsl-injection-error-provider'; import { GlslTextProvider } from './providers/glsl-text-provider'; -export function activate(context: ExtensionContext): void { +import * as os from 'os'; + +export async function activate(context: ExtensionContext): Promise { GlslEditor.initialize(context); + await setContext(Constants.CAN_RUN_COMPILER_CONTEXT, canRunCompiler()); addHostDependentCode(); addDiagnostic(context); addSharedCommands(context); @@ -26,6 +29,9 @@ function addHostDependentCode(): void { } function addDiagnostic(context: ExtensionContext): void { + if (!canRunCompiler()) { + return; + } //diagnostic for (const editor of window.visibleTextEditors) { if (editor.document.languageId === Constants.GLSL) { @@ -67,3 +73,8 @@ function addFeatures(context: ExtensionContext): void { ); window.registerFileDecorationProvider(new GlslFileDecorationProvider()); } + +export function canRunCompiler(): boolean { + const platform = os.platform(); + return (platform === 'win32' || platform === 'darwin' || platform === 'linux') && os.arch() === 'x64'; +} diff --git a/src/extension-web.ts b/src/extension-web.ts index 970bc40..ff251cd 100644 --- a/src/extension-web.ts +++ b/src/extension-web.ts @@ -1,11 +1,13 @@ import { ExtensionContext } from 'vscode'; +import { Constants } from './core/constants'; import { GlslEditor } from './core/glsl-editor'; -import { addSharedCommands, addSharedFeatures } from './extension'; +import { addSharedCommands, addSharedFeatures, setContext } from './extension'; import { HostDependent } from './host-dependent'; -export function activate(context: ExtensionContext): void { +export async function activate(context: ExtensionContext): Promise { GlslEditor.initialize(context); HostDependent.webExtension = true; + await setContext(Constants.CAN_RUN_COMPILER_CONTEXT, false); addSharedCommands(context); addSharedFeatures(context); } diff --git a/src/extension.ts b/src/extension.ts index 432883f..504cc40 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -118,3 +118,7 @@ export function addSharedFeatures(context: ExtensionContext): void { //inlay hints context.subscriptions.push(languages.registerInlayHintsProvider(selector, new GlslInlayHintsProvider())); } + +export async function setContext(name: string, value: T): Promise { + await commands.executeCommand('setContext', name, value); +} diff --git a/src/providers/glsl-command-provider.ts b/src/providers/glsl-command-provider.ts index 1065a50..40512b8 100644 --- a/src/providers/glsl-command-provider.ts +++ b/src/providers/glsl-command-provider.ts @@ -1,5 +1,4 @@ import { Disposable, Uri, ViewColumn, WebviewPanel, env, window } from 'vscode'; -import { Constants } from '../core/constants'; import { GlslEditor } from '../core/glsl-editor'; import { HostDependent } from '../host-dependent'; @@ -36,15 +35,7 @@ export class GlslCommandProvider { public static openPreprocessedGlsl(): void { const doc = window.activeTextEditor.document; - if (doc?.languageId !== Constants.GLSL) { - window.showWarningMessage('The active file has to be a GLSL file.'); - } else if (HostDependent.webExtension) { - window.showWarningMessage( - "The web extension can't generate preprocessed GLSL source code. Try it with the desktop version." - ); - } else { - HostDependent.displayPreprocessedCode(doc); - } + HostDependent.displayPreprocessedCode(doc); } private static openOfflineDoc(name: string): void { diff --git a/linux.vscodeignore b/vscodeignore/linux.vscodeignore similarity index 100% rename from linux.vscodeignore rename to vscodeignore/linux.vscodeignore diff --git a/mac.vscodeignore b/vscodeignore/mac.vscodeignore similarity index 100% rename from mac.vscodeignore rename to vscodeignore/mac.vscodeignore diff --git a/web.vscodeignore b/vscodeignore/web.vscodeignore similarity index 100% rename from web.vscodeignore rename to vscodeignore/web.vscodeignore diff --git a/windows.vscodeignore b/vscodeignore/windows.vscodeignore similarity index 100% rename from windows.vscodeignore rename to vscodeignore/windows.vscodeignore