Skip to content

Commit 8a16567

Browse files
authored
Update download script (#442)
Update the download script for the example server. - Remove static config via config file (removes overhead of updating the file for releases) - Introduce optional version parameter, if not specificed the version wil be derived from the package.json - Remove dependency to shell.js and use node builtins instead
1 parent 281be34 commit 8a16567

File tree

4 files changed

+43
-58
lines changed

4 files changed

+43
-58
lines changed

examples/workflow-standalone/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
"inversify-logger-middleware": "^3.1.0"
3838
},
3939
"devDependencies": {
40-
"@types/shelljs": "0.8.12",
4140
"@types/tar": "6.1.5",
4241
"circular-dependency-plugin": "^5.2.2",
4342
"css-loader": "^6.7.1",

examples/workflow-standalone/scripts/config.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

examples/workflow-standalone/scripts/start-example-server.ts

Lines changed: 43 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,36 @@
1313
*
1414
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
1515
********************************************************************************/
16+
import { execSync } from 'child_process';
1617
import * as fs from 'fs';
1718
import * as path from 'path';
18-
import * as sh from 'shelljs';
1919
import { extract } from 'tar';
20-
import * as config from './config.json';
21-
const serverDirPath = path.resolve(__dirname, '..', 'server');
20+
import * as packageJson from '../../../package.json';
2221

23-
async function run() {
24-
const serverFile = await downloadIfNecessary();
25-
console.log();
22+
const SERVER_DIR_PATH = path.resolve(__dirname, '..', 'server');
23+
const FILE_NAME = 'wf-glsp-server-node';
2624

25+
async function run() {
2726
const port = parsePortArg();
2827
const host = parseHostArg();
28+
const version = parseVersion();
29+
process.chdir(SERVER_DIR_PATH);
30+
31+
const serverFile = await downloadIfNecessary(version);
32+
console.log();
2933

30-
sh.cd(serverDirPath);
31-
sh.exec(`node ${serverFile} -w --port ${port} --host ${host}`);
34+
execSync(`node ${serverFile} -w --port ${port} --host ${host}`, { stdio: 'inherit' });
3235
}
3336

34-
async function downloadIfNecessary(): Promise<string> {
35-
console.log(`Check if server executable with version ${config.version} is present.`);
37+
async function downloadIfNecessary(version: string): Promise<string> {
38+
console.log(`Check if server executable with version ${version} is present.`);
3639

37-
const existingServer = fs.readdirSync(serverDirPath).find(file => file.startsWith(config.fileName));
40+
const existingServer = fs.readdirSync(SERVER_DIR_PATH).find(file => file.startsWith(FILE_NAME));
3841
if (existingServer) {
39-
const existingVersion = existingServer.replace(config.fileName + '-', '').replace('.js', '');
40-
const latestVersion = sh
41-
.exec(`npm show @eclipse-glsp-examples/workflow-server-bundled@${config.version} version`, { silent: true })
42-
.stdout.trim();
42+
const existingVersion = existingServer.replace(FILE_NAME + '-', '').replace('.js', '');
43+
const latestVersion = execSync(`npm show @eclipse-glsp-examples/workflow-server-bundled@${version} version`, {
44+
encoding: 'utf-8'
45+
}).trim();
4346
if (existingVersion === latestVersion) {
4447
console.log('Server executable already present. Skip download"');
4548
return existingServer;
@@ -48,32 +51,31 @@ async function downloadIfNecessary(): Promise<string> {
4851

4952
console.log('Server executable with correct version not found. Download from npm.');
5053
if (existingServer) {
51-
fs.rmSync(path.resolve(serverDirPath, existingServer));
52-
fs.rmSync(path.resolve(serverDirPath, existingServer.replace('.js', '.js.map')));
54+
fs.rmSync(path.resolve(SERVER_DIR_PATH, existingServer));
55+
fs.rmSync(path.resolve(SERVER_DIR_PATH, existingServer.replace('.js', '.js.map')));
5356
}
54-
sh.cd(serverDirPath);
55-
const packResultJson = sh
56-
.exec(`npm pack @eclipse-glsp-examples/workflow-server-bundled@${config.version} --json`, { silent: true })
57-
.stdout.trim();
58-
const version = JSON.parse(packResultJson)[0].version;
59-
const tarBall = fs.readdirSync(serverDirPath).find(file => file.endsWith('.tar.gz') || file.endsWith('.tgz'))!;
57+
const packResultJson = execSync(`npm pack @eclipse-glsp-examples/workflow-server-bundled@${version} --json`, {
58+
encoding: 'utf-8'
59+
}).trim();
60+
const newVersion = JSON.parse(packResultJson)[0].version;
61+
const tarBall = fs.readdirSync(SERVER_DIR_PATH).find(file => file.endsWith('.tar.gz') || file.endsWith('.tgz'))!;
6062
console.log('Extract downloaded server tarball');
6163
await extract({
6264
file: tarBall,
63-
cwd: serverDirPath
65+
cwd: SERVER_DIR_PATH
6466
});
6567

66-
const tempDir = path.resolve(serverDirPath, 'package');
67-
fs.copyFileSync(path.resolve(tempDir, 'wf-glsp-server-node.js'), path.resolve(serverDirPath, `${config.fileName}-${version}.js`));
68+
const tempDir = path.resolve(SERVER_DIR_PATH, 'package');
69+
fs.copyFileSync(path.resolve(tempDir, 'wf-glsp-server-node.js'), path.resolve(SERVER_DIR_PATH, `${FILE_NAME}-${newVersion}.js`));
6870
fs.copyFileSync(
6971
path.resolve(tempDir, 'wf-glsp-server-node.js.map'),
70-
path.resolve(serverDirPath, `${config.fileName}-${version}.js.map`)
72+
path.resolve(SERVER_DIR_PATH, `${FILE_NAME}-${newVersion}.js.map`)
7173
);
7274

7375
console.log('Remove temporary files');
7476
fs.rmSync(tempDir, { force: true, recursive: true });
75-
fs.rmSync(path.resolve(serverDirPath, tarBall), { force: true });
76-
return `${config.fileName}-${version}.js`;
77+
fs.rmSync(path.resolve(SERVER_DIR_PATH, tarBall), { force: true });
78+
return `${FILE_NAME}-${newVersion}.js`;
7779
}
7880

7981
function parsePortArg(): number {
@@ -82,7 +84,7 @@ function parsePortArg(): number {
8284
if (portIndex >= 0) {
8385
port = parseInt(process.argv[portIndex + 1]);
8486
}
85-
if(isNaN(port)) {
87+
if (isNaN(port)) {
8688
console.error('Invalid port number');
8789
process.exit(1);
8890
}
@@ -92,14 +94,23 @@ function parsePortArg(): number {
9294
function parseHostArg(): string {
9395
let host = 'localhost';
9496
const hostIndex = process.argv.indexOf('--host');
95-
if(hostIndex >= 0) {
97+
if (hostIndex >= 0) {
9698
host = process.argv[hostIndex + 1];
9799
}
98-
if(typeof host !== 'string') {
100+
if (typeof host !== 'string') {
99101
console.error('Invalid host');
100102
process.exit(1);
101103
}
102104
return host;
103105
}
104106

107+
function parseVersion(): string {
108+
const versionIndex = process.argv.indexOf('--version');
109+
if (versionIndex >= 0) {
110+
return process.argv[versionIndex + 1];
111+
}
112+
// If no version is specified, use the version of the current package
113+
return packageJson.version.endsWith('-next') ? 'next' : packageJson.version;
114+
}
115+
105116
run();

yarn.lock

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,14 +1055,6 @@
10551055
resolved "https://registry.yarnpkg.com/@types/file-saver/-/file-saver-2.0.7.tgz#8dbb2f24bdc7486c54aa854eb414940bbd056f7d"
10561056
integrity sha512-dNKVfHd/jk0SkR/exKGj2ggkB45MAkzvWCaqLUUgkyjITkGNzH8H+yUwr+BLJUBjZOe9w8X3wgmXhZDRg1ED6A==
10571057

1058-
"@types/glob@~7.2.0":
1059-
version "7.2.0"
1060-
resolved "https://registry.yarnpkg.com/@types/glob/-/glob-7.2.0.tgz#bc1b5bf3aa92f25bd5dd39f35c57361bdce5b2eb"
1061-
integrity sha512-ZUxbzKl0IfJILTS6t7ip5fQQM/J3TJYubDm3nMbgubNNYS62eXeUpoLUC8/7fJNiFYHTrGPQn7hspDUzIHX3UA==
1062-
dependencies:
1063-
"@types/minimatch" "*"
1064-
"@types/node" "*"
1065-
10661058
"@types/jsdom@^21.1.3":
10671059
version "21.1.6"
10681060
resolved "https://registry.yarnpkg.com/@types/jsdom/-/jsdom-21.1.6.tgz#bcbc7b245787ea863f3da1ef19aa1dcfb9271a1b"
@@ -1087,11 +1079,6 @@
10871079
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.191.tgz#09511e7f7cba275acd8b419ddac8da9a6a79e2fa"
10881080
integrity sha512-BdZ5BCCvho3EIXw6wUCXHe7rS53AIDPLE+JzwgT+OsJk53oBfbSmZZ7CX4VaRoN78N+TJpFi9QPlfIVNmJYWxQ==
10891081

1090-
"@types/minimatch@*":
1091-
version "5.1.2"
1092-
resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-5.1.2.tgz#07508b45797cb81ec3f273011b054cd0755eddca"
1093-
integrity sha512-K0VQKziLUWkVKiRVrx4a40iPaxTUefQmjtkQofBkYRcoaaL/8rhwDWww9qWbrgicNOgnpIsMxyNIUM4+n6dUIA==
1094-
10951082
"@types/minimatch@^3.0.3":
10961083
version "3.0.5"
10971084
resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.5.tgz#1001cc5e6a3704b83c236027e77f2f58ea010f40"
@@ -1131,14 +1118,6 @@
11311118
resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.5.8.tgz#8268a8c57a3e4abd25c165ecd36237db7948a55e"
11321119
integrity sha512-I8EUhyrgfLrcTkzV3TSsGyl1tSuPrEDzr0yd5m90UgNxQkyDXULk3b6MlQqTCpZpNtWe1K0hzclnZkTcLBe2UQ==
11331120

1134-
1135-
version "0.8.12"
1136-
resolved "https://registry.yarnpkg.com/@types/shelljs/-/shelljs-0.8.12.tgz#79dc9632af7d5ca1b5afb65a6bfc1422d79b5fa0"
1137-
integrity sha512-ZA8U81/gldY+rR5zl/7HSHrG2KDfEb3lzG6uCUDhW1DTQE9yC/VBQ45fXnXq8f3CgInfhZmjtdu/WOUlrXRQUg==
1138-
dependencies:
1139-
"@types/glob" "~7.2.0"
1140-
"@types/node" "*"
1141-
11421121
"@types/sinon@^10.0.19":
11431122
version "10.0.20"
11441123
resolved "https://registry.yarnpkg.com/@types/sinon/-/sinon-10.0.20.tgz#f1585debf4c0d99f9938f4111e5479fb74865146"

0 commit comments

Comments
 (0)