html/json: compute server module without server package.json

This commit is contained in:
Martin Aeschlimann
2020-06-11 14:59:51 +02:00
parent 4b9f0916af
commit 6af2987903
2 changed files with 16 additions and 38 deletions

View File

@@ -57,6 +57,7 @@ interface IPackageInfo {
name: string;
version: string;
aiKey: string;
main: string;
}
interface Settings {
@@ -91,11 +92,11 @@ export function activate(context: ExtensionContext) {
let rangeFormatting: Disposable | undefined = undefined;
const packageInfo = getPackageInfo(context);
telemetryReporter = packageInfo && new TelemetryReporter(packageInfo.name, packageInfo.version, packageInfo.aiKey);
let clientPackageJSON = getPackageInfo(context);
telemetryReporter = new TelemetryReporter(clientPackageJSON.name, clientPackageJSON.version, clientPackageJSON.aiKey);
const serverMain = readJSONFile(context.asAbsolutePath('./server/package.json')).main;
const serverModule = context.asAbsolutePath(path.join('server', serverMain));
const serverMain = `./server/${clientPackageJSON.main.indexOf('/dist/') !== -1 ? 'dist' : 'out'}/jsonServerMain`;
const serverModule = context.asAbsolutePath(serverMain);
// The debug options for the server
const debugOptions = { execArgv: ['--nolazy', '--inspect=' + (9000 + Math.round(Math.random() * 10000))] };
@@ -520,24 +521,13 @@ function getSchemaId(schema: JSONSchemaSettings, folderUri?: Uri) {
return url;
}
function getPackageInfo(context: ExtensionContext): IPackageInfo | undefined {
const extensionPackage = readJSONFile(context.asAbsolutePath('./package.json'));
if (extensionPackage) {
return {
name: extensionPackage.name,
version: extensionPackage.version,
aiKey: extensionPackage.aiKey
};
}
return undefined;
}
function readJSONFile(location: string) {
function getPackageInfo(context: ExtensionContext): IPackageInfo {
const location = context.asAbsolutePath('./package.json');
try {
return JSON.parse(fs.readFileSync(location).toString());
} catch (e) {
console.log(`Problems reading ${location}: ${e}`);
return {};
return { name: '', version: '', aiKey: '', main: '' };
}
}