From 30f84237ce62a256cd1ec444bc7f00e69ed41a13 Mon Sep 17 00:00:00 2001 From: liuderchi Date: Thu, 5 Oct 2017 14:00:10 +0800 Subject: [PATCH] add build-yaml-lang-server.js to fix build error in windows platform --- build-yaml-lang-server.js | 42 +++++++++++++++++++++++++++++++++++++++ package.json | 5 ++--- 2 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 build-yaml-lang-server.js diff --git a/build-yaml-lang-server.js b/build-yaml-lang-server.js new file mode 100644 index 0000000..c008189 --- /dev/null +++ b/build-yaml-lang-server.js @@ -0,0 +1,42 @@ +const fs= require('fs') +const path= require('path') +const childProcess = require('child_process') + +const commands = [ + { + name: 'Server Install', + run: () => childProcess.spawnSync( + 'npm', + ['install', '--prefix', 'node_modules/yaml-language-server'], + { encoding: 'utf8' } + ), + }, + { + name: 'Server Compile', + run: () => childProcess.spawnSync( + 'npm', + ['run', 'compile', '--prefix', 'node_modules/yaml-language-server'], + { encoding: 'utf8' } + ), + }, +] + +commands.forEach(cmd => { + console.log(`Doing ${cmd.name}...`) + const { status } = cmd.run() + if (status !== 0) { + console.log(`${cmd.name} failed. Exit ${status}`) + process.exit(-1) + } +}) + +const serverPath = path.join(__dirname, 'node_modules/yaml-language-server/out/server/src/server.js') +console.log(`Checking built yaml lang server path: ${serverPath}`) + +try { + fs.accessSync(serverPath) +} catch (e) { + console.log(`Yaml lang server ${serverPath} not found. Build failed.`) + process.exit(-1) +} +console.log('Server build success.') diff --git a/package.json b/package.json index cbb7339..c9c9669 100644 --- a/package.json +++ b/package.json @@ -5,9 +5,8 @@ "main": "src/main.js", "scripts": { "install": "napa", - "postinstall": "npm run buildYamlServer", - "buildYamlServer": "npm install --prefix node_modules/yaml-language-server && npm run compile --prefix node_modules/yaml-language-server", - "lint": "eslint ./src", + "postinstall": "node build-yaml-lang-server.js", + "lint": "eslint ./", "test": "npm run lint" }, "repository": "https://github.com/liuderchi/ide-yaml.git",