@theia/cli 1.45.0 → 1.46.0-next.72

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/theia.js CHANGED
@@ -1,590 +1,590 @@
1
- "use strict";
2
- // *****************************************************************************
3
- // Copyright (C) 2017 TypeFox and others.
4
- //
5
- // This program and the accompanying materials are made available under the
6
- // terms of the Eclipse Public License v. 2.0 which is available at
7
- // http://www.eclipse.org/legal/epl-2.0.
8
- //
9
- // This Source Code may also be made available under the following Secondary
10
- // Licenses when the conditions for such availability set forth in the Eclipse
11
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
- // with the GNU Classpath Exception which is available at
13
- // https://www.gnu.org/software/classpath/license.html.
14
- //
15
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16
- // *****************************************************************************
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- const fs = require("fs");
19
- const path = require("path");
20
- const temp = require("temp");
21
- const yargs = require("yargs");
22
- const yargsFactory = require("yargs/yargs");
23
- const application_manager_1 = require("@theia/application-manager");
24
- const application_package_1 = require("@theia/application-package");
25
- const check_dependencies_1 = require("./check-dependencies");
26
- const download_plugins_1 = require("./download-plugins");
27
- const run_test_1 = require("./run-test");
28
- const localization_manager_1 = require("@theia/localization-manager");
29
- const node_request_service_1 = require("@theia/request/lib/node-request-service");
30
- const ovsx_client_1 = require("@theia/ovsx-client");
31
- const { executablePath } = require('puppeteer');
32
- process.on('unhandledRejection', (reason, promise) => {
33
- throw reason;
34
- });
35
- process.on('uncaughtException', error => {
36
- if (error) {
37
- console.error('Uncaught Exception: ', error.toString());
38
- if (error.stack) {
39
- console.error(error.stack);
40
- }
41
- }
42
- process.exit(1);
43
- });
44
- theiaCli();
45
- function toStringArray(argv) {
46
- return argv === null || argv === void 0 ? void 0 : argv.map(arg => String(arg));
47
- }
48
- function rebuildCommand(command, target) {
49
- return {
50
- command,
51
- describe: `Rebuild/revert native node modules for "${target}"`,
52
- builder: {
53
- 'cacheRoot': {
54
- type: 'string',
55
- describe: 'Root folder where to store the .browser_modules cache'
56
- },
57
- 'modules': {
58
- alias: 'm',
59
- type: 'array',
60
- describe: 'List of modules to rebuild/revert'
61
- },
62
- 'forceAbi': {
63
- type: 'number',
64
- describe: 'The Node ABI version to rebuild for'
65
- }
66
- },
67
- handler: ({ cacheRoot, modules, forceAbi }) => {
68
- // Note: `modules` is actually `string[] | undefined`.
69
- if (modules) {
70
- // It is ergonomic to pass arguments as --modules="a,b,c,..."
71
- // but yargs doesn't parse it this way by default.
72
- const flattened = [];
73
- for (const value of modules) {
74
- if (value.includes(',')) {
75
- flattened.push(...value.split(',').map(mod => mod.trim()));
76
- }
77
- else {
78
- flattened.push(value);
79
- }
80
- }
81
- modules = flattened;
82
- }
83
- (0, application_manager_1.rebuild)(target, { cacheRoot, modules, forceAbi });
84
- }
85
- };
86
- }
87
- function defineCommonOptions(cli) {
88
- return cli
89
- .option('app-target', {
90
- description: 'The target application type. Overrides `theia.target` in the application\'s package.json',
91
- choices: ['browser', 'electron'],
92
- });
93
- }
94
- async function theiaCli() {
95
- const { version } = await fs.promises.readFile(path.join(__dirname, '../package.json'), 'utf8').then(JSON.parse);
96
- yargs.scriptName('theia').version(version);
97
- const projectPath = process.cwd();
98
- // Create a sub `yargs` parser to read `app-target` without
99
- // affecting the global `yargs` instance used by the CLI.
100
- const { appTarget } = defineCommonOptions(yargsFactory()).help(false).parse();
101
- const manager = new application_manager_1.ApplicationPackageManager({ projectPath, appTarget });
102
- const localizationManager = new localization_manager_1.LocalizationManager();
103
- const { target } = manager.pck;
104
- defineCommonOptions(yargs)
105
- .command({
106
- command: 'start [theia-args...]',
107
- describe: `Start the ${target} backend`,
108
- // Disable this command's `--help` option so that it is forwarded to Theia's CLI
109
- builder: cli => cli.help(false),
110
- handler: async ({ theiaArgs }) => {
111
- manager.start(toStringArray(theiaArgs));
112
- }
113
- })
114
- .command({
115
- command: 'clean',
116
- describe: `Clean for the ${target} target`,
117
- handler: async () => {
118
- await manager.clean();
119
- }
120
- })
121
- .command({
122
- command: 'copy',
123
- describe: 'Copy various files from `src-gen` to `lib`',
124
- handler: async () => {
125
- await manager.copy();
126
- }
127
- })
128
- .command({
129
- command: 'generate',
130
- describe: `Generate various files for the ${target} target`,
131
- builder: cli => application_manager_1.ApplicationPackageManager.defineGeneratorOptions(cli),
132
- handler: async ({ mode, splitFrontend }) => {
133
- await manager.generate({ mode, splitFrontend });
134
- }
135
- })
136
- .command({
137
- command: 'build [webpack-args...]',
138
- describe: `Generate and bundle the ${target} frontend using webpack`,
139
- builder: cli => application_manager_1.ApplicationPackageManager.defineGeneratorOptions(cli)
140
- .option('webpack-help', {
141
- boolean: true,
142
- description: 'Display Webpack\'s help',
143
- default: false
144
- }),
145
- handler: async ({ mode, splitFrontend, webpackHelp, webpackArgs = [] }) => {
146
- await manager.build(webpackHelp
147
- ? ['--help']
148
- : [
149
- // Forward the `mode` argument to Webpack too:
150
- '--mode', mode,
151
- ...toStringArray(webpackArgs)
152
- ], { mode, splitFrontend });
153
- }
154
- })
155
- .command(rebuildCommand('rebuild', target))
156
- .command(rebuildCommand('rebuild:browser', 'browser'))
157
- .command(rebuildCommand('rebuild:electron', 'electron'))
158
- .command({
159
- command: 'check:hoisted',
160
- describe: 'Check that all dependencies are hoisted',
161
- builder: {
162
- 'suppress': {
163
- alias: 's',
164
- describe: 'Suppress exiting with failure code',
165
- boolean: true,
166
- default: false
167
- }
168
- },
169
- handler: ({ suppress }) => {
170
- (0, check_dependencies_1.default)({
171
- workspaces: ['packages/*'],
172
- include: ['**'],
173
- exclude: ['.bin/**', '.cache/**'],
174
- skipHoisted: false,
175
- skipUniqueness: true,
176
- skipSingleTheiaVersion: true,
177
- onlyTheiaExtensions: false,
178
- suppress
179
- });
180
- }
181
- })
182
- .command({
183
- command: 'check:theia-version',
184
- describe: 'Check that all dependencies have been resolved to the same Theia version',
185
- builder: {
186
- 'suppress': {
187
- alias: 's',
188
- describe: 'Suppress exiting with failure code',
189
- boolean: true,
190
- default: false
191
- }
192
- },
193
- handler: ({ suppress }) => {
194
- (0, check_dependencies_1.default)({
195
- workspaces: undefined,
196
- include: ['@theia/**'],
197
- exclude: [],
198
- skipHoisted: true,
199
- skipUniqueness: false,
200
- skipSingleTheiaVersion: false,
201
- onlyTheiaExtensions: false,
202
- suppress
203
- });
204
- }
205
- })
206
- .command({
207
- command: 'check:theia-extensions',
208
- describe: 'Check uniqueness of Theia extension versions or whether they are hoisted',
209
- builder: {
210
- 'suppress': {
211
- alias: 's',
212
- describe: 'Suppress exiting with failure code',
213
- boolean: true,
214
- default: false
215
- }
216
- },
217
- handler: ({ suppress }) => {
218
- (0, check_dependencies_1.default)({
219
- workspaces: undefined,
220
- include: ['**'],
221
- exclude: [],
222
- skipHoisted: true,
223
- skipUniqueness: false,
224
- skipSingleTheiaVersion: true,
225
- onlyTheiaExtensions: true,
226
- suppress
227
- });
228
- }
229
- })
230
- .command({
231
- command: 'check:dependencies',
232
- describe: 'Check uniqueness of dependency versions or whether they are hoisted',
233
- builder: {
234
- 'workspaces': {
235
- alias: 'w',
236
- describe: 'Glob patterns of workspaces to analyze, relative to `cwd`',
237
- array: true,
238
- defaultDescription: 'All glob patterns listed in the package.json\'s workspaces',
239
- demandOption: false
240
- },
241
- 'include': {
242
- alias: 'i',
243
- describe: 'Glob pattern of dependencies\' package names to be included, e.g. -i "@theia/**"',
244
- array: true,
245
- default: ['**']
246
- },
247
- 'exclude': {
248
- alias: 'e',
249
- describe: 'Glob pattern of dependencies\' package names to be excluded',
250
- array: true,
251
- defaultDescription: 'None',
252
- default: []
253
- },
254
- 'skip-hoisted': {
255
- alias: 'h',
256
- describe: 'Skip checking whether dependencies are hoisted',
257
- boolean: true,
258
- default: false
259
- },
260
- 'skip-uniqueness': {
261
- alias: 'u',
262
- describe: 'Skip checking whether all dependencies are resolved to a unique version',
263
- boolean: true,
264
- default: false
265
- },
266
- 'skip-single-theia-version': {
267
- alias: 't',
268
- describe: 'Skip checking whether all @theia/* dependencies are resolved to a single version',
269
- boolean: true,
270
- default: false
271
- },
272
- 'only-theia-extensions': {
273
- alias: 'o',
274
- describe: 'Only check dependencies which are Theia extensions',
275
- boolean: true,
276
- default: false
277
- },
278
- 'suppress': {
279
- alias: 's',
280
- describe: 'Suppress exiting with failure code',
281
- boolean: true,
282
- default: false
283
- }
284
- },
285
- handler: ({ workspaces, include, exclude, skipHoisted, skipUniqueness, skipSingleTheiaVersion, onlyTheiaExtensions, suppress }) => {
286
- (0, check_dependencies_1.default)({
287
- workspaces,
288
- include,
289
- exclude,
290
- skipHoisted,
291
- skipUniqueness,
292
- skipSingleTheiaVersion,
293
- onlyTheiaExtensions,
294
- suppress
295
- });
296
- }
297
- })
298
- .command({
299
- command: 'download:plugins',
300
- describe: 'Download defined external plugins',
301
- builder: {
302
- 'packed': {
303
- alias: 'p',
304
- describe: 'Controls whether to pack or unpack plugins',
305
- boolean: true,
306
- default: false,
307
- },
308
- 'ignore-errors': {
309
- alias: 'i',
310
- describe: 'Ignore errors while downloading plugins',
311
- boolean: true,
312
- default: false,
313
- },
314
- 'api-version': {
315
- alias: 'v',
316
- describe: 'Supported API version for plugins',
317
- default: application_package_1.DEFAULT_SUPPORTED_API_VERSION
318
- },
319
- 'api-url': {
320
- alias: 'u',
321
- describe: 'Open-VSX Registry API URL',
322
- default: 'https://open-vsx.org/api'
323
- },
324
- 'parallel': {
325
- describe: 'Download in parallel',
326
- boolean: true,
327
- default: true
328
- },
329
- 'rate-limit': {
330
- describe: 'Amount of maximum open-vsx requests per second',
331
- number: true,
332
- default: 15
333
- },
334
- 'proxy-url': {
335
- describe: 'Proxy URL'
336
- },
337
- 'proxy-authorization': {
338
- describe: 'Proxy authorization information'
339
- },
340
- 'strict-ssl': {
341
- describe: 'Whether to enable strict SSL mode',
342
- boolean: true,
343
- default: false
344
- },
345
- 'ovsx-router-config': {
346
- describe: 'JSON configuration file for the OVSX router client',
347
- type: 'string'
348
- }
349
- },
350
- handler: async ({ apiUrl, proxyUrl, proxyAuthorization, strictSsl, ovsxRouterConfig, ...options }) => {
351
- const requestService = new node_request_service_1.NodeRequestService();
352
- await requestService.configure({
353
- proxyUrl,
354
- proxyAuthorization,
355
- strictSSL: strictSsl
356
- });
357
- let client;
358
- if (ovsxRouterConfig) {
359
- const routerConfig = await fs.promises.readFile(ovsxRouterConfig, 'utf8').then(JSON.parse, error => {
360
- console.error(error);
361
- });
362
- if (routerConfig) {
363
- client = await ovsx_client_1.OVSXRouterClient.FromConfig(routerConfig, ovsx_client_1.OVSXHttpClient.createClientFactory(requestService), [ovsx_client_1.RequestContainsFilterFactory, ovsx_client_1.ExtensionIdMatchesFilterFactory]);
364
- }
365
- }
366
- if (!client) {
367
- client = new ovsx_client_1.OVSXHttpClient(apiUrl, requestService);
368
- }
369
- await (0, download_plugins_1.default)(client, requestService, options);
370
- },
371
- })
372
- .command({
373
- command: 'nls-localize [languages...]',
374
- describe: 'Localize json files using the DeepL API',
375
- builder: {
376
- 'file': {
377
- alias: 'f',
378
- describe: 'The source file which should be translated',
379
- demandOption: true
380
- },
381
- 'deepl-key': {
382
- alias: 'k',
383
- describe: 'DeepL key used for API access. See https://www.deepl.com/docs-api for more information',
384
- demandOption: true
385
- },
386
- 'free-api': {
387
- describe: 'Indicates whether the specified DeepL API key belongs to the free API',
388
- boolean: true,
389
- default: false,
390
- },
391
- 'source-language': {
392
- alias: 's',
393
- describe: 'The source language of the translation file'
394
- }
395
- },
396
- handler: async ({ freeApi, deeplKey, file, sourceLanguage, languages = [] }) => {
397
- await localizationManager.localize({
398
- sourceFile: file,
399
- freeApi: freeApi !== null && freeApi !== void 0 ? freeApi : true,
400
- authKey: deeplKey,
401
- targetLanguages: languages,
402
- sourceLanguage
403
- });
404
- }
405
- })
406
- .command({
407
- command: 'nls-extract',
408
- describe: 'Extract translation key/value pairs from source code',
409
- builder: {
410
- 'output': {
411
- alias: 'o',
412
- describe: 'Output file for the extracted translations',
413
- demandOption: true
414
- },
415
- 'root': {
416
- alias: 'r',
417
- describe: 'The directory which contains the source code',
418
- default: '.'
419
- },
420
- 'merge': {
421
- alias: 'm',
422
- describe: 'Whether to merge new with existing translation values',
423
- boolean: true,
424
- default: false
425
- },
426
- 'exclude': {
427
- alias: 'e',
428
- describe: 'Allows to exclude translation keys starting with this value'
429
- },
430
- 'files': {
431
- alias: 'f',
432
- describe: 'Glob pattern matching the files to extract from (starting from --root).',
433
- array: true
434
- },
435
- 'logs': {
436
- alias: 'l',
437
- describe: 'File path to a log file'
438
- },
439
- 'quiet': {
440
- alias: 'q',
441
- describe: 'Prevents errors from being logged to console',
442
- boolean: true,
443
- default: false
444
- }
445
- },
446
- handler: async (options) => {
447
- await (0, localization_manager_1.extract)(options);
448
- }
449
- })
450
- .command({
451
- command: 'test [theia-args...]',
452
- builder: {
453
- 'test-inspect': {
454
- describe: 'Whether to auto-open a DevTools panel for test page.',
455
- boolean: true,
456
- default: false
457
- },
458
- 'test-extension': {
459
- describe: 'Test file extension(s) to load',
460
- array: true,
461
- default: ['js']
462
- },
463
- 'test-file': {
464
- describe: 'Specify test file(s) to be loaded prior to root suite execution',
465
- array: true,
466
- default: []
467
- },
468
- 'test-ignore': {
469
- describe: 'Ignore test file(s) or glob pattern(s)',
470
- array: true,
471
- default: []
472
- },
473
- 'test-recursive': {
474
- describe: 'Look for tests in subdirectories',
475
- boolean: true,
476
- default: false
477
- },
478
- 'test-sort': {
479
- describe: 'Sort test files',
480
- boolean: true,
481
- default: false
482
- },
483
- 'test-spec': {
484
- describe: 'One or more test files, directories, or globs to test',
485
- array: true,
486
- default: ['test']
487
- },
488
- 'test-coverage': {
489
- describe: 'Report test coverage consumable by istanbul',
490
- boolean: true,
491
- default: false
492
- }
493
- },
494
- handler: async ({ testInspect, testExtension, testFile, testIgnore, testRecursive, testSort, testSpec, testCoverage, theiaArgs }) => {
495
- if (!process.env.THEIA_CONFIG_DIR) {
496
- process.env.THEIA_CONFIG_DIR = temp.track().mkdirSync('theia-test-config-dir');
497
- }
498
- await (0, run_test_1.default)({
499
- start: () => new Promise((resolve, reject) => {
500
- const serverProcess = manager.start(toStringArray(theiaArgs));
501
- serverProcess.on('message', resolve);
502
- serverProcess.on('error', reject);
503
- serverProcess.on('close', (code, signal) => reject(`Server process exited unexpectedly: ${code !== null && code !== void 0 ? code : signal}`));
504
- }),
505
- launch: {
506
- args: ['--no-sandbox'],
507
- // eslint-disable-next-line no-null/no-null
508
- defaultViewport: null,
509
- devtools: testInspect,
510
- executablePath: executablePath()
511
- },
512
- files: {
513
- extension: testExtension,
514
- file: testFile,
515
- ignore: testIgnore,
516
- recursive: testRecursive,
517
- sort: testSort,
518
- spec: testSpec
519
- },
520
- coverage: testCoverage
521
- });
522
- }
523
- })
524
- .command({
525
- command: 'ffmpeg:replace [ffmpeg-path]',
526
- describe: '',
527
- builder: {
528
- 'electronDist': {
529
- description: 'Electron distribution location.',
530
- },
531
- 'electronVersion': {
532
- description: 'Electron version for which to pull the "clean" ffmpeg library.',
533
- },
534
- 'ffmpegPath': {
535
- description: 'Absolute path to the ffmpeg shared library.',
536
- },
537
- 'platform': {
538
- description: 'Dictates where the library is located within the Electron distribution.',
539
- choices: ['darwin', 'linux', 'win32'],
540
- },
541
- },
542
- handler: async (options) => {
543
- const ffmpeg = await Promise.resolve().then(() => require('@theia/ffmpeg'));
544
- await ffmpeg.replaceFfmpeg(options);
545
- },
546
- })
547
- .command({
548
- command: 'ffmpeg:check [ffmpeg-path]',
549
- describe: '(electron-only) Check that ffmpeg doesn\'t contain proprietary codecs',
550
- builder: {
551
- 'electronDist': {
552
- description: 'Electron distribution location',
553
- },
554
- 'ffmpegPath': {
555
- describe: 'Absolute path to the ffmpeg shared library',
556
- },
557
- 'json': {
558
- description: 'Output the found codecs as JSON on stdout',
559
- boolean: true,
560
- },
561
- 'platform': {
562
- description: 'Dictates where the library is located within the Electron distribution',
563
- choices: ['darwin', 'linux', 'win32'],
564
- },
565
- },
566
- handler: async (options) => {
567
- const ffmpeg = await Promise.resolve().then(() => require('@theia/ffmpeg'));
568
- await ffmpeg.checkFfmpeg(options);
569
- },
570
- })
571
- .parserConfiguration({
572
- 'unknown-options-as-args': true,
573
- })
574
- .strictCommands()
575
- .demandCommand(1, 'Please run a command')
576
- .fail((msg, err, cli) => {
577
- process.exitCode = 1;
578
- if (err) {
579
- // One of the handlers threw an error:
580
- console.error(err);
581
- }
582
- else {
583
- // Yargs detected a problem with commands and/or arguments while parsing:
584
- cli.showHelp();
585
- console.error(msg);
586
- }
587
- })
588
- .parse();
589
- }
1
+ "use strict";
2
+ // *****************************************************************************
3
+ // Copyright (C) 2017 TypeFox and others.
4
+ //
5
+ // This program and the accompanying materials are made available under the
6
+ // terms of the Eclipse Public License v. 2.0 which is available at
7
+ // http://www.eclipse.org/legal/epl-2.0.
8
+ //
9
+ // This Source Code may also be made available under the following Secondary
10
+ // Licenses when the conditions for such availability set forth in the Eclipse
11
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
+ // with the GNU Classpath Exception which is available at
13
+ // https://www.gnu.org/software/classpath/license.html.
14
+ //
15
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16
+ // *****************************************************************************
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ const fs = require("fs");
19
+ const path = require("path");
20
+ const temp = require("temp");
21
+ const yargs = require("yargs");
22
+ const yargsFactory = require("yargs/yargs");
23
+ const application_manager_1 = require("@theia/application-manager");
24
+ const application_package_1 = require("@theia/application-package");
25
+ const check_dependencies_1 = require("./check-dependencies");
26
+ const download_plugins_1 = require("./download-plugins");
27
+ const run_test_1 = require("./run-test");
28
+ const localization_manager_1 = require("@theia/localization-manager");
29
+ const node_request_service_1 = require("@theia/request/lib/node-request-service");
30
+ const ovsx_client_1 = require("@theia/ovsx-client");
31
+ const { executablePath } = require('puppeteer');
32
+ process.on('unhandledRejection', (reason, promise) => {
33
+ throw reason;
34
+ });
35
+ process.on('uncaughtException', error => {
36
+ if (error) {
37
+ console.error('Uncaught Exception: ', error.toString());
38
+ if (error.stack) {
39
+ console.error(error.stack);
40
+ }
41
+ }
42
+ process.exit(1);
43
+ });
44
+ theiaCli();
45
+ function toStringArray(argv) {
46
+ return argv === null || argv === void 0 ? void 0 : argv.map(arg => String(arg));
47
+ }
48
+ function rebuildCommand(command, target) {
49
+ return {
50
+ command,
51
+ describe: `Rebuild/revert native node modules for "${target}"`,
52
+ builder: {
53
+ 'cacheRoot': {
54
+ type: 'string',
55
+ describe: 'Root folder where to store the .browser_modules cache'
56
+ },
57
+ 'modules': {
58
+ alias: 'm',
59
+ type: 'array',
60
+ describe: 'List of modules to rebuild/revert'
61
+ },
62
+ 'forceAbi': {
63
+ type: 'number',
64
+ describe: 'The Node ABI version to rebuild for'
65
+ }
66
+ },
67
+ handler: ({ cacheRoot, modules, forceAbi }) => {
68
+ // Note: `modules` is actually `string[] | undefined`.
69
+ if (modules) {
70
+ // It is ergonomic to pass arguments as --modules="a,b,c,..."
71
+ // but yargs doesn't parse it this way by default.
72
+ const flattened = [];
73
+ for (const value of modules) {
74
+ if (value.includes(',')) {
75
+ flattened.push(...value.split(',').map(mod => mod.trim()));
76
+ }
77
+ else {
78
+ flattened.push(value);
79
+ }
80
+ }
81
+ modules = flattened;
82
+ }
83
+ (0, application_manager_1.rebuild)(target, { cacheRoot, modules, forceAbi });
84
+ }
85
+ };
86
+ }
87
+ function defineCommonOptions(cli) {
88
+ return cli
89
+ .option('app-target', {
90
+ description: 'The target application type. Overrides `theia.target` in the application\'s package.json',
91
+ choices: ['browser', 'electron', 'browser-only'],
92
+ });
93
+ }
94
+ async function theiaCli() {
95
+ const { version } = await fs.promises.readFile(path.join(__dirname, '../package.json'), 'utf8').then(JSON.parse);
96
+ yargs.scriptName('theia').version(version);
97
+ const projectPath = process.cwd();
98
+ // Create a sub `yargs` parser to read `app-target` without
99
+ // affecting the global `yargs` instance used by the CLI.
100
+ const { appTarget } = defineCommonOptions(yargsFactory()).help(false).parse();
101
+ const manager = new application_manager_1.ApplicationPackageManager({ projectPath, appTarget });
102
+ const localizationManager = new localization_manager_1.LocalizationManager();
103
+ const { target } = manager.pck;
104
+ defineCommonOptions(yargs)
105
+ .command({
106
+ command: 'start [theia-args...]',
107
+ describe: `Start the ${target} backend`,
108
+ // Disable this command's `--help` option so that it is forwarded to Theia's CLI
109
+ builder: cli => cli.help(false),
110
+ handler: async ({ theiaArgs }) => {
111
+ manager.start(toStringArray(theiaArgs));
112
+ }
113
+ })
114
+ .command({
115
+ command: 'clean',
116
+ describe: `Clean for the ${target} target`,
117
+ handler: async () => {
118
+ await manager.clean();
119
+ }
120
+ })
121
+ .command({
122
+ command: 'copy',
123
+ describe: 'Copy various files from `src-gen` to `lib`',
124
+ handler: async () => {
125
+ await manager.copy();
126
+ }
127
+ })
128
+ .command({
129
+ command: 'generate',
130
+ describe: `Generate various files for the ${target} target`,
131
+ builder: cli => application_manager_1.ApplicationPackageManager.defineGeneratorOptions(cli),
132
+ handler: async ({ mode, splitFrontend }) => {
133
+ await manager.generate({ mode, splitFrontend });
134
+ }
135
+ })
136
+ .command({
137
+ command: 'build [webpack-args...]',
138
+ describe: `Generate and bundle the ${target} frontend using webpack`,
139
+ builder: cli => application_manager_1.ApplicationPackageManager.defineGeneratorOptions(cli)
140
+ .option('webpack-help', {
141
+ boolean: true,
142
+ description: 'Display Webpack\'s help',
143
+ default: false
144
+ }),
145
+ handler: async ({ mode, splitFrontend, webpackHelp, webpackArgs = [] }) => {
146
+ await manager.build(webpackHelp
147
+ ? ['--help']
148
+ : [
149
+ // Forward the `mode` argument to Webpack too:
150
+ '--mode', mode,
151
+ ...toStringArray(webpackArgs)
152
+ ], { mode, splitFrontend });
153
+ }
154
+ })
155
+ .command(rebuildCommand('rebuild', target))
156
+ .command(rebuildCommand('rebuild:browser', 'browser'))
157
+ .command(rebuildCommand('rebuild:electron', 'electron'))
158
+ .command({
159
+ command: 'check:hoisted',
160
+ describe: 'Check that all dependencies are hoisted',
161
+ builder: {
162
+ 'suppress': {
163
+ alias: 's',
164
+ describe: 'Suppress exiting with failure code',
165
+ boolean: true,
166
+ default: false
167
+ }
168
+ },
169
+ handler: ({ suppress }) => {
170
+ (0, check_dependencies_1.default)({
171
+ workspaces: ['packages/*'],
172
+ include: ['**'],
173
+ exclude: ['.bin/**', '.cache/**'],
174
+ skipHoisted: false,
175
+ skipUniqueness: true,
176
+ skipSingleTheiaVersion: true,
177
+ onlyTheiaExtensions: false,
178
+ suppress
179
+ });
180
+ }
181
+ })
182
+ .command({
183
+ command: 'check:theia-version',
184
+ describe: 'Check that all dependencies have been resolved to the same Theia version',
185
+ builder: {
186
+ 'suppress': {
187
+ alias: 's',
188
+ describe: 'Suppress exiting with failure code',
189
+ boolean: true,
190
+ default: false
191
+ }
192
+ },
193
+ handler: ({ suppress }) => {
194
+ (0, check_dependencies_1.default)({
195
+ workspaces: undefined,
196
+ include: ['@theia/**'],
197
+ exclude: [],
198
+ skipHoisted: true,
199
+ skipUniqueness: false,
200
+ skipSingleTheiaVersion: false,
201
+ onlyTheiaExtensions: false,
202
+ suppress
203
+ });
204
+ }
205
+ })
206
+ .command({
207
+ command: 'check:theia-extensions',
208
+ describe: 'Check uniqueness of Theia extension versions or whether they are hoisted',
209
+ builder: {
210
+ 'suppress': {
211
+ alias: 's',
212
+ describe: 'Suppress exiting with failure code',
213
+ boolean: true,
214
+ default: false
215
+ }
216
+ },
217
+ handler: ({ suppress }) => {
218
+ (0, check_dependencies_1.default)({
219
+ workspaces: undefined,
220
+ include: ['**'],
221
+ exclude: [],
222
+ skipHoisted: true,
223
+ skipUniqueness: false,
224
+ skipSingleTheiaVersion: true,
225
+ onlyTheiaExtensions: true,
226
+ suppress
227
+ });
228
+ }
229
+ })
230
+ .command({
231
+ command: 'check:dependencies',
232
+ describe: 'Check uniqueness of dependency versions or whether they are hoisted',
233
+ builder: {
234
+ 'workspaces': {
235
+ alias: 'w',
236
+ describe: 'Glob patterns of workspaces to analyze, relative to `cwd`',
237
+ array: true,
238
+ defaultDescription: 'All glob patterns listed in the package.json\'s workspaces',
239
+ demandOption: false
240
+ },
241
+ 'include': {
242
+ alias: 'i',
243
+ describe: 'Glob pattern of dependencies\' package names to be included, e.g. -i "@theia/**"',
244
+ array: true,
245
+ default: ['**']
246
+ },
247
+ 'exclude': {
248
+ alias: 'e',
249
+ describe: 'Glob pattern of dependencies\' package names to be excluded',
250
+ array: true,
251
+ defaultDescription: 'None',
252
+ default: []
253
+ },
254
+ 'skip-hoisted': {
255
+ alias: 'h',
256
+ describe: 'Skip checking whether dependencies are hoisted',
257
+ boolean: true,
258
+ default: false
259
+ },
260
+ 'skip-uniqueness': {
261
+ alias: 'u',
262
+ describe: 'Skip checking whether all dependencies are resolved to a unique version',
263
+ boolean: true,
264
+ default: false
265
+ },
266
+ 'skip-single-theia-version': {
267
+ alias: 't',
268
+ describe: 'Skip checking whether all @theia/* dependencies are resolved to a single version',
269
+ boolean: true,
270
+ default: false
271
+ },
272
+ 'only-theia-extensions': {
273
+ alias: 'o',
274
+ describe: 'Only check dependencies which are Theia extensions',
275
+ boolean: true,
276
+ default: false
277
+ },
278
+ 'suppress': {
279
+ alias: 's',
280
+ describe: 'Suppress exiting with failure code',
281
+ boolean: true,
282
+ default: false
283
+ }
284
+ },
285
+ handler: ({ workspaces, include, exclude, skipHoisted, skipUniqueness, skipSingleTheiaVersion, onlyTheiaExtensions, suppress }) => {
286
+ (0, check_dependencies_1.default)({
287
+ workspaces,
288
+ include,
289
+ exclude,
290
+ skipHoisted,
291
+ skipUniqueness,
292
+ skipSingleTheiaVersion,
293
+ onlyTheiaExtensions,
294
+ suppress
295
+ });
296
+ }
297
+ })
298
+ .command({
299
+ command: 'download:plugins',
300
+ describe: 'Download defined external plugins',
301
+ builder: {
302
+ 'packed': {
303
+ alias: 'p',
304
+ describe: 'Controls whether to pack or unpack plugins',
305
+ boolean: true,
306
+ default: false,
307
+ },
308
+ 'ignore-errors': {
309
+ alias: 'i',
310
+ describe: 'Ignore errors while downloading plugins',
311
+ boolean: true,
312
+ default: false,
313
+ },
314
+ 'api-version': {
315
+ alias: 'v',
316
+ describe: 'Supported API version for plugins',
317
+ default: application_package_1.DEFAULT_SUPPORTED_API_VERSION
318
+ },
319
+ 'api-url': {
320
+ alias: 'u',
321
+ describe: 'Open-VSX Registry API URL',
322
+ default: 'https://open-vsx.org/api'
323
+ },
324
+ 'parallel': {
325
+ describe: 'Download in parallel',
326
+ boolean: true,
327
+ default: true
328
+ },
329
+ 'rate-limit': {
330
+ describe: 'Amount of maximum open-vsx requests per second',
331
+ number: true,
332
+ default: 15
333
+ },
334
+ 'proxy-url': {
335
+ describe: 'Proxy URL'
336
+ },
337
+ 'proxy-authorization': {
338
+ describe: 'Proxy authorization information'
339
+ },
340
+ 'strict-ssl': {
341
+ describe: 'Whether to enable strict SSL mode',
342
+ boolean: true,
343
+ default: false
344
+ },
345
+ 'ovsx-router-config': {
346
+ describe: 'JSON configuration file for the OVSX router client',
347
+ type: 'string'
348
+ }
349
+ },
350
+ handler: async ({ apiUrl, proxyUrl, proxyAuthorization, strictSsl, ovsxRouterConfig, ...options }) => {
351
+ const requestService = new node_request_service_1.NodeRequestService();
352
+ await requestService.configure({
353
+ proxyUrl,
354
+ proxyAuthorization,
355
+ strictSSL: strictSsl
356
+ });
357
+ let client;
358
+ if (ovsxRouterConfig) {
359
+ const routerConfig = await fs.promises.readFile(ovsxRouterConfig, 'utf8').then(JSON.parse, error => {
360
+ console.error(error);
361
+ });
362
+ if (routerConfig) {
363
+ client = await ovsx_client_1.OVSXRouterClient.FromConfig(routerConfig, ovsx_client_1.OVSXHttpClient.createClientFactory(requestService), [ovsx_client_1.RequestContainsFilterFactory, ovsx_client_1.ExtensionIdMatchesFilterFactory]);
364
+ }
365
+ }
366
+ if (!client) {
367
+ client = new ovsx_client_1.OVSXHttpClient(apiUrl, requestService);
368
+ }
369
+ await (0, download_plugins_1.default)(client, requestService, options);
370
+ },
371
+ })
372
+ .command({
373
+ command: 'nls-localize [languages...]',
374
+ describe: 'Localize json files using the DeepL API',
375
+ builder: {
376
+ 'file': {
377
+ alias: 'f',
378
+ describe: 'The source file which should be translated',
379
+ demandOption: true
380
+ },
381
+ 'deepl-key': {
382
+ alias: 'k',
383
+ describe: 'DeepL key used for API access. See https://www.deepl.com/docs-api for more information',
384
+ demandOption: true
385
+ },
386
+ 'free-api': {
387
+ describe: 'Indicates whether the specified DeepL API key belongs to the free API',
388
+ boolean: true,
389
+ default: false,
390
+ },
391
+ 'source-language': {
392
+ alias: 's',
393
+ describe: 'The source language of the translation file'
394
+ }
395
+ },
396
+ handler: async ({ freeApi, deeplKey, file, sourceLanguage, languages = [] }) => {
397
+ await localizationManager.localize({
398
+ sourceFile: file,
399
+ freeApi: freeApi !== null && freeApi !== void 0 ? freeApi : true,
400
+ authKey: deeplKey,
401
+ targetLanguages: languages,
402
+ sourceLanguage
403
+ });
404
+ }
405
+ })
406
+ .command({
407
+ command: 'nls-extract',
408
+ describe: 'Extract translation key/value pairs from source code',
409
+ builder: {
410
+ 'output': {
411
+ alias: 'o',
412
+ describe: 'Output file for the extracted translations',
413
+ demandOption: true
414
+ },
415
+ 'root': {
416
+ alias: 'r',
417
+ describe: 'The directory which contains the source code',
418
+ default: '.'
419
+ },
420
+ 'merge': {
421
+ alias: 'm',
422
+ describe: 'Whether to merge new with existing translation values',
423
+ boolean: true,
424
+ default: false
425
+ },
426
+ 'exclude': {
427
+ alias: 'e',
428
+ describe: 'Allows to exclude translation keys starting with this value'
429
+ },
430
+ 'files': {
431
+ alias: 'f',
432
+ describe: 'Glob pattern matching the files to extract from (starting from --root).',
433
+ array: true
434
+ },
435
+ 'logs': {
436
+ alias: 'l',
437
+ describe: 'File path to a log file'
438
+ },
439
+ 'quiet': {
440
+ alias: 'q',
441
+ describe: 'Prevents errors from being logged to console',
442
+ boolean: true,
443
+ default: false
444
+ }
445
+ },
446
+ handler: async (options) => {
447
+ await (0, localization_manager_1.extract)(options);
448
+ }
449
+ })
450
+ .command({
451
+ command: 'test [theia-args...]',
452
+ builder: {
453
+ 'test-inspect': {
454
+ describe: 'Whether to auto-open a DevTools panel for test page.',
455
+ boolean: true,
456
+ default: false
457
+ },
458
+ 'test-extension': {
459
+ describe: 'Test file extension(s) to load',
460
+ array: true,
461
+ default: ['js']
462
+ },
463
+ 'test-file': {
464
+ describe: 'Specify test file(s) to be loaded prior to root suite execution',
465
+ array: true,
466
+ default: []
467
+ },
468
+ 'test-ignore': {
469
+ describe: 'Ignore test file(s) or glob pattern(s)',
470
+ array: true,
471
+ default: []
472
+ },
473
+ 'test-recursive': {
474
+ describe: 'Look for tests in subdirectories',
475
+ boolean: true,
476
+ default: false
477
+ },
478
+ 'test-sort': {
479
+ describe: 'Sort test files',
480
+ boolean: true,
481
+ default: false
482
+ },
483
+ 'test-spec': {
484
+ describe: 'One or more test files, directories, or globs to test',
485
+ array: true,
486
+ default: ['test']
487
+ },
488
+ 'test-coverage': {
489
+ describe: 'Report test coverage consumable by istanbul',
490
+ boolean: true,
491
+ default: false
492
+ }
493
+ },
494
+ handler: async ({ testInspect, testExtension, testFile, testIgnore, testRecursive, testSort, testSpec, testCoverage, theiaArgs }) => {
495
+ if (!process.env.THEIA_CONFIG_DIR) {
496
+ process.env.THEIA_CONFIG_DIR = temp.track().mkdirSync('theia-test-config-dir');
497
+ }
498
+ await (0, run_test_1.default)({
499
+ start: () => new Promise((resolve, reject) => {
500
+ const serverProcess = manager.start(toStringArray(theiaArgs));
501
+ serverProcess.on('message', resolve);
502
+ serverProcess.on('error', reject);
503
+ serverProcess.on('close', (code, signal) => reject(`Server process exited unexpectedly: ${code !== null && code !== void 0 ? code : signal}`));
504
+ }),
505
+ launch: {
506
+ args: ['--no-sandbox'],
507
+ // eslint-disable-next-line no-null/no-null
508
+ defaultViewport: null,
509
+ devtools: testInspect,
510
+ executablePath: executablePath()
511
+ },
512
+ files: {
513
+ extension: testExtension,
514
+ file: testFile,
515
+ ignore: testIgnore,
516
+ recursive: testRecursive,
517
+ sort: testSort,
518
+ spec: testSpec
519
+ },
520
+ coverage: testCoverage
521
+ });
522
+ }
523
+ })
524
+ .command({
525
+ command: 'ffmpeg:replace [ffmpeg-path]',
526
+ describe: '',
527
+ builder: {
528
+ 'electronDist': {
529
+ description: 'Electron distribution location.',
530
+ },
531
+ 'electronVersion': {
532
+ description: 'Electron version for which to pull the "clean" ffmpeg library.',
533
+ },
534
+ 'ffmpegPath': {
535
+ description: 'Absolute path to the ffmpeg shared library.',
536
+ },
537
+ 'platform': {
538
+ description: 'Dictates where the library is located within the Electron distribution.',
539
+ choices: ['darwin', 'linux', 'win32'],
540
+ },
541
+ },
542
+ handler: async (options) => {
543
+ const ffmpeg = await Promise.resolve().then(() => require('@theia/ffmpeg'));
544
+ await ffmpeg.replaceFfmpeg(options);
545
+ },
546
+ })
547
+ .command({
548
+ command: 'ffmpeg:check [ffmpeg-path]',
549
+ describe: '(electron-only) Check that ffmpeg doesn\'t contain proprietary codecs',
550
+ builder: {
551
+ 'electronDist': {
552
+ description: 'Electron distribution location',
553
+ },
554
+ 'ffmpegPath': {
555
+ describe: 'Absolute path to the ffmpeg shared library',
556
+ },
557
+ 'json': {
558
+ description: 'Output the found codecs as JSON on stdout',
559
+ boolean: true,
560
+ },
561
+ 'platform': {
562
+ description: 'Dictates where the library is located within the Electron distribution',
563
+ choices: ['darwin', 'linux', 'win32'],
564
+ },
565
+ },
566
+ handler: async (options) => {
567
+ const ffmpeg = await Promise.resolve().then(() => require('@theia/ffmpeg'));
568
+ await ffmpeg.checkFfmpeg(options);
569
+ },
570
+ })
571
+ .parserConfiguration({
572
+ 'unknown-options-as-args': true,
573
+ })
574
+ .strictCommands()
575
+ .demandCommand(1, 'Please run a command')
576
+ .fail((msg, err, cli) => {
577
+ process.exitCode = 1;
578
+ if (err) {
579
+ // One of the handlers threw an error:
580
+ console.error(err);
581
+ }
582
+ else {
583
+ // Yargs detected a problem with commands and/or arguments while parsing:
584
+ cli.showHelp();
585
+ console.error(msg);
586
+ }
587
+ })
588
+ .parse();
589
+ }
590
590
  //# sourceMappingURL=theia.js.map