Skip to content

Commit

Permalink
GLSP-1363: Bundle CLI tool
Browse files Browse the repository at this point in the history
Bundle CLI tool with eslint
Also: Update tsconfig target to ES2019 to be in line with Theia
#1363
  • Loading branch information
tortmayr committed Jul 7, 2024
1 parent 85305d0 commit 5d1b694
Show file tree
Hide file tree
Showing 10 changed files with 287 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
module.exports = {
root: true,
extends: '@eclipse-glsp',
ignorePatterns: ['**/{node_modules,lib}', '**/.eslintrc.js'],
ignorePatterns: ['**/{node_modules,lib}', '**/.eslintrc.js', '**/esbuild.js'],

parserOptions: {
tsconfigRootDir: __dirname,
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
node_modules/
*.log
lib
dist
tsconfig.tsbuildinfo
eslint.xml
10 changes: 0 additions & 10 deletions dev-packages/cli/.eslintrc.js

This file was deleted.

2 changes: 0 additions & 2 deletions dev-packages/cli/bin/glsp

This file was deleted.

30 changes: 30 additions & 0 deletions dev-packages/cli/esbuild.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const esbuild = require('esbuild');

/** @param {import('esbuild').BuildOptions} context. */
async function doWatch(options) {
const ctx = await esbuild.context(options);
await ctx.watch();
console.log('Watching for changes...');
}

/** @type {import('esbuild').BuildOptions} */
const opts = {
entryPoints: ['src/cli.ts'],
bundle: true,
outfile: 'dist/cli.js',
platform: 'node',
sourcemap: true,
packages: 'external'
};

const production = process.argv.includes('-p') || process.argv.includes('--production');
if (production) {
opts.minify = true;
opts.sourcemap = false;
}
const watch = process.argv.includes('-w') || process.argv.includes('--watch');
if (!watch) {
esbuild.build(opts).catch(() => process.exit(1));
} else {
doWatch(opts);
}
37 changes: 17 additions & 20 deletions dev-packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
"name": "@eclipse-glsp/cli",
"version": "2.2.0-next",
"description": "CLI Tooling & scripts for GLSP components",
"keywords": [
"eclipse",
"tsconfig"
],
"homepage": "https://www.eclipse.org/glsp/",
"bugs": "https://github.com/eclipse-glsp/glsp/issues",
"repository": {
Expand All @@ -24,23 +20,32 @@
}
],
"bin": {
"glsp": "bin/glsp"
"glsp": "dist/cli.js"
},
"files": [
"src",
"bin",
"lib"
"dist"
],
"scripts": {
"build": "tsc -b",
"clean": "rimraf lib tsconfig.tsbuildinfo",
"bundle": "node esbuild.js",
"bundle:prod": "yarn clean dist && yarn bundle --production",
"clean": "rimraf lib dist tsconfig.tsbuildinfo",
"clean:dist": "rimraf dist",
"lint": "eslint --ext .ts,.tsx ./src",
"lint:ci": "yarn lint -o eslint.xml -f checkstyle",
"start": "node --enable-source-maps lib/app.js",
"watch": "tsc -w"
"start": "node --enable-source-maps dist/cli.js",
"watch": "node esbuild.js -w",
"watch:tsc": "tsc -b -w"
},
"dependencies": {
"devDependencies": {
"@eclipse-glsp/config": "2.2.0-next",
"@types/glob": "^8.1.0",
"@types/node-fetch": "^2.6.6",
"@types/readline-sync": "^1.4.5",
"@types/semver": "^7.5.3",
"@types/shelljs": "^0.8.13",
"commander": "^10.0.1",
"esbuild": "^0.23.0",
"glob": "^10.3.10",
"globby": "13.2.2",
"node-fetch": "^2.6.11",
Expand All @@ -49,14 +54,6 @@
"semver": "^7.5.1",
"shelljs": "^0.8.5"
},
"devDependencies": {
"@eclipse-glsp/config": "2.2.0-next",
"@types/glob": "^8.1.0",
"@types/node-fetch": "^2.6.6",
"@types/readline-sync": "^1.4.5",
"@types/semver": "^7.5.3",
"@types/shelljs": "^0.8.13"
},
"publishConfig": {
"access": "public"
}
Expand Down
3 changes: 1 addition & 2 deletions dev-packages/cli/src/app.ts → dev-packages/cli/src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node
/********************************************************************************
* Copyright (c) 2022 EclipseSource and others.
* Copyright (c) 2022-2024 EclipseSource and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand All @@ -22,7 +22,6 @@ import { UpdateNextCommand } from './commands/update-next';
import { baseCommand } from './util/command-util';

export const COMMAND_VERSION = '1.1.0-next';

const app = baseCommand() //
.version(COMMAND_VERSION)
.name('glsp')
Expand Down
4 changes: 2 additions & 2 deletions dev-packages/ts-config/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
"resolveJsonModule": true,
"module": "CommonJS",
"moduleResolution": "Node",
"target": "ES2017",
"target": "ES2019",
"jsx": "react",
"lib": ["ES2017", "dom"],
"lib": ["ES2019", "Dom"],
"sourceMap": true,
"types": ["node", "reflect-metadata"]
}
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
],
"scripts": {
"all": "yarn install && yarn lint",
"build": "yarn compile",
"build": "yarn compile && yarn cli bundle",
"check:headers": "yarn start:cli checkHeaders . -t lastCommit",
"check:pr": "yarn all && yarn check:headers",
"clean": "lerna run clean",
"cli": " yarn --cwd dev-packages/cli",
"compile": "tsc -b",
"lint": "eslint --ext .ts,.tsx .",
"lint:ci": "yarn lint -o eslint.xml -f checkstyle",
Expand All @@ -19,8 +20,7 @@
"publish:latest": "lerna publish from-git --no-git-reset --no-git-tag-version --no-verify-access --no-push",
"publish:next": "lerna publish preminor --exact --canary --preid next --dist-tag next --no-git-reset --no-git-tag-version --no-push --ignore-scripts --yes",
"publish:prepare": "lerna version --ignore-scripts --yes --no-push",
"start:cli": " yarn --cwd dev-packages/cli start",
"watch": "tsc -b -w --preserveWatchOutput"
"watch": "concurrently --kill-others -n tsc,bundle -c red,yellow \"tsc -b -w --preserveWatchOutput\" \"yarn -s cli watch\""
},
"devDependencies": {
"@istanbuljs/nyc-config-typescript": "^1.0.2",
Expand All @@ -31,6 +31,7 @@
"@typescript-eslint/eslint-plugin": "^5.59.7",
"@typescript-eslint/parser": "^5.59.7",
"chai": "^4.3.7",
"concurrently": "^8.2.2",
"eslint": "^8.41.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-chai-friendly": "^0.7.2",
Expand Down
Loading

0 comments on commit 5d1b694

Please sign in to comment.