-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fetch metafield definitions on start-up #597
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'theme-check-vscode': minor | ||
--- | ||
|
||
Fetch metafield definitions on start-up |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import * as child_process from 'child_process'; | ||
import { promisify } from 'node:util'; | ||
|
||
const exec = promisify(child_process.exec); | ||
|
||
const isWin = process.platform === 'win32'; | ||
|
||
export async function fetchMetafieldDefinitions() { | ||
const path = getShopifyCliPath(); | ||
|
||
if (!path) { | ||
return; | ||
} | ||
|
||
try { | ||
await exec(`${path} theme metafields pull`, { timeout: 10_000 }); | ||
} catch (_) { | ||
// CLI command can break because of incorrect version or not being logged in | ||
// If this fails, the user must fetch their own metafield definitions | ||
} | ||
} | ||
|
||
// eslint-disable-next-line no-unused-vars | ||
async function getShopifyCliPath() { | ||
if (isWin) { | ||
const { stdout } = await exec(`where.exe shopify`); | ||
const executables = stdout | ||
.replace(/\r/g, '') | ||
.split('\n') | ||
.filter((exe) => exe.endsWith('bat')); | ||
return executables.length > 0 ? executables[0] : ''; | ||
} else { | ||
const { stdout } = await exec(`which shopify`); | ||
return stdout.split('\n')[0].replace('\r', ''); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import type { AbstractFileSystem } from '@shopify/theme-check-common'; | ||
import { getConnection, NodeFileSystem, startServer } from '@shopify/theme-language-server-node'; | ||
import { VsCodeFileSystem } from '../common/VsCodeFileSystem'; | ||
import { fetchMetafieldDefinitions } from './metafieldDefinitions'; | ||
|
||
const connection = getConnection(); | ||
|
||
|
@@ -10,6 +11,7 @@ const fileSystems: Record<string, AbstractFileSystem> = { | |
}; | ||
|
||
startServer(connection, new VsCodeFileSystem(connection, fileSystems)); | ||
fetchMetafieldDefinitions(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should somehow be injected in startServer's IIRC the metafields should be loaded per theme root, not per workspace. I don't 100% know how the shopify cli works and if there's an auth per theme, but I don't think someone running a monorepo will necessarily have the same metafield definitions for shop A & shop B |
||
|
||
process.on('uncaughtException', (e) => { | ||
console.error(e); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current CLI does not have the ability to pull metafields, so tophat this build the CLI PR here and hardcode this value to the path.
E.g.
const path = '<where-ever-you-cloned-it>/cli/packages/cli/bin/dev.js'