Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add template gallery as template picker #52

Merged
merged 14 commits into from
Mar 16, 2024
Merged
43 changes: 33 additions & 10 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ jobs:
rust-target: x86_64-pc-windows-msvc
platform: win32
arch: x64
regular_build: 'true'
- os: windows-latest
rust-target: aarch64-pc-windows-msvc
platform: win32
Expand All @@ -48,6 +49,7 @@ jobs:
rust-target: x86_64-unknown-linux-gnu
platform: linux
arch: x64
regular_build: 'true'
- os: ubuntu-20.04
rust-target: aarch64-unknown-linux-gnu
platform: linux
Expand All @@ -64,7 +66,7 @@ jobs:
rust-target: aarch64-apple-darwin
platform: darwin
arch: arm64

regular_build: 'true'
name: build (${{ matrix.platform }}-${{ matrix.arch }})
runs-on: ${{ matrix.os }}
env:
Expand All @@ -73,111 +75,129 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: recursive
if: (startsWith(github.ref, 'refs/tags/') || matrix.regular_build == 'true')
- uses: actions/checkout@v4
with:
repository: Enter-tainer/typst-preview
path: external/typst-preview
if: (startsWith(github.ref, 'refs/tags/') || matrix.regular_build == 'true')
- name: Run sccache-cache
uses: mozilla-actions/[email protected]
if: (startsWith(github.ref, 'refs/tags/') || matrix.regular_build == 'true')
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 16
if: (startsWith(github.ref, 'refs/tags/') || matrix.regular_build == 'true')
- name: Hack typst-preview
run: |
mv src/main.rs src/main.rsx
working-directory: ./external/typst-preview
if: (startsWith(github.ref, 'refs/tags/') || matrix.regular_build == 'true')
- name: Build typst-dom
run: |
yarn
yarn build
working-directory: ./external/typst-preview/addons/typst-dom
if: (startsWith(github.ref, 'refs/tags/') || matrix.regular_build == 'true')
- name: Build frontend
run: yarn
working-directory: ./external/typst-preview/addons/frontend
if: (startsWith(github.ref, 'refs/tags/') || matrix.regular_build == 'true')
- name: Build typst-preview
run: |
yarn
yarn run compile
working-directory: ./external/typst-preview/addons/vscode
if: (startsWith(github.ref, 'refs/tags/') || matrix.regular_build == 'true')
- name: Install deps
run: yarn install
if: (startsWith(github.ref, 'refs/tags/') || matrix.regular_build == 'true')
- name: Build vscode extension
run: |
yarn
yarn run compile
working-directory: ./editors/vscode
if: (startsWith(github.ref, 'refs/tags/') || matrix.regular_build == 'true')
- name: rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.rust-target }}
if: (startsWith(github.ref, 'refs/tags/') || matrix.regular_build == 'true')
- name: Install llvm
if: matrix.platform == 'linux'
if: matrix.platform == 'linux' && (startsWith(github.ref, 'refs/tags/') || matrix.regular_build == 'true')
run: |
sudo apt-get update
sudo apt-get install llvm
- name: Install AArch64 target toolchain
if: matrix.rust-target == 'aarch64-unknown-linux-gnu'
if: matrix.rust-target == 'aarch64-unknown-linux-gnu' && (startsWith(github.ref, 'refs/tags/') || matrix.regular_build == 'true')
run: |
sudo apt-get update
sudo apt-get install gcc-aarch64-linux-gnu
- name: Install ARM target toolchain
if: matrix.rust-target == 'arm-unknown-linux-gnueabihf'
if: matrix.rust-target == 'arm-unknown-linux-gnueabihf' && (startsWith(github.ref, 'refs/tags/') || matrix.regular_build == 'true')
run: |
sudo apt-get update
sudo apt-get install gcc-arm-linux-gnueabihf
- name: Build tinymist binary
shell: pwsh
run: |
cargo build --release -p tinymist --target ${{ matrix.rust-target }}
if: startsWith(github.ref, 'refs/tags/') || matrix.regular_build == 'true'
- name: Rename debug symbols for windows
if: matrix.platform == 'win32'
if: matrix.platform == 'win32' && (startsWith(github.ref, 'refs/tags/') || matrix.regular_build == 'true')
run: |
cd target/${{ matrix.rust-target }}/release
cp tinymist.pdb tinymist-${{ env.target }}.pdb
- name: Upload split debug symbols for windows
if: matrix.platform == 'win32'
if: matrix.platform == 'win32' && (startsWith(github.ref, 'refs/tags/') || matrix.regular_build == 'true')
uses: actions/upload-artifact@v4
with:
name: tinymist-${{ env.target }}.pdb
path: target/${{ matrix.rust-target }}/release/tinymist-${{ env.target }}.pdb
- name: Split debug symbols for linux
if: matrix.platform == 'linux'
if: matrix.platform == 'linux' && (startsWith(github.ref, 'refs/tags/') || matrix.regular_build == 'true')
run: |
cd target/${{ matrix.rust-target }}/release
llvm-objcopy --compress-debug-sections --only-keep-debug "tinymist" "tinymist-${{ env.target }}.debug"
llvm-objcopy --strip-debug --add-gnu-debuglink="tinymist-${{ env.target }}.debug" "tinymist"
- name: Upload split debug symbols for linux
if: matrix.platform == 'linux'
if: matrix.platform == 'linux' && (startsWith(github.ref, 'refs/tags/') || matrix.regular_build == 'true')
uses: actions/upload-artifact@v4
with:
name: tinymist-${{ env.target }}.debug
path: target/${{ matrix.rust-target }}/release/tinymist-${{ env.target }}.debug
compression-level: 0
- name: Collect debug symbols for mac
if: matrix.platform == 'darwin'
if: matrix.platform == 'darwin' && (startsWith(github.ref, 'refs/tags/') || matrix.regular_build == 'true')
run: |
dsymutil -f "target/${{ matrix.rust-target }}/release/tinymist"
mv "target/${{ matrix.rust-target }}/release/tinymist.dwarf" "target/${{ matrix.rust-target }}/release/tinymist-${{ env.target }}.dwarf"
- name: Upload split debug symbols for mac
if: matrix.platform == 'darwin'
if: matrix.platform == 'darwin' && (startsWith(github.ref, 'refs/tags/') || matrix.regular_build == 'true')
uses: actions/upload-artifact@v4
with:
name: tinymist-${{ env.target }}.dwarf
path: target/${{ matrix.rust-target }}/release/tinymist-${{ env.target }}.dwarf
- name: Copy binary to output directory
if: (startsWith(github.ref, 'refs/tags/') || matrix.regular_build == 'true')
shell: pwsh
run: |
cp "target/${{ matrix.rust-target }}/release/tinymist$(If ('${{ matrix.platform }}' -eq 'win32') { '.exe' } else { '' } )" "editors/vscode/out/"
cp "target/${{ matrix.rust-target }}/release/tinymist$(If ('${{ matrix.platform }}' -eq 'win32') { '.exe' } else { '' } )" "tinymist-${{ env.target }}$(If ('${{ matrix.platform }}' -eq 'win32') { '.exe' } else { '' } )"
- name: Upload binary artifact
if: (startsWith(github.ref, 'refs/tags/') || matrix.regular_build == 'true')
uses: actions/upload-artifact@v4
with:
name: tinymist-${{ env.target }}
path: tinymist-${{ env.target }}${{ fromJSON('["", ".exe"]')[matrix.platform == 'win32'] }}
- name: Package extension
if: (startsWith(github.ref, 'refs/tags/') || matrix.regular_build == 'true')
shell: pwsh
run: yarn run package -- --target ${{ env.target }} -o tinymist-${{ env.target }}.vsix
working-directory: ./editors/vscode
- name: Upload VSIX artifact
if: (startsWith(github.ref, 'refs/tags/') || matrix.regular_build == 'true')
uses: actions/upload-artifact@v4
with:
name: tinymist-${{ env.target }}.vsix
Expand All @@ -186,6 +206,7 @@ jobs:
build_alpine:
name: build (x86_64-unknown-linux-musl)
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
container:
image: rust:alpine
volumes:
Expand Down Expand Up @@ -224,6 +245,8 @@ jobs:
yarn
yarn run compile
working-directory: ./external/typst-preview/addons/vscode
- name: Install deps
run: yarn install
- name: Build vscode extension
run: |
yarn
Expand Down
115 changes: 83 additions & 32 deletions editors/vscode/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,89 @@
module.exports = {
env: {
es2021: true,
node: true,
},
const tsRule = {
files: ['*.ts'],
ignorePatterns: ['esbuild.config.mjs'],
extends: [
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"plugin:@typescript-eslint/strict",
"prettier",
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
],
overrides: [],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: "latest",
sourceType: "module",
project: "tsconfig.json",
ecmaVersion: 10,
project: ['./tsconfig.lib.json'],
sourceType: 'module',
ecmaFeatures: {
modules: true,
},
},
plugins: [
'@typescript-eslint',
// "@angular-eslint/eslint-plugin"
],
rules: {
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": ["error", { argsIgnorePattern: "^_" }],
"@typescript-eslint/no-unused-vars": ["error", { argsIgnorePattern: "^_" }],
"class-methods-use-this": "off",
"@typescript-eslint/explicit-function-return-type": "error",
"@typescript-eslint/no-explicit-any": "error",
"init-declarations": "off",
"@typescript-eslint/init-declarations": "error",
"no-undef-init": "off",
"@typescript-eslint/strict-boolean-expressions": [
"error",
{
allowString: false,
allowNumber: false,
allowNullableObject: false,
allowNullableEnum: false,
},
],
'@typescript-eslint/indent': [
'error',
2,
{
SwitchCase: 1,
},
],
'@typescript-eslint/member-delimiter-style': [
'error',
{
multiline: {
delimiter: 'semi',
requireLast: true,
},
singleline: {
delimiter: 'semi',
requireLast: false,
},
},
],
semi: [2, 'always'],
'@typescript-eslint/no-inferrable-types': [
'error',
{
ignoreParameters: true,
ignoreProperties: true,
},
],
'@typescript-eslint/ban-ts-comment': 0,
'@typescript-eslint/no-empty-function': 0,
'@typescript-eslint/no-var-requires': 0,
'@typescript-eslint/no-explicit-any': 0,
'@typescript-eslint/no-floating-promises': 0,
'@typescript-eslint/no-unsafe-assignment': 0,
'@typescript-eslint/no-unsafe-return': 0,
'@typescript-eslint/no-unsafe-call': 0,
'@typescript-eslint/no-unsafe-member-access': 0,
'@typescript-eslint/unbound-method': 0,
// "@angular-eslint/use-injectable-provided-in": "error",
// "@angular-eslint/no-attribute-decorator": "error"
},
};
};

// noinspection SpellCheckingInspection
module.exports = {
env: {
browser: true,
node: true,
es6: true,
es2015: true,
es2017: true,
},
overrides: [
tsRule,
// {
// "files": ["*.component.html"],
// "parser": "@angular-eslint/template-parser",
// "plugins": ["@angular-eslint/template"],
// "rules": {
// "@angular-eslint/template/banana-in-a-box": "error",
// "@angular-eslint/template/no-negated-async": "error"
// }
// },
],
};

15 changes: 11 additions & 4 deletions editors/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,11 @@
"command": "tinymist.initTemplate",
"title": "Initialize a new Typst project based on a template",
"category": "Typst"
},
{
"command": "tinymist.showTemplateGallery",
"title": "Show available Typst templates for picking up a template to initialize",
"category": "Typst"
}
],
"menus": {
Expand Down Expand Up @@ -358,11 +363,12 @@
"onCommand:tinymist.clearCache"
],
"scripts": {
"build:frontend": "cd ../../tools/editor-tools/ && yarn run build",
"build-base": "esbuild ./src/extension.ts --bundle --outfile=out/extension.js --external:vscode --format=cjs --platform=node --target=node16",
"vscode:prepublish": "npm run build-base -- --minify",
"package": "vsce package",
"compile": "npm run build-base -- --sourcemap",
"watch": "npm run build-base -- --sourcemap --watch",
"vscode:prepublish": "yarn run build-base -- --minify && yarn run build:frontend && node scripts/postinstall.cjs",
"package": "vsce package --yarn",
"compile": "yarn run build-base -- --sourcemap && yarn run build:frontend && node scripts/postinstall.cjs",
"watch": "yarn run build-base -- --sourcemap --watch",
"check": "tsc --noEmit",
"lint": "eslint ./src --ext .ts",
"lint-fix": "eslint ./src --ext .ts --fix",
Expand All @@ -388,6 +394,7 @@
"eslint-plugin-promise": "^6.1.1",
"ovsx": "^0.8.3",
"prettier": "^3.0.3",
"rimraf": "^5.0.5",
"typescript": "^5.2.2"
}
}
28 changes: 28 additions & 0 deletions editors/vscode/scripts/postinstall.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

const path = require('path');
const fs = require('fs');
const rimraf = require('rimraf');

const vscodeDir = path.join(__dirname, '../');
const editorToolsDir = path.join(vscodeDir, '../../tools/editor-tools/');

rimraf.sync(path.join(vscodeDir, 'out/editor-tools/'));
fs.mkdirSync(path.join(vscodeDir, 'out/editor-tools/'), { recursive: true });

function copyDir(src, dest) {
fs.readdirSync(src).forEach((item) => {
const srcPath = path.join(src, item);
const destPath = path.join(dest, item);
if (fs.lstatSync(srcPath).isDirectory()) {
fs.mkdirSync(destPath,
{ recursive: true });
copyDir(srcPath, destPath);
}
else {
fs.copyFileSync(srcPath, destPath);
}
});
}

copyDir(path.join(editorToolsDir, "dist"), path.join(vscodeDir, 'out/editor-tools/'));

Loading