Skip to content

Commit

Permalink
feat(developer): VSCode plugin for building
Browse files Browse the repository at this point in the history
- initial checkin of previous code
- add README.md
- add build.sh

Fixes: #12756
  • Loading branch information
srl295 committed Dec 3, 2024
1 parent 02620c1 commit 85dbd3a
Show file tree
Hide file tree
Showing 20 changed files with 5,468 additions and 3,048 deletions.
1 change: 1 addition & 0 deletions developer/src/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ builder_describe \
":test=test/auto Various older tests (others in each module)" \
":tike Keyman Developer IDE" \
":inst Bundled installers" \
":keyman-vscode-plugin Keyman VSCode Plugin" \
"--npm-publish+ For publish, do a npm publish, not npm pack (only for CI)" \
"--dry-run,-n+ Don't actually publish anything to external endpoints, just dry run"

Expand Down
6 changes: 6 additions & 0 deletions developer/src/keyman-vscode-plugin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
out
dist
node_modules
.vscode-test/
*.vsix
!.vscode
5 changes: 5 additions & 0 deletions developer/src/keyman-vscode-plugin/.vscode-test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { defineConfig } from '@vscode/test-cli';

export default defineConfig({
files: 'out/test/**/*.test.js',
});
8 changes: 8 additions & 0 deletions developer/src/keyman-vscode-plugin/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"dbaeumer.vscode-eslint",
"ms-vscode.extension-test-runner"
]
}
19 changes: 19 additions & 0 deletions developer/src/keyman-vscode-plugin/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Run Extension",
"type": "extensionHost",
"request": "launch",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}",
"--disable-extensions",
// Note: you can add an argument here with a workspace folder to launch on open
],
"outFiles": [
"${workspaceFolder}/out/**/*.js"
],
"preLaunchTask": "${defaultBuildTask}"
}
]
}
11 changes: 11 additions & 0 deletions developer/src/keyman-vscode-plugin/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Place your settings in this file to overwrite default and user settings.
{
"files.exclude": {
"out": false // set this to true to hide the "out" folder with the compiled JS files
},
"search.exclude": {
"out": true // set this to false to include "out" folder in search results
},
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
"typescript.tsc.autoDetect": "off"
}
20 changes: 20 additions & 0 deletions developer/src/keyman-vscode-plugin/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
{
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "watch",
"problemMatcher": "$tsc-watch",
"isBackground": true,
"presentation": {
"reveal": "never"
},
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
11 changes: 11 additions & 0 deletions developer/src/keyman-vscode-plugin/.vscodeignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.vscode/**
.vscode-test/**
src/**
.gitignore
.yarnrc
vsc-extension-quickstart.md
**/tsconfig.json
**/eslint.config.mjs
**/*.map
**/*.ts
**/.vscode-test.*
33 changes: 33 additions & 0 deletions developer/src/keyman-vscode-plugin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Keyman Developer - keyman-vscode-plugin

This package is a standalone [VSCode](https://code.visualstudio.com) plugin which offers:

- a Build Task for building .kpj files into a package
- when building the .kpj file, all .kmn and .xml (LDML keyboard) files will be compiled as well
- The Build Task assumes that the .kpj will have the same name as the directory. So, `.../some_keyboard/some_keyboard.kpj`

## Building

From the command line,

- `npm i`
- `npm run compile`

You can use `npm run watch` to keep compilation running, but see below.

There is also a `build.sh` which works the usual way.

## Running/Testing locally

- Open this directory (`keyman-vscode-plugin`) in VSCode
- From the Run and Debug toolbar, click Run Extension
- A terminal will automatically open with `npm run watch` recompiling the project.
- Choose a directory containing a .kpj file, and choose the **Terminal > Run Task…** menu item, or the **Tasks: Run Task** command. Select "kpj" and the name, and the compilation should occur in a terminal window.

- You can use the **Developer: Reload Window** command to reload the `[extension development]` window with a new version of the plugin.

## License

Copyright (c) SIL Global.

Keyman is an open source project distributed under the [MIT license](../../../LICENSE.md).
48 changes: 48 additions & 0 deletions developer/src/keyman-vscode-plugin/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env bash
#
# Compiles the keyman-vscode-plugin plugin.
#
## START STANDARD BUILD SCRIPT INCLUDE
# adjust relative paths as necessary
THIS_SCRIPT="$(readlink -f "${BASH_SOURCE[0]}")"
. "${THIS_SCRIPT%/*}/../../../resources/build/builder.inc.sh"
## END STANDARD BUILD SCRIPT INCLUDE

. "$KEYMAN_ROOT/resources/shellHelperFunctions.sh"

builder_describe "Keyman keyman-vscode-plugin module" \
"configure" \
"build" \
"clean" \
"test"

builder_describe_outputs \
configure /node_modules \
build /developer/src/keyman-vscode-plugin/out/extension.js

builder_parse "$@"

function do_clean() {
rm -rf ./out/ ./tsconfig.tsbuildinfo .vscode-test
}

function do_configure() {
verify_npm_setup
}

function do_build() {
npm run compile
}

function do_test() {
npm test
}

builder_run_action clean do_clean
builder_run_action configure do_configure
builder_run_action build do_build
builder_run_action test do_test

#-------------------------------------------------------------------------------------------------------------------

. "$KEYMAN_ROOT/resources/build/build-utils-ci.inc.sh"
28 changes: 28 additions & 0 deletions developer/src/keyman-vscode-plugin/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import typescriptEslint from "@typescript-eslint/eslint-plugin";
import tsParser from "@typescript-eslint/parser";

export default [{
files: ["**/*.ts"],
}, {
plugins: {
"@typescript-eslint": typescriptEslint,
},

languageOptions: {
parser: tsParser,
ecmaVersion: 2022,
sourceType: "module",
},

rules: {
"@typescript-eslint/naming-convention": ["warn", {
selector: "import",
format: ["camelCase", "PascalCase"],
}],

curly: "warn",
eqeqeq: "warn",
"no-throw-literal": "warn",
semi: "warn",
},
}];
63 changes: 63 additions & 0 deletions developer/src/keyman-vscode-plugin/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"name": "@keymanapp/keyman-vscode-plugin",
"displayName": "Keyman VSCode Plugin",
"description": "Plugin for compiling Keyman projects in VSCode",
"version": "0.0.1",
"engines": {
"vscode": "^1.93.0"
},
"repository": {
"type": "git",
"url": "https://github.com/keymanapp/keyman.git"
},
"categories": [
"Other"
],
"activationEvents": [],
"main": "./out/extension.js",
"contributes": {
"commands": [
{
"command": "keyman.compileProject",
"title": "Keyman: Compile Project"
}
],
"taskDefinitions": [
{
"type": "kpj",
"required": [
"task"
],
"properties": {},
"when": ""
}
]
},
"scripts": {
"vscode:prepublish": "npm run compile",
"compile": "tsc -p ./",
"watch": "tsc -watch -p ./",
"pretest": "npm run compile && npm run lint",
"lint": "eslint src",
"test": "vscode-test",
"_prepare": "npm run compile"
},
"devDependencies": {
"@types/mocha": "^10.0.8",
"@types/node": "20.4.1",
"@types/vscode": "^1.93.0",
"@typescript-eslint/eslint-plugin": "^8.7.0",
"@typescript-eslint/parser": "^8.7.0",
"@vscode/test-cli": "^0.0.10",
"@vscode/test-electron": "^2.4.1",
"eslint": "^9.11.1"
},
"license": "MIT",
"dependencies": {
"@keymanapp/common-types": "file:../../../common/web/types",
"@keymanapp/developer-utils": "file:../common/web/utils",
"@keymanapp/kmc-ldml": "file:../kmc-ldml",
"@keymanapp/kmc-kmn": "file:../kmc-kmn",
"@keymanapp/kmc-package": "file:../kmc-package"
}
}
22 changes: 22 additions & 0 deletions developer/src/keyman-vscode-plugin/src/extension.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Keyman is copyright (C) SIL Global. MIT License.
*/

import * as vscode from 'vscode';
import { KpjTaskProvider } from './kpjTasks';

/** for cleaning up the kpj provider */
let kpjTaskProvider: vscode.Disposable | undefined;

/** called when extension is activated */
export function activate(context: vscode.ExtensionContext) {
// TASK STUFF
kpjTaskProvider = vscode.tasks.registerTaskProvider('kpj', KpjTaskProvider);
}

/** called when extension is deactivated */
export function deactivate() {
if (kpjTaskProvider) {
kpjTaskProvider.dispose();
}
}
Loading

0 comments on commit 85dbd3a

Please sign in to comment.