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

Add Windows support #35

Merged
merged 2 commits into from
Jul 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does && work cross platform?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like npm run somehow handles it because that's how I was running the server over there.

"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',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why does this need to change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency with the configuration. This way you can set

"shopifyLiquid.trace.server": "verbose"

In your VS Code settings.json and see the lsp logs in the Output pane. Leaving it as theme-check meant that it had to be "theme-check.server.logs" which feels out of place with the rest of the configuration options.

'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', '');
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

}

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