Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #35 from Shopify/feature/windows-support
Browse files Browse the repository at this point in the history
Add Windows support
  • Loading branch information
charlespwd authored Jul 15, 2021
2 parents a979a77 + c104252 commit 0f7e4a6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ To install the `shopify` CLI, follow these steps:
1. Go to https://shopify.dev/tools/cli/installation
2. Follow the instructions for your operating system

⚠️ **Note:** Windows not yet supported.

## Configuration

- `"shopifyLiquid.shopifyCLIPath": string`, (optional) a path to the `shopify` executable.
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
"url": "https://github.com/shopify/theme-check-vscode.git"
},
"scripts": {
"prebuild": "yarn && rm -rf dist language-configuration.json",
"prebuild": "yarn && rimraf dist language-configuration.json",
"build": "yarn build:extension && yarn build:language-config",
"build:extension": "webpack --mode production",
"build:language-config": "scripts/make-language-configuration",
"dev": "rm -rf dist && webpack --mode development --watch",
"dev": "rimraf dist && webpack --mode development --watch",
"package": "yarn build && vsce package",
"test": "mocha 'src/**/*.test.js'"
},
Expand Down Expand Up @@ -104,6 +104,7 @@
"eslint": "^7.29.0",
"eslint-config-prettier": "^8.3.0",
"mocha": "^8.3.2",
"rimraf": "^3.0.2",
"vscode-test": "^1.3.0",
"webpack": "^5.28.0",
"webpack-cli": "^4.5.0"
Expand Down
23 changes: 13 additions & 10 deletions src/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const { LanguageClient } = require('vscode-languageclient');
class CommandNotFoundError extends Error {}
class IncompatibleVersionError extends Error {}

const isWin = process.platform === 'win32';
const sleep = (ms) => new Promise((res) => setTimeout(res, ms));

let client;
Expand Down Expand Up @@ -47,7 +48,7 @@ async function startServer() {
};

client = new LanguageClient(
'theme-check',
'shopifyLiquid',
'Theme Check Language Server',
serverOptions,
clientOptions,
Expand All @@ -56,7 +57,6 @@ async function startServer() {
client.start();
}


async function stopServer() {
try {
if (client) await Promise.race([client.stop(), sleep(1000)]);
Expand All @@ -71,7 +71,6 @@ async function restartServer() {
if (client) await stopServer();
await startServer();
}
/** */

function onConfigChange(event) {
const didChangeThemeCheck = event.affectsConfiguration(
Expand Down Expand Up @@ -118,21 +117,25 @@ async function getServerOptions() {
}
}

async function which(command) {
const whichCmd = isWin ? 'where' : 'which';
const { stdout } = await exec(`${whichCmd} ${command}`);
return stdout.split('\n')[0].replace('\r', '');
}

async function getShopifyCLIExecutable() {
try {
const { stdout } = await exec('which shopify');
return shopifyCLIExecutable(stdout.replace('\n', ''));
const path = await which('shopify');
return shopifyCLIExecutable(path);
} catch (e) {
return undefined;
}
}

async function getThemeCheckExecutable() {
try {
const { stdout } = await exec(
'which theme-check-language-server',
);
return themeCheckExecutable(stdout.replace('\n', ''));
const path = await which('theme-check-language-server');
return themeCheckExecutable(path);
} catch (e) {
return undefined;
}
Expand Down Expand Up @@ -173,7 +176,7 @@ async function shopifyCLIIsAtLeastVersion2(command) {

async function themeCheckExecutableExists(command) {
try {
await exec(`[[ -f "${command}" ]]`);
!isWin && (await exec(`[[ -f "${command}" ]]`));
} catch (e) {
throw new CommandNotFoundError(
`${command} not found, are you sure this is the correct path?`,
Expand Down

0 comments on commit 0f7e4a6

Please sign in to comment.