mirror of
https://github.com/microsoft/pyright.git
synced 2024-09-11 07:55:56 +03:00
75 lines
2.7 KiB
JavaScript
75 lines
2.7 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
// This file is based on the "installServerIntoExtension" that ships with the
|
|
// vscode-languagserver node package. We needed to modify it because the original
|
|
// version does not copy the package-lock.json file, and it uses npm update
|
|
// rather than npm install.
|
|
|
|
var path = require('path');
|
|
var fs = require('fs');
|
|
var cp = require('child_process');
|
|
|
|
var extensionDirectory = process.argv[2];
|
|
if (!extensionDirectory) {
|
|
console.error('No extension directory provided.');
|
|
process.exit(1)
|
|
}
|
|
extensionDirectory = path.resolve(extensionDirectory)
|
|
if (!fs.existsSync(extensionDirectory)) {
|
|
console.error('Extension directory ' + extensionDirectory + ' doesn\'t exist on disk.');
|
|
process.exit(1);
|
|
}
|
|
|
|
var packageFile = process.argv[3];
|
|
if (!packageFile) {
|
|
console.error('No package.json file provided.');
|
|
process.exit(1);
|
|
}
|
|
packageFile = path.resolve(packageFile);
|
|
if (!fs.existsSync(packageFile)) {
|
|
console.error('Package file ' + packageFile + ' doesn\'t exist on disk.');
|
|
process.exit(1);
|
|
}
|
|
var tsconfigFile = process.argv[4];
|
|
if (!tsconfigFile) {
|
|
console.error('No tsconfig.json file provided');
|
|
process.exit(1);
|
|
}
|
|
tsconfigFile = path.resolve(tsconfigFile);
|
|
if (!fs.existsSync(tsconfigFile)) {
|
|
console.error('tsconfig file ' + tsconfigFile + ' doesn\'t exist on disk.')
|
|
process.exit(1);
|
|
}
|
|
|
|
var extensionServerDirectory = path.join(extensionDirectory, 'server')
|
|
|
|
var json = require(tsconfigFile);
|
|
var compilerOptions = json.compilerOptions;
|
|
if (compilerOptions) {
|
|
var outDir = compilerOptions.outDir;
|
|
if (!outDir || path.join(path.dirname(tsconfigFile), outDir) !== extensionServerDirectory) {
|
|
console.error('outDir in ' + process.argv[4] + ' must point to ' + extensionServerDirectory + ' but it points to ' + path.join(path.dirname(tsconfigFile), outDir));
|
|
console.error('Please change outDir in ' + process.argv[4] + ' to ' + path.relative(path.dirname(tsconfigFile), extensionServerDirectory).replace(/\\/g, '/'));
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
if (!fs.existsSync(extensionServerDirectory)) {
|
|
fs.mkdirSync(extensionServerDirectory);
|
|
}
|
|
|
|
var dest = path.join(extensionServerDirectory, 'package.json');
|
|
console.log('Copying package.json to extension\'s server location...');
|
|
fs.writeFileSync(dest, fs.readFileSync(packageFile));
|
|
|
|
var packageLockFile = process.argv[5];
|
|
if (fs.existsSync(packageLockFile)) {
|
|
const packageLockFileDest = path.join(extensionServerDirectory, 'package-lock.json');
|
|
packageLockFile = path.resolve(packageLockFile);
|
|
console.log('Copying package-lock.json to extension\'s server location...');
|
|
fs.writeFileSync(packageLockFileDest, fs.readFileSync(packageLockFile));
|
|
}
|
|
|
|
console.log('Installing server npm modules into extension\'s server location...');
|
|
cp.execSync('npm install --production --prefix ' + extensionServerDirectory);
|