Skip to content

Commit

Permalink
refactor theme pack specs to support latest Node 18.20.x
Browse files Browse the repository at this point in the history
  • Loading branch information
thescientist13 committed May 3, 2024
1 parent 61c4c3e commit ac2d3f2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
import fs from 'fs/promises';
import os from 'os';
import { spawnSync } from 'child_process';

const packageJson = JSON.parse(await fs.readFile(new URL('./package.json', import.meta.url), 'utf-8'));
const myThemePackPlugin = () => [{
const myThemePackPlugin = (options = {}) => [{
type: 'context',
name: 'my-theme-pack:context',
provider: () => {
const { name } = packageJson;
const command = os.platform() === 'win32' ? 'npm.cmd' : 'npm';
const ls = spawnSync(command, ['ls', name]);

const isInstalled = ls.stdout.toString().indexOf('(empty)') < 0;
const templateLocation = isInstalled
? new URL(`./node_modules/${name}/dist/layouts/`, import.meta.url)
: new URL('./fixtures/layouts/', import.meta.url);
const templateLocation = options.__isDevelopment // eslint-disable-line no-underscore-dangle
? new URL('./fixtures/layouts/', import.meta.url)
: new URL(`./node_modules/${name}/dist/layouts/`, import.meta.url);

return {
templates: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ class MyThemePackDevelopmentResource extends ResourceInterface {

export default {
plugins: [
...myThemePackPlugin(),
...myThemePackPlugin({
__isDevelopment: true
}),
{
type: 'resource',
name: 'my-theme-pack:resource',
Expand Down

0 comments on commit ac2d3f2

Please sign in to comment.