@theia/application-manager 1.48.1 → 1.48.3
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/README.md +25 -25
- package/lib/application-package-manager.d.ts +45 -45
- package/lib/application-package-manager.js +225 -225
- package/lib/application-process.d.ts +19 -19
- package/lib/application-process.js +72 -72
- package/lib/expose-loader.d.ts +8 -8
- package/lib/expose-loader.js +69 -69
- package/lib/generator/abstract-generator.d.ts +17 -17
- package/lib/generator/abstract-generator.js +57 -57
- package/lib/generator/backend-generator.d.ts +7 -7
- package/lib/generator/backend-generator.js +196 -196
- package/lib/generator/frontend-generator.d.ts +13 -13
- package/lib/generator/frontend-generator.js +212 -212
- package/lib/generator/index.d.ts +3 -3
- package/lib/generator/index.js +21 -21
- package/lib/generator/webpack-generator.d.ts +12 -12
- package/lib/generator/webpack-generator.js +493 -493
- package/lib/index.d.ts +3 -3
- package/lib/index.js +21 -21
- package/lib/package.spec.js +25 -25
- package/lib/rebuild.d.ts +24 -24
- package/lib/rebuild.js +309 -309
- package/package.json +6 -6
- package/src/application-package-manager.ts +263 -263
- package/src/application-process.ts +80 -80
- package/src/expose-loader.ts +80 -80
- package/src/generator/abstract-generator.ts +69 -69
- package/src/generator/backend-generator.ts +198 -198
- package/src/generator/frontend-generator.ts +222 -222
- package/src/generator/index.ts +19 -19
- package/src/generator/webpack-generator.ts +501 -501
- package/src/index.ts +19 -19
- package/src/package.spec.ts +28 -28
- package/src/rebuild.ts +345 -345
|
@@ -1,80 +1,80 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2017 TypeFox and others.
|
|
3
|
-
//
|
|
4
|
-
// This program and the accompanying materials are made available under the
|
|
5
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
//
|
|
8
|
-
// This Source Code may also be made available under the following Secondary
|
|
9
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
// with the GNU Classpath Exception which is available at
|
|
12
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
//
|
|
14
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
|
|
17
|
-
import * as path from 'path';
|
|
18
|
-
import * as fs from 'fs-extra';
|
|
19
|
-
import * as cp from 'child_process';
|
|
20
|
-
import { ApplicationPackage } from '@theia/application-package';
|
|
21
|
-
|
|
22
|
-
export class ApplicationProcess {
|
|
23
|
-
|
|
24
|
-
protected readonly defaultOptions = {
|
|
25
|
-
cwd: this.pck.projectPath,
|
|
26
|
-
env: process.env
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
constructor(
|
|
30
|
-
protected readonly pck: ApplicationPackage,
|
|
31
|
-
protected readonly binProjectPath: string
|
|
32
|
-
) { }
|
|
33
|
-
|
|
34
|
-
spawn(command: string, args?: string[], options?: cp.SpawnOptions): cp.ChildProcess {
|
|
35
|
-
return cp.spawn(command, args || [], Object.assign({}, this.defaultOptions, options));
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
fork(modulePath: string, args?: string[], options?: cp.ForkOptions): cp.ChildProcess {
|
|
39
|
-
return cp.fork(modulePath, args, Object.assign({}, this.defaultOptions, options));
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
canRun(command: string): boolean {
|
|
43
|
-
return fs.existsSync(this.resolveBin(command));
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
run(command: string, args: string[], options?: cp.SpawnOptions): Promise<void> {
|
|
47
|
-
const commandProcess = this.spawnBin(command, args, options);
|
|
48
|
-
return this.promisify(command, commandProcess);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
spawnBin(command: string, args: string[], options?: cp.SpawnOptions): cp.ChildProcess {
|
|
52
|
-
const binPath = this.resolveBin(command);
|
|
53
|
-
return this.spawn(binPath, args, options);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
protected resolveBin(command: string): string {
|
|
57
|
-
const commandPath = path.resolve(this.binProjectPath, 'node_modules', '.bin', command);
|
|
58
|
-
return process.platform === 'win32' ? commandPath + '.cmd' : commandPath;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
protected promisify(command: string, p: cp.ChildProcess): Promise<void> {
|
|
62
|
-
return new Promise((resolve, reject) => {
|
|
63
|
-
p.stdout!.on('data', data => this.pck.log(data.toString()));
|
|
64
|
-
p.stderr!.on('data', data => this.pck.error(data.toString()));
|
|
65
|
-
p.on('error', reject);
|
|
66
|
-
p.on('close', (code, signal) => {
|
|
67
|
-
if (signal) {
|
|
68
|
-
reject(new Error(`${command} exited with an unexpected signal: ${signal}.`));
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
if (code === 0) {
|
|
72
|
-
resolve();
|
|
73
|
-
} else {
|
|
74
|
-
reject(new Error(`${command} exited with an unexpected code: ${code}.`));
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
}
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2017 TypeFox and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import * as path from 'path';
|
|
18
|
+
import * as fs from 'fs-extra';
|
|
19
|
+
import * as cp from 'child_process';
|
|
20
|
+
import { ApplicationPackage } from '@theia/application-package';
|
|
21
|
+
|
|
22
|
+
export class ApplicationProcess {
|
|
23
|
+
|
|
24
|
+
protected readonly defaultOptions = {
|
|
25
|
+
cwd: this.pck.projectPath,
|
|
26
|
+
env: process.env
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
constructor(
|
|
30
|
+
protected readonly pck: ApplicationPackage,
|
|
31
|
+
protected readonly binProjectPath: string
|
|
32
|
+
) { }
|
|
33
|
+
|
|
34
|
+
spawn(command: string, args?: string[], options?: cp.SpawnOptions): cp.ChildProcess {
|
|
35
|
+
return cp.spawn(command, args || [], Object.assign({}, this.defaultOptions, options));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
fork(modulePath: string, args?: string[], options?: cp.ForkOptions): cp.ChildProcess {
|
|
39
|
+
return cp.fork(modulePath, args, Object.assign({}, this.defaultOptions, options));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
canRun(command: string): boolean {
|
|
43
|
+
return fs.existsSync(this.resolveBin(command));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
run(command: string, args: string[], options?: cp.SpawnOptions): Promise<void> {
|
|
47
|
+
const commandProcess = this.spawnBin(command, args, options);
|
|
48
|
+
return this.promisify(command, commandProcess);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
spawnBin(command: string, args: string[], options?: cp.SpawnOptions): cp.ChildProcess {
|
|
52
|
+
const binPath = this.resolveBin(command);
|
|
53
|
+
return this.spawn(binPath, args, options);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
protected resolveBin(command: string): string {
|
|
57
|
+
const commandPath = path.resolve(this.binProjectPath, 'node_modules', '.bin', command);
|
|
58
|
+
return process.platform === 'win32' ? commandPath + '.cmd' : commandPath;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
protected promisify(command: string, p: cp.ChildProcess): Promise<void> {
|
|
62
|
+
return new Promise((resolve, reject) => {
|
|
63
|
+
p.stdout!.on('data', data => this.pck.log(data.toString()));
|
|
64
|
+
p.stderr!.on('data', data => this.pck.error(data.toString()));
|
|
65
|
+
p.on('error', reject);
|
|
66
|
+
p.on('close', (code, signal) => {
|
|
67
|
+
if (signal) {
|
|
68
|
+
reject(new Error(`${command} exited with an unexpected signal: ${signal}.`));
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
if (code === 0) {
|
|
72
|
+
resolve();
|
|
73
|
+
} else {
|
|
74
|
+
reject(new Error(`${command} exited with an unexpected code: ${code}.`));
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
}
|
package/src/expose-loader.ts
CHANGED
|
@@ -1,80 +1,80 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2020 TypeFox and others.
|
|
3
|
-
//
|
|
4
|
-
// This program and the accompanying materials are made available under the
|
|
5
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
//
|
|
8
|
-
// This Source Code may also be made available under the following Secondary
|
|
9
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
// with the GNU Classpath Exception which is available at
|
|
12
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
//
|
|
14
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
|
|
17
|
-
import * as fs from 'fs-extra';
|
|
18
|
-
import * as path from 'path';
|
|
19
|
-
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
20
|
-
import type { RawSourceMap } from 'source-map';
|
|
21
|
-
import { ApplicationPackage } from '@theia/application-package/lib/application-package';
|
|
22
|
-
|
|
23
|
-
const modulePackages: { dir: string, name?: string }[] = [];
|
|
24
|
-
for (const extensionPackage of new ApplicationPackage({ projectPath: process.cwd() }).extensionPackages) {
|
|
25
|
-
modulePackages.push({
|
|
26
|
-
name: extensionPackage.name,
|
|
27
|
-
dir: path.dirname(extensionPackage.raw.installed!.packagePath)
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function exposeModule(modulePackage: { dir: string, name?: string }, resourcePath: string, source: string): string {
|
|
32
|
-
if (!modulePackage.name) {
|
|
33
|
-
return source;
|
|
34
|
-
}
|
|
35
|
-
const { dir, name } = path.parse(resourcePath);
|
|
36
|
-
let moduleName = path.join(modulePackage.name, dir.substring(modulePackage.dir.length));
|
|
37
|
-
if (name !== 'index') {
|
|
38
|
-
moduleName = path.join(moduleName, name);
|
|
39
|
-
}
|
|
40
|
-
if (path.sep !== '/') {
|
|
41
|
-
moduleName = moduleName.split(path.sep).join('/');
|
|
42
|
-
}
|
|
43
|
-
return source + `\n;(globalThis['theia'] = globalThis['theia'] || {})['${moduleName}'] = this;\n`;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Expose bundled modules on window.theia.moduleName namespace, e.g.
|
|
48
|
-
* window['theia']['@theia/core/lib/common/uri'].
|
|
49
|
-
* Such syntax can be used by external code, for instance, for testing.
|
|
50
|
-
*/
|
|
51
|
-
// TODO: webpack@5.36.2 is missing a `LoaderContext` interface so we'll use any in the meantime
|
|
52
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
53
|
-
export = function (this: any, source: string, sourceMap?: RawSourceMap): string | undefined {
|
|
54
|
-
if (this.cacheable) {
|
|
55
|
-
this.cacheable();
|
|
56
|
-
}
|
|
57
|
-
let modulePackage = modulePackages.find(({ dir }) => this.resourcePath.startsWith(dir + path.sep));
|
|
58
|
-
if (modulePackage) {
|
|
59
|
-
this.callback(undefined, exposeModule(modulePackage, this.resourcePath, source), sourceMap);
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
const searchString = path.sep + 'node_modules';
|
|
63
|
-
const index = this.resourcePath.lastIndexOf(searchString);
|
|
64
|
-
if (index !== -1) {
|
|
65
|
-
const nodeModulesPath = this.resourcePath.substring(0, index + searchString.length);
|
|
66
|
-
let dir = this.resourcePath;
|
|
67
|
-
while ((dir = path.dirname(dir)) !== nodeModulesPath) {
|
|
68
|
-
try {
|
|
69
|
-
const { name } = fs.readJSONSync(path.join(dir, 'package.json'));
|
|
70
|
-
modulePackage = { name, dir };
|
|
71
|
-
modulePackages.push(modulePackage);
|
|
72
|
-
this.callback(undefined, exposeModule(modulePackage, this.resourcePath, source), sourceMap);
|
|
73
|
-
return;
|
|
74
|
-
} catch {
|
|
75
|
-
/** no-op */
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
this.callback(undefined, source, sourceMap);
|
|
80
|
-
};
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2020 TypeFox and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import * as fs from 'fs-extra';
|
|
18
|
+
import * as path from 'path';
|
|
19
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
20
|
+
import type { RawSourceMap } from 'source-map';
|
|
21
|
+
import { ApplicationPackage } from '@theia/application-package/lib/application-package';
|
|
22
|
+
|
|
23
|
+
const modulePackages: { dir: string, name?: string }[] = [];
|
|
24
|
+
for (const extensionPackage of new ApplicationPackage({ projectPath: process.cwd() }).extensionPackages) {
|
|
25
|
+
modulePackages.push({
|
|
26
|
+
name: extensionPackage.name,
|
|
27
|
+
dir: path.dirname(extensionPackage.raw.installed!.packagePath)
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function exposeModule(modulePackage: { dir: string, name?: string }, resourcePath: string, source: string): string {
|
|
32
|
+
if (!modulePackage.name) {
|
|
33
|
+
return source;
|
|
34
|
+
}
|
|
35
|
+
const { dir, name } = path.parse(resourcePath);
|
|
36
|
+
let moduleName = path.join(modulePackage.name, dir.substring(modulePackage.dir.length));
|
|
37
|
+
if (name !== 'index') {
|
|
38
|
+
moduleName = path.join(moduleName, name);
|
|
39
|
+
}
|
|
40
|
+
if (path.sep !== '/') {
|
|
41
|
+
moduleName = moduleName.split(path.sep).join('/');
|
|
42
|
+
}
|
|
43
|
+
return source + `\n;(globalThis['theia'] = globalThis['theia'] || {})['${moduleName}'] = this;\n`;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Expose bundled modules on window.theia.moduleName namespace, e.g.
|
|
48
|
+
* window['theia']['@theia/core/lib/common/uri'].
|
|
49
|
+
* Such syntax can be used by external code, for instance, for testing.
|
|
50
|
+
*/
|
|
51
|
+
// TODO: webpack@5.36.2 is missing a `LoaderContext` interface so we'll use any in the meantime
|
|
52
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
53
|
+
export = function (this: any, source: string, sourceMap?: RawSourceMap): string | undefined {
|
|
54
|
+
if (this.cacheable) {
|
|
55
|
+
this.cacheable();
|
|
56
|
+
}
|
|
57
|
+
let modulePackage = modulePackages.find(({ dir }) => this.resourcePath.startsWith(dir + path.sep));
|
|
58
|
+
if (modulePackage) {
|
|
59
|
+
this.callback(undefined, exposeModule(modulePackage, this.resourcePath, source), sourceMap);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const searchString = path.sep + 'node_modules';
|
|
63
|
+
const index = this.resourcePath.lastIndexOf(searchString);
|
|
64
|
+
if (index !== -1) {
|
|
65
|
+
const nodeModulesPath = this.resourcePath.substring(0, index + searchString.length);
|
|
66
|
+
let dir = this.resourcePath;
|
|
67
|
+
while ((dir = path.dirname(dir)) !== nodeModulesPath) {
|
|
68
|
+
try {
|
|
69
|
+
const { name } = fs.readJSONSync(path.join(dir, 'package.json'));
|
|
70
|
+
modulePackage = { name, dir };
|
|
71
|
+
modulePackages.push(modulePackage);
|
|
72
|
+
this.callback(undefined, exposeModule(modulePackage, this.resourcePath, source), sourceMap);
|
|
73
|
+
return;
|
|
74
|
+
} catch {
|
|
75
|
+
/** no-op */
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
this.callback(undefined, source, sourceMap);
|
|
80
|
+
};
|
|
@@ -1,69 +1,69 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2017 TypeFox and others.
|
|
3
|
-
//
|
|
4
|
-
// This program and the accompanying materials are made available under the
|
|
5
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
//
|
|
8
|
-
// This Source Code may also be made available under the following Secondary
|
|
9
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
// with the GNU Classpath Exception which is available at
|
|
12
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
//
|
|
14
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
|
|
17
|
-
import * as fs from 'fs-extra';
|
|
18
|
-
import { ApplicationPackage } from '@theia/application-package';
|
|
19
|
-
|
|
20
|
-
export interface GeneratorOptions {
|
|
21
|
-
mode?: 'development' | 'production'
|
|
22
|
-
splitFrontend?: boolean
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export abstract class AbstractGenerator {
|
|
26
|
-
|
|
27
|
-
constructor(
|
|
28
|
-
protected readonly pck: ApplicationPackage,
|
|
29
|
-
protected options: GeneratorOptions = {}
|
|
30
|
-
) { }
|
|
31
|
-
|
|
32
|
-
protected ifBrowser(value: string, defaultValue: string = ''): string {
|
|
33
|
-
return this.pck.ifBrowser(value, defaultValue);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
protected ifElectron(value: string, defaultValue: string = ''): string {
|
|
37
|
-
return this.pck.ifElectron(value, defaultValue);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
protected ifBrowserOnly(value: string, defaultValue: string = ''): string {
|
|
41
|
-
return this.pck.ifBrowserOnly(value, defaultValue);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
protected async write(path: string, content: string): Promise<void> {
|
|
45
|
-
await fs.ensureFile(path);
|
|
46
|
-
await fs.writeFile(path, content);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
protected ifMonaco(value: () => string, defaultValue: () => string = () => ''): string {
|
|
50
|
-
return this.ifPackage([
|
|
51
|
-
'@theia/monaco',
|
|
52
|
-
'@theia/monaco-editor-core'
|
|
53
|
-
], value, defaultValue);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
protected ifPackage(packageName: string | string[], value: string | (() => string), defaultValue: string | (() => string) = ''): string {
|
|
57
|
-
const packages = Array.isArray(packageName) ? packageName : [packageName];
|
|
58
|
-
if (this.pck.extensionPackages.some(e => packages.includes(e.name))) {
|
|
59
|
-
return typeof value === 'string' ? value : value();
|
|
60
|
-
} else {
|
|
61
|
-
return typeof defaultValue === 'string' ? defaultValue : defaultValue();
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
protected prettyStringify(object: object): string {
|
|
66
|
-
return JSON.stringify(object, undefined, 4);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
}
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2017 TypeFox and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import * as fs from 'fs-extra';
|
|
18
|
+
import { ApplicationPackage } from '@theia/application-package';
|
|
19
|
+
|
|
20
|
+
export interface GeneratorOptions {
|
|
21
|
+
mode?: 'development' | 'production'
|
|
22
|
+
splitFrontend?: boolean
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export abstract class AbstractGenerator {
|
|
26
|
+
|
|
27
|
+
constructor(
|
|
28
|
+
protected readonly pck: ApplicationPackage,
|
|
29
|
+
protected options: GeneratorOptions = {}
|
|
30
|
+
) { }
|
|
31
|
+
|
|
32
|
+
protected ifBrowser(value: string, defaultValue: string = ''): string {
|
|
33
|
+
return this.pck.ifBrowser(value, defaultValue);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
protected ifElectron(value: string, defaultValue: string = ''): string {
|
|
37
|
+
return this.pck.ifElectron(value, defaultValue);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
protected ifBrowserOnly(value: string, defaultValue: string = ''): string {
|
|
41
|
+
return this.pck.ifBrowserOnly(value, defaultValue);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
protected async write(path: string, content: string): Promise<void> {
|
|
45
|
+
await fs.ensureFile(path);
|
|
46
|
+
await fs.writeFile(path, content);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
protected ifMonaco(value: () => string, defaultValue: () => string = () => ''): string {
|
|
50
|
+
return this.ifPackage([
|
|
51
|
+
'@theia/monaco',
|
|
52
|
+
'@theia/monaco-editor-core'
|
|
53
|
+
], value, defaultValue);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
protected ifPackage(packageName: string | string[], value: string | (() => string), defaultValue: string | (() => string) = ''): string {
|
|
57
|
+
const packages = Array.isArray(packageName) ? packageName : [packageName];
|
|
58
|
+
if (this.pck.extensionPackages.some(e => packages.includes(e.name))) {
|
|
59
|
+
return typeof value === 'string' ? value : value();
|
|
60
|
+
} else {
|
|
61
|
+
return typeof defaultValue === 'string' ? defaultValue : defaultValue();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
protected prettyStringify(object: object): string {
|
|
66
|
+
return JSON.stringify(object, undefined, 4);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
}
|